]> andersk Git - openssh.git/blobdiff - clientloop.c
- stevesk@cvs.openbsd.org 2008/12/29 02:23:26
[openssh.git] / clientloop.c
index 62adbb78ec624d7f3a30661fff99a65a795ae7e1..fdeedc351d94ea2102bbadc30b393a3645dd9078 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: clientloop.c,v 1.198 2008/06/12 15:19:17 djm Exp $ */
+/* $OpenBSD: clientloop.c,v 1.207 2008/12/09 22:37:33 stevesk Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
 #include "atomicio.h"
 #include "sshpty.h"
 #include "misc.h"
-#include "monitor_fdpass.h"
 #include "match.h"
 #include "msg.h"
 
@@ -152,7 +151,6 @@ static int stdin_eof;               /* EOF has been encountered on stderr. */
 static Buffer stdin_buffer;    /* Buffer for stdin data. */
 static Buffer stdout_buffer;   /* Buffer for stdout data. */
 static Buffer stderr_buffer;   /* Buffer for stderr data. */
-static u_long stdin_bytes, stdout_bytes, stderr_bytes;
 static u_int buffer_high;/* Soft max buffer size. */
 static int connection_in;      /* Connection to server (input). */
 static int connection_out;     /* Connection to server (output). */
@@ -437,7 +435,6 @@ 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);
@@ -663,7 +660,8 @@ 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 || errno == EINTR))
+               if (len < 0 &&
+                   (errno == EAGAIN || errno == EINTR || errno == EWOULDBLOCK))
                        len = 0;
 
                if (len < 0) {
@@ -742,14 +740,14 @@ client_expect_confirm(int id, const char *request, int do_close)
 void
 client_register_global_confirm(global_confirm_cb *cb, void *ctx)
 {
-       struct global_confirm *gc, *first_gc;
+       struct global_confirm *gc, *last_gc;
 
        /* Coalesce identical callbacks */
-       first_gc = TAILQ_FIRST(&global_confirms);
-       if (first_gc && first_gc->cb == cb && first_gc->ctx == ctx) {
-               if (++first_gc->ref_count >= INT_MAX)
-                       fatal("%s: first_gc->ref_count = %d",
-                           __func__, first_gc->ref_count);
+       last_gc = TAILQ_LAST(&global_confirms, global_confirms);
+       if (last_gc && last_gc->cb == cb && last_gc->ctx == ctx) {
+               if (++last_gc->ref_count >= INT_MAX)
+                       fatal("%s: last_gc->ref_count = %d",
+                           __func__, last_gc->ref_count);
                return;
        }
 
@@ -766,7 +764,7 @@ process_cmdline(void)
        void (*handler)(int);
        char *s, *cmd, *cancel_host;
        int delete = 0;
-       int local = 0;
+       int local = 0, remote = 0, dynamic = 0;
        u_short cancel_port;
        Forward fwd;
 
@@ -791,6 +789,8 @@ process_cmdline(void)
                    "Request local forward");
                logit("      -R[bind_address:]port:host:hostport    "
                    "Request remote forward");
+               logit("      -D[bind_address:]port                  "
+                   "Request dynamic forward");
                logit("      -KR[bind_address:]port                 "
                    "Cancel remote forward");
                if (!options.permit_local_command)
@@ -810,17 +810,22 @@ process_cmdline(void)
                delete = 1;
                s++;
        }
-       if (*s != 'L' && *s != 'R') {
+       if (*s == 'L')
+               local = 1;
+       else if (*s == 'R')
+               remote = 1;
+       else if (*s == 'D')
+               dynamic = 1;
+       else {
                logit("Invalid command.");
                goto out;
        }
-       if (*s == 'L')
-               local = 1;
-       if (local && delete) {
+
+       if ((local || dynamic) && delete) {
                logit("Not supported.");
                goto out;
        }
-       if ((!local || delete) && !compat20) {
+       if (remote && delete && !compat20) {
                logit("Not supported for SSH protocol version 1.");
                goto out;
        }
@@ -844,11 +849,11 @@ process_cmdline(void)
                }
                channel_request_rforward_cancel(cancel_host, cancel_port);
        } else {
-               if (!parse_forward(&fwd, s)) {
+               if (!parse_forward(&fwd, s, dynamic ? 1 : 0)) {
                        logit("Bad forwarding specification.");
                        goto out;
                }
-               if (local) {
+               if (local || dynamic) {
                        if (channel_setup_local_fwd_listener(fwd.listen_host,
                            fwd.listen_port, fwd.connect_host,
                            fwd.connect_port, options.gateway_ports) < 0) {
@@ -1037,7 +1042,6 @@ process_escapes(Channel *c, Buffer *bin, Buffer *bout, Buffer *berr,
 Supported escape sequences:\r\n\
   %c.  - terminate session\r\n\
   %cB  - send a BREAK to the remote system\r\n\
-  %cC  - open a command line\r\n\
   %cR  - Request rekey (SSH protocol 2 only)\r\n\
   %c#  - list forwarded connections\r\n\
   %c?  - this message\r\n\
@@ -1046,8 +1050,7 @@ Supported escape sequences:\r\n\
                                            escape_char, escape_char,
                                            escape_char, escape_char,
                                            escape_char, escape_char,
-                                           escape_char, escape_char,
-                                           escape_char);
+                                           escape_char, escape_char);
                                } else {
                                        snprintf(string, sizeof string,
 "%c?\r\n\
@@ -1082,6 +1085,8 @@ Supported escape sequences:\r\n\
                                continue;
 
                        case 'C':
+                               if (c && c->ctl_fd != -1)
+                                       goto noescape;
                                process_cmdline();
                                continue;
 
@@ -1129,7 +1134,8 @@ client_process_input(fd_set *readset)
        if (FD_ISSET(fileno(stdin), readset)) {
                /* Read as much as possible. */
                len = read(fileno(stdin), buf, sizeof(buf));
-               if (len < 0 && (errno == EAGAIN || errno == EINTR))
+               if (len < 0 &&
+                   (errno == EAGAIN || errno == EINTR || errno == EWOULDBLOCK))
                        return;         /* we'll try again later */
                if (len <= 0) {
                        /*
@@ -1186,7 +1192,8 @@ client_process_output(fd_set *writeset)
                len = write(fileno(stdout), buffer_ptr(&stdout_buffer),
                    buffer_len(&stdout_buffer));
                if (len <= 0) {
-                       if (errno == EINTR || errno == EAGAIN)
+                       if (errno == EINTR || errno == EAGAIN ||
+                           errno == EWOULDBLOCK)
                                len = 0;
                        else {
                                /*
@@ -1202,7 +1209,6 @@ client_process_output(fd_set *writeset)
                }
                /* 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)) {
@@ -1210,7 +1216,8 @@ client_process_output(fd_set *writeset)
                len = write(fileno(stderr), buffer_ptr(&stderr_buffer),
                    buffer_len(&stderr_buffer));
                if (len <= 0) {
-                       if (errno == EINTR || errno == EAGAIN)
+                       if (errno == EINTR || errno == EAGAIN ||
+                           errno == EWOULDBLOCK)
                                len = 0;
                        else {
                                /*
@@ -1223,7 +1230,6 @@ client_process_output(fd_set *writeset)
                }
                /* Consume printed characters from the buffer. */
                buffer_consume(&stderr_buffer, len);
-               stderr_bytes += len;
        }
 }
 
@@ -1298,6 +1304,7 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id)
        fd_set *readset = NULL, *writeset = NULL;
        double start_time, total_time;
        int max_fd = 0, max_fd2 = 0, len, rekeying = 0;
+       u_int64_t ibytes, obytes;
        u_int nalloc = 0;
        char buf[100];
 
@@ -1329,9 +1336,6 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id)
                max_fd = MAX(max_fd, fileno(stdout));
                max_fd = MAX(max_fd, fileno(stderr));
        }
-       stdin_bytes = 0;
-       stdout_bytes = 0;
-       stderr_bytes = 0;
        quit_pending = 0;
        escape_char1 = escape_char_arg;
 
@@ -1517,7 +1521,6 @@ 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. */
@@ -1529,7 +1532,6 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id)
                        break;
                }
                buffer_consume(&stderr_buffer, len);
-               stderr_bytes += len;
        }
 
        /* Clear and free any buffers. */
@@ -1540,13 +1542,13 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id)
 
        /* Report bytes transferred, and transfer rates. */
        total_time = get_current_time() - start_time;
-       debug("Transferred: stdin %lu, stdout %lu, stderr %lu bytes in %.1f "
-           "seconds", stdin_bytes, stdout_bytes, stderr_bytes, total_time);
+       packet_get_state(MODE_IN, NULL, NULL, NULL, &ibytes);
+       packet_get_state(MODE_OUT, NULL, NULL, NULL, &obytes);
+       verbose("Transferred: sent %llu, received %llu bytes, in %.1f seconds",
+           obytes, ibytes, total_time);
        if (total_time > 0)
-               debug("Bytes per second: stdin %.1f, stdout %.1f, stderr %.1f",
-                   stdin_bytes / total_time, stdout_bytes / total_time,
-                   stderr_bytes / total_time);
-
+               verbose("Bytes per second: sent %.1f, received %.1f",
+                   obytes / total_time, ibytes / total_time);
        /* Return the exit status of the program. */
        debug("Exit status %d", exit_status);
        return exit_status;
@@ -1726,7 +1728,7 @@ client_request_tun_fwd(int tun_mode, int local_tun, int remote_tun)
                return 0;
 
        if (!compat20) {
-               error("Tunnel forwarding is not support for protocol 1");
+               error("Tunnel forwarding is not supported for protocol 1");
                return -1;
        }
 
@@ -1850,7 +1852,7 @@ client_input_channel_req(int type, u_int32_t seq, void *ctxt)
        if (reply) {
                packet_start(success ?
                    SSH2_MSG_CHANNEL_SUCCESS : SSH2_MSG_CHANNEL_FAILURE);
-               packet_put_int(id);
+               packet_put_int(c->remote_id);
                packet_send();
        }
        xfree(rtype);
This page took 0.046571 seconds and 4 git commands to generate.