summaryrefslogtreecommitdiff
path: root/ssh.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2008-06-13 04:50:27 +1000
committerDarren Tucker <dtucker@zip.com.au>2008-06-13 04:50:27 +1000
commit9f407c4422a7f8283eda674e10755d0b4f1c2413 (patch)
tree64b489e36a0e022ecd27b87c19d7529bf3733464 /ssh.c
parent2fb66caca2c9e69c6a0584060114fcd52e59d5ff (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.c53
1 files changed, 26 insertions, 27 deletions
diff --git a/ssh.c b/ssh.c
index e3737bb9c..6c39c85b9 100644
--- a/ssh.c
+++ b/ssh.c
@@ -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;
164int subsystem_flag = 0; 164int subsystem_flag = 0;
165 165
166/* # of replies received for global requests */ 166/* # of replies received for global requests */
167static int client_global_request_id = 0; 167static int remote_forward_confirms_received = 0;
168 168
169/* pid of proxycommand child process */ 169/* pid of proxycommand child process */
170pid_t proxy_command_pid = 0; 170pid_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 */
821static void
822ssh_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
820static void 842static void
821ssh_init_forwarding(void) 843ssh_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
1037void
1038client_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 */
1063static void 1062static void
1064ssh_session2_setup(int id, void *arg) 1063ssh_session2_setup(int id, void *arg)