]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - command.c
Send and receive challenge via sideband.
[paraslash.git] / command.c
index 9cf1967faa4bdb4a3f12d313e2a322881f787d1f..5790f11d278f95d4ad09964ab76af5d0ebf9e772 100644 (file)
--- a/command.c
+++ b/command.c
@@ -854,6 +854,8 @@ out:
        return ret;
 }
 
+#define HANDSHAKE_BUFSIZE 4096
+
 /**
  * Perform user authentication and execute a command.
  *
@@ -884,10 +886,9 @@ out:
 __noreturn void handle_connect(int fd, const char *peername)
 {
        int ret;
-       char buf[4096];
        unsigned char rand_buf[CHALLENGE_SIZE + 2 * SESSION_KEY_LEN];
        unsigned char challenge_hash[HASH_SIZE];
-       char *p, *command = NULL;
+       char *p, *command = NULL, *buf = para_malloc(HANDSHAKE_BUFSIZE) /* must be on the heap */;
        size_t numbytes;
        struct command_context cc_struct = {.peer = peername}, *cc = &cc_struct;
 
@@ -905,7 +906,7 @@ __noreturn void handle_connect(int fd, const char *peername)
        if (ret < 0)
                goto net_err;
        /* recv auth request line */
-       ret = recv_buffer(fd, buf, sizeof(buf));
+       ret = recv_buffer(fd, buf, HANDSHAKE_BUFSIZE);
        if (ret < 0)
                goto net_err;
        ret = parse_auth_request(buf, ret, &cc->u, &cc->use_sideband);
@@ -932,9 +933,17 @@ __noreturn void handle_connect(int fd, const char *peername)
        }
        PARA_DEBUG_LOG("sending %u byte challenge + rc4 keys (%zu bytes)\n",
                CHALLENGE_SIZE, numbytes);
-       ret = write_all(fd, buf, numbytes);
-       if (ret < 0)
-               goto net_err;
+       if (cc->use_sideband) {
+               ret = send_sb(&cc->scc, buf, numbytes, SBD_CHALLENGE, false);
+               buf = NULL;
+               if (ret < 0)
+                       goto net_err;
+               buf = para_malloc(HANDSHAKE_BUFSIZE);
+       } else {
+               ret = write_all(fd, buf, numbytes);
+               if (ret < 0)
+                       goto net_err;
+       }
        /* recv challenge response */
        ret = recv_bin_buffer(fd, buf, HASH_SIZE);
        if (ret < 0)
@@ -995,6 +1004,7 @@ err_out:
 net_err:
        PARA_NOTICE_LOG("%s\n", para_strerror(-ret));
 out:
+       free(buf);
        free(command);
        sc_free(cc->scc.recv);
        sc_free(cc->scc.send);