X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=client_common.c;h=85978c8ea24db5e5c0f90610e8feb77851eb6739;hp=b5d34ed7b7d3d7a6cf8ee6f95eafa3facc776834;hb=8aa0f575bcca12ab63ab53141c2144448c457478;hpb=a5ec1a6f44b149c0b018c1da8c1703109c5bdc8c diff --git a/client_common.c b/client_common.c index b5d34ed7..85978c8e 100644 --- a/client_common.c +++ b/client_common.c @@ -8,7 +8,6 @@ #include #include -#include #include "para.h" #include "error.h" @@ -21,8 +20,8 @@ #include "string.h" #include "client.cmdline.h" #include "client.h" -#include "hash.h" #include "buffer_tree.h" +#include "version.h" /** The size of the receiving buffer. */ #define CLIENT_BUFSIZE 4000 @@ -45,6 +44,7 @@ void client_close(struct client_task *ct) free(ct->user); free(ct->config_file); free(ct->key_file); + btr_free_node(ct->btrn); client_cmdline_parser_free(&ct->conf); free(ct); } @@ -182,7 +182,7 @@ static void client_post_select(struct sched *s, struct task *t) /* decrypted challenge/session key buffer */ unsigned char crypt_buf[1024]; /* the SHA1 of the decrypted challenge */ - unsigned char challenge_sha1[HASH_SIZE]; + unsigned char challenge_hash[HASH_SIZE]; ret = client_recv_buffer(ct, &s->rfds, buf, sizeof(buf), &n); if (ret < 0 || n == 0) @@ -192,13 +192,13 @@ static void client_post_select(struct sched *s, struct task *t) (unsigned char *)buf, n); if (ret < 0) goto out; - sha1_hash((char *)crypt_buf, CHALLENGE_SIZE, challenge_sha1); + hash_function((char *)crypt_buf, CHALLENGE_SIZE, challenge_hash); ct->scc.send = sc_new(crypt_buf + CHALLENGE_SIZE, SESSION_KEY_LEN); ct->scc.recv = sc_new(crypt_buf + CHALLENGE_SIZE + SESSION_KEY_LEN, SESSION_KEY_LEN); - hash_to_asc(challenge_sha1, buf); + hash_to_asc(challenge_hash, buf); PARA_INFO_LOG("--> %s\n", buf); - ret = send_bin_buffer(ct->scc.fd, (char *)challenge_sha1, + ret = send_bin_buffer(ct->scc.fd, (char *)challenge_hash, HASH_SIZE); if (ret < 0) goto out; @@ -310,7 +310,7 @@ out: } /* connect to para_server and register the client task */ -static int client_connect(struct client_task *ct) +static int client_connect(struct sched *s, struct client_task *ct) { int ret; @@ -327,7 +327,7 @@ static int client_connect(struct client_task *ct) ct->task.pre_select = client_pre_select; ct->task.post_select = client_post_select; sprintf(ct->task.status, "client"); - register_task(&ct->task); + register_task(s, &ct->task); return 1; err_out: close(ct->scc.fd); @@ -345,6 +345,7 @@ err_out: * \param loglevel If not \p NULL, the number of the loglevel is stored here. * \param parent Add the new buffer tree node as a child of this node. * \param child Add the new buffer tree node as a parent of this node. + * \param sched The scheduler instance to register the task to. * * Check the command line options given by \a argc and argv, set default values * for user name and rsa key file, read further option from the config file. @@ -353,7 +354,8 @@ err_out: * \return Standard. */ int client_open(int argc, char *argv[], struct client_task **ct_ptr, - int *loglevel, struct btr_node *parent, struct btr_node *child) + int *loglevel, struct btr_node *parent, struct btr_node *child, + struct sched *sched) { char *home = para_homedir(); int ret; @@ -395,9 +397,16 @@ int client_open(int argc, char *argv[], struct client_task **ct_ptr, ct->user = ct->conf.user_given? para_strdup(ct->conf.user_arg) : para_logname(); - ct->key_file = ct->conf.key_file_given? - para_strdup(ct->conf.key_file_arg) : - make_message("%s/.paraslash/key.%s", home, ct->user); + if (ct->conf.key_file_given) + ct->key_file = para_strdup(ct->conf.key_file_arg); + else { + ct->key_file = make_message("%s/.paraslash/key.%s", + home, ct->user); + if (!file_exists(ct->key_file)) { + free(ct->key_file); + ct->key_file = make_message("%s/.ssh/id_rsa", home); + } + } if (loglevel) *loglevel = get_loglevel_by_name(ct->conf.loglevel_arg); @@ -406,13 +415,12 @@ int client_open(int argc, char *argv[], struct client_task **ct_ptr, PARA_INFO_LOG("key_file: %s\n", ct->key_file); PARA_NOTICE_LOG("connecting %s:%d\n", ct->conf.hostname_arg, ct->conf.server_port_arg); - ret = client_connect(ct); + ret = client_connect(sched, ct); out: free(home); if (ret < 0) { PARA_ERROR_LOG("%s\n", para_strerror(-ret)); btr_remove_node(ct->btrn); - btr_free_node(ct->btrn); client_close(ct); *ct_ptr = NULL; }