]> andersk Git - gssapi-openssh.git/blobdiff - openssh/packet.c
merged OpenSSH 3.9p1 to trunk
[gssapi-openssh.git] / openssh / packet.c
index b466fa016b315e691513939bacfdb09b7ae4c6e7..62ef30f9067f434e228d7235ab9b87c5466d5a35 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: packet.c,v 1.145 2006/09/19 21:14:08 markus Exp $ */
+/* $OpenBSD: packet.c,v 1.151 2008/02/22 20:44:02 dtucker Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -136,6 +136,8 @@ static int server_side = 0;
 /* Set to true if we are authenticated. */
 static int after_authentication = 0;
 
+int keep_alive_timeouts = 0;
+
 /* Session key information for Encryption and MAC */
 Newkeys *newkeys[MODE_MAX];
 static struct packet_state {
@@ -629,7 +631,7 @@ set_newkeys(int mode)
                enc  = &newkeys[mode]->enc;
                mac  = &newkeys[mode]->mac;
                comp = &newkeys[mode]->comp;
-               memset(mac->key, 0, mac->key_len);
+               mac_clear(mac);
                xfree(enc->name);
                xfree(enc->iv);
                xfree(enc->key);
@@ -644,14 +646,15 @@ set_newkeys(int mode)
        enc  = &newkeys[mode]->enc;
        mac  = &newkeys[mode]->mac;
        comp = &newkeys[mode]->comp;
-       if (mac->md != NULL)
+       if (mac_init(mac) == 0)
                mac->enabled = 1;
        DBG(debug("cipher_init_context: %d", mode));
        cipher_init(cc, enc->cipher, enc->key, enc->key_len,
            enc->iv, enc->block_size, crypt_type);
        /* Deleting the keys does not gain extra security */
        /* memset(enc->iv,  0, enc->block_size);
-          memset(enc->key, 0, enc->key_len); */
+          memset(enc->key, 0, enc->key_len);
+          memset(mac->key, 0, mac->key_len); */
        if ((comp->type == COMP_ZLIB ||
            (comp->type == COMP_DELAYED && after_authentication)) &&
            comp->enabled == 0) {
@@ -709,7 +712,7 @@ packet_enable_delayed_compress(void)
 /*
  * Finalize packet in SSH2 format (compress, mac, encrypt, enqueue)
  */
-static void
+static int
 packet_send2_wrapped(void)
 {
        u_char type, *cp, *macbuf = NULL;
@@ -821,11 +824,13 @@ packet_send2_wrapped(void)
                set_newkeys(MODE_OUT);
        else if (type == SSH2_MSG_USERAUTH_SUCCESS && server_side)
                packet_enable_delayed_compress();
+       return(packet_length);
 }
 
-static void
+static int
 packet_send2(void)
 {
+        static int packet_length = 0;
        static int rekeying = 0;
        struct packet *p;
        u_char type, *cp;
@@ -843,7 +848,7 @@ packet_send2(void)
                        memcpy(&p->payload, &outgoing_packet, sizeof(Buffer));
                        buffer_init(&outgoing_packet);
                        TAILQ_INSERT_TAIL(&outgoing, p, next);
-                       return;
+                       return(sizeof(Buffer));
                }
        }
 
@@ -851,7 +856,7 @@ packet_send2(void)
        if (type == SSH2_MSG_KEXINIT)
                rekeying = 1;
 
-       packet_send2_wrapped();
+       packet_length = packet_send2_wrapped();
 
        /* after a NEWKEYS message we can send the complete queue */
        if (type == SSH2_MSG_NEWKEYS) {
@@ -864,19 +869,22 @@ packet_send2(void)
                            sizeof(Buffer));
                        TAILQ_REMOVE(&outgoing, p, next);
                        xfree(p);
-                       packet_send2_wrapped();
+                       packet_length += packet_send2_wrapped();
                }
        }
+       return(packet_length);
 }
 
-void
+int
 packet_send(void)
 {
+  int packet_len = 0;
        if (compat20)
-               packet_send2();
+               packet_len = packet_send2();
        else
                packet_send1();
        DBG(debug("packet_send done"));
+       return(packet_len);
 }
 
 /*
@@ -1191,10 +1199,12 @@ packet_read_poll_seqnr(u_int32_t *seqnr_p)
        for (;;) {
                if (compat20) {
                        type = packet_read_poll2(seqnr_p);
+                       keep_alive_timeouts = 0;
                        if (type)
                                DBG(debug("received packet type %d", type));
                        switch (type) {
                        case SSH2_MSG_IGNORE:
+                               debug3("Received SSH2_MSG_IGNORE");
                                break;
                        case SSH2_MSG_DEBUG:
                                packet_get_char();
@@ -1235,7 +1245,6 @@ packet_read_poll_seqnr(u_int32_t *seqnr_p)
                                logit("Received disconnect from %s: %.400s",
                                    get_remote_ipaddr(), msg);
                                cleanup_exit(255);
-                               xfree(msg);
                                break;
                        default:
                                if (type)
@@ -1415,21 +1424,23 @@ packet_disconnect(const char *fmt,...)
 
 /* Checks if there is any buffered output, and tries to write some of the output. */
 
-void
+int
 packet_write_poll(void)
 {
-       int len = buffer_len(&output);
+       int len = 0;
+       len = buffer_len(&output);
 
        if (len > 0) {
                len = write(connection_out, buffer_ptr(&output), len);
                if (len <= 0) {
                        if (errno == EAGAIN)
-                               return;
+                         return (0);
                        else
                                fatal("Write failed: %.100s", strerror(errno));
                }
                buffer_consume(&output, len);
        }
+       return(len);
 }
 
 /*
@@ -1437,14 +1448,15 @@ packet_write_poll(void)
  * written.
  */
 
-void
+int
 packet_write_wait(void)
 {
        fd_set *setp;
+       u_int bytes_sent = 0;
 
        setp = (fd_set *)xcalloc(howmany(connection_out + 1, NFDBITS),
            sizeof(fd_mask));
-       packet_write_poll();
+       bytes_sent += packet_write_poll();
        while (packet_have_data_to_write()) {
                memset(setp, 0, howmany(connection_out + 1, NFDBITS) *
                    sizeof(fd_mask));
@@ -1452,9 +1464,10 @@ packet_write_wait(void)
                while (select(connection_out + 1, NULL, setp, NULL, NULL) == -1 &&
                    (errno == EAGAIN || errno == EINTR))
                        ;
-               packet_write_poll();
+               bytes_sent += packet_write_poll();
        }
        xfree(setp);
+       return (bytes_sent);
 }
 
 /* Returns true if there is buffered data to write to the connection. */
@@ -1575,8 +1588,8 @@ packet_send_ignore(int nbytes)
                rnd >>= 8;
        }
 }
-int rekey_requested = 0;
 
+int rekey_requested = 0;
 void
 packet_request_rekeying(void)
 {
@@ -1618,3 +1631,9 @@ packet_set_authenticated(void)
 {
        after_authentication = 1;
 }
+
+int
+packet_authentication_state(void)
+{
+       return(after_authentication);
+}
This page took 0.094198 seconds and 4 git commands to generate.