]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - client_common.c
Kill the client-0.2.6 compatibility mode and the --plain option.
[paraslash.git] / client_common.c
index e5be430dfdb43021bfc9a01443593423cc5802b6..deb3a26ded485f79855516fcd2c1c5f9772761b6 100644 (file)
@@ -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);
@@ -178,8 +179,7 @@ static void client_post_select(struct sched *s, struct task *t)
                        ct->status = CL_RECEIVED_WELCOME;
                return;
        case CL_RECEIVED_WELCOME: /* send auth command */
-               sprintf(ct->buf, "auth %s%s", ct->conf.plain_given?
-                       "" : "rc4 ", ct->user);
+               sprintf(ct->buf, "auth rc4 %s", ct->user);
                PARA_INFO_LOG("--> %s\n", ct->buf);
                t->error = send_buffer(ct->fd, ct->buf);
                if (t->error >= 0)
@@ -220,13 +220,11 @@ static void client_post_select(struct sched *s, struct task *t)
                bytes_received = t->error;
                PARA_DEBUG_LOG("++++ server info ++++\n%s\n++++ end of server "
                        "info ++++\n", ct->buf);
-               /* check if server has sent "Proceed" message */
+               /* check if server has sent "Proceed" message and the rc4 keys */
                t->error = -E_CLIENT_AUTH;
-               if (!strstr(ct->buf, PROCEED_MSG))
+               if (bytes_received < PROCEED_MSG_LEN + 2 * RC4_KEY_LEN)
                        return;
-               t->error = 0;
-               ct->status = CL_RECEIVED_PROCEED;
-               if (bytes_received < PROCEED_MSG_LEN + 32)
+               if (!strstr(ct->buf, PROCEED_MSG))
                        return;
                PARA_INFO_LOG("decrypting session key\n");
                t->error = para_decrypt_buffer(ct->key_file, rc4_buf,
@@ -237,6 +235,8 @@ static void client_post_select(struct sched *s, struct task *t)
                RC4_set_key(&ct->rc4_send_key, RC4_KEY_LEN, rc4_buf);
                RC4_set_key(&ct->rc4_recv_key, RC4_KEY_LEN, rc4_buf + RC4_KEY_LEN);
                enable_crypt(ct->fd, rc4_recv, rc4_send, ct);
+               ct->status = CL_RECEIVED_PROCEED;
+               return;
                }
        case CL_RECEIVED_PROCEED: /* concat args and send command */
                {
@@ -312,6 +312,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 +320,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 +347,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,8 +365,9 @@ int client_open(int argc, char *argv[], struct client_task **ct_ptr)
                        &ct->conf, &params))
                        goto out;
        }
-       ret = 1;
-       PARA_INFO_LOG("loglevel: %d\n", ct->conf.loglevel_arg);
+       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);
        PARA_NOTICE_LOG("connecting %s:%d\n", ct->conf.hostname_arg,