View | Details | Raw Unified | Return to bug 1654
Collapse All | Expand All

(-)usr.bin/ssh/ssh.c (+16 lines)
Lines 638-643 main(int ac, char **av) Link Here
638
	struct Forward fwd;
638
	struct Forward fwd;
639
	struct addrinfo *addrs = NULL;
639
	struct addrinfo *addrs = NULL;
640
	size_t n, len;
640
	size_t n, len;
641
	u_int j;
641
642
642
	/* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
643
	/* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
643
	sanitise_stdfd();
644
	sanitise_stdfd();
Lines 1404-1409 main(int ac, char **av) Link Here
1404
		free(p);
1405
		free(p);
1405
		free(options.forward_agent_sock_path);
1406
		free(options.forward_agent_sock_path);
1406
		options.forward_agent_sock_path = cp;
1407
		options.forward_agent_sock_path = cp;
1408
	}
1409
1410
	for (j = 0; j < options.num_user_hostfiles; j++) {
1411
		if (options.user_hostfiles[j] != NULL) {
1412
			cp = tilde_expand_filename(options.user_hostfiles[j],
1413
			    getuid());
1414
			p = default_client_percent_dollar_expand(cp,
1415
			    pw->pw_dir, host, options.user, pw->pw_name);
1416
			if (strcmp(options.user_hostfiles[j], p) != 0)
1417
				debug3("expanded UserKnownHostsFile '%s' -> "
1418
				    "'%s'", options.user_hostfiles[j], p);
1419
			free(options.user_hostfiles[j]);
1420
			free(cp);
1421
			options.user_hostfiles[j] = p;
1422
		}
1407
	}
1423
	}
1408
1424
1409
	for (i = 0; i < options.num_local_forwards; i++) {
1425
	for (i = 0; i < options.num_local_forwards; i++) {
(-)usr.bin/ssh/ssh_config.5 (-3 / +11 lines)
Lines 1739-1744 having to remember to give the user name Link Here
1739
.It Cm UserKnownHostsFile
1739
.It Cm UserKnownHostsFile
1740
Specifies one or more files to use for the user
1740
Specifies one or more files to use for the user
1741
host key database, separated by whitespace.
1741
host key database, separated by whitespace.
1742
Each filename may use tilde notation to refer to the user's home directory,
1743
the tokens described in the
1744
.Sx TOKENS
1745
section and environment variables as described in the
1746
.Sx ENVIRONMENT VARIABLES
1747
section.
1742
The default is
1748
The default is
1743
.Pa ~/.ssh/known_hosts ,
1749
.Pa ~/.ssh/known_hosts ,
1744
.Pa ~/.ssh/known_hosts2 .
1750
.Pa ~/.ssh/known_hosts2 .
Lines 1875-1882 The local username. Link Here
1875
.Cm LocalForward ,
1881
.Cm LocalForward ,
1876
.Cm Match exec ,
1882
.Cm Match exec ,
1877
.Cm RemoteCommand ,
1883
.Cm RemoteCommand ,
1884
.Cm RemoteForward ,
1878
and
1885
and
1879
.Cm RemoteForward
1886
.Com UserKnownHostsFile
1880
accept the tokens %%, %C, %d, %h, %i, %L, %l, %n, %p, %r, and %u.
1887
accept the tokens %%, %C, %d, %h, %i, %L, %l, %n, %p, %r, and %u.
1881
.Pp
1888
.Pp
1882
.Cm Hostname
1889
.Cm Hostname
Lines 1900-1908 returned and the setting for that keywor Link Here
1900
The keywords
1907
The keywords
1901
.Cm CertificateFile ,
1908
.Cm CertificateFile ,
1902
.Cm ControlPath ,
1909
.Cm ControlPath ,
1903
.Cm IdentityAgent
1910
.Cm IdentityAgent ,
1904
and
1905
.Cm IdentityFile
1911
.Cm IdentityFile
1912
and
1913
.Cm UserKnownHostsFile
1906
support environment variables.
1914
support environment variables.
1907
The keywords
1915
The keywords
1908
.Cm LocalForward
1916
.Cm LocalForward
(-)regress/usr.bin/ssh/percent.sh (-9 / +28 lines)
Lines 20-31 trial() Link Here
20
20
21
	trace "test $opt=$arg $expect"
21
	trace "test $opt=$arg $expect"
22
	rm -f $OBJ/actual
22
	rm -f $OBJ/actual
23
	got=""
23
	case "$opt" in
24
	case "$opt" in
24
	localcommand)
25
	localcommand)
25
		${SSH} -F $OBJ/ssh_proxy -o $opt="echo '$arg' >$OBJ/actual" \
26
		${SSH} -F $OBJ/ssh_proxy -o $opt="echo '$arg' >$OBJ/actual" \
26
		    somehost true
27
		    somehost true
27
		got=`cat $OBJ/actual`
28
		got=`cat $OBJ/actual`
28
		;;
29
		;;
30
	userknownhostsfile)
31
		# Move the userknownhosts file to what the expansion says,
32
		# make sure ssh works then put it back.
33
		mv "$OBJ/known_hosts" "$OBJ/$expect"
34
		${SSH} -F $OBJ/ssh_proxy -o $opt="$OBJ/$arg" somehost true && \
35
			got="$expect"
36
		mv "$OBJ/$expect" "$OBJ/known_hosts"
37
		;;
29
	matchexec)
38
	matchexec)
30
		(cat $OBJ/ssh_proxy && \
39
		(cat $OBJ/ssh_proxy && \
31
		 echo "Match Exec \"echo '$arg' >$OBJ/actual\"") \
40
		 echo "Match Exec \"echo '$arg' >$OBJ/actual\"") \
Lines 50-62 trial() Link Here
50
}
59
}
51
60
52
for i in matchexec localcommand remotecommand controlpath identityagent \
61
for i in matchexec localcommand remotecommand controlpath identityagent \
53
    forwardagent localforward remoteforward; do
62
    forwardagent localforward remoteforward userknownhostsfile; do
54
	verbose $tid $i percent
63
	verbose $tid $i percent
55
	if [ "$i" = "localcommand" ]; then
64
	case "$i" in
56
		REMUSER=$USER
65
	localcommand|userknownhostsfile)
66
		# Any test that's going to actually make a connection needs
67
		# to use the real username.
68
		REMUSER=$USER ;;
69
	*)
70
		REMUSER=remuser ;;
71
	esac
72
	if [ "$i" = "$localcommand" ]; then
57
		trial $i '%T' NONE
73
		trial $i '%T' NONE
58
	else
59
		REMUSER=remuser
60
	fi
74
	fi
61
	# Matches implementation in readconf.c:ssh_connection_hash()
75
	# Matches implementation in readconf.c:ssh_connection_hash()
62
	HASH=`printf "${HOSTNAME}127.0.0.1${PORT}$REMUSER" |
76
	HASH=`printf "${HOSTNAME}127.0.0.1${PORT}$REMUSER" |
Lines 65-84 for i in matchexec localcommand remoteco Link Here
65
	trial $i '%C' $HASH
79
	trial $i '%C' $HASH
66
	trial $i '%i' $USERID
80
	trial $i '%i' $USERID
67
	trial $i '%h' 127.0.0.1
81
	trial $i '%h' 127.0.0.1
68
	trial $i '%d' $HOME
69
	trial $i '%L' $HOST
82
	trial $i '%L' $HOST
70
	trial $i '%l' $HOSTNAME
83
	trial $i '%l' $HOSTNAME
71
	trial $i '%n' somehost
84
	trial $i '%n' somehost
72
	trial $i '%p' $PORT
85
	trial $i '%p' $PORT
73
	trial $i '%r' $REMUSER
86
	trial $i '%r' $REMUSER
74
	trial $i '%u' $USER
87
	trial $i '%u' $USER
75
	trial $i '%%/%C/%i/%h/%d/%L/%l/%n/%p/%r/%u' \
88
	# We can't specify a full path outside the regress dir, so skip tests
76
	    "%/$HASH/$USERID/127.0.0.1/$HOME/$HOST/$HOSTNAME/somehost/$PORT/$REMUSER/$USER"
89
	# containing %d for UserKnownHostsFile
90
	if [ "$i" != "userknownhostsfile" ]; then
91
		trial $i '%d' $HOME
92
		trial $i '%%/%C/%i/%h/%d/%L/%l/%n/%p/%r/%u' \
93
		    "%/$HASH/$USERID/127.0.0.1/$HOME/$HOST/$HOSTNAME/somehost/$PORT/$REMUSER/$USER"
94
	fi
77
done
95
done
78
96
79
# Subset of above since we don't expand shell-style variables on anything that
97
# Subset of above since we don't expand shell-style variables on anything that
80
# runs a command because the shell will expand those.
98
# runs a command because the shell will expand those.
81
for i in controlpath identityagent forwardagent localforward remoteforward; do
99
for i in controlpath identityagent forwardagent localforward remoteforward \
100
    userknownhostsfile; do
82
	verbose $tid $i dollar
101
	verbose $tid $i dollar
83
	FOO=bar
102
	FOO=bar
84
	export FOO
103
	export FOO

Return to bug 1654