]> andersk Git - openssh.git/blobdiff - clientloop.c
- markus@cvs.openbsd.org 2001/04/04 09:48:35
[openssh.git] / clientloop.c
index 547ccabfe881d36af842a4dd0066a974b45e6cff..1ed245e22ff6de4c07f8134d6f7a4619a2e9e38f 100644 (file)
@@ -59,7 +59,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: clientloop.c,v 1.51 2001/02/13 21:51:09 markus Exp $");
+RCSID("$OpenBSD: clientloop.c,v 1.54 2001/04/04 00:06:53 markus Exp $");
 
 #include "ssh.h"
 #include "ssh1.h"
@@ -73,6 +73,7 @@ RCSID("$OpenBSD: clientloop.c,v 1.51 2001/02/13 21:51:09 markus Exp $");
 #include "buffer.h"
 #include "bufaux.h"
 #include "key.h"
+#include "kex.h"
 #include "log.h"
 #include "readconf.h"
 #include "clientloop.h"
@@ -130,6 +131,9 @@ static int connection_out;  /* Connection to server (output). */
 void   client_init_dispatch(void);
 int    session_ident = -1;
 
+/*XXX*/
+extern Kex *xxx_kex;
+
 /* Returns the user\'s terminal to normal mode if it had been put in raw mode. */
 
 void
@@ -279,10 +283,8 @@ client_check_initial_eof_on_stdin(void)
                         */
                        if ((u_char) buf[0] == escape_char)
                                escape_pending = 1;
-                       else {
+                       else
                                buffer_append(&stdin_buffer, buf, 1);
-                               stdin_bytes += 1;
-                       }
                }
                leave_non_blocking();
        }
@@ -310,6 +312,7 @@ client_make_packets_from_stdin_data(void)
                packet_put_string(buffer_ptr(&stdin_buffer), len);
                packet_send();
                buffer_consume(&stdin_buffer, len);
+               stdin_bytes += len;
                /* If we have a pending EOF, send it now. */
                if (stdin_eof && buffer_len(&stdin_buffer) == 0) {
                        packet_start(SSH_CMSG_EOF);
@@ -420,7 +423,6 @@ client_wait_until_can_do_something(fd_set **readsetp, fd_set **writesetp,
                /* Note: we might still have data in the buffers. */
                snprintf(buf, sizeof buf, "select: %s\r\n", strerror(errno));
                buffer_append(&stderr_buffer, buf, strlen(buf));
-               stderr_bytes += strlen(buf);
                quit_pending = 1;
        }
 }
@@ -486,7 +488,6 @@ client_process_net_input(fd_set * readset)
                        snprintf(buf, sizeof buf, "Connection to %.300s closed by remote host.\r\n",
                                 host);
                        buffer_append(&stderr_buffer, buf, strlen(buf));
-                       stderr_bytes += strlen(buf);
                        quit_pending = 1;
                        return;
                }
@@ -494,7 +495,7 @@ client_process_net_input(fd_set * readset)
                 * There is a kernel bug on Solaris that causes select to
                 * sometimes wake up even though there is no data available.
                 */
-               if (len < 0 && errno == EAGAIN)
+               if (len < 0 && (errno == EAGAIN || errno == EINTR))
                        len = 0;
 
                if (len < 0) {
@@ -502,7 +503,6 @@ client_process_net_input(fd_set * readset)
                        snprintf(buf, sizeof buf, "Read from remote host %.300s: %.100s\r\n",
                                 host, strerror(errno));
                        buffer_append(&stderr_buffer, buf, strlen(buf));
-                       stderr_bytes += strlen(buf);
                        quit_pending = 1;
                        return;
                }
@@ -536,7 +536,6 @@ process_escapes(Buffer *bin, Buffer *bout, Buffer *berr, char *buf, int len)
                                /* Terminate the connection. */
                                snprintf(string, sizeof string, "%c.\r\n", escape_char);
                                buffer_append(berr, string, strlen(string));
-                               /*stderr_bytes += strlen(string); XXX*/
 
                                quit_pending = 1;
                                return -1;
@@ -546,7 +545,6 @@ process_escapes(Buffer *bin, Buffer *bout, Buffer *berr, char *buf, int len)
                                /* Print a message to that effect to the user. */
                                snprintf(string, sizeof string, "%c^Z [suspend ssh]\r\n", escape_char);
                                buffer_append(berr, string, strlen(string));
-                               /*stderr_bytes += strlen(string); XXX*/
 
                                /* Restore terminal modes and suspend. */
                                client_suspend_self(bin, bout, berr);
@@ -554,6 +552,11 @@ process_escapes(Buffer *bin, Buffer *bout, Buffer *berr, char *buf, int len)
                                /* We have been continued. */
                                continue;
 
+                       case 'R':
+                               debug("Rekeying");
+                               kex_send_kexinit(xxx_kex);
+                               continue;
+
                        case '&':
                                /* XXX does not work yet with proto 2 */
                                if (compat20)
@@ -656,7 +659,6 @@ Supported escape sequences:\r\n\
 void
 client_process_input(fd_set * readset)
 {
-       int ret;
        int len;
        char buf[8192];
 
@@ -673,7 +675,6 @@ client_process_input(fd_set * readset)
                        if (len < 0) {
                                snprintf(buf, sizeof buf, "read: %.100s\r\n", strerror(errno));
                                buffer_append(&stderr_buffer, buf, strlen(buf));
-                               stderr_bytes += strlen(buf);
                        }
                        /* Mark that we have seen EOF. */
                        stdin_eof = 1;
@@ -694,16 +695,14 @@ client_process_input(fd_set * readset)
                         * Just append the data to buffer.
                         */
                        buffer_append(&stdin_buffer, buf, len);
-                       stdin_bytes += len;
                } else {
                        /*
                         * Normal, successful read.  But we have an escape character
                         * and have to process the characters one by one.
                         */
-                       ret = process_escapes(&stdin_buffer, &stdout_buffer, &stderr_buffer, buf, len);
-                       if (ret == -1)
+                       if (process_escapes(&stdin_buffer, &stdout_buffer,
+                           &stderr_buffer, buf, len) == -1)
                                return;
-                       stdout_bytes += ret;
                }
        }
 }
@@ -729,13 +728,13 @@ client_process_output(fd_set * writeset)
                                 */
                                snprintf(buf, sizeof buf, "write stdout: %.50s\r\n", strerror(errno));
                                buffer_append(&stderr_buffer, buf, strlen(buf));
-                               stderr_bytes += strlen(buf);
                                quit_pending = 1;
                                return;
                        }
                }
                /* Consume printed data from the buffer. */
                buffer_consume(&stdout_buffer, len);
+               stdout_bytes += len; 
        }
        /* Write buffered output to stderr. */
        if (FD_ISSET(fileno(stderr), writeset)) {
@@ -753,6 +752,7 @@ client_process_output(fd_set * writeset)
                }
                /* Consume printed characters from the buffer. */
                buffer_consume(&stderr_buffer, len);
+               stderr_bytes += len; 
        }
 }
 
@@ -771,7 +771,7 @@ client_process_output(fd_set * writeset)
 void
 client_process_buffered_input_packets(void)
 {
-       dispatch_run(DISPATCH_NONBLOCK, &quit_pending, NULL);
+       dispatch_run(DISPATCH_NONBLOCK, &quit_pending, compat20 ? xxx_kex : NULL);
 }
 
 /* scan buf[] for '~' before sending data to the peer */
@@ -939,7 +939,6 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id)
        if (have_pty && options.log_level != SYSLOG_LEVEL_QUIET) {
                snprintf(buf, sizeof buf, "Connection to %.64s closed.\r\n", host);
                buffer_append(&stderr_buffer, buf, strlen(buf));
-               stderr_bytes += strlen(buf);
        }
        /* Output any buffered data for stdout. */
        while (buffer_len(&stdout_buffer) > 0) {
@@ -950,6 +949,7 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id)
                        break;
                }
                buffer_consume(&stdout_buffer, len);
+               stdout_bytes += len; 
        }
 
        /* Output any buffered data for stderr. */
@@ -961,6 +961,7 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id)
                        break;
                }
                buffer_consume(&stderr_buffer, len);
+               stderr_bytes += len; 
        }
 
        if (have_pty)
@@ -995,7 +996,6 @@ client_input_stdout_data(int type, int plen, void *ctxt)
        char *data = packet_get_string(&data_len);
        packet_integrity_check(plen, 4 + data_len, type);
        buffer_append(&stdout_buffer, data, data_len);
-       stdout_bytes += data_len;
        memset(data, 0, data_len);
        xfree(data);
 }
@@ -1006,7 +1006,6 @@ client_input_stderr_data(int type, int plen, void *ctxt)
        char *data = packet_get_string(&data_len);
        packet_integrity_check(plen, 4 + data_len, type);
        buffer_append(&stderr_buffer, data, data_len);
-       stdout_bytes += data_len;
        memset(data, 0, data_len);
        xfree(data);
 }
@@ -1206,7 +1205,10 @@ client_input_channel_req(int type, int plen, void *ctxt)
 void
 client_init_dispatch_20(void)
 {
-       dispatch_init(&dispatch_protocol_error);
+       int i;
+       /* dispatch_init(&dispatch_protocol_error); */
+       for (i = 50; i <= 254; i++)
+               dispatch_set(i, &dispatch_protocol_error);
        dispatch_set(SSH2_MSG_CHANNEL_CLOSE, &channel_input_oclose);
        dispatch_set(SSH2_MSG_CHANNEL_DATA, &channel_input_data);
        dispatch_set(SSH2_MSG_CHANNEL_EOF, &channel_input_ieof);
This page took 0.068123 seconds and 4 git commands to generate.