summaryrefslogtreecommitdiff
path: root/serverloop.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2004-03-01 02:25:32 +0000
committerColin Watson <cjwatson@debian.org>2004-03-01 02:25:32 +0000
commitea8116a11e3de70036dbc665ccb0d486cf89cac9 (patch)
treed73ccdff78d8608e156465af42e6a1b3527fb2d6 /serverloop.c
parente39b311381a5609cc05acf298c42fba196dc524b (diff)
parentf5bda272678ec6dccaa5f29379cf60cb855018e8 (diff)
Merge 3.8p1 to the trunk. This builds and runs, but I haven't tested it
extensively yet. ProtocolKeepAlives is now just a compatibility alias for ServerAliveInterval.
Diffstat (limited to 'serverloop.c')
-rw-r--r--serverloop.c60
1 files changed, 28 insertions, 32 deletions
diff --git a/serverloop.c b/serverloop.c
index 6dbb4fd12..c4e35a377 100644
--- a/serverloop.c
+++ b/serverloop.c
@@ -35,7 +35,7 @@
35 */ 35 */
36 36
37#include "includes.h" 37#include "includes.h"
38RCSID("$OpenBSD: serverloop.c,v 1.110 2003/06/24 08:23:46 markus Exp $"); 38RCSID("$OpenBSD: serverloop.c,v 1.115 2004/01/19 21:25:15 markus Exp $");
39 39
40#include "xmalloc.h" 40#include "xmalloc.h"
41#include "packet.h" 41#include "packet.h"
@@ -60,7 +60,7 @@ extern ServerOptions options;
60 60
61/* XXX */ 61/* XXX */
62extern Kex *xxx_kex; 62extern Kex *xxx_kex;
63static Authctxt *xxx_authctxt; 63extern Authctxt *the_authctxt;
64 64
65static Buffer stdin_buffer; /* Buffer for stdin data. */ 65static Buffer stdin_buffer; /* Buffer for stdin data. */
66static Buffer stdout_buffer; /* Buffer for stdout data. */ 66static Buffer stdout_buffer; /* Buffer for stdout data. */
@@ -212,26 +212,23 @@ make_packets_from_stdout_data(void)
212static void 212static void
213client_alive_check(void) 213client_alive_check(void)
214{ 214{
215 static int had_channel = 0; 215 int channel_id;
216 int id;
217
218 id = channel_find_open();
219 if (id == -1) {
220 if (!had_channel)
221 return;
222 packet_disconnect("No open channels after timeout!");
223 }
224 had_channel = 1;
225 216
226 /* timeout, check to see how many we have had */ 217 /* timeout, check to see how many we have had */
227 if (++client_alive_timeouts > options.client_alive_count_max) 218 if (++client_alive_timeouts > options.client_alive_count_max)
228 packet_disconnect("Timeout, your session not responding."); 219 packet_disconnect("Timeout, your session not responding.");
229 220
230 /* 221 /*
231 * send a bogus channel request with "wantreply", 222 * send a bogus global/channel request with "wantreply",
232 * we should get back a failure 223 * we should get back a failure
233 */ 224 */
234 channel_request_start(id, "keepalive@openssh.com", 1); 225 if ((channel_id = channel_find_open()) == -1) {
226 packet_start(SSH2_MSG_GLOBAL_REQUEST);
227 packet_put_cstring("keepalive@openssh.com");
228 packet_put_char(1); /* boolean: want reply */
229 } else {
230 channel_request_start(channel_id, "keepalive@openssh.com", 1);
231 }
235 packet_send(); 232 packet_send();
236} 233}
237 234
@@ -355,13 +352,13 @@ process_input(fd_set * readset)
355 connection_closed = 1; 352 connection_closed = 1;
356 if (compat20) 353 if (compat20)
357 return; 354 return;
358 fatal_cleanup(); 355 cleanup_exit(255);
359 } else if (len < 0) { 356 } else if (len < 0) {
360 if (errno != EINTR && errno != EAGAIN) { 357 if (errno != EINTR && errno != EAGAIN) {
361 verbose("Read error from remote host " 358 verbose("Read error from remote host "
362 "%.100s: %.100s", 359 "%.100s: %.100s",
363 get_remote_ipaddr(), strerror(errno)); 360 get_remote_ipaddr(), strerror(errno));
364 fatal_cleanup(); 361 cleanup_exit(255);
365 } 362 }
366 } else { 363 } else {
367 /* Buffer any received data. */ 364 /* Buffer any received data. */
@@ -756,8 +753,6 @@ server_loop2(Authctxt *authctxt)
756 max_fd = MAX(connection_in, connection_out); 753 max_fd = MAX(connection_in, connection_out);
757 max_fd = MAX(max_fd, notify_pipe[0]); 754 max_fd = MAX(max_fd, notify_pipe[0]);
758 755
759 xxx_authctxt = authctxt;
760
761 server_init_dispatch(); 756 server_init_dispatch();
762 757
763 for (;;) { 758 for (;;) {
@@ -799,9 +794,9 @@ server_loop2(Authctxt *authctxt)
799} 794}
800 795
801static void 796static void
802server_input_channel_failure(int type, u_int32_t seq, void *ctxt) 797server_input_keep_alive(int type, u_int32_t seq, void *ctxt)
803{ 798{
804 debug("Got CHANNEL_FAILURE for keepalive"); 799 debug("Got %d/%u for keepalive", type, seq);
805 /* 800 /*
806 * reset timeout, since we got a sane answer from the client. 801 * reset timeout, since we got a sane answer from the client.
807 * even if this was generated by something other than 802 * even if this was generated by something other than
@@ -810,7 +805,6 @@ server_input_channel_failure(int type, u_int32_t seq, void *ctxt)
810 client_alive_timeouts = 0; 805 client_alive_timeouts = 0;
811} 806}
812 807
813
814static void 808static void
815server_input_stdin_data(int type, u_int32_t seq, void *ctxt) 809server_input_stdin_data(int type, u_int32_t seq, void *ctxt)
816{ 810{
@@ -856,7 +850,7 @@ server_input_window_size(int type, u_int32_t seq, void *ctxt)
856} 850}
857 851
858static Channel * 852static Channel *
859server_request_direct_tcpip(char *ctype) 853server_request_direct_tcpip(void)
860{ 854{
861 Channel *c; 855 Channel *c;
862 int sock; 856 int sock;
@@ -878,14 +872,14 @@ server_request_direct_tcpip(char *ctype)
878 xfree(originator); 872 xfree(originator);
879 if (sock < 0) 873 if (sock < 0)
880 return NULL; 874 return NULL;
881 c = channel_new(ctype, SSH_CHANNEL_CONNECTING, 875 c = channel_new("direct-tcpip", SSH_CHANNEL_CONNECTING,
882 sock, sock, -1, CHAN_TCP_WINDOW_DEFAULT, 876 sock, sock, -1, CHAN_TCP_WINDOW_DEFAULT,
883 CHAN_TCP_PACKET_DEFAULT, 0, "direct-tcpip", 1); 877 CHAN_TCP_PACKET_DEFAULT, 0, "direct-tcpip", 1);
884 return c; 878 return c;
885} 879}
886 880
887static Channel * 881static Channel *
888server_request_session(char *ctype) 882server_request_session(void)
889{ 883{
890 Channel *c; 884 Channel *c;
891 885
@@ -897,10 +891,10 @@ server_request_session(char *ctype)
897 * SSH_CHANNEL_LARVAL. Additionally, a callback for handling all 891 * SSH_CHANNEL_LARVAL. Additionally, a callback for handling all
898 * CHANNEL_REQUEST messages is registered. 892 * CHANNEL_REQUEST messages is registered.
899 */ 893 */
900 c = channel_new(ctype, SSH_CHANNEL_LARVAL, 894 c = channel_new("session", SSH_CHANNEL_LARVAL,
901 -1, -1, -1, /*window size*/0, CHAN_SES_PACKET_DEFAULT, 895 -1, -1, -1, /*window size*/0, CHAN_SES_PACKET_DEFAULT,
902 0, "server-session", 1); 896 0, "server-session", 1);
903 if (session_open(xxx_authctxt, c->self) != 1) { 897 if (session_open(the_authctxt, c->self) != 1) {
904 debug("session open failed, free channel %d", c->self); 898 debug("session open failed, free channel %d", c->self);
905 channel_free(c); 899 channel_free(c);
906 return NULL; 900 return NULL;
@@ -926,9 +920,9 @@ server_input_channel_open(int type, u_int32_t seq, void *ctxt)
926 ctype, rchan, rwindow, rmaxpack); 920 ctype, rchan, rwindow, rmaxpack);
927 921
928 if (strcmp(ctype, "session") == 0) { 922 if (strcmp(ctype, "session") == 0) {
929 c = server_request_session(ctype); 923 c = server_request_session();
930 } else if (strcmp(ctype, "direct-tcpip") == 0) { 924 } else if (strcmp(ctype, "direct-tcpip") == 0) {
931 c = server_request_direct_tcpip(ctype); 925 c = server_request_direct_tcpip();
932 } 926 }
933 if (c != NULL) { 927 if (c != NULL) {
934 debug("server_input_channel_open: confirm %s", ctype); 928 debug("server_input_channel_open: confirm %s", ctype);
@@ -974,9 +968,9 @@ server_input_global_request(int type, u_int32_t seq, void *ctxt)
974 char *listen_address; 968 char *listen_address;
975 u_short listen_port; 969 u_short listen_port;
976 970
977 pw = auth_get_user(); 971 pw = the_authctxt->pw;
978 if (pw == NULL) 972 if (pw == NULL || !the_authctxt->valid)
979 fatal("server_input_global_request: no user"); 973 fatal("server_input_global_request: no/invalid user");
980 listen_address = packet_get_string(NULL); 974 listen_address = packet_get_string(NULL);
981 listen_port = (u_short)packet_get_int(); 975 listen_port = (u_short)packet_get_int();
982 debug("server_input_global_request: tcpip-forward listen %s port %d", 976 debug("server_input_global_request: tcpip-forward listen %s port %d",
@@ -1050,7 +1044,9 @@ server_init_dispatch_20(void)
1050 dispatch_set(SSH2_MSG_CHANNEL_WINDOW_ADJUST, &channel_input_window_adjust); 1044 dispatch_set(SSH2_MSG_CHANNEL_WINDOW_ADJUST, &channel_input_window_adjust);
1051 dispatch_set(SSH2_MSG_GLOBAL_REQUEST, &server_input_global_request); 1045 dispatch_set(SSH2_MSG_GLOBAL_REQUEST, &server_input_global_request);
1052 /* client_alive */ 1046 /* client_alive */
1053 dispatch_set(SSH2_MSG_CHANNEL_FAILURE, &server_input_channel_failure); 1047 dispatch_set(SSH2_MSG_CHANNEL_FAILURE, &server_input_keep_alive);
1048 dispatch_set(SSH2_MSG_REQUEST_SUCCESS, &server_input_keep_alive);
1049 dispatch_set(SSH2_MSG_REQUEST_FAILURE, &server_input_keep_alive);
1054 /* rekeying */ 1050 /* rekeying */
1055 dispatch_set(SSH2_MSG_KEXINIT, &kex_input_kexinit); 1051 dispatch_set(SSH2_MSG_KEXINIT, &kex_input_kexinit);
1056} 1052}