blob: 9602e050de5384f66682e47438a85277916a5489 [file] [log] [blame]
djm@openbsd.org135e3022019-01-19 22:30:52 +00001/* $OpenBSD: serverloop.c,v 1.213 2019/01/19 22:30:52 djm Exp $ */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002/*
Damien Miller95def091999-11-25 00:26:21 +11003 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * All rights reserved
Damien Miller95def091999-11-25 00:26:21 +11006 * Server main loop for handling the interactive session.
Damien Millere4340be2000-09-16 13:29:08 +11007 *
8 * As far as I am concerned, the code I have written for this software
9 * can be used freely for any purpose. Any derived versions of this
10 * software must be clearly marked as such, and if the derived work is
11 * incompatible with the protocol description in the RFC file, it must be
12 * called by a name other than "ssh" or "Secure Shell".
13 *
Damien Millerefb4afe2000-04-12 18:45:05 +100014 * SSH2 support by Markus Friedl.
Ben Lindstrom44697232001-07-04 03:32:30 +000015 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
Damien Millere4340be2000-09-16 13:29:08 +110016 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
19 * are met:
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
27 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Damien Millerefb4afe2000-04-12 18:45:05 +100036 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100037
38#include "includes.h"
Damien Miller9cf6d072006-03-15 11:29:24 +110039
40#include <sys/types.h>
41#include <sys/wait.h>
Damien Miller8ec8c3e2006-07-10 20:35:38 +100042#include <sys/socket.h>
Damien Miller9aec9192006-08-05 10:57:45 +100043#ifdef HAVE_SYS_TIME_H
44# include <sys/time.h>
45#endif
Damien Miller8ec8c3e2006-07-10 20:35:38 +100046
47#include <netinet/in.h>
Damien Miller99bd21e2006-03-15 11:11:28 +110048
Darren Tucker39972492006-07-12 22:22:46 +100049#include <errno.h>
Damien Miller57cf6382006-07-10 21:13:46 +100050#include <fcntl.h>
Damien Miller9f2abc42006-07-10 20:53:08 +100051#include <pwd.h>
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +000052#include <limits.h>
Damien Miller6ff3cad2006-03-15 11:52:09 +110053#include <signal.h>
Damien Millere3476ed2006-07-24 14:13:33 +100054#include <string.h>
Damien Miller99bd21e2006-03-15 11:11:28 +110055#include <termios.h>
Damien Miller1cdde6f2006-07-24 14:07:35 +100056#include <unistd.h>
Damien Millerd7834352006-08-05 12:39:39 +100057#include <stdarg.h>
Damien Miller69b69aa2000-10-28 14:19:58 +110058
Damien Millerb84886b2008-05-19 15:05:07 +100059#include "openbsd-compat/sys-queue.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100060#include "xmalloc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100061#include "packet.h"
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +000062#include "sshbuf.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000063#include "log.h"
Damien Miller7acefbb2014-07-18 14:11:24 +100064#include "misc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100065#include "servconf.h"
Damien Miller16aed052002-09-22 01:26:27 +100066#include "canohost.h"
Ben Lindstromd95c09c2001-02-18 19:13:33 +000067#include "sshpty.h"
Ben Lindstromc7637672001-06-09 00:36:26 +000068#include "channels.h"
Damien Millerb38eff82000-04-01 11:09:21 +100069#include "compat.h"
Damien Millerefb4afe2000-04-12 18:45:05 +100070#include "ssh2.h"
markus@openbsd.org5467fbc2018-07-11 18:53:29 +000071#include "sshkey.h"
Damien Millerd7834352006-08-05 12:39:39 +100072#include "cipher.h"
73#include "kex.h"
74#include "hostfile.h"
Ben Lindstromdb65e8f2001-01-19 04:26:52 +000075#include "auth.h"
Damien Millerefb4afe2000-04-12 18:45:05 +100076#include "session.h"
Damien Millerb38eff82000-04-01 11:09:21 +100077#include "dispatch.h"
Damien Millerf6d9e222000-06-18 14:50:44 +100078#include "auth-options.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000079#include "serverloop.h"
djm@openbsd.org523463a2015-02-16 22:13:32 +000080#include "ssherr.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100081
Damien Miller50a41ed2000-10-16 12:14:42 +110082extern ServerOptions options;
83
Ben Lindstrom8ac91062001-04-04 17:57:54 +000084/* XXX */
Darren Tucker3e33cec2003-10-02 16:12:36 +100085extern Authctxt *the_authctxt;
djm@openbsd.org7c856852018-03-03 03:15:51 +000086extern struct sshauthopt *auth_opts;
Damien Miller24ecf612005-11-05 15:16:52 +110087extern int use_privsep;
Ben Lindstrom8ac91062001-04-04 17:57:54 +000088
Darren Tucker8901fa92008-06-11 09:34:01 +100089static int no_more_sessions = 0; /* Disallow further sessions. */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100090
Damien Miller5428f641999-11-25 11:54:57 +110091/*
92 * This SIGCHLD kludge is used to detect when the child exits. The server
93 * will exit after that, as soon as forwarded connections have terminated.
94 */
Ben Lindstrombba81212001-06-25 05:01:22 +000095
Ben Lindstrom5e71c542001-12-06 16:48:14 +000096static volatile sig_atomic_t child_terminated = 0; /* The child has terminated. */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100097
Damien Miller24ecf612005-11-05 15:16:52 +110098/* Cleanup on signals (!use_privsep case only) */
99static volatile sig_atomic_t received_sigterm = 0;
100
Ben Lindstrombba81212001-06-25 05:01:22 +0000101/* prototypes */
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000102static void server_init_dispatch(struct ssh *);
Damien Millerb38eff82000-04-01 11:09:21 +1000103
djm@openbsd.orgb7548b12017-10-23 05:08:00 +0000104/* requested tunnel forwarding interface(s), shared with session.c */
105char *tun_fwd_ifnames = NULL;
106
dtucker@openbsd.org73ddb252018-07-27 05:13:02 +0000107/* returns 1 if bind to specified port by specified user is permitted */
108static int
109bind_permitted(int port, uid_t uid)
110{
111 if (use_privsep)
112 return 1; /* allow system to decide */
113 if (port < IPPORT_RESERVED && uid != 0)
114 return 0;
115 return 1;
116}
117
Damien Millerf6681a32001-12-21 14:53:11 +1100118/*
119 * we write to this pipe if a SIGCHLD is caught in order to avoid
120 * the race between select() and child_terminated
121 */
122static int notify_pipe[2];
123static void
124notify_setup(void)
125{
126 if (pipe(notify_pipe) < 0) {
127 error("pipe(notify_pipe) failed %s", strerror(errno));
Damien Miller814ace02011-05-20 19:02:47 +1000128 } else if ((fcntl(notify_pipe[0], F_SETFD, FD_CLOEXEC) == -1) ||
129 (fcntl(notify_pipe[1], F_SETFD, FD_CLOEXEC) == -1)) {
Damien Millerf6681a32001-12-21 14:53:11 +1100130 error("fcntl(notify_pipe, F_SETFD) failed %s", strerror(errno));
131 close(notify_pipe[0]);
132 close(notify_pipe[1]);
133 } else {
134 set_nonblock(notify_pipe[0]);
135 set_nonblock(notify_pipe[1]);
136 return;
137 }
138 notify_pipe[0] = -1; /* read end */
139 notify_pipe[1] = -1; /* write end */
140}
141static void
142notify_parent(void)
143{
144 if (notify_pipe[1] != -1)
Darren Tuckerdbee3082013-05-16 20:32:29 +1000145 (void)write(notify_pipe[1], "", 1);
Damien Millerf6681a32001-12-21 14:53:11 +1100146}
147static void
148notify_prepare(fd_set *readset)
149{
150 if (notify_pipe[0] != -1)
151 FD_SET(notify_pipe[0], readset);
152}
153static void
154notify_done(fd_set *readset)
155{
156 char c;
157
158 if (notify_pipe[0] != -1 && FD_ISSET(notify_pipe[0], readset))
159 while (read(notify_pipe[0], &c, 1) != -1)
djm@openbsd.org027607f2018-06-08 01:55:40 +0000160 debug2("%s: reading", __func__);
Damien Millerf6681a32001-12-21 14:53:11 +1100161}
162
Damien Millerf0b15df2006-03-26 13:59:20 +1100163/*ARGSUSED*/
Ben Lindstrombba81212001-06-25 05:01:22 +0000164static void
Damien Miller95def091999-11-25 00:26:21 +1100165sigchld_handler(int sig)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000166{
Damien Miller95def091999-11-25 00:26:21 +1100167 int save_errno = errno;
Damien Millerefb4afe2000-04-12 18:45:05 +1000168 child_terminated = 1;
Damien Millerf6681a32001-12-21 14:53:11 +1100169 notify_parent();
Damien Millerefb4afe2000-04-12 18:45:05 +1000170 errno = save_errno;
171}
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000172
Damien Millerf0b15df2006-03-26 13:59:20 +1100173/*ARGSUSED*/
Damien Miller24ecf612005-11-05 15:16:52 +1100174static void
175sigterm_handler(int sig)
176{
177 received_sigterm = sig;
178}
179
Damien Miller8c3902a2001-10-10 15:01:40 +1000180static void
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000181client_alive_check(struct ssh *ssh)
Damien Miller8c3902a2001-10-10 15:01:40 +1000182{
dtucker@openbsd.org48c23a32017-12-10 05:55:29 +0000183 char remote_id[512];
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000184 int r, channel_id;
Damien Miller056cf732002-01-22 23:21:39 +1100185
Damien Miller8c3902a2001-10-10 15:01:40 +1000186 /* timeout, check to see how many we have had */
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000187 if (ssh_packet_inc_alive_timeouts(ssh) >
188 options.client_alive_count_max) {
dtucker@openbsd.org48c23a32017-12-10 05:55:29 +0000189 sshpkt_fmt_connection_id(ssh, remote_id, sizeof(remote_id));
190 logit("Timeout, client not responding from %s", remote_id);
Damien Miller985a4482006-10-24 03:02:41 +1000191 cleanup_exit(255);
192 }
Damien Miller8c3902a2001-10-10 15:01:40 +1000193
Damien Miller8c3902a2001-10-10 15:01:40 +1000194 /*
Damien Millerb5820f42003-12-17 16:27:32 +1100195 * send a bogus global/channel request with "wantreply",
Damien Miller8c3902a2001-10-10 15:01:40 +1000196 * we should get back a failure
197 */
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000198 if ((channel_id = channel_find_open(ssh)) == -1) {
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000199 if ((r = sshpkt_start(ssh, SSH2_MSG_GLOBAL_REQUEST)) != 0 ||
200 (r = sshpkt_put_cstring(ssh, "keepalive@openssh.com"))
201 != 0 ||
202 (r = sshpkt_put_u8(ssh, 1)) != 0) /* boolean: want reply */
203 fatal("%s: %s", __func__, ssh_err(r));
Damien Millerb5820f42003-12-17 16:27:32 +1100204 } else {
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000205 channel_request_start(ssh, channel_id,
206 "keepalive@openssh.com", 1);
Damien Millerb5820f42003-12-17 16:27:32 +1100207 }
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000208 if ((r = sshpkt_send(ssh)) != 0)
209 fatal("%s: %s", __func__, ssh_err(r));
Damien Miller8c3902a2001-10-10 15:01:40 +1000210}
211
Damien Miller95def091999-11-25 00:26:21 +1100212/*
213 * Sleep in select() until we can do something. This will initialize the
214 * select masks. Upon return, the masks will indicate which descriptors
215 * have data or can accept data. Optionally, a maximum time can be specified
216 * for the duration of the wait (0 = infinite).
217 */
Ben Lindstrombba81212001-06-25 05:01:22 +0000218static void
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000219wait_until_can_do_something(struct ssh *ssh,
220 int connection_in, int connection_out,
markus@openbsd.org6cb6dcf2016-08-13 17:47:40 +0000221 fd_set **readsetp, fd_set **writesetp, int *maxfdp,
djm@openbsd.org988e4292016-03-04 03:35:44 +0000222 u_int *nallocp, u_int64_t max_time_ms)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000223{
Damien Miller95def091999-11-25 00:26:21 +1100224 struct timeval tv, *tvp;
225 int ret;
Damien Miller6c6da332012-06-20 22:31:26 +1000226 time_t minwait_secs = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000227 int client_alive_scheduled = 0;
dtucker@openbsd.orgb60ff202017-08-11 03:58:36 +0000228 static time_t last_client_time;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000229
Damien Millera6508752012-04-22 11:21:10 +1000230 /* Allocate and update select() masks for channel descriptors. */
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000231 channel_prepare_select(ssh, readsetp, writesetp, maxfdp,
djm@openbsd.org71e5a532017-08-30 03:59:08 +0000232 nallocp, &minwait_secs);
Damien Millera6508752012-04-22 11:21:10 +1000233
djm@openbsd.org988e4292016-03-04 03:35:44 +0000234 /* XXX need proper deadline system for rekey/client alive */
Damien Millera6508752012-04-22 11:21:10 +1000235 if (minwait_secs != 0)
deraadt@openbsd.org9136ec12016-09-12 01:22:38 +0000236 max_time_ms = MINIMUM(max_time_ms, (u_int)minwait_secs * 1000);
Damien Millera6508752012-04-22 11:21:10 +1000237
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000238 /*
Damien Miller9f0f5c62001-12-21 14:45:46 +1100239 * if using client_alive, set the max timeout accordingly,
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000240 * and indicate that this particular timeout was for client
241 * alive by setting the client_alive_scheduled flag.
242 *
243 * this could be randomized somewhat to make traffic
Damien Miller9f0f5c62001-12-21 14:45:46 +1100244 * analysis more difficult, but we're not doing it yet.
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000245 */
markus@openbsd.org6cb6dcf2016-08-13 17:47:40 +0000246 if (options.client_alive_interval) {
djm@openbsd.org988e4292016-03-04 03:35:44 +0000247 uint64_t keepalive_ms =
248 (uint64_t)options.client_alive_interval * 1000;
249
Ben Lindstrom2f0304c2001-04-29 19:49:14 +0000250 client_alive_scheduled = 1;
djm@openbsd.org988e4292016-03-04 03:35:44 +0000251 if (max_time_ms == 0 || max_time_ms > keepalive_ms)
252 max_time_ms = keepalive_ms;
Ben Lindstrom36857f62001-07-18 15:48:57 +0000253 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000254
Damien Milleraf5f2e62001-10-10 15:01:16 +1000255#if 0
markus@openbsd.org6cb6dcf2016-08-13 17:47:40 +0000256 /* wrong: bad condition XXX */
257 if (channel_not_very_much_buffered_data())
Damien Milleraf5f2e62001-10-10 15:01:16 +1000258#endif
markus@openbsd.org6cb6dcf2016-08-13 17:47:40 +0000259 FD_SET(connection_in, *readsetp);
Damien Millerf6681a32001-12-21 14:53:11 +1100260 notify_prepare(*readsetp);
Damien Miller95def091999-11-25 00:26:21 +1100261
Damien Miller5428f641999-11-25 11:54:57 +1100262 /*
263 * If we have buffered packet data going to the client, mark that
264 * descriptor.
265 */
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000266 if (ssh_packet_have_data_to_write(ssh))
Damien Miller5e953212001-01-30 09:14:00 +1100267 FD_SET(connection_out, *writesetp);
Damien Miller95def091999-11-25 00:26:21 +1100268
Damien Miller5428f641999-11-25 11:54:57 +1100269 /*
270 * If child has terminated and there is enough buffer space to read
271 * from it, then read as much as is available and exit.
272 */
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000273 if (child_terminated && ssh_packet_not_very_much_data_to_write(ssh))
djm@openbsd.org988e4292016-03-04 03:35:44 +0000274 if (max_time_ms == 0 || client_alive_scheduled)
275 max_time_ms = 100;
Damien Miller95def091999-11-25 00:26:21 +1100276
djm@openbsd.org988e4292016-03-04 03:35:44 +0000277 if (max_time_ms == 0)
Damien Miller95def091999-11-25 00:26:21 +1100278 tvp = NULL;
279 else {
djm@openbsd.org988e4292016-03-04 03:35:44 +0000280 tv.tv_sec = max_time_ms / 1000;
281 tv.tv_usec = 1000 * (max_time_ms % 1000);
Damien Miller95def091999-11-25 00:26:21 +1100282 tvp = &tv;
283 }
284
285 /* Wait for something to happen, or the timeout to expire. */
Damien Miller5e953212001-01-30 09:14:00 +1100286 ret = select((*maxfdp)+1, *readsetp, *writesetp, NULL, tvp);
Damien Miller95def091999-11-25 00:26:21 +1100287
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000288 if (ret == -1) {
Damien Miller79faeff2001-11-12 11:06:32 +1100289 memset(*readsetp, 0, *nallocp);
290 memset(*writesetp, 0, *nallocp);
Damien Miller95def091999-11-25 00:26:21 +1100291 if (errno != EINTR)
292 error("select: %.100s", strerror(errno));
dtucker@openbsd.orgb60ff202017-08-11 03:58:36 +0000293 } else if (client_alive_scheduled) {
294 time_t now = monotime();
295
296 if (ret == 0) { /* timeout */
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000297 client_alive_check(ssh);
dtucker@openbsd.orgb60ff202017-08-11 03:58:36 +0000298 } else if (FD_ISSET(connection_in, *readsetp)) {
299 last_client_time = now;
300 } else if (last_client_time != 0 && last_client_time +
dtucker@openbsd.org42a8f8b2017-08-11 04:16:35 +0000301 options.client_alive_interval <= now) {
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000302 client_alive_check(ssh);
dtucker@openbsd.orgb60ff202017-08-11 03:58:36 +0000303 last_client_time = now;
304 }
305 }
Damien Millerf6681a32001-12-21 14:53:11 +1100306
307 notify_done(*readsetp);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000308}
309
Damien Miller95def091999-11-25 00:26:21 +1100310/*
311 * Processes input from the client and the program. Input data is stored
312 * in buffers and processed later.
313 */
markus@openbsd.org6cb6dcf2016-08-13 17:47:40 +0000314static int
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000315process_input(struct ssh *ssh, fd_set *readset, int connection_in)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000316{
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000317 int r, len;
Damien Miller95def091999-11-25 00:26:21 +1100318 char buf[16384];
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000319
Damien Miller95def091999-11-25 00:26:21 +1100320 /* Read and buffer any input data from the client. */
321 if (FD_ISSET(connection_in, readset)) {
markus@openbsd.orga3068632016-01-14 16:17:39 +0000322 len = read(connection_in, buf, sizeof(buf));
Damien Miller95def091999-11-25 00:26:21 +1100323 if (len == 0) {
djm@openbsd.org95767262016-03-07 19:02:43 +0000324 verbose("Connection closed by %.100s port %d",
325 ssh_remote_ipaddr(ssh), ssh_remote_port(ssh));
markus@openbsd.org6cb6dcf2016-08-13 17:47:40 +0000326 return -1;
Damien Millerdcb6ecd2000-05-17 22:34:22 +1000327 } else if (len < 0) {
Damien Millerd8968ad2008-07-04 23:10:49 +1000328 if (errno != EINTR && errno != EAGAIN &&
329 errno != EWOULDBLOCK) {
Damien Miller16aed052002-09-22 01:26:27 +1000330 verbose("Read error from remote host "
djm@openbsd.org95767262016-03-07 19:02:43 +0000331 "%.100s port %d: %.100s",
332 ssh_remote_ipaddr(ssh),
333 ssh_remote_port(ssh), strerror(errno));
Darren Tucker3e33cec2003-10-02 16:12:36 +1000334 cleanup_exit(255);
Damien Millerdcb6ecd2000-05-17 22:34:22 +1000335 }
336 } else {
337 /* Buffer any received data. */
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000338 if ((r = ssh_packet_process_incoming(ssh, buf, len))
339 != 0)
340 fatal("%s: ssh_packet_process_incoming: %s",
341 __func__, ssh_err(r));
Damien Miller95def091999-11-25 00:26:21 +1100342 }
Damien Miller95def091999-11-25 00:26:21 +1100343 }
markus@openbsd.org6cb6dcf2016-08-13 17:47:40 +0000344 return 0;
Damien Miller95def091999-11-25 00:26:21 +1100345}
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000346
Damien Miller95def091999-11-25 00:26:21 +1100347/*
348 * Sends data from internal buffers to client program stdin.
349 */
Ben Lindstrombba81212001-06-25 05:01:22 +0000350static void
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000351process_output(struct ssh *ssh, fd_set *writeset, int connection_out)
Damien Miller95def091999-11-25 00:26:21 +1100352{
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000353 int r;
354
Damien Miller95def091999-11-25 00:26:21 +1100355 /* Send any buffered packet data to the client. */
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000356 if (FD_ISSET(connection_out, writeset)) {
357 if ((r = ssh_packet_write_poll(ssh)) != 0)
358 fatal("%s: ssh_packet_write_poll: %s",
359 __func__, ssh_err(r));
360 }
Damien Miller95def091999-11-25 00:26:21 +1100361}
362
Ben Lindstrombba81212001-06-25 05:01:22 +0000363static void
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000364process_buffered_input_packets(struct ssh *ssh)
Damien Millerb38eff82000-04-01 11:09:21 +1000365{
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000366 ssh_dispatch_run_fatal(ssh, DISPATCH_NONBLOCK, NULL);
Damien Millerb38eff82000-04-01 11:09:21 +1000367}
368
Damien Miller3ec27592001-10-12 11:35:04 +1000369static void
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000370collect_children(struct ssh *ssh)
Damien Miller3ec27592001-10-12 11:35:04 +1000371{
372 pid_t pid;
373 sigset_t oset, nset;
374 int status;
375
376 /* block SIGCHLD while we check for dead children */
377 sigemptyset(&nset);
378 sigaddset(&nset, SIGCHLD);
379 sigprocmask(SIG_BLOCK, &nset, &oset);
380 if (child_terminated) {
Damien Millerec04f362006-03-15 12:01:34 +1100381 debug("Received SIGCHLD.");
Ben Lindstrom47fd8112002-04-02 20:48:19 +0000382 while ((pid = waitpid(-1, &status, WNOHANG)) > 0 ||
383 (pid < 0 && errno == EINTR))
384 if (pid > 0)
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000385 session_close_by_pid(ssh, pid, status);
Damien Miller3ec27592001-10-12 11:35:04 +1000386 child_terminated = 0;
387 }
388 sigprocmask(SIG_SETMASK, &oset, NULL);
389}
390
Damien Miller4af51302000-04-16 11:18:38 +1000391void
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000392server_loop2(struct ssh *ssh, Authctxt *authctxt)
Damien Millerefb4afe2000-04-12 18:45:05 +1000393{
Damien Miller5e953212001-01-30 09:14:00 +1100394 fd_set *readset = NULL, *writeset = NULL;
djm@openbsd.org19bcf2e2016-02-08 10:57:07 +0000395 int max_fd;
markus@openbsd.org6cb6dcf2016-08-13 17:47:40 +0000396 u_int nalloc = 0, connection_in, connection_out;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000397 u_int64_t rekey_timeout_ms = 0;
Damien Millerefb4afe2000-04-12 18:45:05 +1000398
399 debug("Entering interactive session for SSH2.");
400
Darren Tucker389125b2018-02-15 21:43:01 +1100401 signal(SIGCHLD, sigchld_handler);
Damien Millerefb4afe2000-04-12 18:45:05 +1000402 child_terminated = 0;
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000403 connection_in = ssh_packet_get_connection_in(ssh);
404 connection_out = ssh_packet_get_connection_out(ssh);
Damien Miller5e953212001-01-30 09:14:00 +1100405
Damien Miller24ecf612005-11-05 15:16:52 +1100406 if (!use_privsep) {
407 signal(SIGTERM, sigterm_handler);
408 signal(SIGINT, sigterm_handler);
409 signal(SIGQUIT, sigterm_handler);
410 }
411
Damien Millerf6681a32001-12-21 14:53:11 +1100412 notify_setup();
413
deraadt@openbsd.org9136ec12016-09-12 01:22:38 +0000414 max_fd = MAXIMUM(connection_in, connection_out);
415 max_fd = MAXIMUM(max_fd, notify_pipe[0]);
Damien Millerf6681a32001-12-21 14:53:11 +1100416
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000417 server_init_dispatch(ssh);
Damien Millerefb4afe2000-04-12 18:45:05 +1000418
419 for (;;) {
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000420 process_buffered_input_packets(ssh);
Ben Lindstrom8e312f32001-04-04 23:50:21 +0000421
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000422 if (!ssh_packet_is_rekeying(ssh) &&
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000423 ssh_packet_not_very_much_data_to_write(ssh))
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000424 channel_output_poll(ssh);
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000425 if (options.rekey_interval > 0 &&
426 !ssh_packet_is_rekeying(ssh)) {
427 rekey_timeout_ms = ssh_packet_get_rekey_timeout(ssh) *
428 1000;
429 } else {
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000430 rekey_timeout_ms = 0;
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000431 }
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000432
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000433 wait_until_can_do_something(ssh, connection_in, connection_out,
markus@openbsd.org6cb6dcf2016-08-13 17:47:40 +0000434 &readset, &writeset, &max_fd, &nalloc, rekey_timeout_ms);
Damien Miller52b77be2001-10-10 15:14:37 +1000435
Damien Miller24ecf612005-11-05 15:16:52 +1100436 if (received_sigterm) {
Darren Tucker3e1027c2012-12-07 13:07:46 +1100437 logit("Exiting on signal %d", (int)received_sigterm);
Damien Miller24ecf612005-11-05 15:16:52 +1100438 /* Clean up sessions, utmp, etc. */
439 cleanup_exit(255);
440 }
441
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000442 collect_children(ssh);
443 if (!ssh_packet_is_rekeying(ssh))
444 channel_after_select(ssh, readset, writeset);
445 if (process_input(ssh, readset, connection_in) < 0)
Ben Lindstrome34ab4c2001-04-07 01:12:11 +0000446 break;
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000447 process_output(ssh, writeset, connection_out);
Damien Millerefb4afe2000-04-12 18:45:05 +1000448 }
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000449 collect_children(ssh);
Damien Miller3ec27592001-10-12 11:35:04 +1000450
Darren Tuckera627d422013-06-02 07:31:17 +1000451 free(readset);
452 free(writeset);
Damien Miller5e953212001-01-30 09:14:00 +1100453
Damien Miller52b77be2001-10-10 15:14:37 +1000454 /* free all channels, no more reads and writes */
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000455 channel_free_all(ssh);
Ben Lindstrom4983d5e2001-07-04 05:17:40 +0000456
Damien Miller3ec27592001-10-12 11:35:04 +1000457 /* free remaining sessions, e.g. remove wtmp entries */
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000458 session_destroy_all(ssh, NULL);
Damien Millerefb4afe2000-04-12 18:45:05 +1000459}
460
markus@openbsd.org3fdc88a2015-01-19 20:07:45 +0000461static int
markus@openbsd.org2ae666a2017-05-30 14:23:52 +0000462server_input_keep_alive(int type, u_int32_t seq, struct ssh *ssh)
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000463{
Damien Millerb5820f42003-12-17 16:27:32 +1100464 debug("Got %d/%u for keepalive", type, seq);
Damien Miller9f0f5c62001-12-21 14:45:46 +1100465 /*
Ben Lindstrom2f0304c2001-04-29 19:49:14 +0000466 * reset timeout, since we got a sane answer from the client.
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000467 * even if this was generated by something other than
468 * the bogus CHANNEL_REQUEST we send for keepalives.
469 */
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000470 ssh_packet_set_alive_timeouts(ssh, 0);
markus@openbsd.org3fdc88a2015-01-19 20:07:45 +0000471 return 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000472}
473
Ben Lindstrombba81212001-06-25 05:01:22 +0000474static Channel *
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000475server_request_direct_tcpip(struct ssh *ssh, int *reason, const char **errmsg)
Damien Millerefb4afe2000-04-12 18:45:05 +1000476{
Damien Milleraa5b3f82012-12-03 09:50:54 +1100477 Channel *c = NULL;
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000478 char *target = NULL, *originator = NULL;
479 u_int target_port = 0, originator_port = 0;
480 int r;
Damien Millerefb4afe2000-04-12 18:45:05 +1000481
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000482 if ((r = sshpkt_get_cstring(ssh, &target, NULL)) != 0 ||
483 (r = sshpkt_get_u32(ssh, &target_port)) != 0 ||
484 (r = sshpkt_get_cstring(ssh, &originator, NULL)) != 0 ||
485 (r = sshpkt_get_u32(ssh, &originator_port)) != 0 ||
486 (r = sshpkt_get_end(ssh)) != 0)
487 sshpkt_fatal(ssh, r, "%s: parse packet", __func__);
488 if (target_port > 0xFFFF) {
489 error("%s: invalid target port", __func__);
490 *reason = SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED;
491 goto out;
492 }
493 if (originator_port > 0xFFFF) {
494 error("%s: invalid originator port", __func__);
495 *reason = SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED;
496 goto out;
497 }
Damien Millerb1715dc2000-05-30 13:44:51 +1000498
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000499 debug("%s: originator %s port %u, target %s port %u", __func__,
djm@openbsd.org7c856852018-03-03 03:15:51 +0000500 originator, originator_port, target, target_port);
Damien Millerf6d9e222000-06-18 14:50:44 +1000501
Damien Milleraa5b3f82012-12-03 09:50:54 +1100502 /* XXX fine grained permissions */
503 if ((options.allow_tcp_forwarding & FORWARD_LOCAL) != 0 &&
djm@openbsd.org7c856852018-03-03 03:15:51 +0000504 auth_opts->permit_port_forwarding_flag &&
505 !options.disable_forwarding) {
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000506 c = channel_connect_to_port(ssh, target, target_port,
dtucker@openbsd.org858252f2017-02-01 02:59:09 +0000507 "direct-tcpip", "direct-tcpip", reason, errmsg);
Damien Milleraa5b3f82012-12-03 09:50:54 +1100508 } else {
509 logit("refused local port forward: "
510 "originator %s port %d, target %s port %d",
511 originator, originator_port, target, target_port);
dtucker@openbsd.org858252f2017-02-01 02:59:09 +0000512 if (reason != NULL)
513 *reason = SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED;
Damien Milleraa5b3f82012-12-03 09:50:54 +1100514 }
Damien Millerbd740252008-05-19 15:37:09 +1000515
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000516 out:
Darren Tuckera627d422013-06-02 07:31:17 +1000517 free(originator);
518 free(target);
Ben Lindstrom99c73b32001-05-05 04:09:47 +0000519 return c;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100520}
521
Ben Lindstrombba81212001-06-25 05:01:22 +0000522static Channel *
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000523server_request_direct_streamlocal(struct ssh *ssh)
Damien Miller7acefbb2014-07-18 14:11:24 +1000524{
525 Channel *c = NULL;
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000526 char *target = NULL, *originator = NULL;
527 u_int originator_port = 0;
djm@openbsd.org51045862017-01-04 05:37:40 +0000528 struct passwd *pw = the_authctxt->pw;
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000529 int r;
djm@openbsd.org51045862017-01-04 05:37:40 +0000530
531 if (pw == NULL || !the_authctxt->valid)
djm@openbsd.org7c856852018-03-03 03:15:51 +0000532 fatal("%s: no/invalid user", __func__);
Damien Miller7acefbb2014-07-18 14:11:24 +1000533
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000534 if ((r = sshpkt_get_cstring(ssh, &target, NULL)) != 0 ||
535 (r = sshpkt_get_cstring(ssh, &originator, NULL)) != 0 ||
536 (r = sshpkt_get_u32(ssh, &originator_port)) != 0 ||
537 (r = sshpkt_get_end(ssh)) != 0)
538 sshpkt_fatal(ssh, r, "%s: parse packet", __func__);
539 if (originator_port > 0xFFFF) {
540 error("%s: invalid originator port", __func__);
541 goto out;
542 }
Damien Miller7acefbb2014-07-18 14:11:24 +1000543
djm@openbsd.org7c856852018-03-03 03:15:51 +0000544 debug("%s: originator %s port %d, target %s", __func__,
Damien Miller7acefbb2014-07-18 14:11:24 +1000545 originator, originator_port, target);
546
547 /* XXX fine grained permissions */
548 if ((options.allow_streamlocal_forwarding & FORWARD_LOCAL) != 0 &&
djm@openbsd.org7c856852018-03-03 03:15:51 +0000549 auth_opts->permit_port_forwarding_flag &&
550 !options.disable_forwarding && (pw->pw_uid == 0 || use_privsep)) {
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000551 c = channel_connect_to_path(ssh, target,
Damien Miller7acefbb2014-07-18 14:11:24 +1000552 "direct-streamlocal@openssh.com", "direct-streamlocal");
553 } else {
554 logit("refused streamlocal port forward: "
555 "originator %s port %d, target %s",
556 originator, originator_port, target);
557 }
558
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000559out:
Damien Miller7acefbb2014-07-18 14:11:24 +1000560 free(originator);
561 free(target);
Damien Miller7acefbb2014-07-18 14:11:24 +1000562 return c;
563}
564
565static Channel *
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000566server_request_tun(struct ssh *ssh)
Damien Millerd27b9472005-12-13 19:29:02 +1100567{
568 Channel *c = NULL;
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000569 u_int mode, tun;
570 int r, sock;
djm@openbsd.orgb7548b12017-10-23 05:08:00 +0000571 char *tmp, *ifname = NULL;
Damien Millerd27b9472005-12-13 19:29:02 +1100572
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000573 if ((r = sshpkt_get_u32(ssh, &mode)) != 0)
574 sshpkt_fatal(ssh, r, "%s: parse mode", __func__);
Damien Miller7b58e802005-12-13 19:33:19 +1100575 switch (mode) {
576 case SSH_TUNMODE_POINTOPOINT:
577 case SSH_TUNMODE_ETHERNET:
578 break;
579 default:
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000580 ssh_packet_send_debug(ssh, "Unsupported tunnel device mode.");
Damien Miller7b58e802005-12-13 19:33:19 +1100581 return NULL;
582 }
583 if ((options.permit_tun & mode) == 0) {
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000584 ssh_packet_send_debug(ssh, "Server has rejected tunnel device "
Damien Miller7b58e802005-12-13 19:33:19 +1100585 "forwarding");
Damien Millerd27b9472005-12-13 19:29:02 +1100586 return NULL;
587 }
588
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000589 if ((r = sshpkt_get_u32(ssh, &tun)) != 0)
590 sshpkt_fatal(ssh, r, "%s: parse device", __func__);
591 if (tun > INT_MAX) {
592 debug("%s: invalid tun", __func__);
593 goto done;
594 }
djm@openbsd.org7c856852018-03-03 03:15:51 +0000595 if (auth_opts->force_tun_device != -1) {
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000596 if (tun != SSH_TUNID_ANY &&
597 auth_opts->force_tun_device != (int)tun)
Damien Millerd27b9472005-12-13 19:29:02 +1100598 goto done;
djm@openbsd.org7c856852018-03-03 03:15:51 +0000599 tun = auth_opts->force_tun_device;
Damien Millerd27b9472005-12-13 19:29:02 +1100600 }
djm@openbsd.orgb7548b12017-10-23 05:08:00 +0000601 sock = tun_open(tun, mode, &ifname);
Damien Millerd27b9472005-12-13 19:29:02 +1100602 if (sock < 0)
603 goto done;
djm@openbsd.orgb7548b12017-10-23 05:08:00 +0000604 debug("Tunnel forwarding using interface %s", ifname);
Darren Tucker3c511432018-02-13 09:07:29 +1100605
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000606 c = channel_new(ssh, "tun", SSH_CHANNEL_OPEN, sock, sock, -1,
Damien Millerd27b9472005-12-13 19:29:02 +1100607 CHAN_TCP_WINDOW_DEFAULT, CHAN_TCP_PACKET_DEFAULT, 0, "tun", 1);
608 c->datagram = 1;
Damien Miller598bbc22005-12-31 16:33:36 +1100609#if defined(SSH_TUN_FILTER)
610 if (mode == SSH_TUNMODE_POINTOPOINT)
Damien Miller871f1e42017-09-12 18:01:35 +1000611 channel_register_filter(ssh, c->self, sys_tun_infilter,
Darren Tucker1cf65ae2008-06-13 05:09:18 +1000612 sys_tun_outfilter, NULL, NULL);
Damien Miller598bbc22005-12-31 16:33:36 +1100613#endif
Damien Millerd27b9472005-12-13 19:29:02 +1100614
djm@openbsd.orgb7548b12017-10-23 05:08:00 +0000615 /*
616 * Update the list of names exposed to the session
617 * XXX remove these if the tunnels are closed (won't matter
618 * much if they are already in the environment though)
619 */
620 tmp = tun_fwd_ifnames;
621 xasprintf(&tun_fwd_ifnames, "%s%s%s",
622 tun_fwd_ifnames == NULL ? "" : tun_fwd_ifnames,
623 tun_fwd_ifnames == NULL ? "" : ",",
624 ifname);
625 free(tmp);
626 free(ifname);
627
Damien Millerd27b9472005-12-13 19:29:02 +1100628 done:
629 if (c == NULL)
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000630 ssh_packet_send_debug(ssh, "Failed to open the tunnel device.");
Damien Millerd27b9472005-12-13 19:29:02 +1100631 return c;
632}
633
634static Channel *
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000635server_request_session(struct ssh *ssh)
Damien Miller0bc1bd82000-11-13 22:57:25 +1100636{
Ben Lindstrom99c73b32001-05-05 04:09:47 +0000637 Channel *c;
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000638 int r;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100639
640 debug("input_session_request");
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000641 if ((r = sshpkt_get_end(ssh)) != 0)
642 sshpkt_fatal(ssh, r, "%s: parse packet", __func__);
Darren Tucker8901fa92008-06-11 09:34:01 +1000643
644 if (no_more_sessions) {
djm@openbsd.org135e3022019-01-19 22:30:52 +0000645 ssh_packet_disconnect(ssh, "Possible attack: attempt to open a "
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000646 "session after additional sessions disabled");
Darren Tucker8901fa92008-06-11 09:34:01 +1000647 }
648
Damien Miller0bc1bd82000-11-13 22:57:25 +1100649 /*
650 * A server session has no fd to read or write until a
651 * CHANNEL_REQUEST for a shell is made, so we set the type to
652 * SSH_CHANNEL_LARVAL. Additionally, a callback for handling all
653 * CHANNEL_REQUEST messages is registered.
654 */
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000655 c = channel_new(ssh, "session", SSH_CHANNEL_LARVAL,
Ben Lindstrom99c73b32001-05-05 04:09:47 +0000656 -1, -1, -1, /*window size*/0, CHAN_SES_PACKET_DEFAULT,
Damien Millerb1ca8bb2003-05-14 13:45:42 +1000657 0, "server-session", 1);
Darren Tucker3e33cec2003-10-02 16:12:36 +1000658 if (session_open(the_authctxt, c->self) != 1) {
Ben Lindstrom99c73b32001-05-05 04:09:47 +0000659 debug("session open failed, free channel %d", c->self);
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000660 channel_free(ssh, c);
Ben Lindstrom99c73b32001-05-05 04:09:47 +0000661 return NULL;
662 }
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000663 channel_register_cleanup(ssh, c->self, session_close_by_channel, 0);
Ben Lindstrom99c73b32001-05-05 04:09:47 +0000664 return c;
Damien Millerefb4afe2000-04-12 18:45:05 +1000665}
666
markus@openbsd.org3fdc88a2015-01-19 20:07:45 +0000667static int
markus@openbsd.org2ae666a2017-05-30 14:23:52 +0000668server_input_channel_open(int type, u_int32_t seq, struct ssh *ssh)
Damien Millerefb4afe2000-04-12 18:45:05 +1000669{
670 Channel *c = NULL;
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000671 char *ctype = NULL;
dtucker@openbsd.org858252f2017-02-01 02:59:09 +0000672 const char *errmsg = NULL;
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000673 int r, reason = SSH2_OPEN_CONNECT_FAILED;
674 u_int rchan = 0, rmaxpack = 0, rwindow = 0;
Damien Millerefb4afe2000-04-12 18:45:05 +1000675
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000676 if ((r = sshpkt_get_cstring(ssh, &ctype, NULL)) != 0 ||
677 (r = sshpkt_get_u32(ssh, &rchan)) != 0 ||
678 (r = sshpkt_get_u32(ssh, &rwindow)) != 0 ||
679 (r = sshpkt_get_u32(ssh, &rmaxpack)) != 0)
680 sshpkt_fatal(ssh, r, "%s: parse packet", __func__);
681 debug("%s: ctype %s rchan %u win %u max %u", __func__,
Damien Millerefb4afe2000-04-12 18:45:05 +1000682 ctype, rchan, rwindow, rmaxpack);
683
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000684 if (rchan > INT_MAX) {
685 error("%s: invalid remote channel ID", __func__);
686 } else if (strcmp(ctype, "session") == 0) {
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000687 c = server_request_session(ssh);
Damien Millerefb4afe2000-04-12 18:45:05 +1000688 } else if (strcmp(ctype, "direct-tcpip") == 0) {
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000689 c = server_request_direct_tcpip(ssh, &reason, &errmsg);
Damien Miller7acefbb2014-07-18 14:11:24 +1000690 } else if (strcmp(ctype, "direct-streamlocal@openssh.com") == 0) {
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000691 c = server_request_direct_streamlocal(ssh);
Damien Millerd27b9472005-12-13 19:29:02 +1100692 } else if (strcmp(ctype, "tun@openssh.com") == 0) {
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000693 c = server_request_tun(ssh);
Damien Millerefb4afe2000-04-12 18:45:05 +1000694 }
695 if (c != NULL) {
djm@openbsd.org027607f2018-06-08 01:55:40 +0000696 debug("%s: confirm %s", __func__, ctype);
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000697 c->remote_id = (int)rchan;
djm@openbsd.org9f532292017-09-12 06:35:31 +0000698 c->have_remote_id = 1;
Damien Millerefb4afe2000-04-12 18:45:05 +1000699 c->remote_window = rwindow;
700 c->remote_maxpacket = rmaxpack;
Ben Lindstrom69128662001-05-08 20:07:39 +0000701 if (c->type != SSH_CHANNEL_CONNECTING) {
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000702 if ((r = sshpkt_start(ssh, SSH2_MSG_CHANNEL_OPEN_CONFIRMATION)) != 0 ||
703 (r = sshpkt_put_u32(ssh, c->remote_id)) != 0 ||
704 (r = sshpkt_put_u32(ssh, c->self)) != 0 ||
705 (r = sshpkt_put_u32(ssh, c->local_window)) != 0 ||
706 (r = sshpkt_put_u32(ssh, c->local_maxpacket)) != 0 ||
707 (r = sshpkt_send(ssh)) != 0) {
708 sshpkt_fatal(ssh, r,
709 "%s: send open confirm", __func__);
710 }
Ben Lindstrom69128662001-05-08 20:07:39 +0000711 }
Damien Millerefb4afe2000-04-12 18:45:05 +1000712 } else {
djm@openbsd.org027607f2018-06-08 01:55:40 +0000713 debug("%s: failure %s", __func__, ctype);
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000714 if ((r = sshpkt_start(ssh, SSH2_MSG_CHANNEL_OPEN_FAILURE)) != 0 ||
715 (r = sshpkt_put_u32(ssh, rchan)) != 0 ||
716 (r = sshpkt_put_u32(ssh, reason)) != 0 ||
717 (r = sshpkt_put_cstring(ssh, errmsg ? errmsg : "open failed")) != 0 ||
718 (r = sshpkt_put_cstring(ssh, "")) != 0 ||
719 (r = sshpkt_send(ssh)) != 0) {
720 sshpkt_fatal(ssh, r,
721 "%s: send open failure", __func__);
722 }
Damien Millerefb4afe2000-04-12 18:45:05 +1000723 }
Darren Tuckera627d422013-06-02 07:31:17 +1000724 free(ctype);
markus@openbsd.org3fdc88a2015-01-19 20:07:45 +0000725 return 0;
Damien Millerefb4afe2000-04-12 18:45:05 +1000726}
727
markus@openbsd.org3fdc88a2015-01-19 20:07:45 +0000728static int
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000729server_input_hostkeys_prove(struct ssh *ssh, struct sshbuf **respp)
djm@openbsd.org523463a2015-02-16 22:13:32 +0000730{
djm@openbsd.org523463a2015-02-16 22:13:32 +0000731 struct sshbuf *resp = NULL;
732 struct sshbuf *sigbuf = NULL;
733 struct sshkey *key = NULL, *key_pub = NULL, *key_prv = NULL;
djm@openbsd.org78607312017-12-18 23:16:23 +0000734 int r, ndx, kexsigtype, use_kexsigtype, success = 0;
djm@openbsd.org523463a2015-02-16 22:13:32 +0000735 const u_char *blob;
736 u_char *sig = 0;
737 size_t blen, slen;
738
739 if ((resp = sshbuf_new()) == NULL || (sigbuf = sshbuf_new()) == NULL)
740 fatal("%s: sshbuf_new", __func__);
741
djm@openbsd.org78607312017-12-18 23:16:23 +0000742 kexsigtype = sshkey_type_plain(
743 sshkey_type_from_name(ssh->kex->hostkey_alg));
djm@openbsd.org523463a2015-02-16 22:13:32 +0000744 while (ssh_packet_remaining(ssh) > 0) {
745 sshkey_free(key);
746 key = NULL;
747 if ((r = sshpkt_get_string_direct(ssh, &blob, &blen)) != 0 ||
748 (r = sshkey_from_blob(blob, blen, &key)) != 0) {
749 error("%s: couldn't parse key: %s",
750 __func__, ssh_err(r));
751 goto out;
752 }
753 /*
754 * Better check that this is actually one of our hostkeys
755 * before attempting to sign anything with it.
756 */
757 if ((ndx = ssh->kex->host_key_index(key, 1, ssh)) == -1) {
758 error("%s: unknown host %s key",
759 __func__, sshkey_type(key));
760 goto out;
761 }
762 /*
763 * XXX refactor: make kex->sign just use an index rather
764 * than passing in public and private keys
765 */
766 if ((key_prv = get_hostkey_by_index(ndx)) == NULL &&
767 (key_pub = get_hostkey_public_by_index(ndx, ssh)) == NULL) {
768 error("%s: can't retrieve hostkey %d", __func__, ndx);
769 goto out;
770 }
771 sshbuf_reset(sigbuf);
772 free(sig);
773 sig = NULL;
djm@openbsd.org78607312017-12-18 23:16:23 +0000774 /*
775 * For RSA keys, prefer to use the signature type negotiated
776 * during KEX to the default (SHA1).
777 */
778 use_kexsigtype = kexsigtype == KEY_RSA &&
779 sshkey_type_plain(key->type) == KEY_RSA;
djm@openbsd.org44732de2015-02-20 22:17:21 +0000780 if ((r = sshbuf_put_cstring(sigbuf,
781 "hostkeys-prove-00@openssh.com")) != 0 ||
782 (r = sshbuf_put_string(sigbuf,
djm@openbsd.org523463a2015-02-16 22:13:32 +0000783 ssh->kex->session_id, ssh->kex->session_id_len)) != 0 ||
djm@openbsd.org523463a2015-02-16 22:13:32 +0000784 (r = sshkey_puts(key, sigbuf)) != 0 ||
djm@openbsd.org04c091f2019-01-19 21:43:56 +0000785 (r = ssh->kex->sign(ssh, key_prv, key_pub, &sig, &slen,
djm@openbsd.org04c7e282017-12-18 02:25:15 +0000786 sshbuf_ptr(sigbuf), sshbuf_len(sigbuf),
djm@openbsd.org04c091f2019-01-19 21:43:56 +0000787 use_kexsigtype ? ssh->kex->hostkey_alg : NULL)) != 0 ||
djm@openbsd.org523463a2015-02-16 22:13:32 +0000788 (r = sshbuf_put_string(resp, sig, slen)) != 0) {
789 error("%s: couldn't prepare signature: %s",
790 __func__, ssh_err(r));
791 goto out;
792 }
793 }
794 /* Success */
795 *respp = resp;
796 resp = NULL; /* don't free it */
797 success = 1;
798 out:
799 free(sig);
800 sshbuf_free(resp);
801 sshbuf_free(sigbuf);
802 sshkey_free(key);
803 return success;
804}
805
806static int
markus@openbsd.org2ae666a2017-05-30 14:23:52 +0000807server_input_global_request(int type, u_int32_t seq, struct ssh *ssh)
Damien Miller0bc1bd82000-11-13 22:57:25 +1100808{
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000809 char *rtype = NULL;
810 u_char want_reply = 0;
djm@openbsd.org523463a2015-02-16 22:13:32 +0000811 int r, success = 0, allocated_listen_port = 0;
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000812 u_int port = 0;
djm@openbsd.org523463a2015-02-16 22:13:32 +0000813 struct sshbuf *resp = NULL;
djm@openbsd.org51045862017-01-04 05:37:40 +0000814 struct passwd *pw = the_authctxt->pw;
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000815 struct Forward fwd;
djm@openbsd.org51045862017-01-04 05:37:40 +0000816
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000817 memset(&fwd, 0, sizeof(fwd));
djm@openbsd.org51045862017-01-04 05:37:40 +0000818 if (pw == NULL || !the_authctxt->valid)
djm@openbsd.org027607f2018-06-08 01:55:40 +0000819 fatal("%s: no/invalid user", __func__);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100820
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000821 if ((r = sshpkt_get_cstring(ssh, &rtype, NULL)) != 0 ||
822 (r = sshpkt_get_u8(ssh, &want_reply)) != 0)
823 sshpkt_fatal(ssh, r, "%s: parse packet", __func__);
djm@openbsd.org027607f2018-06-08 01:55:40 +0000824 debug("%s: rtype %s want_reply %d", __func__, rtype, want_reply);
Kevin Stevesef4eea92001-02-05 12:42:17 +0000825
Ben Lindstrom7bb8b492001-03-17 00:47:54 +0000826 /* -R style forwarding */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100827 if (strcmp(rtype, "tcpip-forward") == 0) {
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000828 if ((r = sshpkt_get_cstring(ssh, &fwd.listen_host, NULL)) != 0 ||
829 (r = sshpkt_get_u32(ssh, &port)) != 0)
830 sshpkt_fatal(ssh, r, "%s: parse tcpip-forward", __func__);
831 debug("%s: tcpip-forward listen %s port %u", __func__,
832 fwd.listen_host, port);
833 if (port <= INT_MAX)
834 fwd.listen_port = (int)port;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100835 /* check permissions */
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000836 if (port > INT_MAX ||
837 (options.allow_tcp_forwarding & FORWARD_REMOTE) == 0 ||
djm@openbsd.org7c856852018-03-03 03:15:51 +0000838 !auth_opts->permit_port_forwarding_flag ||
839 options.disable_forwarding ||
Darren Tucker5f41f032016-04-08 21:14:13 +1000840 (!want_reply && fwd.listen_port == 0) ||
dtucker@openbsd.org1c4ef0b2016-10-23 22:04:05 +0000841 (fwd.listen_port != 0 &&
842 !bind_permitted(fwd.listen_port, pw->pw_uid))) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100843 success = 0;
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000844 ssh_packet_send_debug(ssh, "Server has disabled port forwarding.");
Damien Miller0bc1bd82000-11-13 22:57:25 +1100845 } else {
846 /* Start listening on the port */
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000847 success = channel_setup_remote_fwd_listener(ssh, &fwd,
Damien Miller7acefbb2014-07-18 14:11:24 +1000848 &allocated_listen_port, &options.fwd_opts);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100849 }
djm@openbsd.org523463a2015-02-16 22:13:32 +0000850 if ((resp = sshbuf_new()) == NULL)
851 fatal("%s: sshbuf_new", __func__);
djm@openbsd.orgb1d6b392015-11-28 06:41:03 +0000852 if (allocated_listen_port != 0 &&
853 (r = sshbuf_put_u32(resp, allocated_listen_port)) != 0)
djm@openbsd.org523463a2015-02-16 22:13:32 +0000854 fatal("%s: sshbuf_put_u32: %s", __func__, ssh_err(r));
Darren Tuckere7066df2004-05-24 10:18:05 +1000855 } else if (strcmp(rtype, "cancel-tcpip-forward") == 0) {
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000856 if ((r = sshpkt_get_cstring(ssh, &fwd.listen_host, NULL)) != 0 ||
857 (r = sshpkt_get_u32(ssh, &port)) != 0)
858 sshpkt_fatal(ssh, r, "%s: parse cancel-tcpip-forward", __func__);
Darren Tuckere7066df2004-05-24 10:18:05 +1000859
Darren Tuckere7066df2004-05-24 10:18:05 +1000860 debug("%s: cancel-tcpip-forward addr %s port %d", __func__,
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000861 fwd.listen_host, port);
862 if (port <= INT_MAX) {
863 fwd.listen_port = (int)port;
864 success = channel_cancel_rport_listener(ssh, &fwd);
865 }
Damien Miller7acefbb2014-07-18 14:11:24 +1000866 } else if (strcmp(rtype, "streamlocal-forward@openssh.com") == 0) {
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000867 if ((r = sshpkt_get_cstring(ssh, &fwd.listen_path, NULL)) != 0)
868 sshpkt_fatal(ssh, r, "%s: parse streamlocal-forward@openssh.com", __func__);
djm@openbsd.org027607f2018-06-08 01:55:40 +0000869 debug("%s: streamlocal-forward listen path %s", __func__,
Damien Miller7acefbb2014-07-18 14:11:24 +1000870 fwd.listen_path);
871
872 /* check permissions */
873 if ((options.allow_streamlocal_forwarding & FORWARD_REMOTE) == 0
djm@openbsd.org7c856852018-03-03 03:15:51 +0000874 || !auth_opts->permit_port_forwarding_flag ||
875 options.disable_forwarding ||
djm@openbsd.org51045862017-01-04 05:37:40 +0000876 (pw->pw_uid != 0 && !use_privsep)) {
Damien Miller7acefbb2014-07-18 14:11:24 +1000877 success = 0;
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000878 ssh_packet_send_debug(ssh, "Server has disabled "
djm@openbsd.org51045862017-01-04 05:37:40 +0000879 "streamlocal forwarding.");
Damien Miller7acefbb2014-07-18 14:11:24 +1000880 } else {
881 /* Start listening on the socket */
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000882 success = channel_setup_remote_fwd_listener(ssh,
Damien Miller7acefbb2014-07-18 14:11:24 +1000883 &fwd, NULL, &options.fwd_opts);
884 }
Damien Miller7acefbb2014-07-18 14:11:24 +1000885 } else if (strcmp(rtype, "cancel-streamlocal-forward@openssh.com") == 0) {
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000886 if ((r = sshpkt_get_cstring(ssh, &fwd.listen_path, NULL)) != 0)
887 sshpkt_fatal(ssh, r, "%s: parse cancel-streamlocal-forward@openssh.com", __func__);
Damien Miller7acefbb2014-07-18 14:11:24 +1000888 debug("%s: cancel-streamlocal-forward path %s", __func__,
889 fwd.listen_path);
890
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000891 success = channel_cancel_rport_listener(ssh, &fwd);
Darren Tucker8901fa92008-06-11 09:34:01 +1000892 } else if (strcmp(rtype, "no-more-sessions@openssh.com") == 0) {
893 no_more_sessions = 1;
894 success = 1;
djm@openbsd.org44732de2015-02-20 22:17:21 +0000895 } else if (strcmp(rtype, "hostkeys-prove-00@openssh.com") == 0) {
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000896 success = server_input_hostkeys_prove(ssh, &resp);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100897 }
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000898 /* XXX sshpkt_get_end() */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100899 if (want_reply) {
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000900 if ((r = sshpkt_start(ssh, success ?
901 SSH2_MSG_REQUEST_SUCCESS : SSH2_MSG_REQUEST_FAILURE)) != 0 ||
902 (success && resp != NULL && (r = sshpkt_putb(ssh, resp)) != 0) ||
903 (r = sshpkt_send(ssh)) != 0 ||
904 (r = ssh_packet_write_wait(ssh)) != 0)
905 sshpkt_fatal(ssh, r, "%s: send reply", __func__);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100906 }
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000907 free(fwd.listen_host);
908 free(fwd.listen_path);
Darren Tuckera627d422013-06-02 07:31:17 +1000909 free(rtype);
djm@openbsd.org523463a2015-02-16 22:13:32 +0000910 sshbuf_free(resp);
markus@openbsd.org3fdc88a2015-01-19 20:07:45 +0000911 return 0;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100912}
Damien Miller4f7becb2006-03-26 14:10:14 +1100913
markus@openbsd.org3fdc88a2015-01-19 20:07:45 +0000914static int
markus@openbsd.org2ae666a2017-05-30 14:23:52 +0000915server_input_channel_req(int type, u_int32_t seq, struct ssh *ssh)
Damien Millerc7ef63d2002-02-05 12:21:42 +1100916{
917 Channel *c;
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000918 int r, success = 0;
919 char *rtype = NULL;
920 u_char want_reply = 0;
921 u_int id = 0;
Damien Millerc7ef63d2002-02-05 12:21:42 +1100922
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000923 if ((r = sshpkt_get_u32(ssh, &id)) != 0 ||
924 (r = sshpkt_get_cstring(ssh, &rtype, NULL)) != 0 ||
925 (r = sshpkt_get_u8(ssh, &want_reply)) != 0)
926 sshpkt_fatal(ssh, r, "%s: parse packet", __func__);
Damien Millerc7ef63d2002-02-05 12:21:42 +1100927
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000928 debug("server_input_channel_req: channel %u request %s reply %d",
929 id, rtype, want_reply);
Damien Millerc7ef63d2002-02-05 12:21:42 +1100930
djm@openbsd.org135e3022019-01-19 22:30:52 +0000931 if (id >= INT_MAX || (c = channel_lookup(ssh, (int)id)) == NULL) {
932 ssh_packet_disconnect(ssh, "%s: unknown channel %d",
933 __func__, id);
934 }
Damien Millerbab9bd42008-05-19 16:06:47 +1000935 if (!strcmp(rtype, "eow@openssh.com")) {
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000936 if ((r = sshpkt_get_end(ssh)) != 0)
937 sshpkt_fatal(ssh, r, "%s: parse packet", __func__);
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000938 chan_rcvd_eow(ssh, c);
Darren Tucker8810dd42008-07-02 22:32:14 +1000939 } else if ((c->type == SSH_CHANNEL_LARVAL ||
940 c->type == SSH_CHANNEL_OPEN) && strcmp(c->ctype, "session") == 0)
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000941 success = session_input_channel_req(ssh, c, rtype);
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000942 if (want_reply && !(c->flags & CHAN_CLOSE_SENT)) {
djm@openbsd.org9f532292017-09-12 06:35:31 +0000943 if (!c->have_remote_id)
944 fatal("%s: channel %d: no remote_id",
945 __func__, c->self);
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000946 if ((r = sshpkt_start(ssh, success ?
947 SSH2_MSG_CHANNEL_SUCCESS : SSH2_MSG_CHANNEL_FAILURE)) != 0 ||
948 (r = sshpkt_put_u32(ssh, c->remote_id)) != 0 ||
949 (r = sshpkt_send(ssh)) != 0)
950 sshpkt_fatal(ssh, r, "%s: send reply", __func__);
Damien Millerc7ef63d2002-02-05 12:21:42 +1100951 }
Darren Tuckera627d422013-06-02 07:31:17 +1000952 free(rtype);
markus@openbsd.org3fdc88a2015-01-19 20:07:45 +0000953 return 0;
Damien Millerc7ef63d2002-02-05 12:21:42 +1100954}
Damien Miller0bc1bd82000-11-13 22:57:25 +1100955
Ben Lindstrombba81212001-06-25 05:01:22 +0000956static void
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000957server_init_dispatch(struct ssh *ssh)
Damien Millerefb4afe2000-04-12 18:45:05 +1000958{
markus@openbsd.org6cb6dcf2016-08-13 17:47:40 +0000959 debug("server_init_dispatch");
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000960 ssh_dispatch_init(ssh, &dispatch_protocol_error);
961 ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_CLOSE, &channel_input_oclose);
962 ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_DATA, &channel_input_data);
963 ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_EOF, &channel_input_ieof);
964 ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_EXTENDED_DATA, &channel_input_extended_data);
965 ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_OPEN, &server_input_channel_open);
966 ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_OPEN_CONFIRMATION, &channel_input_open_confirmation);
967 ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_OPEN_FAILURE, &channel_input_open_failure);
968 ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_REQUEST, &server_input_channel_req);
969 ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_WINDOW_ADJUST, &channel_input_window_adjust);
970 ssh_dispatch_set(ssh, SSH2_MSG_GLOBAL_REQUEST, &server_input_global_request);
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000971 /* client_alive */
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000972 ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_SUCCESS, &server_input_keep_alive);
973 ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_FAILURE, &server_input_keep_alive);
974 ssh_dispatch_set(ssh, SSH2_MSG_REQUEST_SUCCESS, &server_input_keep_alive);
975 ssh_dispatch_set(ssh, SSH2_MSG_REQUEST_FAILURE, &server_input_keep_alive);
Ben Lindstrom8ac91062001-04-04 17:57:54 +0000976 /* rekeying */
djm@openbsd.org7ec5cb42019-01-19 21:40:48 +0000977 ssh_dispatch_set(ssh, SSH2_MSG_KEXINIT, &kex_input_kexinit);
Damien Millerefb4afe2000-04-12 18:45:05 +1000978}