summaryrefslogtreecommitdiff
path: root/usr.bin/ssh/ssh.c
diff options
context:
space:
mode:
authorDamien Miller <djm@cvs.openbsd.org>2019-12-21 02:19:14 +0000
committerDamien Miller <djm@cvs.openbsd.org>2019-12-21 02:19:14 +0000
commitca9d78e5ab97e829184267f11c8d8cf5053d1fb4 (patch)
treee0e47372762017f21e852e4d840c83ca03dbfd94 /usr.bin/ssh/ssh.c
parente2aed18bef0d9db54bed39a75261e64679857a12 (diff)
Allow forwarding a different agent socket to the path specified by
$SSH_AUTH_SOCK, by extending the existing ForwardAgent option to accepting an explicit path or the name of an environment variable in addition to yes/no. Patch by Eric Chiang, manpage by me; ok markus@
Diffstat (limited to 'usr.bin/ssh/ssh.c')
-rw-r--r--usr.bin/ssh/ssh.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/usr.bin/ssh/ssh.c b/usr.bin/ssh/ssh.c
index 6454e59d67e..255ab192fbd 100644
--- a/usr.bin/ssh/ssh.c
+++ b/usr.bin/ssh/ssh.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh.c,v 1.509 2019/11/18 16:10:05 naddy Exp $ */
+/* $OpenBSD: ssh.c,v 1.510 2019/12/21 02:19:13 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -152,6 +152,12 @@ char *config = NULL;
*/
char *host;
+/*
+ * A config can specify a path to forward, overriding SSH_AUTH_SOCK. If this is
+ * not NULL, forward the socket at this path instead.
+ */
+char *forward_agent_sock_path = NULL;
+
/* Various strings used to to percent_expand() arguments */
static char thishost[NI_MAXHOST], shorthost[NI_MAXHOST], portstr[NI_MAXSERV];
static char uidstr[32], *host_arg, *conn_hash_hex;
@@ -1471,6 +1477,32 @@ main(int ac, char **av)
}
}
+ if (options.forward_agent && (options.forward_agent_sock_path != NULL)) {
+ p = tilde_expand_filename(options.forward_agent_sock_path, getuid());
+ cp = percent_expand(p,
+ "d", pw->pw_dir,
+ "h", host,
+ "i", uidstr,
+ "l", thishost,
+ "r", options.user,
+ "u", pw->pw_name,
+ (char *)NULL);
+ free(p);
+
+ if (cp[0] == '$') {
+ if (!valid_env_name(cp + 1)) {
+ fatal("Invalid ForwardAgent environment variable name %s", cp);
+ }
+ if ((p = getenv(cp + 1)) != NULL)
+ forward_agent_sock_path = p;
+ else
+ options.forward_agent = 0;
+ free(cp);
+ } else {
+ forward_agent_sock_path = cp;
+ }
+ }
+
/* Expand ~ in known host file names. */
tilde_expand_paths(options.system_hostfiles,
options.num_system_hostfiles);