[PATCH 1/1] uid for expansion in ControlPath

Christian Hesse list at eworm.de
Thu Aug 6 15:51:37 AEST 2015


From: Christian Hesse <mail at eworm.de>

Modern Linux systems create a private directory in /run/user/ for each
user, named by numeric user id (uid). This adds a new character sequence
'%i' for expansion in ControlPath to match this (and possibly other)
directory.

Signed-off-by: Christian Hesse <mail at eworm.de>
---
 ssh.c        | 5 ++++-
 ssh_config.5 | 4 +++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/ssh.c b/ssh.c
index 59c1f93..c4de144 100644
--- a/ssh.c
+++ b/ssh.c
@@ -505,7 +505,8 @@ main(int ac, char **av)
 {
 	int i, r, opt, exit_status, use_syslog, config_test = 0;
 	char *p, *cp, *line, *argv0, buf[PATH_MAX], *host_arg, *logfile;
-	char thishost[NI_MAXHOST], shorthost[NI_MAXHOST], portstr[NI_MAXSERV];
+	char thishost[NI_MAXHOST], shorthost[NI_MAXHOST], portstr[NI_MAXSERV],
+	    uidstr[11];
 	char cname[NI_MAXHOST];
 	struct stat st;
 	struct passwd *pw;
@@ -1122,6 +1123,7 @@ main(int ac, char **av)
 	strlcpy(shorthost, thishost, sizeof(shorthost));
 	shorthost[strcspn(thishost, ".")] = '\0';
 	snprintf(portstr, sizeof(portstr), "%d", options.port);
+	snprintf(uidstr, sizeof(uidstr), "%d", pw->pw_uid);
 
 	if ((md = ssh_digest_start(SSH_DIGEST_SHA1)) == NULL ||
 	    ssh_digest_update(md, thishost, strlen(thishost)) < 0 ||
@@ -1164,6 +1166,7 @@ main(int ac, char **av)
 		    "p", portstr,
 		    "r", options.user,
 		    "u", pw->pw_name,
+		    "i", uidstr,
 		    (char *)NULL);
 		free(cp);
 	}
diff --git a/ssh_config.5 b/ssh_config.5
index 5b0975f..489452e 100644
--- a/ssh_config.5
+++ b/ssh_config.5
@@ -538,7 +538,9 @@ the destination port,
 .Ql %r
 by the remote login username,
 .Ql %u
-by the username of the user running
+by the username and
+.Ql %i
+by the numeric user id (uid) of the user running
 .Xr ssh 1 , and
 .Ql \&%C
 by a hash of the concatenation: %l%h%p%r.
-- 
2.5.0



More information about the openssh-unix-dev mailing list