blob: ef37ab22c09a82545cc78c271ee58c9180bc42e5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# $OpenBSD: percent.sh,v 1.4 2020/04/03 07:53:10 dtucker Exp $
# Placed in the Public Domain.
tid="percent expansions"
USER=`id -u -n`
USERID=`id -u`
HOST=`hostname -s`
HOSTNAME=`hostname`
# Localcommand is evaluated after connection because %T is not available
# until then. Because of this we use a different method of exercising it,
# and we can't override the remote user otherwise authentication will fail.
# We also have to explicitly enable it.
echo "permitlocalcommand yes" >> $OBJ/ssh_proxy
trial()
{
opt="$1"; arg="$2"; expect="$3"
trace "test $opt=$arg $expect"
rm -f $OBJ/actual
case "$opt" in
localcommand)
${SSH} -F $OBJ/ssh_proxy -o $opt="echo '$arg' >$OBJ/actual" \
somehost true
got=`cat $OBJ/actual`
;;
matchexec)
(cat $OBJ/ssh_proxy && \
echo "Match Exec \"echo '$arg' >$OBJ/actual\"") \
>$OBJ/ssh_proxy_match
${SSH} -F $OBJ/ssh_proxy_match remuser@somehost true || true
got=`cat $OBJ/actual`
;;
*)
got=`${SSH} -F $OBJ/ssh_proxy -o $opt="$arg" -G \
remuser@somehost | awk '$1=="'$opt'"{print $2}'`
esac
if [ "$got" != "$expect" ]; then
fail "$opt=$arg expect $expect got $got"
fi
}
for i in matchexec localcommand remotecommand controlpath identityagent \
forwardagent; do
verbose $tid $i
if [ "$i" = "localcommand" ]; then
REMUSER=$USER
trial $i '%T' NONE
else
REMUSER=remuser
fi
# Matches implementation in readconf.c:ssh_connection_hash()
HASH=`printf "${HOSTNAME}127.0.0.1${PORT}$REMUSER" |
openssl sha1 | cut -f2 -d' '`
trial $i '%%' '%'
trial $i '%C' $HASH
trial $i '%i' $USERID
trial $i '%h' 127.0.0.1
trial $i '%d' $HOME
trial $i '%L' $HOST
trial $i '%l' $HOSTNAME
trial $i '%n' somehost
trial $i '%p' $PORT
trial $i '%r' $REMUSER
trial $i '%u' $USER
trial $i '%%/%C/%i/%h/%d/%L/%l/%n/%p/%r/%u' \
"%/$HASH/$USERID/127.0.0.1/$HOME/$HOST/$HOSTNAME/somehost/$PORT/$REMUSER/$USER"
done
# A subset of options support tilde expansion
for i in controlpath identityagent forwardagent; do
trial $i '~' $HOME/
trial $i '~/.ssh' $HOME/.ssh
done
|