diff options
author | Darren Tucker <dtucker@zip.com.au> | 2011-11-04 10:54:22 +1100 |
---|---|---|
committer | Darren Tucker <dtucker@zip.com.au> | 2011-11-04 10:54:22 +1100 |
commit | 2d6665d944439e48b2d7c283eaddfee0890236e8 (patch) | |
tree | a660052dc10f2be2d08ca451febb28633f871450 /ssh.c | |
parent | 8a057953d2c9e7462e85147c23c65da4a4cfddbc (diff) |
- djm@cvs.openbsd.org 2011/10/24 02:10:46
[ssh.c]
bz#1943: unbreak stdio forwarding when ControlPersist is in user - ssh
was incorrectly requesting the forward in both the control master and
slave. skip requesting it in the master to fix. ok markus@
Diffstat (limited to 'ssh.c')
-rw-r--r-- | ssh.c | 52 |
1 files changed, 27 insertions, 25 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssh.c,v 1.367 2011/10/18 05:15:28 djm Exp $ */ | 1 | /* $OpenBSD: ssh.c,v 1.368 2011/10/24 02:10:46 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 |
@@ -1059,25 +1059,26 @@ client_cleanup_stdio_fwd(int id, void *arg) | |||
1059 | cleanup_exit(0); | 1059 | cleanup_exit(0); |
1060 | } | 1060 | } |
1061 | 1061 | ||
1062 | static int | 1062 | static void |
1063 | client_setup_stdio_fwd(const char *host_to_connect, u_short port_to_connect) | 1063 | ssh_init_stdio_forwarding(void) |
1064 | { | 1064 | { |
1065 | Channel *c; | 1065 | Channel *c; |
1066 | int in, out; | 1066 | int in, out; |
1067 | 1067 | ||
1068 | debug3("client_setup_stdio_fwd %s:%d", host_to_connect, | 1068 | if (stdio_forward_host == NULL) |
1069 | port_to_connect); | 1069 | return; |
1070 | if (!compat20) | ||
1071 | fatal("stdio forwarding require Protocol 2"); | ||
1070 | 1072 | ||
1071 | in = dup(STDIN_FILENO); | 1073 | debug3("%s: %s:%d", __func__, stdio_forward_host, stdio_forward_port); |
1072 | out = dup(STDOUT_FILENO); | ||
1073 | if (in < 0 || out < 0) | ||
1074 | fatal("channel_connect_stdio_fwd: dup() in/out failed"); | ||
1075 | 1074 | ||
1076 | if ((c = channel_connect_stdio_fwd(host_to_connect, port_to_connect, | 1075 | if ((in = dup(STDIN_FILENO)) < 0 || |
1077 | in, out)) == NULL) | 1076 | (out = dup(STDOUT_FILENO)) < 0) |
1078 | return 0; | 1077 | fatal("channel_connect_stdio_fwd: dup() in/out failed"); |
1078 | if ((c = channel_connect_stdio_fwd(stdio_forward_host, | ||
1079 | stdio_forward_port, in, out)) == NULL) | ||
1080 | fatal("%s: channel_connect_stdio_fwd failed", __func__); | ||
1079 | channel_register_cleanup(c->self, client_cleanup_stdio_fwd, 0); | 1081 | channel_register_cleanup(c->self, client_cleanup_stdio_fwd, 0); |
1080 | return 1; | ||
1081 | } | 1082 | } |
1082 | 1083 | ||
1083 | static void | 1084 | static void |
@@ -1086,15 +1087,6 @@ ssh_init_forwarding(void) | |||
1086 | int success = 0; | 1087 | int success = 0; |
1087 | int i; | 1088 | int i; |
1088 | 1089 | ||
1089 | if (stdio_forward_host != NULL) { | ||
1090 | if (!compat20) { | ||
1091 | fatal("stdio forwarding require Protocol 2"); | ||
1092 | } | ||
1093 | if (!client_setup_stdio_fwd(stdio_forward_host, | ||
1094 | stdio_forward_port)) | ||
1095 | fatal("Failed to connect in stdio forward mode."); | ||
1096 | } | ||
1097 | |||
1098 | /* Initiate local TCP/IP port forwardings. */ | 1090 | /* Initiate local TCP/IP port forwardings. */ |
1099 | for (i = 0; i < options.num_local_forwards; i++) { | 1091 | for (i = 0; i < options.num_local_forwards; i++) { |
1100 | debug("Local connections to %.200s:%d forwarded to remote " | 1092 | debug("Local connections to %.200s:%d forwarded to remote " |
@@ -1285,6 +1277,7 @@ ssh_session(void) | |||
1285 | } | 1277 | } |
1286 | 1278 | ||
1287 | /* Initiate port forwardings. */ | 1279 | /* Initiate port forwardings. */ |
1280 | ssh_init_stdio_forwarding(); | ||
1288 | ssh_init_forwarding(); | 1281 | ssh_init_forwarding(); |
1289 | 1282 | ||
1290 | /* Execute a local command */ | 1283 | /* Execute a local command */ |
@@ -1423,15 +1416,18 @@ ssh_session2(void) | |||
1423 | int id = -1; | 1416 | int id = -1; |
1424 | 1417 | ||
1425 | /* XXX should be pre-session */ | 1418 | /* XXX should be pre-session */ |
1419 | if (!options.control_persist) | ||
1420 | ssh_init_stdio_forwarding(); | ||
1426 | ssh_init_forwarding(); | 1421 | ssh_init_forwarding(); |
1427 | 1422 | ||
1428 | /* Start listening for multiplex clients */ | 1423 | /* Start listening for multiplex clients */ |
1429 | muxserver_listen(); | 1424 | muxserver_listen(); |
1430 | 1425 | ||
1431 | /* | 1426 | /* |
1432 | * If we are in control persist mode, then prepare to background | 1427 | * If we are in control persist mode and have a working mux listen |
1433 | * ourselves and have a foreground client attach as a control | 1428 | * socket, then prepare to background ourselves and have a foreground |
1434 | * slave. NB. we must save copies of the flags that we override for | 1429 | * client attach as a control slave. |
1430 | * NB. we must save copies of the flags that we override for | ||
1435 | * the backgrounding, since we defer attachment of the slave until | 1431 | * the backgrounding, since we defer attachment of the slave until |
1436 | * after the connection is fully established (in particular, | 1432 | * after the connection is fully established (in particular, |
1437 | * async rfwd replies have been received for ExitOnForwardFailure). | 1433 | * async rfwd replies have been received for ExitOnForwardFailure). |
@@ -1448,6 +1444,12 @@ ssh_session2(void) | |||
1448 | need_controlpersist_detach = 1; | 1444 | need_controlpersist_detach = 1; |
1449 | fork_after_authentication_flag = 1; | 1445 | fork_after_authentication_flag = 1; |
1450 | } | 1446 | } |
1447 | /* | ||
1448 | * ControlPersist mux listen socket setup failed, attempt the | ||
1449 | * stdio forward setup that we skipped earlier. | ||
1450 | */ | ||
1451 | if (options.control_persist && muxserver_sock == -1) | ||
1452 | ssh_init_stdio_forwarding(); | ||
1451 | 1453 | ||
1452 | if (!no_shell_flag || (datafellows & SSH_BUG_DUMMYCHAN)) | 1454 | if (!no_shell_flag || (datafellows & SSH_BUG_DUMMYCHAN)) |
1453 | id = ssh_session2_open(); | 1455 | id = ssh_session2_open(); |