]> andersk Git - openssh.git/blobdiff - packet.c
- Several patches from SAKAI Kiyotaka <ksakai@kso.netwk.ntt-at.co.jp>
[openssh.git] / packet.c
index 6ff6417a8ce74c0f530a802507db08e2514b756e..d4b16ba78838b7335be153d34b11bd338eb2e9d7 100644 (file)
--- a/packet.c
+++ b/packet.c
@@ -130,7 +130,7 @@ clear_enc_keys(Enc *enc, int len)
 void
 packet_set_ssh2_format(void)
 {
-       debug("use_ssh2_packet_format");
+       DBG(debug("use_ssh2_packet_format"));
        use_ssh2_packet_format = 1;
 }
 
@@ -465,7 +465,7 @@ packet_send1()
        /* Compute packet length without padding (add checksum, remove padding). */
        len = buffer_len(&outgoing_packet) + 4 - 8;
 
-       /* Insert padding. */
+       /* Insert padding. Initialized to zero in packet_start1() */
        padding = 8 - len % 8;
        if (cipher_type != SSH_CIPHER_NONE) {
                cp = buffer_ptr(&outgoing_packet);
@@ -569,12 +569,16 @@ packet_send2()
                padlen += block_size;
        buffer_append_space(&outgoing_packet, &cp, padlen);
        if (enc && enc->type != SSH_CIPHER_NONE) {
+               /* random padding */
                for (i = 0; i < padlen; i++) {
                        if (i % 4 == 0)
                                rand = arc4random();
                        cp[i] = rand & 0xff;
                        rand <<= 8;
                }
+       } else {
+               /* clear padding */
+               memset(cp, 0, padlen);
        }
        /* packet_length includes payload, padding and padding length field */
        packet_length = buffer_len(&outgoing_packet) - 4;
@@ -613,7 +617,7 @@ packet_send2()
                        fatal("packet_send2: no KEX");
                if (mac->md != NULL)
                        mac->enabled = 1;
-               debug("cipher_set_key_iv send_context");
+               DBG(debug("cipher_set_key_iv send_context"));
                cipher_set_key_iv(&send_context, enc->type,
                    enc->key, enc->key_len,
                    enc->iv, enc->iv_len);
@@ -636,13 +640,6 @@ packet_send()
        DBG(debug("packet_send done"));
 }
 
-void
-packet_send_and_wait()
-{
-       packet_send();
-       packet_write_wait();
-}
-
 /*
  * Waits until a packet has been received, and returns its type.  Note that
  * no other data is processed until this returns, so this function should not
@@ -664,10 +661,11 @@ packet_read(int *payload_len_ptr)
        for (;;) {
                /* Try to read a packet from the buffer. */
                type = packet_read_poll(payload_len_ptr);
-               if (type == SSH_SMSG_SUCCESS
+               if (!use_ssh2_packet_format && (
+                   type == SSH_SMSG_SUCCESS
                    || type == SSH_SMSG_FAILURE
                    || type == SSH_CMSG_EOF
-                   || type == SSH_CMSG_EXIT_CONFIRMATION)
+                   || type == SSH_CMSG_EXIT_CONFIRMATION))
                        packet_integrity_check(*payload_len_ptr, 0, type);
                /* If we got a packet, return it. */
                if (type != SSH_MSG_NONE)
@@ -921,7 +919,7 @@ packet_read_poll2(int *payload_len_ptr)
                        fatal("packet_read_poll2: no KEX");
                if (mac->md != NULL)
                        mac->enabled = 1;
-               debug("cipher_set_key_iv receive_context");
+               DBG(debug("cipher_set_key_iv receive_context"));
                cipher_set_key_iv(&receive_context, enc->type,
                    enc->key, enc->key_len,
                    enc->iv, enc->iv_len);
@@ -1093,8 +1091,15 @@ packet_send_debug(const char *fmt,...)
        vsnprintf(buf, sizeof(buf), fmt, args);
        va_end(args);
 
-       packet_start(SSH_MSG_DEBUG);
-       packet_put_string(buf, strlen(buf));
+       if (compat20) {
+               packet_start(SSH2_MSG_DEBUG);
+               packet_put_char(0);     /* bool: always display */
+               packet_put_cstring(buf);
+               packet_put_cstring("");
+       } else {
+               packet_start(SSH_MSG_DEBUG);
+               packet_put_cstring(buf);
+       }
        packet_send();
        packet_write_wait();
 }
@@ -1232,10 +1237,12 @@ packet_set_interactive(int interactive, int keepalives)
                 * Set IP options for an interactive connection.  Use
                 * IPTOS_LOWDELAY and TCP_NODELAY.
                 */
+#ifdef IP_TOS
                int lowdelay = IPTOS_LOWDELAY;
                if (setsockopt(connection_in, IPPROTO_IP, IP_TOS, (void *) &lowdelay,
                    sizeof(lowdelay)) < 0)
                        error("setsockopt IPTOS_LOWDELAY: %.100s", strerror(errno));
+#endif
                if (setsockopt(connection_in, IPPROTO_TCP, TCP_NODELAY, (void *) &on,
                    sizeof(on)) < 0)
                        error("setsockopt TCP_NODELAY: %.100s", strerror(errno));
@@ -1244,10 +1251,12 @@ packet_set_interactive(int interactive, int keepalives)
                 * Set IP options for a non-interactive connection.  Use
                 * IPTOS_THROUGHPUT.
                 */
+#ifdef IP_TOS
                int throughput = IPTOS_THROUGHPUT;
                if (setsockopt(connection_in, IPPROTO_IP, IP_TOS, (void *) &throughput,
                    sizeof(throughput)) < 0)
                        error("setsockopt IPTOS_THROUGHPUT: %.100s", strerror(errno));
+#endif
        }
 }
 
This page took 0.037668 seconds and 4 git commands to generate.