summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2007-08-08 14:32:41 +1000
committerDamien Miller <djm@mindrot.org>2007-08-08 14:32:41 +1000
commitb3ce9fec309a6dd695811d977593961d6dfac710 (patch)
treee6449a59c3fcb324aac3da765c0dbf5eee56d559
parent647d97b1ab1f8ef4dfa6c7a085b409e1c3609c6f (diff)
- djm@cvs.openbsd.org 2007/08/07 07:32:53
[clientloop.c clientloop.h ssh.c] bz#1232: ensure that any specified LocalCommand is executed after the tunnel device is opened. Also, make failures to open a tunnel device fatal when ExitOnForwardFailure is active. Reported by h.goebel AT goebel-consult.de; ok dtucker markus reyk deraadt
-rw-r--r--ChangeLog8
-rw-r--r--clientloop.c46
-rw-r--r--clientloop.h3
-rw-r--r--ssh.c44
4 files changed, 69 insertions, 32 deletions
diff --git a/ChangeLog b/ChangeLog
index c4a7d1261..55319fc23 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,12 @@
10 and synopsis of commands 10 and synopsis of commands
11 lots of good ideas by jmc@ 11 lots of good ideas by jmc@
12 ok jmc@ 12 ok jmc@
13 - djm@cvs.openbsd.org 2007/08/07 07:32:53
14 [clientloop.c clientloop.h ssh.c]
15 bz#1232: ensure that any specified LocalCommand is executed after the
16 tunnel device is opened. Also, make failures to open a tunnel device
17 fatal when ExitOnForwardFailure is active.
18 Reported by h.goebel AT goebel-consult.de; ok dtucker markus reyk deraadt
13 19
1420070724 2020070724
15 - (tim) [openssh.xml.in] make FMRI match what package scripts use. 21 - (tim) [openssh.xml.in] make FMRI match what package scripts use.
@@ -3129,4 +3135,4 @@
3129 OpenServer 6 and add osr5bigcrypt support so when someone migrates 3135 OpenServer 6 and add osr5bigcrypt support so when someone migrates
3130 passwords between UnixWare and OpenServer they will still work. OK dtucker@ 3136 passwords between UnixWare and OpenServer they will still work. OK dtucker@
3131 3137
3132$Id: ChangeLog,v 1.4717 2007/08/08 04:29:58 djm Exp $ 3138$Id: ChangeLog,v 1.4718 2007/08/08 04:32:41 djm Exp $
diff --git a/clientloop.c b/clientloop.c
index 1aeb412a9..538644c20 100644
--- a/clientloop.c
+++ b/clientloop.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: clientloop.c,v 1.179 2007/03/20 03:56:12 tedu Exp $ */ 1/* $OpenBSD: clientloop.c,v 1.180 2007/08/07 07:32:53 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
@@ -1773,6 +1773,50 @@ client_request_agent(const char *request_type, int rchan)
1773 return c; 1773 return c;
1774} 1774}
1775 1775
1776int
1777client_request_tun_fwd(int tun_mode, int local_tun, int remote_tun)
1778{
1779 Channel *c;
1780 int fd;
1781
1782 if (tun_mode == SSH_TUNMODE_NO)
1783 return 0;
1784
1785 if (!compat20) {
1786 error("Tunnel forwarding is not support for protocol 1");
1787 return -1;
1788 }
1789
1790 debug("Requesting tun unit %d in mode %d", local_tun, tun_mode);
1791
1792 /* Open local tunnel device */
1793 if ((fd = tun_open(local_tun, tun_mode)) == -1) {
1794 error("Tunnel device open failed.");
1795 return -1;
1796 }
1797
1798 c = channel_new("tun", SSH_CHANNEL_OPENING, fd, fd, -1,
1799 CHAN_TCP_WINDOW_DEFAULT, CHAN_TCP_PACKET_DEFAULT, 0, "tun", 1);
1800 c->datagram = 1;
1801
1802#if defined(SSH_TUN_FILTER)
1803 if (options.tun_open == SSH_TUNMODE_POINTOPOINT)
1804 channel_register_filter(c->self, sys_tun_infilter,
1805 sys_tun_outfilter);
1806#endif
1807
1808 packet_start(SSH2_MSG_CHANNEL_OPEN);
1809 packet_put_cstring("tun@openssh.com");
1810 packet_put_int(c->self);
1811 packet_put_int(c->local_window_max);
1812 packet_put_int(c->local_maxpacket);
1813 packet_put_int(tun_mode);
1814 packet_put_int(remote_tun);
1815 packet_send();
1816
1817 return 0;
1818}
1819
1776/* XXXX move to generic input handler */ 1820/* XXXX move to generic input handler */
1777static void 1821static void
1778client_input_channel_open(int type, u_int32_t seq, void *ctxt) 1822client_input_channel_open(int type, u_int32_t seq, void *ctxt)
diff --git a/clientloop.h b/clientloop.h
index beec62f70..c7d2233d0 100644
--- a/clientloop.h
+++ b/clientloop.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: clientloop.h,v 1.16 2006/03/25 22:22:42 djm Exp $ */ 1/* $OpenBSD: clientloop.h,v 1.17 2007/08/07 07:32:53 djm Exp $ */
2 2
3/* 3/*
4 * Author: Tatu Ylonen <ylo@cs.hut.fi> 4 * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -44,6 +44,7 @@ void client_x11_get_proto(const char *, const char *, u_int,
44void client_global_request_reply_fwd(int, u_int32_t, void *); 44void client_global_request_reply_fwd(int, u_int32_t, void *);
45void client_session2_setup(int, int, int, const char *, struct termios *, 45void client_session2_setup(int, int, int, const char *, struct termios *,
46 int, Buffer *, char **, dispatch_fn *); 46 int, Buffer *, char **, dispatch_fn *);
47int client_request_tun_fwd(int, int, int);
47 48
48/* Multiplexing protocol version */ 49/* Multiplexing protocol version */
49#define SSHMUX_VER 1 50#define SSHMUX_VER 1
diff --git a/ssh.c b/ssh.c
index 449ec256e..d3a7ffc9b 100644
--- a/ssh.c
+++ b/ssh.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh.c,v 1.300 2007/06/14 22:48:05 djm Exp $ */ 1/* $OpenBSD: ssh.c,v 1.301 2007/08/07 07:32:53 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
@@ -857,6 +857,17 @@ ssh_init_forwarding(void)
857 "forwarding."); 857 "forwarding.");
858 } 858 }
859 } 859 }
860
861 /* Initiate tunnel forwarding. */
862 if (options.tun_open != SSH_TUNMODE_NO) {
863 if (client_request_tun_fwd(options.tun_open,
864 options.tun_local, options.tun_remote) == -1) {
865 if (options.exit_on_forward_failure)
866 fatal("Could not request tunnel forwarding.");
867 else
868 error("Could not request tunnel forwarding.");
869 }
870 }
860} 871}
861 872
862static void 873static void
@@ -1119,33 +1130,6 @@ ssh_session2_setup(int id, void *arg)
1119 packet_send(); 1130 packet_send();
1120 } 1131 }
1121 1132
1122 if (options.tun_open != SSH_TUNMODE_NO) {
1123 Channel *c;
1124 int fd;
1125
1126 debug("Requesting tun.");
1127 if ((fd = tun_open(options.tun_local,
1128 options.tun_open)) >= 0) {
1129 c = channel_new("tun", SSH_CHANNEL_OPENING, fd, fd, -1,
1130 CHAN_TCP_WINDOW_DEFAULT, CHAN_TCP_PACKET_DEFAULT,
1131 0, "tun", 1);
1132 c->datagram = 1;
1133#if defined(SSH_TUN_FILTER)
1134 if (options.tun_open == SSH_TUNMODE_POINTOPOINT)
1135 channel_register_filter(c->self, sys_tun_infilter,
1136 sys_tun_outfilter);
1137#endif
1138 packet_start(SSH2_MSG_CHANNEL_OPEN);
1139 packet_put_cstring("tun@openssh.com");
1140 packet_put_int(c->self);
1141 packet_put_int(c->local_window_max);
1142 packet_put_int(c->local_maxpacket);
1143 packet_put_int(options.tun_open);
1144 packet_put_int(options.tun_remote);
1145 packet_send();
1146 }
1147 }
1148
1149 client_session2_setup(id, tty_flag, subsystem_flag, getenv("TERM"), 1133 client_session2_setup(id, tty_flag, subsystem_flag, getenv("TERM"),
1150 NULL, fileno(stdin), &command, environ, &ssh_subsystem_reply); 1134 NULL, fileno(stdin), &command, environ, &ssh_subsystem_reply);
1151 1135
@@ -1205,7 +1189,6 @@ ssh_session2(void)
1205 1189
1206 /* XXX should be pre-session */ 1190 /* XXX should be pre-session */
1207 ssh_init_forwarding(); 1191 ssh_init_forwarding();
1208 ssh_control_listener();
1209 1192
1210 if (!no_shell_flag || (datafellows & SSH_BUG_DUMMYCHAN)) 1193 if (!no_shell_flag || (datafellows & SSH_BUG_DUMMYCHAN))
1211 id = ssh_session2_open(); 1194 id = ssh_session2_open();
@@ -1215,6 +1198,9 @@ ssh_session2(void)
1215 options.permit_local_command) 1198 options.permit_local_command)
1216 ssh_local_cmd(options.local_command); 1199 ssh_local_cmd(options.local_command);
1217 1200
1201 /* Start listening for multiplex clients */
1202 ssh_control_listener();
1203
1218 /* If requested, let ssh continue in the background. */ 1204 /* If requested, let ssh continue in the background. */
1219 if (fork_after_authentication_flag) 1205 if (fork_after_authentication_flag)
1220 if (daemon(1, 1) < 0) 1206 if (daemon(1, 1) < 0)