X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=client_common.c;h=cf77acd81beda8b79c1df5b607626c57975b3506;hp=e757a3a7a954bb6885a61613ce19c7158f96330f;hb=4d5a9b90c3e9cbdff019776d05792beb57fbfa31;hpb=002731cd3938f3be6b71651e56c062af1adcdec0 diff --git a/client_common.c b/client_common.c index e757a3a7..cf77acd8 100644 --- a/client_common.c +++ b/client_common.c @@ -64,6 +64,7 @@ void client_close(struct client_task *ct) disable_crypt(ct->fd); close(ct->fd); } + free(ct->buf); free(ct->user); free(ct->config_file); free(ct->key_file); @@ -190,15 +191,15 @@ static void client_post_select(struct sched *s, struct task *t) t->error = client_recv_buffer(ct); if (t->error < 0) return; - if (t->error != 64) { + if (t->error < 64) { t->error = -E_INVALID_CHALLENGE; PARA_ERROR_LOG("received the following: %s\n", ct->buf); return; } - PARA_INFO_LOG("<-- [challenge]\n"); + PARA_INFO_LOG("<-- [challenge] (%d bytes)\n", t->error); /* decrypt challenge number */ t->error = para_decrypt_challenge(ct->key_file, &ct->challenge_nr, - (unsigned char *) ct->buf, 64); + (unsigned char *) ct->buf, t->error); if (t->error > 0) ct->status = CL_RECEIVED_CHALLENGE; return; @@ -312,6 +313,7 @@ err_out: * \param argv Usual argument vector. * \param ct_ptr Points to dynamically allocated and initialized client task * struct upon successful return. + * \param loglevel If not \p NULL, the number of the loglevel is stored here. * * 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. @@ -319,13 +321,14 @@ err_out: * * \return Standard. */ -int client_open(int argc, char *argv[], struct client_task **ct_ptr) +int client_open(int argc, char *argv[], struct client_task **ct_ptr, + int *loglevel) { char *home = para_homedir(); - struct stat statbuf; int ret; struct client_task *ct = para_calloc(sizeof(struct client_task)); + ct->buf = para_malloc(CLIENT_BUFSIZE); *ct_ptr = ct; ct->fd = -1; ret = -E_CLIENT_SYNTAX; @@ -345,12 +348,12 @@ int client_open(int argc, char *argv[], struct client_task **ct_ptr) ct->config_file = ct->conf.config_file_given? para_strdup(ct->conf.config_file_arg) : make_message("%s/.paraslash/client.conf", home); - ret = stat(ct->config_file, &statbuf); - if (ret && ct->conf.config_file_given) { + ret = file_exists(ct->config_file); + if (!ret && ct->conf.config_file_given) { ret = -E_NO_CONFIG; goto out; } - if (!ret) { + if (ret) { struct client_cmdline_parser_params params = { .override = 0, .initialize = 0, @@ -363,7 +366,8 @@ int client_open(int argc, char *argv[], struct client_task **ct_ptr) &ct->conf, ¶ms)) goto out; } - ret = 1; + if (loglevel) + *loglevel = get_loglevel_by_name(ct->conf.loglevel_arg); PARA_INFO_LOG("loglevel: %s\n", ct->conf.loglevel_arg); PARA_INFO_LOG("config_file: %s\n", ct->config_file); PARA_INFO_LOG("key_file: %s\n", ct->key_file);