diff options
author | Darren Tucker <dtucker@zip.com.au> | 2008-06-13 04:50:27 +1000 |
---|---|---|
committer | Darren Tucker <dtucker@zip.com.au> | 2008-06-13 04:50:27 +1000 |
commit | 9f407c4422a7f8283eda674e10755d0b4f1c2413 (patch) | |
tree | 64b489e36a0e022ecd27b87c19d7529bf3733464 /ssh.c | |
parent | 2fb66caca2c9e69c6a0584060114fcd52e59d5ff (diff) |
- djm@cvs.openbsd.org 2008/06/12 04:06:00
[clientloop.h ssh.c clientloop.c]
maintain an ordered queue of outstanding global requests that we
expect replies to, similar to the per-channel confirmation queue.
Use this queue to verify success or failure for remote forward
establishment in a race free way.
ok dtucker@
Diffstat (limited to 'ssh.c')
-rw-r--r-- | ssh.c | 53 |
1 files changed, 26 insertions, 27 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssh.c,v 1.314 2008/06/10 22:15:23 djm Exp $ */ | 1 | /* $OpenBSD: ssh.c,v 1.315 2008/06/12 04:06:00 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 |
@@ -164,7 +164,7 @@ Buffer command; | |||
164 | int subsystem_flag = 0; | 164 | int subsystem_flag = 0; |
165 | 165 | ||
166 | /* # of replies received for global requests */ | 166 | /* # of replies received for global requests */ |
167 | static int client_global_request_id = 0; | 167 | static int remote_forward_confirms_received = 0; |
168 | 168 | ||
169 | /* pid of proxycommand child process */ | 169 | /* pid of proxycommand child process */ |
170 | pid_t proxy_command_pid = 0; | 170 | pid_t proxy_command_pid = 0; |
@@ -817,6 +817,28 @@ main(int ac, char **av) | |||
817 | return exit_status; | 817 | return exit_status; |
818 | } | 818 | } |
819 | 819 | ||
820 | /* Callback for remote forward global requests */ | ||
821 | static void | ||
822 | ssh_confirm_remote_forward(int type, u_int32_t seq, void *ctxt) | ||
823 | { | ||
824 | Forward *rfwd = (Forward *)ctxt; | ||
825 | |||
826 | debug("remote forward %s for: listen %d, connect %s:%d", | ||
827 | type == SSH2_MSG_REQUEST_SUCCESS ? "success" : "failure", | ||
828 | rfwd->listen_port, rfwd->connect_host, rfwd->connect_port); | ||
829 | if (type == SSH2_MSG_REQUEST_FAILURE) { | ||
830 | if (options.exit_on_forward_failure) | ||
831 | fatal("Error: remote port forwarding failed for " | ||
832 | "listen port %d", rfwd->listen_port); | ||
833 | else | ||
834 | logit("Warning: remote port forwarding failed for " | ||
835 | "listen port %d", rfwd->listen_port); | ||
836 | } | ||
837 | if (++remote_forward_confirms_received == options.num_remote_forwards) | ||
838 | debug("All remote forwarding requests processed"); | ||
839 | /* XXX fork-after-authentication */ | ||
840 | } | ||
841 | |||
820 | static void | 842 | static void |
821 | ssh_init_forwarding(void) | 843 | ssh_init_forwarding(void) |
822 | { | 844 | { |
@@ -865,6 +887,8 @@ ssh_init_forwarding(void) | |||
865 | logit("Warning: Could not request remote " | 887 | logit("Warning: Could not request remote " |
866 | "forwarding."); | 888 | "forwarding."); |
867 | } | 889 | } |
890 | client_register_global_confirm(ssh_confirm_remote_forward, | ||
891 | &options.remote_forwards[i]); | ||
868 | } | 892 | } |
869 | 893 | ||
870 | /* Initiate tunnel forwarding. */ | 894 | /* Initiate tunnel forwarding. */ |
@@ -1034,31 +1058,6 @@ ssh_session(void) | |||
1034 | options.escape_char : SSH_ESCAPECHAR_NONE, 0); | 1058 | options.escape_char : SSH_ESCAPECHAR_NONE, 0); |
1035 | } | 1059 | } |
1036 | 1060 | ||
1037 | void | ||
1038 | client_global_request_reply_fwd(int type, u_int32_t seq, void *ctxt) | ||
1039 | { | ||
1040 | int i; | ||
1041 | |||
1042 | i = client_global_request_id++; | ||
1043 | if (i >= options.num_remote_forwards) | ||
1044 | return; | ||
1045 | debug("remote forward %s for: listen %d, connect %s:%d", | ||
1046 | type == SSH2_MSG_REQUEST_SUCCESS ? "success" : "failure", | ||
1047 | options.remote_forwards[i].listen_port, | ||
1048 | options.remote_forwards[i].connect_host, | ||
1049 | options.remote_forwards[i].connect_port); | ||
1050 | if (type == SSH2_MSG_REQUEST_FAILURE) { | ||
1051 | if (options.exit_on_forward_failure) | ||
1052 | fatal("Error: remote port forwarding failed for " | ||
1053 | "listen port %d", | ||
1054 | options.remote_forwards[i].listen_port); | ||
1055 | else | ||
1056 | logit("Warning: remote port forwarding failed for " | ||
1057 | "listen port %d", | ||
1058 | options.remote_forwards[i].listen_port); | ||
1059 | } | ||
1060 | } | ||
1061 | |||
1062 | /* request pty/x11/agent/tcpfwd/shell for channel */ | 1061 | /* request pty/x11/agent/tcpfwd/shell for channel */ |
1063 | static void | 1062 | static void |
1064 | ssh_session2_setup(int id, void *arg) | 1063 | ssh_session2_setup(int id, void *arg) |