X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=client.c;h=3fc673e7c6386238b4cada69e2ca2dff3df4c357;hb=3a343b3f6bdf852848b2eb9b7d2f4f3661aa78cd;hp=b77a2f68299ec4f47dc6c90e6b1d95ed4dde017b;hpb=685a2bc66e77978104039b8173a6039a80d8b733;p=paraslash.git diff --git a/client.c b/client.c index b77a2f68..3fc673e7 100644 --- a/client.c +++ b/client.c @@ -51,6 +51,19 @@ INIT_CLIENT_ERRLISTS; static struct private_client_data *pcd; +static void rc4_send(unsigned long len, const unsigned char *indata, + unsigned char *outdata) +{ + RC4(&pcd->rc4_send_key, len, indata, outdata); +} + +static void rc4_recv(unsigned long len, const unsigned char *indata, + unsigned char *outdata) +{ + RC4(&pcd->rc4_recv_key, len, indata, outdata); +} + + /* * client log function */ @@ -78,6 +91,16 @@ static void client_close(struct private_client_data *pcd) free(pcd); } +static void append_str(char **data, const char* append) +{ + if (*data) { + char *tmp = make_message("%s\n%s", *data, append); + free(*data); + *data = tmp; + } else + *data = para_strdup(append); +} + static int client_parse_config(int argc, char *argv[], struct private_client_data **pcd_ptr) { @@ -119,33 +142,6 @@ out: return ret; } -static void rc4_send(unsigned long len, const unsigned char *indata, - unsigned char *outdata) -{ - RC4(&pcd->rc4_send_key, len, indata, outdata); -} - -static void rc4_recv(unsigned long len, const unsigned char *indata, - unsigned char *outdata) -{ - RC4(&pcd->rc4_recv_key, len, indata, outdata); -} - -void (*crypt_function_recv)(unsigned long len, const unsigned char *indata, unsigned char *outdata); -void (*crypt_function_send)(unsigned long len, const unsigned char *indata, unsigned char *outdata); - - -static void append_str(char **data, const char* append) -{ - if (*data) { - char *tmp = make_message("%s\n%s", *data, append); - free(*data); - *data = tmp; - } else - *data = para_strdup(append); -} - - static int send_stdin(int fd) { char buf[8192]; @@ -163,6 +159,36 @@ static int send_stdin(int fd) return 1; } +static int client_open(struct private_client_data *pcd) +{ + int ret; + struct hostent *he; + struct sockaddr_in their_addr; + + /* get the host info */ + PARA_NOTICE_LOG("getting host info of %s\n", + pcd->conf.hostname_arg); + ret = get_host_info(pcd->conf.hostname_arg, &he); + if (ret < 0) + goto out; + /* get new socket */ + ret = get_socket(); + if (ret < 0) + goto out; + pcd->fd = ret; + /* init their_addr */ + init_sockaddr(&their_addr, pcd->conf.server_port_arg, he); + /* connect */ + PARA_NOTICE_LOG("connecting to %s\n", pcd->conf.hostname_arg); + ret = para_connect(pcd->fd, &their_addr); + if (ret < 0) + goto out; + ret = 1; +out: + return ret; +} + + /* * MAIN */ @@ -194,27 +220,7 @@ int main(int argc, char *argv[]) pcd->conf.hostname_arg, pcd->conf.server_port_arg ); - /* concat args */ - for (i = 0; i < pcd->conf.inputs_num; i++) - append_str(&command, pcd->conf.inputs[i]); - crypt_function_recv = NULL; - crypt_function_send = NULL; - /* get the host info */ - PARA_NOTICE_LOG("getting host info of %s\n", - pcd->conf.hostname_arg); - ret = get_host_info(pcd->conf.hostname_arg, &he); - if (ret < 0) - goto out; - /* get new socket */ - ret = get_socket(); - if (ret < 0) - goto out; - pcd->fd = ret; - /* init their_addr */ - init_sockaddr(&their_addr, pcd->conf.server_port_arg, he); - /* connect */ - PARA_NOTICE_LOG("connecting to %s\n", pcd->conf.hostname_arg); - ret = para_connect(pcd->fd, &their_addr); + ret = client_open(pcd); if (ret < 0) goto out; /* receive welcome message */ @@ -269,11 +275,13 @@ int main(int argc, char *argv[]) goto out; RC4_set_key(&pcd->rc4_send_key, RC4_KEY_LEN, rc4_buf); RC4_set_key(&pcd->rc4_recv_key, RC4_KEY_LEN, rc4_buf + RC4_KEY_LEN); - PARA_INFO_LOG("rc4 encrytion activated: %x:%x:%x:%x\n", + PARA_INFO_LOG("rc4 encryption activated: %x:%x:%x:%x\n", rc4_buf[0], rc4_buf[1], rc4_buf[2], rc4_buf[3]); - crypt_function_recv = rc4_recv; - crypt_function_send = rc4_send; + enable_crypt(pcd->fd, rc4_recv, rc4_send); } + /* concat args */ + for (i = 0; i < pcd->conf.inputs_num; i++) + append_str(&command, pcd->conf.inputs[i]); /* send command */ PARA_INFO_LOG("--> %s\n", command); ret = send_buffer(pcd->fd, command);