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