diff options
-rw-r--r-- | clientloop.c | 67 |
1 files changed, 32 insertions, 35 deletions
diff --git a/clientloop.c b/clientloop.c index 5f87b24a2..521467bd2 100644 --- a/clientloop.c +++ b/clientloop.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: clientloop.c,v 1.320 2019/01/19 21:33:57 djm Exp $ */ | 1 | /* $OpenBSD: clientloop.c,v 1.321 2019/01/19 21:39:12 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -112,9 +112,6 @@ | |||
112 | #include "ssherr.h" | 112 | #include "ssherr.h" |
113 | #include "hostfile.h" | 113 | #include "hostfile.h" |
114 | 114 | ||
115 | #include "opacket.h" /* XXX */ | ||
116 | extern struct ssh *active_state; /* XXX */ | ||
117 | |||
118 | /* import options */ | 115 | /* import options */ |
119 | extern Options options; | 116 | extern Options options; |
120 | 117 | ||
@@ -163,7 +160,7 @@ static int need_rekeying; /* Set to non-zero if rekeying is requested. */ | |||
163 | static int session_closed; /* In SSH2: login session closed. */ | 160 | static int session_closed; /* In SSH2: login session closed. */ |
164 | static u_int x11_refuse_time; /* If >0, refuse x11 opens after this time. */ | 161 | static u_int x11_refuse_time; /* If >0, refuse x11 opens after this time. */ |
165 | 162 | ||
166 | static void client_init_dispatch(void); | 163 | static void client_init_dispatch(struct ssh *ssh); |
167 | int session_ident = -1; | 164 | int session_ident = -1; |
168 | 165 | ||
169 | /* Track escape per proto2 channel */ | 166 | /* Track escape per proto2 channel */ |
@@ -515,7 +512,7 @@ client_wait_until_can_do_something(struct ssh *ssh, | |||
515 | int r, ret; | 512 | int r, ret; |
516 | 513 | ||
517 | /* Add any selections by the channel mechanism. */ | 514 | /* Add any selections by the channel mechanism. */ |
518 | channel_prepare_select(active_state, readsetp, writesetp, maxfdp, | 515 | channel_prepare_select(ssh, readsetp, writesetp, maxfdp, |
519 | nallocp, &minwait_secs); | 516 | nallocp, &minwait_secs); |
520 | 517 | ||
521 | /* channel_prepare_select could have closed the last channel */ | 518 | /* channel_prepare_select could have closed the last channel */ |
@@ -1189,9 +1186,9 @@ process_escapes(struct ssh *ssh, Channel *c, | |||
1189 | */ | 1186 | */ |
1190 | 1187 | ||
1191 | static void | 1188 | static void |
1192 | client_process_buffered_input_packets(void) | 1189 | client_process_buffered_input_packets(struct ssh *ssh) |
1193 | { | 1190 | { |
1194 | ssh_dispatch_run_fatal(active_state, DISPATCH_NONBLOCK, &quit_pending); | 1191 | ssh_dispatch_run_fatal(ssh, DISPATCH_NONBLOCK, &quit_pending); |
1195 | } | 1192 | } |
1196 | 1193 | ||
1197 | /* scan buf[] for '~' before sending data to the peer */ | 1194 | /* scan buf[] for '~' before sending data to the peer */ |
@@ -1298,7 +1295,7 @@ client_loop(struct ssh *ssh, int have_pty, int escape_char_arg, | |||
1298 | if ((stderr_buffer = sshbuf_new()) == NULL) | 1295 | if ((stderr_buffer = sshbuf_new()) == NULL) |
1299 | fatal("%s: sshbuf_new failed", __func__); | 1296 | fatal("%s: sshbuf_new failed", __func__); |
1300 | 1297 | ||
1301 | client_init_dispatch(); | 1298 | client_init_dispatch(ssh); |
1302 | 1299 | ||
1303 | /* | 1300 | /* |
1304 | * Set signal handlers, (e.g. to restore non-blocking mode) | 1301 | * Set signal handlers, (e.g. to restore non-blocking mode) |
@@ -1334,7 +1331,7 @@ client_loop(struct ssh *ssh, int have_pty, int escape_char_arg, | |||
1334 | while (!quit_pending) { | 1331 | while (!quit_pending) { |
1335 | 1332 | ||
1336 | /* Process buffered packets sent by the server. */ | 1333 | /* Process buffered packets sent by the server. */ |
1337 | client_process_buffered_input_packets(); | 1334 | client_process_buffered_input_packets(ssh); |
1338 | 1335 | ||
1339 | if (session_closed && !channel_still_open(ssh)) | 1336 | if (session_closed && !channel_still_open(ssh)) |
1340 | break; | 1337 | break; |
@@ -1577,7 +1574,7 @@ client_request_x11(struct ssh *ssh, const char *request_type, int rchan) | |||
1577 | { | 1574 | { |
1578 | Channel *c = NULL; | 1575 | Channel *c = NULL; |
1579 | char *originator; | 1576 | char *originator; |
1580 | int originator_port; | 1577 | u_int originator_port; |
1581 | int r, sock; | 1578 | int r, sock; |
1582 | 1579 | ||
1583 | if (!options.forward_x11) { | 1580 | if (!options.forward_x11) { |
@@ -1592,11 +1589,12 @@ client_request_x11(struct ssh *ssh, const char *request_type, int rchan) | |||
1592 | return NULL; | 1589 | return NULL; |
1593 | } | 1590 | } |
1594 | if ((r = sshpkt_get_cstring(ssh, &originator, NULL)) != 0 || | 1591 | if ((r = sshpkt_get_cstring(ssh, &originator, NULL)) != 0 || |
1595 | (r = sshpkt_get_u32(ssh, (u_int *)&originator_port)) != 0 || | 1592 | (r = sshpkt_get_u32(ssh, &originator_port)) != 0 || |
1596 | (r = sshpkt_get_end(ssh)) != 0) | 1593 | (r = sshpkt_get_end(ssh)) != 0) |
1597 | fatal("%s: %s", __func__, ssh_err(r)); | 1594 | fatal("%s: %s", __func__, ssh_err(r)); |
1598 | /* XXX check permission */ | 1595 | /* XXX check permission */ |
1599 | debug("client_request_x11: request from %s %d", originator, | 1596 | /* XXX range check originator port? */ |
1597 | debug("client_request_x11: request from %s %u", originator, | ||
1600 | originator_port); | 1598 | originator_port); |
1601 | free(originator); | 1599 | free(originator); |
1602 | sock = x11_connect_display(ssh); | 1600 | sock = x11_connect_display(ssh); |
@@ -1673,7 +1671,7 @@ client_request_tun_fwd(struct ssh *ssh, int tun_mode, | |||
1673 | (r = sshpkt_put_u32(ssh, tun_mode)) != 0 || | 1671 | (r = sshpkt_put_u32(ssh, tun_mode)) != 0 || |
1674 | (r = sshpkt_put_u32(ssh, remote_tun)) != 0 || | 1672 | (r = sshpkt_put_u32(ssh, remote_tun)) != 0 || |
1675 | (r = sshpkt_send(ssh)) != 0) | 1673 | (r = sshpkt_send(ssh)) != 0) |
1676 | fatal("%s: %s", __func__, ssh_err(r)); | 1674 | sshpkt_fatal(ssh, r, "%s: send reply", __func__); |
1677 | 1675 | ||
1678 | return ifname; | 1676 | return ifname; |
1679 | } | 1677 | } |
@@ -2055,9 +2053,8 @@ key_accepted_by_hostkeyalgs(const struct sshkey *key) | |||
2055 | * HostkeyAlgorithms preference before they are accepted. | 2053 | * HostkeyAlgorithms preference before they are accepted. |
2056 | */ | 2054 | */ |
2057 | static int | 2055 | static int |
2058 | client_input_hostkeys(void) | 2056 | client_input_hostkeys(struct ssh *ssh) |
2059 | { | 2057 | { |
2060 | struct ssh *ssh = active_state; /* XXX */ | ||
2061 | const u_char *blob = NULL; | 2058 | const u_char *blob = NULL; |
2062 | size_t i, len = 0; | 2059 | size_t i, len = 0; |
2063 | struct sshbuf *buf = NULL; | 2060 | struct sshbuf *buf = NULL; |
@@ -2217,7 +2214,7 @@ client_input_global_request(int type, u_int32_t seq, struct ssh *ssh) | |||
2217 | debug("client_input_global_request: rtype %s want_reply %d", | 2214 | debug("client_input_global_request: rtype %s want_reply %d", |
2218 | rtype, want_reply); | 2215 | rtype, want_reply); |
2219 | if (strcmp(rtype, "hostkeys-00@openssh.com") == 0) | 2216 | if (strcmp(rtype, "hostkeys-00@openssh.com") == 0) |
2220 | success = client_input_hostkeys(); | 2217 | success = client_input_hostkeys(ssh); |
2221 | if (want_reply) { | 2218 | if (want_reply) { |
2222 | if ((r = sshpkt_start(ssh, success ? SSH2_MSG_REQUEST_SUCCESS : | 2219 | if ((r = sshpkt_start(ssh, success ? SSH2_MSG_REQUEST_SUCCESS : |
2223 | SSH2_MSG_REQUEST_FAILURE)) != 0 || | 2220 | SSH2_MSG_REQUEST_FAILURE)) != 0 || |
@@ -2353,29 +2350,29 @@ client_session2_setup(struct ssh *ssh, int id, int want_tty, int want_subsystem, | |||
2353 | } | 2350 | } |
2354 | 2351 | ||
2355 | static void | 2352 | static void |
2356 | client_init_dispatch(void) | 2353 | client_init_dispatch(struct ssh *ssh) |
2357 | { | 2354 | { |
2358 | dispatch_init(&dispatch_protocol_error); | 2355 | ssh_dispatch_init(ssh, &dispatch_protocol_error); |
2359 | 2356 | ||
2360 | dispatch_set(SSH2_MSG_CHANNEL_CLOSE, &channel_input_oclose); | 2357 | ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_CLOSE, &channel_input_oclose); |
2361 | dispatch_set(SSH2_MSG_CHANNEL_DATA, &channel_input_data); | 2358 | ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_DATA, &channel_input_data); |
2362 | dispatch_set(SSH2_MSG_CHANNEL_EOF, &channel_input_ieof); | 2359 | ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_EOF, &channel_input_ieof); |
2363 | dispatch_set(SSH2_MSG_CHANNEL_EXTENDED_DATA, &channel_input_extended_data); | 2360 | ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_EXTENDED_DATA, &channel_input_extended_data); |
2364 | dispatch_set(SSH2_MSG_CHANNEL_OPEN, &client_input_channel_open); | 2361 | ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_OPEN, &client_input_channel_open); |
2365 | dispatch_set(SSH2_MSG_CHANNEL_OPEN_CONFIRMATION, &channel_input_open_confirmation); | 2362 | ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_OPEN_CONFIRMATION, &channel_input_open_confirmation); |
2366 | dispatch_set(SSH2_MSG_CHANNEL_OPEN_FAILURE, &channel_input_open_failure); | 2363 | ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_OPEN_FAILURE, &channel_input_open_failure); |
2367 | dispatch_set(SSH2_MSG_CHANNEL_REQUEST, &client_input_channel_req); | 2364 | ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_REQUEST, &client_input_channel_req); |
2368 | dispatch_set(SSH2_MSG_CHANNEL_WINDOW_ADJUST, &channel_input_window_adjust); | 2365 | ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_WINDOW_ADJUST, &channel_input_window_adjust); |
2369 | dispatch_set(SSH2_MSG_CHANNEL_SUCCESS, &channel_input_status_confirm); | 2366 | ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_SUCCESS, &channel_input_status_confirm); |
2370 | dispatch_set(SSH2_MSG_CHANNEL_FAILURE, &channel_input_status_confirm); | 2367 | ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_FAILURE, &channel_input_status_confirm); |
2371 | dispatch_set(SSH2_MSG_GLOBAL_REQUEST, &client_input_global_request); | 2368 | ssh_dispatch_set(ssh, SSH2_MSG_GLOBAL_REQUEST, &client_input_global_request); |
2372 | 2369 | ||
2373 | /* rekeying */ | 2370 | /* rekeying */ |
2374 | dispatch_set(SSH2_MSG_KEXINIT, &kex_input_kexinit); | 2371 | ssh_dispatch_set(ssh, SSH2_MSG_KEXINIT, &kex_input_kexinit); |
2375 | 2372 | ||
2376 | /* global request reply messages */ | 2373 | /* global request reply messages */ |
2377 | dispatch_set(SSH2_MSG_REQUEST_FAILURE, &client_global_request_reply); | 2374 | ssh_dispatch_set(ssh, SSH2_MSG_REQUEST_FAILURE, &client_global_request_reply); |
2378 | dispatch_set(SSH2_MSG_REQUEST_SUCCESS, &client_global_request_reply); | 2375 | ssh_dispatch_set(ssh, SSH2_MSG_REQUEST_SUCCESS, &client_global_request_reply); |
2379 | } | 2376 | } |
2380 | 2377 | ||
2381 | void | 2378 | void |