summaryrefslogtreecommitdiff
path: root/ssh.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2019-12-21 02:19:13 +0000
committerDamien Miller <djm@mindrot.org>2019-12-21 13:22:07 +1100
commit40be78f503277bd91c958fa25ea9ef918a2ffd3d (patch)
treeb17303fad21f97437b44cf3264a03abfd503ebdf /ssh.c
parent416f15372bfb5be1709a0ad1d00ef5d8ebfb9e0e (diff)
upstream: 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@ OpenBSD-Commit-ID: 98f2ed80bf34ea54d8b2ddd19ac14ebbf40e9265
Diffstat (limited to 'ssh.c')
-rw-r--r--ssh.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/ssh.c b/ssh.c
index 13299f7d..12760af2 100644
--- a/ssh.c
+++ b/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
@@ -168,6 +168,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;
@@ -1498,6 +1504,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);