diff options
author | djm@openbsd.org <djm@openbsd.org> | 2019-12-21 03:19:13 +0100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2019-12-21 03:22:07 +0100 |
commit | 40be78f503277bd91c958fa25ea9ef918a2ffd3d (patch) | |
tree | b17303fad21f97437b44cf3264a03abfd503ebdf /ssh.c | |
parent | upstream: SSH U2F keys can now be used as host keys. Fix a garden (diff) | |
download | openssh-40be78f503277bd91c958fa25ea9ef918a2ffd3d.tar.xz openssh-40be78f503277bd91c958fa25ea9ef918a2ffd3d.zip |
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.c | 34 |
1 files changed, 33 insertions, 1 deletions
@@ -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); |