Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1 | /* |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 2 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
| 3 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
| 4 | * All rights reserved |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 5 | * Server main loop for handling the interactive session. |
Damien Miller | e4340be | 2000-09-16 13:29:08 +1100 | [diff] [blame] | 6 | * |
| 7 | * As far as I am concerned, the code I have written for this software |
| 8 | * can be used freely for any purpose. Any derived versions of this |
| 9 | * software must be clearly marked as such, and if the derived work is |
| 10 | * incompatible with the protocol description in the RFC file, it must be |
| 11 | * called by a name other than "ssh" or "Secure Shell". |
| 12 | * |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 13 | * SSH2 support by Markus Friedl. |
Ben Lindstrom | 92a2e38 | 2001-03-05 06:59:27 +0000 | [diff] [blame] | 14 | * Copyright (c) 2000 Markus Friedl. All rights reserved. |
Damien Miller | e4340be | 2000-09-16 13:29:08 +1100 | [diff] [blame] | 15 | * |
| 16 | * Redistribution and use in source and binary forms, with or without |
| 17 | * modification, are permitted provided that the following conditions |
| 18 | * are met: |
| 19 | * 1. Redistributions of source code must retain the above copyright |
| 20 | * notice, this list of conditions and the following disclaimer. |
| 21 | * 2. Redistributions in binary form must reproduce the above copyright |
| 22 | * notice, this list of conditions and the following disclaimer in the |
| 23 | * documentation and/or other materials provided with the distribution. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 26 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 27 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 28 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 30 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 31 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 32 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 33 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 34 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 35 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 36 | |
| 37 | #include "includes.h" |
Ben Lindstrom | a370005 | 2001-04-05 23:26:32 +0000 | [diff] [blame] | 38 | RCSID("$OpenBSD: serverloop.c,v 1.59 2001/04/05 10:42:51 markus Exp $"); |
Damien Miller | 69b69aa | 2000-10-28 14:19:58 +1100 | [diff] [blame] | 39 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 40 | #include "xmalloc.h" |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 41 | #include "packet.h" |
| 42 | #include "buffer.h" |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 43 | #include "log.h" |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 44 | #include "servconf.h" |
Ben Lindstrom | d95c09c | 2001-02-18 19:13:33 +0000 | [diff] [blame] | 45 | #include "sshpty.h" |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 46 | #include "channels.h" |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 47 | #include "compat.h" |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 48 | #include "ssh1.h" |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 49 | #include "ssh2.h" |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 50 | #include "auth.h" |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 51 | #include "session.h" |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 52 | #include "dispatch.h" |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 53 | #include "auth-options.h" |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 54 | #include "serverloop.h" |
| 55 | #include "misc.h" |
Ben Lindstrom | 8ac9106 | 2001-04-04 17:57:54 +0000 | [diff] [blame] | 56 | #include "kex.h" |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 57 | |
Damien Miller | 50a41ed | 2000-10-16 12:14:42 +1100 | [diff] [blame] | 58 | extern ServerOptions options; |
| 59 | |
Ben Lindstrom | 8ac9106 | 2001-04-04 17:57:54 +0000 | [diff] [blame] | 60 | /* XXX */ |
| 61 | extern Kex *xxx_kex; |
| 62 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 63 | static Buffer stdin_buffer; /* Buffer for stdin data. */ |
| 64 | static Buffer stdout_buffer; /* Buffer for stdout data. */ |
| 65 | static Buffer stderr_buffer; /* Buffer for stderr data. */ |
| 66 | static int fdin; /* Descriptor for stdin (for writing) */ |
| 67 | static int fdout; /* Descriptor for stdout (for reading); |
| 68 | May be same number as fdin. */ |
| 69 | static int fderr; /* Descriptor for stderr. May be -1. */ |
| 70 | static long stdin_bytes = 0; /* Number of bytes written to stdin. */ |
| 71 | static long stdout_bytes = 0; /* Number of stdout bytes sent to client. */ |
| 72 | static long stderr_bytes = 0; /* Number of stderr bytes sent to client. */ |
| 73 | static long fdout_bytes = 0; /* Number of stdout bytes read from program. */ |
| 74 | static int stdin_eof = 0; /* EOF message received from client. */ |
| 75 | static int fdout_eof = 0; /* EOF encountered reading from fdout. */ |
| 76 | static int fderr_eof = 0; /* EOF encountered readung from fderr. */ |
Damien Miller | 225736c | 2001-02-19 21:51:08 +1100 | [diff] [blame] | 77 | static int fdin_is_tty = 0; /* fdin points to a tty. */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 78 | static int connection_in; /* Connection to client (input). */ |
| 79 | static int connection_out; /* Connection to client (output). */ |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 80 | static u_int buffer_high;/* "Soft" max buffer size. */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 81 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 82 | /* |
| 83 | * This SIGCHLD kludge is used to detect when the child exits. The server |
| 84 | * will exit after that, as soon as forwarded connections have terminated. |
| 85 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 86 | |
Damien Miller | 166fca8 | 2000-04-20 07:42:21 +1000 | [diff] [blame] | 87 | static pid_t child_pid; /* Pid of the child. */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 88 | static volatile int child_terminated; /* The child has terminated. */ |
| 89 | static volatile int child_wait_status; /* Status from wait(). */ |
| 90 | |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 91 | void server_init_dispatch(void); |
| 92 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 93 | void |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 94 | sigchld_handler(int sig) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 95 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 96 | int save_errno = errno; |
Damien Miller | 166fca8 | 2000-04-20 07:42:21 +1000 | [diff] [blame] | 97 | pid_t wait_pid; |
| 98 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 99 | debug("Received SIGCHLD."); |
| 100 | wait_pid = wait((int *) &child_wait_status); |
| 101 | if (wait_pid != -1) { |
| 102 | if (wait_pid != child_pid) |
| 103 | error("Strange, got SIGCHLD and wait returned pid %d but child is %d", |
| 104 | wait_pid, child_pid); |
| 105 | if (WIFEXITED(child_wait_status) || |
Damien Miller | 43dc8da | 2000-11-29 15:55:17 +1100 | [diff] [blame] | 106 | WIFSIGNALED(child_wait_status)) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 107 | child_terminated = 1; |
| 108 | } |
| 109 | signal(SIGCHLD, sigchld_handler); |
| 110 | errno = save_errno; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 111 | } |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 112 | void |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 113 | sigchld_handler2(int sig) |
| 114 | { |
| 115 | int save_errno = errno; |
| 116 | debug("Received SIGCHLD."); |
| 117 | child_terminated = 1; |
Kevin Steves | b6e773a | 2001-02-04 13:20:36 +0000 | [diff] [blame] | 118 | mysignal(SIGCHLD, sigchld_handler2); |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 119 | errno = save_errno; |
| 120 | } |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 121 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 122 | /* |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 123 | * Make packets from buffered stderr data, and buffer it for sending |
| 124 | * to the client. |
| 125 | */ |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 126 | void |
Ben Lindstrom | 31ca54a | 2001-02-09 02:11:24 +0000 | [diff] [blame] | 127 | make_packets_from_stderr_data(void) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 128 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 129 | int len; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 130 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 131 | /* Send buffered stderr data to the client. */ |
| 132 | while (buffer_len(&stderr_buffer) > 0 && |
Damien Miller | 037a0dc | 1999-12-07 15:38:31 +1100 | [diff] [blame] | 133 | packet_not_very_much_data_to_write()) { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 134 | len = buffer_len(&stderr_buffer); |
| 135 | if (packet_is_interactive()) { |
| 136 | if (len > 512) |
| 137 | len = 512; |
| 138 | } else { |
| 139 | /* Keep the packets at reasonable size. */ |
| 140 | if (len > packet_get_maxsize()) |
| 141 | len = packet_get_maxsize(); |
| 142 | } |
| 143 | packet_start(SSH_SMSG_STDERR_DATA); |
| 144 | packet_put_string(buffer_ptr(&stderr_buffer), len); |
| 145 | packet_send(); |
| 146 | buffer_consume(&stderr_buffer, len); |
| 147 | stderr_bytes += len; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 148 | } |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 149 | } |
| 150 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 151 | /* |
| 152 | * Make packets from buffered stdout data, and buffer it for sending to the |
| 153 | * client. |
| 154 | */ |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 155 | void |
Ben Lindstrom | 31ca54a | 2001-02-09 02:11:24 +0000 | [diff] [blame] | 156 | make_packets_from_stdout_data(void) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 157 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 158 | int len; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 159 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 160 | /* Send buffered stdout data to the client. */ |
| 161 | while (buffer_len(&stdout_buffer) > 0 && |
Damien Miller | 037a0dc | 1999-12-07 15:38:31 +1100 | [diff] [blame] | 162 | packet_not_very_much_data_to_write()) { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 163 | len = buffer_len(&stdout_buffer); |
| 164 | if (packet_is_interactive()) { |
| 165 | if (len > 512) |
| 166 | len = 512; |
| 167 | } else { |
| 168 | /* Keep the packets at reasonable size. */ |
| 169 | if (len > packet_get_maxsize()) |
Kevin Steves | ef4eea9 | 2001-02-05 12:42:17 +0000 | [diff] [blame] | 170 | len = packet_get_maxsize(); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 171 | } |
| 172 | packet_start(SSH_SMSG_STDOUT_DATA); |
| 173 | packet_put_string(buffer_ptr(&stdout_buffer), len); |
| 174 | packet_send(); |
| 175 | buffer_consume(&stdout_buffer, len); |
| 176 | stdout_bytes += len; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 177 | } |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 178 | } |
| 179 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 180 | /* |
| 181 | * Sleep in select() until we can do something. This will initialize the |
| 182 | * select masks. Upon return, the masks will indicate which descriptors |
| 183 | * have data or can accept data. Optionally, a maximum time can be specified |
| 184 | * for the duration of the wait (0 = infinite). |
| 185 | */ |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 186 | void |
Damien Miller | 5e95321 | 2001-01-30 09:14:00 +1100 | [diff] [blame] | 187 | wait_until_can_do_something(fd_set **readsetp, fd_set **writesetp, int *maxfdp, |
| 188 | u_int max_time_milliseconds) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 189 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 190 | struct timeval tv, *tvp; |
| 191 | int ret; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 192 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 193 | /* When select fails we restart from here. */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 194 | retry_select: |
| 195 | |
Damien Miller | 5e95321 | 2001-01-30 09:14:00 +1100 | [diff] [blame] | 196 | /* Allocate and update select() masks for channel descriptors. */ |
Ben Lindstrom | be2cc43 | 2001-04-04 23:46:07 +0000 | [diff] [blame] | 197 | channel_prepare_select(readsetp, writesetp, maxfdp, 0); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 198 | |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 199 | if (compat20) { |
Damien Miller | e247cc4 | 2000-05-07 12:03:14 +1000 | [diff] [blame] | 200 | /* wrong: bad condition XXX */ |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 201 | if (channel_not_very_much_buffered_data()) |
Damien Miller | 5e95321 | 2001-01-30 09:14:00 +1100 | [diff] [blame] | 202 | FD_SET(connection_in, *readsetp); |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 203 | } else { |
Damien Miller | b1715dc | 2000-05-30 13:44:51 +1000 | [diff] [blame] | 204 | /* |
| 205 | * Read packets from the client unless we have too much |
| 206 | * buffered stdin or channel data. |
| 207 | */ |
| 208 | if (buffer_len(&stdin_buffer) < buffer_high && |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 209 | channel_not_very_much_buffered_data()) |
Damien Miller | 5e95321 | 2001-01-30 09:14:00 +1100 | [diff] [blame] | 210 | FD_SET(connection_in, *readsetp); |
Damien Miller | b1715dc | 2000-05-30 13:44:51 +1000 | [diff] [blame] | 211 | /* |
| 212 | * If there is not too much data already buffered going to |
| 213 | * the client, try to get some more data from the program. |
| 214 | */ |
| 215 | if (packet_not_very_much_data_to_write()) { |
| 216 | if (!fdout_eof) |
Damien Miller | 5e95321 | 2001-01-30 09:14:00 +1100 | [diff] [blame] | 217 | FD_SET(fdout, *readsetp); |
Damien Miller | b1715dc | 2000-05-30 13:44:51 +1000 | [diff] [blame] | 218 | if (!fderr_eof) |
Damien Miller | 5e95321 | 2001-01-30 09:14:00 +1100 | [diff] [blame] | 219 | FD_SET(fderr, *readsetp); |
Damien Miller | b1715dc | 2000-05-30 13:44:51 +1000 | [diff] [blame] | 220 | } |
| 221 | /* |
| 222 | * If we have buffered data, try to write some of that data |
| 223 | * to the program. |
| 224 | */ |
| 225 | if (fdin != -1 && buffer_len(&stdin_buffer) > 0) |
Damien Miller | 5e95321 | 2001-01-30 09:14:00 +1100 | [diff] [blame] | 226 | FD_SET(fdin, *writesetp); |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 227 | } |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 228 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 229 | /* |
| 230 | * If we have buffered packet data going to the client, mark that |
| 231 | * descriptor. |
| 232 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 233 | if (packet_have_data_to_write()) |
Damien Miller | 5e95321 | 2001-01-30 09:14:00 +1100 | [diff] [blame] | 234 | FD_SET(connection_out, *writesetp); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 235 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 236 | /* |
| 237 | * If child has terminated and there is enough buffer space to read |
| 238 | * from it, then read as much as is available and exit. |
| 239 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 240 | if (child_terminated && packet_not_very_much_data_to_write()) |
| 241 | if (max_time_milliseconds == 0) |
| 242 | max_time_milliseconds = 100; |
| 243 | |
| 244 | if (max_time_milliseconds == 0) |
| 245 | tvp = NULL; |
| 246 | else { |
| 247 | tv.tv_sec = max_time_milliseconds / 1000; |
| 248 | tv.tv_usec = 1000 * (max_time_milliseconds % 1000); |
| 249 | tvp = &tv; |
| 250 | } |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 251 | if (tvp!=NULL) |
Ben Lindstrom | f4c7311 | 2001-03-05 05:58:23 +0000 | [diff] [blame] | 252 | debug3("tvp!=NULL kid %d mili %d", child_terminated, max_time_milliseconds); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 253 | |
| 254 | /* Wait for something to happen, or the timeout to expire. */ |
Damien Miller | 5e95321 | 2001-01-30 09:14:00 +1100 | [diff] [blame] | 255 | ret = select((*maxfdp)+1, *readsetp, *writesetp, NULL, tvp); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 256 | |
| 257 | if (ret < 0) { |
| 258 | if (errno != EINTR) |
| 259 | error("select: %.100s", strerror(errno)); |
| 260 | else |
| 261 | goto retry_select; |
| 262 | } |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 263 | } |
| 264 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 265 | /* |
| 266 | * Processes input from the client and the program. Input data is stored |
| 267 | * in buffers and processed later. |
| 268 | */ |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 269 | void |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 270 | process_input(fd_set * readset) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 271 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 272 | int len; |
| 273 | char buf[16384]; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 274 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 275 | /* Read and buffer any input data from the client. */ |
| 276 | if (FD_ISSET(connection_in, readset)) { |
| 277 | len = read(connection_in, buf, sizeof(buf)); |
| 278 | if (len == 0) { |
| 279 | verbose("Connection closed by remote host."); |
| 280 | fatal_cleanup(); |
Damien Miller | dcb6ecd | 2000-05-17 22:34:22 +1000 | [diff] [blame] | 281 | } else if (len < 0) { |
| 282 | if (errno != EINTR && errno != EAGAIN) { |
| 283 | verbose("Read error from remote host: %.100s", strerror(errno)); |
| 284 | fatal_cleanup(); |
| 285 | } |
| 286 | } else { |
| 287 | /* Buffer any received data. */ |
| 288 | packet_process_incoming(buf, len); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 289 | } |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 290 | } |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 291 | if (compat20) |
| 292 | return; |
| 293 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 294 | /* Read and buffer any available stdout data from the program. */ |
| 295 | if (!fdout_eof && FD_ISSET(fdout, readset)) { |
| 296 | len = read(fdout, buf, sizeof(buf)); |
Damien Miller | dcb6ecd | 2000-05-17 22:34:22 +1000 | [diff] [blame] | 297 | if (len < 0 && (errno == EINTR || errno == EAGAIN)) { |
| 298 | /* do nothing */ |
| 299 | } else if (len <= 0) { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 300 | fdout_eof = 1; |
Damien Miller | dcb6ecd | 2000-05-17 22:34:22 +1000 | [diff] [blame] | 301 | } else { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 302 | buffer_append(&stdout_buffer, buf, len); |
| 303 | fdout_bytes += len; |
| 304 | } |
| 305 | } |
| 306 | /* Read and buffer any available stderr data from the program. */ |
| 307 | if (!fderr_eof && FD_ISSET(fderr, readset)) { |
| 308 | len = read(fderr, buf, sizeof(buf)); |
Damien Miller | dcb6ecd | 2000-05-17 22:34:22 +1000 | [diff] [blame] | 309 | if (len < 0 && (errno == EINTR || errno == EAGAIN)) { |
| 310 | /* do nothing */ |
| 311 | } else if (len <= 0) { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 312 | fderr_eof = 1; |
Damien Miller | dcb6ecd | 2000-05-17 22:34:22 +1000 | [diff] [blame] | 313 | } else { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 314 | buffer_append(&stderr_buffer, buf, len); |
Damien Miller | dcb6ecd | 2000-05-17 22:34:22 +1000 | [diff] [blame] | 315 | } |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 316 | } |
| 317 | } |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 318 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 319 | /* |
| 320 | * Sends data from internal buffers to client program stdin. |
| 321 | */ |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 322 | void |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 323 | process_output(fd_set * writeset) |
| 324 | { |
Ben Lindstrom | aa630de | 2001-02-10 23:44:47 +0000 | [diff] [blame] | 325 | struct termios tio; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 326 | int len; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 327 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 328 | /* Write buffered data to program stdin. */ |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 329 | if (!compat20 && fdin != -1 && FD_ISSET(fdin, writeset)) { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 330 | len = write(fdin, buffer_ptr(&stdin_buffer), |
Damien Miller | 037a0dc | 1999-12-07 15:38:31 +1100 | [diff] [blame] | 331 | buffer_len(&stdin_buffer)); |
Damien Miller | dcb6ecd | 2000-05-17 22:34:22 +1000 | [diff] [blame] | 332 | if (len < 0 && (errno == EINTR || errno == EAGAIN)) { |
| 333 | /* do nothing */ |
| 334 | } else if (len <= 0) { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 335 | #ifdef USE_PIPES |
| 336 | close(fdin); |
| 337 | #else |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 338 | if (fdin != fdout) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 339 | close(fdin); |
| 340 | else |
| 341 | shutdown(fdin, SHUT_WR); /* We will no longer send. */ |
| 342 | #endif |
| 343 | fdin = -1; |
| 344 | } else { |
Ben Lindstrom | aa630de | 2001-02-10 23:44:47 +0000 | [diff] [blame] | 345 | /* Successful write. */ |
Damien Miller | 225736c | 2001-02-19 21:51:08 +1100 | [diff] [blame] | 346 | if (fdin_is_tty && tcgetattr(fdin, &tio) == 0 && |
Damien Miller | 79438cc | 2001-02-16 12:34:57 +1100 | [diff] [blame] | 347 | !(tio.c_lflag & ECHO) && (tio.c_lflag & ICANON)) { |
Kevin Steves | b7f036f | 2001-02-15 17:27:15 +0000 | [diff] [blame] | 348 | /* |
| 349 | * Simulate echo to reduce the impact of |
| 350 | * traffic analysis |
| 351 | */ |
Ben Lindstrom | e229b25 | 2001-03-05 06:28:06 +0000 | [diff] [blame] | 352 | packet_send_ignore(len); |
Ben Lindstrom | aa630de | 2001-02-10 23:44:47 +0000 | [diff] [blame] | 353 | packet_send(); |
| 354 | } |
| 355 | /* Consume the data from the buffer. */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 356 | buffer_consume(&stdin_buffer, len); |
| 357 | /* Update the count of bytes written to the program. */ |
| 358 | stdin_bytes += len; |
| 359 | } |
| 360 | } |
| 361 | /* Send any buffered packet data to the client. */ |
| 362 | if (FD_ISSET(connection_out, writeset)) |
| 363 | packet_write_poll(); |
| 364 | } |
| 365 | |
| 366 | /* |
| 367 | * Wait until all buffered output has been sent to the client. |
| 368 | * This is used when the program terminates. |
| 369 | */ |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 370 | void |
Ben Lindstrom | 31ca54a | 2001-02-09 02:11:24 +0000 | [diff] [blame] | 371 | drain_output(void) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 372 | { |
| 373 | /* Send any buffered stdout data to the client. */ |
| 374 | if (buffer_len(&stdout_buffer) > 0) { |
| 375 | packet_start(SSH_SMSG_STDOUT_DATA); |
| 376 | packet_put_string(buffer_ptr(&stdout_buffer), |
| 377 | buffer_len(&stdout_buffer)); |
| 378 | packet_send(); |
| 379 | /* Update the count of sent bytes. */ |
| 380 | stdout_bytes += buffer_len(&stdout_buffer); |
| 381 | } |
| 382 | /* Send any buffered stderr data to the client. */ |
| 383 | if (buffer_len(&stderr_buffer) > 0) { |
| 384 | packet_start(SSH_SMSG_STDERR_DATA); |
| 385 | packet_put_string(buffer_ptr(&stderr_buffer), |
| 386 | buffer_len(&stderr_buffer)); |
| 387 | packet_send(); |
| 388 | /* Update the count of sent bytes. */ |
| 389 | stderr_bytes += buffer_len(&stderr_buffer); |
| 390 | } |
| 391 | /* Wait until all buffered data has been written to the client. */ |
| 392 | packet_write_wait(); |
| 393 | } |
| 394 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 395 | void |
Ben Lindstrom | 31ca54a | 2001-02-09 02:11:24 +0000 | [diff] [blame] | 396 | process_buffered_input_packets(void) |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 397 | { |
Ben Lindstrom | 8ac9106 | 2001-04-04 17:57:54 +0000 | [diff] [blame] | 398 | dispatch_run(DISPATCH_NONBLOCK, NULL, compat20 ? xxx_kex : NULL); |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 399 | } |
| 400 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 401 | /* |
| 402 | * Performs the interactive session. This handles data transmission between |
| 403 | * the client and the program. Note that the notion of stdin, stdout, and |
| 404 | * stderr in this function is sort of reversed: this function writes to |
| 405 | * stdin (of the child program), and reads from stdout and stderr (of the |
| 406 | * child program). |
| 407 | */ |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 408 | void |
Damien Miller | 166fca8 | 2000-04-20 07:42:21 +1000 | [diff] [blame] | 409 | server_loop(pid_t pid, int fdin_arg, int fdout_arg, int fderr_arg) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 410 | { |
Damien Miller | 5e95321 | 2001-01-30 09:14:00 +1100 | [diff] [blame] | 411 | fd_set *readset = NULL, *writeset = NULL; |
| 412 | int max_fd; |
Damien Miller | 166fca8 | 2000-04-20 07:42:21 +1000 | [diff] [blame] | 413 | int wait_status; /* Status returned by wait(). */ |
| 414 | pid_t wait_pid; /* pid returned by wait(). */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 415 | int waiting_termination = 0; /* Have displayed waiting close message. */ |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 416 | u_int max_time_milliseconds; |
| 417 | u_int previous_stdout_buffer_bytes; |
| 418 | u_int stdout_buffer_bytes; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 419 | int type; |
| 420 | |
| 421 | debug("Entering interactive session."); |
| 422 | |
| 423 | /* Initialize the SIGCHLD kludge. */ |
| 424 | child_pid = pid; |
| 425 | child_terminated = 0; |
| 426 | signal(SIGCHLD, sigchld_handler); |
| 427 | |
| 428 | /* Initialize our global variables. */ |
| 429 | fdin = fdin_arg; |
| 430 | fdout = fdout_arg; |
| 431 | fderr = fderr_arg; |
Damien Miller | dcb6ecd | 2000-05-17 22:34:22 +1000 | [diff] [blame] | 432 | |
| 433 | /* nonblocking IO */ |
| 434 | set_nonblock(fdin); |
| 435 | set_nonblock(fdout); |
Damien Miller | 7d6656c | 2000-05-20 15:22:36 +1000 | [diff] [blame] | 436 | /* we don't have stderr for interactive terminal sessions, see below */ |
| 437 | if (fderr != -1) |
| 438 | set_nonblock(fderr); |
Damien Miller | dcb6ecd | 2000-05-17 22:34:22 +1000 | [diff] [blame] | 439 | |
Damien Miller | 225736c | 2001-02-19 21:51:08 +1100 | [diff] [blame] | 440 | if (!(datafellows & SSH_BUG_IGNOREMSG) && isatty(fdin)) |
| 441 | fdin_is_tty = 1; |
| 442 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 443 | connection_in = packet_get_connection_in(); |
| 444 | connection_out = packet_get_connection_out(); |
| 445 | |
| 446 | previous_stdout_buffer_bytes = 0; |
| 447 | |
| 448 | /* Set approximate I/O buffer size. */ |
| 449 | if (packet_is_interactive()) |
| 450 | buffer_high = 4096; |
| 451 | else |
| 452 | buffer_high = 64 * 1024; |
| 453 | |
| 454 | /* Initialize max_fd to the maximum of the known file descriptors. */ |
Damien Miller | 5e95321 | 2001-01-30 09:14:00 +1100 | [diff] [blame] | 455 | max_fd = MAX(fdin, fdout); |
| 456 | if (fderr != -1) |
| 457 | max_fd = MAX(max_fd, fderr); |
| 458 | max_fd = MAX(max_fd, connection_in); |
| 459 | max_fd = MAX(max_fd, connection_out); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 460 | |
| 461 | /* Initialize Initialize buffers. */ |
| 462 | buffer_init(&stdin_buffer); |
| 463 | buffer_init(&stdout_buffer); |
| 464 | buffer_init(&stderr_buffer); |
| 465 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 466 | /* |
| 467 | * If we have no separate fderr (which is the case when we have a pty |
| 468 | * - there we cannot make difference between data sent to stdout and |
| 469 | * stderr), indicate that we have seen an EOF from stderr. This way |
| 470 | * we don\'t need to check the descriptor everywhere. |
| 471 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 472 | if (fderr == -1) |
| 473 | fderr_eof = 1; |
| 474 | |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 475 | server_init_dispatch(); |
| 476 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 477 | /* Main loop of the server for the interactive session mode. */ |
| 478 | for (;;) { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 479 | |
| 480 | /* Process buffered packets from the client. */ |
| 481 | process_buffered_input_packets(); |
| 482 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 483 | /* |
| 484 | * If we have received eof, and there is no more pending |
| 485 | * input data, cause a real eof by closing fdin. |
| 486 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 487 | if (stdin_eof && fdin != -1 && buffer_len(&stdin_buffer) == 0) { |
| 488 | #ifdef USE_PIPES |
| 489 | close(fdin); |
| 490 | #else |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 491 | if (fdin != fdout) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 492 | close(fdin); |
| 493 | else |
| 494 | shutdown(fdin, SHUT_WR); /* We will no longer send. */ |
| 495 | #endif |
| 496 | fdin = -1; |
| 497 | } |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 498 | /* Make packets from buffered stderr data to send to the client. */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 499 | make_packets_from_stderr_data(); |
| 500 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 501 | /* |
| 502 | * Make packets from buffered stdout data to send to the |
| 503 | * client. If there is very little to send, this arranges to |
| 504 | * not send them now, but to wait a short while to see if we |
| 505 | * are getting more data. This is necessary, as some systems |
| 506 | * wake up readers from a pty after each separate character. |
| 507 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 508 | max_time_milliseconds = 0; |
| 509 | stdout_buffer_bytes = buffer_len(&stdout_buffer); |
| 510 | if (stdout_buffer_bytes != 0 && stdout_buffer_bytes < 256 && |
| 511 | stdout_buffer_bytes != previous_stdout_buffer_bytes) { |
| 512 | /* try again after a while */ |
| 513 | max_time_milliseconds = 10; |
| 514 | } else { |
| 515 | /* Send it now. */ |
| 516 | make_packets_from_stdout_data(); |
| 517 | } |
| 518 | previous_stdout_buffer_bytes = buffer_len(&stdout_buffer); |
| 519 | |
| 520 | /* Send channel data to the client. */ |
| 521 | if (packet_not_very_much_data_to_write()) |
| 522 | channel_output_poll(); |
| 523 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 524 | /* |
| 525 | * Bail out of the loop if the program has closed its output |
| 526 | * descriptors, and we have no more data to send to the |
| 527 | * client, and there is no pending buffered data. |
| 528 | */ |
Damien Miller | 43dc8da | 2000-11-29 15:55:17 +1100 | [diff] [blame] | 529 | if (fdout_eof && fderr_eof && !packet_have_data_to_write() && |
| 530 | buffer_len(&stdout_buffer) == 0 && buffer_len(&stderr_buffer) == 0) { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 531 | if (!channel_still_open()) |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 532 | break; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 533 | if (!waiting_termination) { |
| 534 | const char *s = "Waiting for forwarded connections to terminate...\r\n"; |
| 535 | char *cp; |
| 536 | waiting_termination = 1; |
| 537 | buffer_append(&stderr_buffer, s, strlen(s)); |
| 538 | |
| 539 | /* Display list of open channels. */ |
| 540 | cp = channel_open_message(); |
| 541 | buffer_append(&stderr_buffer, cp, strlen(cp)); |
| 542 | xfree(cp); |
| 543 | } |
| 544 | } |
| 545 | /* Sleep in select() until we can do something. */ |
Damien Miller | 5e95321 | 2001-01-30 09:14:00 +1100 | [diff] [blame] | 546 | wait_until_can_do_something(&readset, &writeset, &max_fd, |
| 547 | max_time_milliseconds); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 548 | |
| 549 | /* Process any channel events. */ |
Damien Miller | 5e95321 | 2001-01-30 09:14:00 +1100 | [diff] [blame] | 550 | channel_after_select(readset, writeset); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 551 | |
| 552 | /* Process input from the client and from program stdout/stderr. */ |
Damien Miller | 5e95321 | 2001-01-30 09:14:00 +1100 | [diff] [blame] | 553 | process_input(readset); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 554 | |
| 555 | /* Process output to the client and to program stdin. */ |
Damien Miller | 5e95321 | 2001-01-30 09:14:00 +1100 | [diff] [blame] | 556 | process_output(writeset); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 557 | } |
Damien Miller | 5e95321 | 2001-01-30 09:14:00 +1100 | [diff] [blame] | 558 | if (readset) |
| 559 | xfree(readset); |
| 560 | if (writeset) |
| 561 | xfree(writeset); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 562 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 563 | /* Cleanup and termination code. */ |
| 564 | |
| 565 | /* Wait until all output has been sent to the client. */ |
| 566 | drain_output(); |
| 567 | |
| 568 | debug("End of interactive session; stdin %ld, stdout (read %ld, sent %ld), stderr %ld bytes.", |
| 569 | stdin_bytes, fdout_bytes, stdout_bytes, stderr_bytes); |
| 570 | |
| 571 | /* Free and clear the buffers. */ |
| 572 | buffer_free(&stdin_buffer); |
| 573 | buffer_free(&stdout_buffer); |
| 574 | buffer_free(&stderr_buffer); |
| 575 | |
| 576 | /* Close the file descriptors. */ |
| 577 | if (fdout != -1) |
| 578 | close(fdout); |
| 579 | fdout = -1; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 580 | fdout_eof = 1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 581 | if (fderr != -1) |
| 582 | close(fderr); |
| 583 | fderr = -1; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 584 | fderr_eof = 1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 585 | if (fdin != -1) |
| 586 | close(fdin); |
| 587 | fdin = -1; |
| 588 | |
| 589 | /* Stop listening for channels; this removes unix domain sockets. */ |
| 590 | channel_stop_listening(); |
| 591 | |
| 592 | /* Wait for the child to exit. Get its exit status. */ |
| 593 | wait_pid = wait(&wait_status); |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 594 | if (wait_pid == -1) { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 595 | /* |
| 596 | * It is possible that the wait was handled by SIGCHLD |
| 597 | * handler. This may result in either: this call |
| 598 | * returning with EINTR, or: this call returning ECHILD. |
| 599 | */ |
| 600 | if (child_terminated) |
| 601 | wait_status = child_wait_status; |
| 602 | else |
| 603 | packet_disconnect("wait: %.100s", strerror(errno)); |
| 604 | } else { |
| 605 | /* Check if it matches the process we forked. */ |
| 606 | if (wait_pid != pid) |
| 607 | error("Strange, wait returned pid %d, expected %d", |
Damien Miller | aae6c61 | 1999-12-06 11:47:28 +1100 | [diff] [blame] | 608 | wait_pid, pid); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | /* We no longer want our SIGCHLD handler to be called. */ |
| 612 | signal(SIGCHLD, SIG_DFL); |
| 613 | |
| 614 | /* Check if it exited normally. */ |
| 615 | if (WIFEXITED(wait_status)) { |
| 616 | /* Yes, normal exit. Get exit status and send it to the client. */ |
| 617 | debug("Command exited with status %d.", WEXITSTATUS(wait_status)); |
| 618 | packet_start(SSH_SMSG_EXITSTATUS); |
| 619 | packet_put_int(WEXITSTATUS(wait_status)); |
| 620 | packet_send(); |
| 621 | packet_write_wait(); |
| 622 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 623 | /* |
| 624 | * Wait for exit confirmation. Note that there might be |
| 625 | * other packets coming before it; however, the program has |
| 626 | * already died so we just ignore them. The client is |
| 627 | * supposed to respond with the confirmation when it receives |
| 628 | * the exit status. |
| 629 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 630 | do { |
| 631 | int plen; |
| 632 | type = packet_read(&plen); |
| 633 | } |
| 634 | while (type != SSH_CMSG_EXIT_CONFIRMATION); |
| 635 | |
| 636 | debug("Received exit confirmation."); |
| 637 | return; |
| 638 | } |
| 639 | /* Check if the program terminated due to a signal. */ |
| 640 | if (WIFSIGNALED(wait_status)) |
| 641 | packet_disconnect("Command terminated on signal %d.", |
| 642 | WTERMSIG(wait_status)); |
| 643 | |
| 644 | /* Some weird exit cause. Just exit. */ |
| 645 | packet_disconnect("wait returned status %04x.", wait_status); |
| 646 | /* NOTREACHED */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 647 | } |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 648 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 649 | void |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 650 | server_loop2(void) |
| 651 | { |
Damien Miller | 5e95321 | 2001-01-30 09:14:00 +1100 | [diff] [blame] | 652 | fd_set *readset = NULL, *writeset = NULL; |
Ben Lindstrom | 8e312f3 | 2001-04-04 23:50:21 +0000 | [diff] [blame] | 653 | int had_channel = 0, rekeying = 0, max_fd, status; |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 654 | pid_t pid; |
| 655 | |
| 656 | debug("Entering interactive session for SSH2."); |
| 657 | |
Kevin Steves | b6e773a | 2001-02-04 13:20:36 +0000 | [diff] [blame] | 658 | mysignal(SIGCHLD, sigchld_handler2); |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 659 | child_terminated = 0; |
| 660 | connection_in = packet_get_connection_in(); |
| 661 | connection_out = packet_get_connection_out(); |
Damien Miller | 5e95321 | 2001-01-30 09:14:00 +1100 | [diff] [blame] | 662 | |
| 663 | max_fd = MAX(connection_in, connection_out); |
| 664 | |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 665 | server_init_dispatch(); |
| 666 | |
| 667 | for (;;) { |
| 668 | process_buffered_input_packets(); |
Ben Lindstrom | 8e312f3 | 2001-04-04 23:50:21 +0000 | [diff] [blame] | 669 | |
Ben Lindstrom | a370005 | 2001-04-05 23:26:32 +0000 | [diff] [blame] | 670 | rekeying = (xxx_kex != NULL && !xxx_kex->done); |
Ben Lindstrom | 8e312f3 | 2001-04-04 23:50:21 +0000 | [diff] [blame] | 671 | |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 672 | if (!had_channel && channel_still_open()) |
| 673 | had_channel = 1; |
| 674 | if (had_channel && !channel_still_open()) { |
| 675 | debug("!channel_still_open."); |
| 676 | break; |
| 677 | } |
Ben Lindstrom | 8e312f3 | 2001-04-04 23:50:21 +0000 | [diff] [blame] | 678 | if (!rekeying && packet_not_very_much_data_to_write()) |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 679 | channel_output_poll(); |
Ben Lindstrom | 8e312f3 | 2001-04-04 23:50:21 +0000 | [diff] [blame] | 680 | wait_until_can_do_something(&readset, &writeset, &max_fd, |
| 681 | rekeying); |
Damien Miller | 43dc8da | 2000-11-29 15:55:17 +1100 | [diff] [blame] | 682 | if (child_terminated) { |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 683 | while ((pid = waitpid(-1, &status, WNOHANG)) > 0) |
| 684 | session_close_by_pid(pid, status); |
| 685 | child_terminated = 0; |
| 686 | } |
Ben Lindstrom | 8e312f3 | 2001-04-04 23:50:21 +0000 | [diff] [blame] | 687 | if (!rekeying) |
| 688 | channel_after_select(readset, writeset); |
Damien Miller | 5e95321 | 2001-01-30 09:14:00 +1100 | [diff] [blame] | 689 | process_input(readset); |
| 690 | process_output(writeset); |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 691 | } |
Damien Miller | 5e95321 | 2001-01-30 09:14:00 +1100 | [diff] [blame] | 692 | if (readset) |
| 693 | xfree(readset); |
| 694 | if (writeset) |
| 695 | xfree(writeset); |
| 696 | |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 697 | signal(SIGCHLD, SIG_DFL); |
| 698 | while ((pid = waitpid(-1, &status, WNOHANG)) > 0) |
| 699 | session_close_by_pid(pid, status); |
| 700 | channel_stop_listening(); |
| 701 | } |
| 702 | |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 703 | void |
Damien Miller | 62cee00 | 2000-09-23 17:15:56 +1100 | [diff] [blame] | 704 | server_input_stdin_data(int type, int plen, void *ctxt) |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 705 | { |
| 706 | char *data; |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 707 | u_int data_len; |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 708 | |
| 709 | /* Stdin data from the client. Append it to the buffer. */ |
| 710 | /* Ignore any data if the client has closed stdin. */ |
| 711 | if (fdin == -1) |
| 712 | return; |
| 713 | data = packet_get_string(&data_len); |
| 714 | packet_integrity_check(plen, (4 + data_len), type); |
| 715 | buffer_append(&stdin_buffer, data, data_len); |
| 716 | memset(data, 0, data_len); |
| 717 | xfree(data); |
| 718 | } |
| 719 | |
| 720 | void |
Damien Miller | 62cee00 | 2000-09-23 17:15:56 +1100 | [diff] [blame] | 721 | server_input_eof(int type, int plen, void *ctxt) |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 722 | { |
| 723 | /* |
| 724 | * Eof from the client. The stdin descriptor to the |
| 725 | * program will be closed when all buffered data has |
| 726 | * drained. |
| 727 | */ |
| 728 | debug("EOF received for stdin."); |
| 729 | packet_integrity_check(plen, 0, type); |
| 730 | stdin_eof = 1; |
| 731 | } |
| 732 | |
| 733 | void |
Damien Miller | 62cee00 | 2000-09-23 17:15:56 +1100 | [diff] [blame] | 734 | server_input_window_size(int type, int plen, void *ctxt) |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 735 | { |
| 736 | int row = packet_get_int(); |
| 737 | int col = packet_get_int(); |
| 738 | int xpixel = packet_get_int(); |
| 739 | int ypixel = packet_get_int(); |
| 740 | |
| 741 | debug("Window change received."); |
| 742 | packet_integrity_check(plen, 4 * 4, type); |
| 743 | if (fdin != -1) |
| 744 | pty_change_window_size(fdin, row, col, xpixel, ypixel); |
| 745 | } |
| 746 | |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 747 | Channel * |
| 748 | server_request_direct_tcpip(char *ctype) |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 749 | { |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 750 | int sock, newch; |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 751 | char *target, *originator; |
| 752 | int target_port, originator_port; |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 753 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 754 | target = packet_get_string(NULL); |
| 755 | target_port = packet_get_int(); |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 756 | originator = packet_get_string(NULL); |
| 757 | originator_port = packet_get_int(); |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 758 | packet_done(); |
Damien Miller | b1715dc | 2000-05-30 13:44:51 +1000 | [diff] [blame] | 759 | |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 760 | debug("server_request_direct_tcpip: originator %s port %d, target %s port %d", |
Damien Miller | b1715dc | 2000-05-30 13:44:51 +1000 | [diff] [blame] | 761 | originator, originator_port, target, target_port); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 762 | |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 763 | /* XXX check permission */ |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 764 | sock = channel_connect_to(target, target_port); |
| 765 | xfree(target); |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 766 | xfree(originator); |
| 767 | if (sock < 0) |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 768 | return NULL; |
Ben Lindstrom | 7ad9710 | 2000-12-06 01:42:49 +0000 | [diff] [blame] | 769 | newch = channel_new(ctype, SSH_CHANNEL_CONNECTING, |
Damien Miller | e4340be | 2000-09-16 13:29:08 +1100 | [diff] [blame] | 770 | sock, sock, -1, CHAN_TCP_WINDOW_DEFAULT, |
Damien Miller | 69b69aa | 2000-10-28 14:19:58 +1100 | [diff] [blame] | 771 | CHAN_TCP_PACKET_DEFAULT, 0, xstrdup("direct-tcpip"), 1); |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 772 | return (newch >= 0) ? channel_lookup(newch) : NULL; |
| 773 | } |
| 774 | |
| 775 | Channel * |
| 776 | server_request_session(char *ctype) |
| 777 | { |
| 778 | int newch; |
| 779 | |
| 780 | debug("input_session_request"); |
| 781 | packet_done(); |
| 782 | /* |
| 783 | * A server session has no fd to read or write until a |
| 784 | * CHANNEL_REQUEST for a shell is made, so we set the type to |
| 785 | * SSH_CHANNEL_LARVAL. Additionally, a callback for handling all |
| 786 | * CHANNEL_REQUEST messages is registered. |
| 787 | */ |
| 788 | newch = channel_new(ctype, SSH_CHANNEL_LARVAL, |
| 789 | -1, -1, -1, 0, CHAN_SES_PACKET_DEFAULT, |
| 790 | 0, xstrdup("server-session"), 1); |
| 791 | if (session_open(newch) == 1) { |
| 792 | channel_register_callback(newch, SSH2_MSG_CHANNEL_REQUEST, |
| 793 | session_input_channel_req, (void *)0); |
| 794 | channel_register_cleanup(newch, session_close_by_channel); |
| 795 | return channel_lookup(newch); |
| 796 | } else { |
| 797 | debug("session open failed, free channel %d", newch); |
| 798 | channel_free(newch); |
| 799 | } |
| 800 | return NULL; |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 801 | } |
| 802 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 803 | void |
Damien Miller | 62cee00 | 2000-09-23 17:15:56 +1100 | [diff] [blame] | 804 | server_input_channel_open(int type, int plen, void *ctxt) |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 805 | { |
| 806 | Channel *c = NULL; |
| 807 | char *ctype; |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 808 | u_int len; |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 809 | int rchan; |
| 810 | int rmaxpack; |
| 811 | int rwindow; |
| 812 | |
| 813 | ctype = packet_get_string(&len); |
| 814 | rchan = packet_get_int(); |
| 815 | rwindow = packet_get_int(); |
| 816 | rmaxpack = packet_get_int(); |
| 817 | |
Damien Miller | 62cee00 | 2000-09-23 17:15:56 +1100 | [diff] [blame] | 818 | debug("server_input_channel_open: ctype %s rchan %d win %d max %d", |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 819 | ctype, rchan, rwindow, rmaxpack); |
| 820 | |
| 821 | if (strcmp(ctype, "session") == 0) { |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 822 | c = server_request_session(ctype); |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 823 | } else if (strcmp(ctype, "direct-tcpip") == 0) { |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 824 | c = server_request_direct_tcpip(ctype); |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 825 | } |
| 826 | if (c != NULL) { |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 827 | debug("server_input_channel_open: confirm %s", ctype); |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 828 | c->remote_id = rchan; |
| 829 | c->remote_window = rwindow; |
| 830 | c->remote_maxpacket = rmaxpack; |
| 831 | |
| 832 | packet_start(SSH2_MSG_CHANNEL_OPEN_CONFIRMATION); |
| 833 | packet_put_int(c->remote_id); |
| 834 | packet_put_int(c->self); |
| 835 | packet_put_int(c->local_window); |
| 836 | packet_put_int(c->local_maxpacket); |
| 837 | packet_send(); |
| 838 | } else { |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 839 | debug("server_input_channel_open: failure %s", ctype); |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 840 | packet_start(SSH2_MSG_CHANNEL_OPEN_FAILURE); |
| 841 | packet_put_int(rchan); |
| 842 | packet_put_int(SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED); |
| 843 | packet_put_cstring("bla bla"); |
| 844 | packet_put_cstring(""); |
| 845 | packet_send(); |
| 846 | } |
| 847 | xfree(ctype); |
| 848 | } |
| 849 | |
Kevin Steves | ef4eea9 | 2001-02-05 12:42:17 +0000 | [diff] [blame] | 850 | void |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 851 | server_input_global_request(int type, int plen, void *ctxt) |
| 852 | { |
| 853 | char *rtype; |
| 854 | int want_reply; |
| 855 | int success = 0; |
| 856 | |
| 857 | rtype = packet_get_string(NULL); |
| 858 | want_reply = packet_get_char(); |
| 859 | debug("server_input_global_request: rtype %s want_reply %d", rtype, want_reply); |
Kevin Steves | ef4eea9 | 2001-02-05 12:42:17 +0000 | [diff] [blame] | 860 | |
Ben Lindstrom | 7bb8b49 | 2001-03-17 00:47:54 +0000 | [diff] [blame] | 861 | /* -R style forwarding */ |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 862 | if (strcmp(rtype, "tcpip-forward") == 0) { |
| 863 | struct passwd *pw; |
| 864 | char *listen_address; |
| 865 | u_short listen_port; |
| 866 | |
| 867 | pw = auth_get_user(); |
| 868 | if (pw == NULL) |
| 869 | fatal("server_input_global_request: no user"); |
| 870 | listen_address = packet_get_string(NULL); /* XXX currently ignored */ |
| 871 | listen_port = (u_short)packet_get_int(); |
| 872 | debug("server_input_global_request: tcpip-forward listen %s port %d", |
| 873 | listen_address, listen_port); |
| 874 | |
| 875 | /* check permissions */ |
| 876 | if (!options.allow_tcp_forwarding || |
| 877 | no_port_forwarding_flag || |
| 878 | (listen_port < IPPORT_RESERVED && pw->pw_uid != 0)) { |
| 879 | success = 0; |
| 880 | packet_send_debug("Server has disabled port forwarding."); |
| 881 | } else { |
| 882 | /* Start listening on the port */ |
Kevin Steves | 1205750 | 2001-02-05 14:54:34 +0000 | [diff] [blame] | 883 | success = channel_request_forwarding( |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 884 | listen_address, listen_port, |
| 885 | /*unspec host_to_connect*/ "<unspec host>", |
| 886 | /*unspec port_to_connect*/ 0, |
| 887 | options.gateway_ports, /*remote*/ 1); |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 888 | } |
| 889 | xfree(listen_address); |
| 890 | } |
| 891 | if (want_reply) { |
| 892 | packet_start(success ? |
| 893 | SSH2_MSG_REQUEST_SUCCESS : SSH2_MSG_REQUEST_FAILURE); |
| 894 | packet_send(); |
| 895 | packet_write_wait(); |
| 896 | } |
| 897 | xfree(rtype); |
| 898 | } |
| 899 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 900 | void |
Ben Lindstrom | 31ca54a | 2001-02-09 02:11:24 +0000 | [diff] [blame] | 901 | server_init_dispatch_20(void) |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 902 | { |
| 903 | debug("server_init_dispatch_20"); |
| 904 | dispatch_init(&dispatch_protocol_error); |
| 905 | dispatch_set(SSH2_MSG_CHANNEL_CLOSE, &channel_input_oclose); |
| 906 | dispatch_set(SSH2_MSG_CHANNEL_DATA, &channel_input_data); |
| 907 | dispatch_set(SSH2_MSG_CHANNEL_EOF, &channel_input_ieof); |
| 908 | dispatch_set(SSH2_MSG_CHANNEL_EXTENDED_DATA, &channel_input_extended_data); |
| 909 | dispatch_set(SSH2_MSG_CHANNEL_OPEN, &server_input_channel_open); |
| 910 | dispatch_set(SSH2_MSG_CHANNEL_OPEN_CONFIRMATION, &channel_input_open_confirmation); |
| 911 | dispatch_set(SSH2_MSG_CHANNEL_OPEN_FAILURE, &channel_input_open_failure); |
| 912 | dispatch_set(SSH2_MSG_CHANNEL_REQUEST, &channel_input_channel_request); |
| 913 | dispatch_set(SSH2_MSG_CHANNEL_WINDOW_ADJUST, &channel_input_window_adjust); |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 914 | dispatch_set(SSH2_MSG_GLOBAL_REQUEST, &server_input_global_request); |
Ben Lindstrom | 8ac9106 | 2001-04-04 17:57:54 +0000 | [diff] [blame] | 915 | |
| 916 | /* rekeying */ |
| 917 | dispatch_set(SSH2_MSG_KEXINIT, &kex_input_kexinit); |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 918 | } |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 919 | void |
Ben Lindstrom | 31ca54a | 2001-02-09 02:11:24 +0000 | [diff] [blame] | 920 | server_init_dispatch_13(void) |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 921 | { |
| 922 | debug("server_init_dispatch_13"); |
| 923 | dispatch_init(NULL); |
| 924 | dispatch_set(SSH_CMSG_EOF, &server_input_eof); |
| 925 | dispatch_set(SSH_CMSG_STDIN_DATA, &server_input_stdin_data); |
| 926 | dispatch_set(SSH_CMSG_WINDOW_SIZE, &server_input_window_size); |
| 927 | dispatch_set(SSH_MSG_CHANNEL_CLOSE, &channel_input_close); |
| 928 | dispatch_set(SSH_MSG_CHANNEL_CLOSE_CONFIRMATION, &channel_input_close_confirmation); |
| 929 | dispatch_set(SSH_MSG_CHANNEL_DATA, &channel_input_data); |
| 930 | dispatch_set(SSH_MSG_CHANNEL_OPEN_CONFIRMATION, &channel_input_open_confirmation); |
| 931 | dispatch_set(SSH_MSG_CHANNEL_OPEN_FAILURE, &channel_input_open_failure); |
| 932 | dispatch_set(SSH_MSG_PORT_OPEN, &channel_input_port_open); |
| 933 | } |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 934 | void |
Ben Lindstrom | 31ca54a | 2001-02-09 02:11:24 +0000 | [diff] [blame] | 935 | server_init_dispatch_15(void) |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 936 | { |
| 937 | server_init_dispatch_13(); |
| 938 | debug("server_init_dispatch_15"); |
| 939 | dispatch_set(SSH_MSG_CHANNEL_CLOSE, &channel_input_ieof); |
| 940 | dispatch_set(SSH_MSG_CHANNEL_CLOSE_CONFIRMATION, &channel_input_oclose); |
| 941 | } |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 942 | void |
Ben Lindstrom | 31ca54a | 2001-02-09 02:11:24 +0000 | [diff] [blame] | 943 | server_init_dispatch(void) |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 944 | { |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 945 | if (compat20) |
| 946 | server_init_dispatch_20(); |
| 947 | else if (compat13) |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 948 | server_init_dispatch_13(); |
| 949 | else |
| 950 | server_init_dispatch_15(); |
| 951 | } |