summaryrefslogtreecommitdiff
path: root/usr.bin/ssh/sshconnect.c
diff options
context:
space:
mode:
authorDamien Miller <djm@cvs.openbsd.org>2019-09-13 04:27:36 +0000
committerDamien Miller <djm@cvs.openbsd.org>2019-09-13 04:27:36 +0000
commiteef477855e863d2648901e1232cebfd946d99642 (patch)
tree53c30ee2b16aac4d44efed3b53061c1c0288edf8 /usr.bin/ssh/sshconnect.c
parent055b3b7036bddec35450fef578812d3b8ed06247 (diff)
allow %n to be expanded in ProxyCommand strings
From Zachary Harmany via github.com/openssh/openssh-portable/pull/118 ok dtucker@
Diffstat (limited to 'usr.bin/ssh/sshconnect.c')
-rw-r--r--usr.bin/ssh/sshconnect.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/usr.bin/ssh/sshconnect.c b/usr.bin/ssh/sshconnect.c
index cf50da405ec..768425ecae9 100644
--- a/usr.bin/ssh/sshconnect.c
+++ b/usr.bin/ssh/sshconnect.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sshconnect.c,v 1.317 2019/06/28 13:35:04 deraadt Exp $ */
+/* $OpenBSD: sshconnect.c,v 1.318 2019/09/13 04:27:35 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -73,14 +73,18 @@ static void warn_changed_key(struct sshkey *);
/* Expand a proxy command */
static char *
expand_proxy_command(const char *proxy_command, const char *user,
- const char *host, int port)
+ const char *host, const char *host_arg, int port)
{
char *tmp, *ret, strport[NI_MAXSERV];
snprintf(strport, sizeof strport, "%d", port);
xasprintf(&tmp, "exec %s", proxy_command);
- ret = percent_expand(tmp, "h", host, "p", strport,
- "r", options.user, (char *)NULL);
+ ret = percent_expand(tmp,
+ "h", host,
+ "n", host_arg,
+ "p", strport,
+ "r", options.user,
+ (char *)NULL);
free(tmp);
return ret;
}
@@ -108,8 +112,8 @@ stderr_null(void)
* a connected fd back to us.
*/
static int
-ssh_proxy_fdpass_connect(struct ssh *ssh, const char *host, u_short port,
- const char *proxy_command)
+ssh_proxy_fdpass_connect(struct ssh *ssh, const char *host,
+ const char *host_arg, u_short port, const char *proxy_command)
{
char *command_string;
int sp[2], sock;
@@ -124,7 +128,7 @@ ssh_proxy_fdpass_connect(struct ssh *ssh, const char *host, u_short port,
"proxy dialer: %.100s", strerror(errno));
command_string = expand_proxy_command(proxy_command, options.user,
- host, port);
+ host_arg, host, port);
debug("Executing proxy dialer command: %.500s", command_string);
/* Fork and execute the proxy command. */
@@ -190,8 +194,8 @@ ssh_proxy_fdpass_connect(struct ssh *ssh, const char *host, u_short port,
* Connect to the given ssh server using a proxy command.
*/
static int
-ssh_proxy_connect(struct ssh *ssh, const char *host, u_short port,
- const char *proxy_command)
+ssh_proxy_connect(struct ssh *ssh, const char *host, const char *host_arg,
+ u_short port, const char *proxy_command)
{
char *command_string;
int pin[2], pout[2];
@@ -207,7 +211,7 @@ ssh_proxy_connect(struct ssh *ssh, const char *host, u_short port,
strerror(errno));
command_string = expand_proxy_command(proxy_command, options.user,
- host, port);
+ host_arg, host, port);
debug("Executing proxy command: %.500s", command_string);
/* Fork and execute the proxy command. */
@@ -519,9 +523,9 @@ ssh_connect_direct(struct ssh *ssh, const char *host, struct addrinfo *aitop,
}
int
-ssh_connect(struct ssh *ssh, const char *host, struct addrinfo *addrs,
- struct sockaddr_storage *hostaddr, u_short port, int family,
- int connection_attempts, int *timeout_ms, int want_keepalive)
+ssh_connect(struct ssh *ssh, const char *host, const char *host_arg,
+ struct addrinfo *addrs, struct sockaddr_storage *hostaddr, u_short port,
+ int family, int connection_attempts, int *timeout_ms, int want_keepalive)
{
int in, out;
@@ -540,10 +544,11 @@ ssh_connect(struct ssh *ssh, const char *host, struct addrinfo *addrs,
return -1; /* ssh_packet_set_connection logs error */
return 0;
} else if (options.proxy_use_fdpass) {
- return ssh_proxy_fdpass_connect(ssh, host, port,
+ return ssh_proxy_fdpass_connect(ssh, host, host_arg, port,
options.proxy_command);
}
- return ssh_proxy_connect(ssh, host, port, options.proxy_command);
+ return ssh_proxy_connect(ssh, host, host_arg, port,
+ options.proxy_command);
}
/* defaults to 'no' */