diff options
author | djm@openbsd.org <djm@openbsd.org> | 2019-09-13 04:27:35 +0000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2019-09-13 14:28:44 +1000 |
commit | fbe24b142915331ceb2a3a76be3dc5b6d204fddf (patch) | |
tree | 6adb5c456a64cdd74ca004a6ec8633cc53f4eac9 | |
parent | 2ce1d11600e13bee0667d6b717ffcc18a057b821 (diff) |
upstream: allow %n to be expanded in ProxyCommand strings
From Zachary Harmany via github.com/openssh/openssh-portable/pull/118
ok dtucker@
OpenBSD-Commit-ID: 7eebf1b7695f50c66d42053d352a4db9e8fb84b6
-rw-r--r-- | ssh.c | 4 | ||||
-rw-r--r-- | ssh_config.5 | 4 | ||||
-rw-r--r-- | sshconnect.c | 35 | ||||
-rw-r--r-- | sshconnect.h | 7 |
4 files changed, 28 insertions, 22 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssh.c,v 1.506 2019/09/06 14:45:34 naddy Exp $ */ | 1 | /* $OpenBSD: ssh.c,v 1.507 2019/09/13 04:27:35 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 |
@@ -1369,7 +1369,7 @@ main(int ac, char **av) | |||
1369 | timeout_ms = options.connection_timeout * 1000; | 1369 | timeout_ms = options.connection_timeout * 1000; |
1370 | 1370 | ||
1371 | /* Open a connection to the remote host. */ | 1371 | /* Open a connection to the remote host. */ |
1372 | if (ssh_connect(ssh, host, addrs, &hostaddr, options.port, | 1372 | if (ssh_connect(ssh, host_arg, host, addrs, &hostaddr, options.port, |
1373 | options.address_family, options.connection_attempts, | 1373 | options.address_family, options.connection_attempts, |
1374 | &timeout_ms, options.tcp_keep_alive) != 0) | 1374 | &timeout_ms, options.tcp_keep_alive) != 0) |
1375 | exit(255); | 1375 | exit(255); |
diff --git a/ssh_config.5 b/ssh_config.5 index b10c55492..867c916a7 100644 --- a/ssh_config.5 +++ b/ssh_config.5 | |||
@@ -33,7 +33,7 @@ | |||
33 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 33 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
34 | .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 34 | .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" $OpenBSD: ssh_config.5,v 1.302 2019/09/13 04:07:42 djm Exp $ | 36 | .\" $OpenBSD: ssh_config.5,v 1.303 2019/09/13 04:27:35 djm Exp $ |
37 | .Dd $Mdocdate: September 13 2019 $ | 37 | .Dd $Mdocdate: September 13 2019 $ |
38 | .Dt SSH_CONFIG 5 | 38 | .Dt SSH_CONFIG 5 |
39 | .Os | 39 | .Os |
@@ -1821,7 +1821,7 @@ accept the tokens %%, %d, %h, %i, %l, %r, and %u. | |||
1821 | accepts the tokens %%, %C, %d, %h, %i, %l, %n, %p, %r, %T, and %u. | 1821 | accepts the tokens %%, %C, %d, %h, %i, %l, %n, %p, %r, %T, and %u. |
1822 | .Pp | 1822 | .Pp |
1823 | .Cm ProxyCommand | 1823 | .Cm ProxyCommand |
1824 | accepts the tokens %%, %h, %p, and %r. | 1824 | accepts the tokens %%, %h, %n, %p, and %r. |
1825 | .Pp | 1825 | .Pp |
1826 | .Cm RemoteCommand | 1826 | .Cm RemoteCommand |
1827 | accepts the tokens %%, %C, %d, %h, %i, %l, %n, %p, %r, and %u. | 1827 | accepts the tokens %%, %C, %d, %h, %i, %l, %n, %p, %r, and %u. |
diff --git a/sshconnect.c b/sshconnect.c index ed44fccb8..740780443 100644 --- a/sshconnect.c +++ b/sshconnect.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sshconnect.c,v 1.317 2019/06/28 13:35:04 deraadt Exp $ */ | 1 | /* $OpenBSD: sshconnect.c,v 1.318 2019/09/13 04:27:35 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 |
@@ -87,14 +87,18 @@ static void warn_changed_key(struct sshkey *); | |||
87 | /* Expand a proxy command */ | 87 | /* Expand a proxy command */ |
88 | static char * | 88 | static char * |
89 | expand_proxy_command(const char *proxy_command, const char *user, | 89 | expand_proxy_command(const char *proxy_command, const char *user, |
90 | const char *host, int port) | 90 | const char *host, const char *host_arg, int port) |
91 | { | 91 | { |
92 | char *tmp, *ret, strport[NI_MAXSERV]; | 92 | char *tmp, *ret, strport[NI_MAXSERV]; |
93 | 93 | ||
94 | snprintf(strport, sizeof strport, "%d", port); | 94 | snprintf(strport, sizeof strport, "%d", port); |
95 | xasprintf(&tmp, "exec %s", proxy_command); | 95 | xasprintf(&tmp, "exec %s", proxy_command); |
96 | ret = percent_expand(tmp, "h", host, "p", strport, | 96 | ret = percent_expand(tmp, |
97 | "r", options.user, (char *)NULL); | 97 | "h", host, |
98 | "n", host_arg, | ||
99 | "p", strport, | ||
100 | "r", options.user, | ||
101 | (char *)NULL); | ||
98 | free(tmp); | 102 | free(tmp); |
99 | return ret; | 103 | return ret; |
100 | } | 104 | } |
@@ -122,8 +126,8 @@ stderr_null(void) | |||
122 | * a connected fd back to us. | 126 | * a connected fd back to us. |
123 | */ | 127 | */ |
124 | static int | 128 | static int |
125 | ssh_proxy_fdpass_connect(struct ssh *ssh, const char *host, u_short port, | 129 | ssh_proxy_fdpass_connect(struct ssh *ssh, const char *host, |
126 | const char *proxy_command) | 130 | const char *host_arg, u_short port, const char *proxy_command) |
127 | { | 131 | { |
128 | char *command_string; | 132 | char *command_string; |
129 | int sp[2], sock; | 133 | int sp[2], sock; |
@@ -138,7 +142,7 @@ ssh_proxy_fdpass_connect(struct ssh *ssh, const char *host, u_short port, | |||
138 | "proxy dialer: %.100s", strerror(errno)); | 142 | "proxy dialer: %.100s", strerror(errno)); |
139 | 143 | ||
140 | command_string = expand_proxy_command(proxy_command, options.user, | 144 | command_string = expand_proxy_command(proxy_command, options.user, |
141 | host, port); | 145 | host_arg, host, port); |
142 | debug("Executing proxy dialer command: %.500s", command_string); | 146 | debug("Executing proxy dialer command: %.500s", command_string); |
143 | 147 | ||
144 | /* Fork and execute the proxy command. */ | 148 | /* Fork and execute the proxy command. */ |
@@ -204,8 +208,8 @@ ssh_proxy_fdpass_connect(struct ssh *ssh, const char *host, u_short port, | |||
204 | * Connect to the given ssh server using a proxy command. | 208 | * Connect to the given ssh server using a proxy command. |
205 | */ | 209 | */ |
206 | static int | 210 | static int |
207 | ssh_proxy_connect(struct ssh *ssh, const char *host, u_short port, | 211 | ssh_proxy_connect(struct ssh *ssh, const char *host, const char *host_arg, |
208 | const char *proxy_command) | 212 | u_short port, const char *proxy_command) |
209 | { | 213 | { |
210 | char *command_string; | 214 | char *command_string; |
211 | int pin[2], pout[2]; | 215 | int pin[2], pout[2]; |
@@ -221,7 +225,7 @@ ssh_proxy_connect(struct ssh *ssh, const char *host, u_short port, | |||
221 | strerror(errno)); | 225 | strerror(errno)); |
222 | 226 | ||
223 | command_string = expand_proxy_command(proxy_command, options.user, | 227 | command_string = expand_proxy_command(proxy_command, options.user, |
224 | host, port); | 228 | host_arg, host, port); |
225 | debug("Executing proxy command: %.500s", command_string); | 229 | debug("Executing proxy command: %.500s", command_string); |
226 | 230 | ||
227 | /* Fork and execute the proxy command. */ | 231 | /* Fork and execute the proxy command. */ |
@@ -543,9 +547,9 @@ ssh_connect_direct(struct ssh *ssh, const char *host, struct addrinfo *aitop, | |||
543 | } | 547 | } |
544 | 548 | ||
545 | int | 549 | int |
546 | ssh_connect(struct ssh *ssh, const char *host, struct addrinfo *addrs, | 550 | ssh_connect(struct ssh *ssh, const char *host, const char *host_arg, |
547 | struct sockaddr_storage *hostaddr, u_short port, int family, | 551 | struct addrinfo *addrs, struct sockaddr_storage *hostaddr, u_short port, |
548 | int connection_attempts, int *timeout_ms, int want_keepalive) | 552 | int family, int connection_attempts, int *timeout_ms, int want_keepalive) |
549 | { | 553 | { |
550 | int in, out; | 554 | int in, out; |
551 | 555 | ||
@@ -564,10 +568,11 @@ ssh_connect(struct ssh *ssh, const char *host, struct addrinfo *addrs, | |||
564 | return -1; /* ssh_packet_set_connection logs error */ | 568 | return -1; /* ssh_packet_set_connection logs error */ |
565 | return 0; | 569 | return 0; |
566 | } else if (options.proxy_use_fdpass) { | 570 | } else if (options.proxy_use_fdpass) { |
567 | return ssh_proxy_fdpass_connect(ssh, host, port, | 571 | return ssh_proxy_fdpass_connect(ssh, host, host_arg, port, |
568 | options.proxy_command); | 572 | options.proxy_command); |
569 | } | 573 | } |
570 | return ssh_proxy_connect(ssh, host, port, options.proxy_command); | 574 | return ssh_proxy_connect(ssh, host, host_arg, port, |
575 | options.proxy_command); | ||
571 | } | 576 | } |
572 | 577 | ||
573 | /* defaults to 'no' */ | 578 | /* defaults to 'no' */ |
diff --git a/sshconnect.h b/sshconnect.h index b455d7c20..2e84b8bc5 100644 --- a/sshconnect.h +++ b/sshconnect.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sshconnect.h,v 1.38 2019/06/21 04:21:05 djm Exp $ */ | 1 | /* $OpenBSD: sshconnect.h,v 1.39 2019/09/13 04:27:35 djm Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2000 Markus Friedl. All rights reserved. | 4 | * Copyright (c) 2000 Markus Friedl. All rights reserved. |
@@ -33,8 +33,9 @@ struct Sensitive { | |||
33 | struct addrinfo; | 33 | struct addrinfo; |
34 | struct ssh; | 34 | struct ssh; |
35 | 35 | ||
36 | int ssh_connect(struct ssh *, const char *, struct addrinfo *, | 36 | int ssh_connect(struct ssh *, const char *, const char *, |
37 | struct sockaddr_storage *, u_short, int, int, int *, int); | 37 | struct addrinfo *, struct sockaddr_storage *, u_short, |
38 | int, int, int *, int); | ||
38 | void ssh_kill_proxy_command(void); | 39 | void ssh_kill_proxy_command(void); |
39 | 40 | ||
40 | void ssh_login(struct ssh *, Sensitive *, const char *, | 41 | void ssh_login(struct ssh *, Sensitive *, const char *, |