1 # $OpenBSD: cfgmatch.sh,v 1.4 2006/12/13 08:36:36 dtucker Exp $
2 # Placed in the Public Domain.
4 tid
="sshd_config match"
6 pidfile
=$OBJ/remote_pid
8 fwd
="-L $fwdport:127.0.0.1:$PORT"
13 if [ ! -z "$pid" ]; then
19 cp $OBJ/sshd_proxy
$OBJ/sshd_proxy_bak
21 echo "PermitOpen 127.0.0.1:1" >>$OBJ/sshd_config
22 echo "Match Address 127.0.0.1" >>$OBJ/sshd_config
23 echo "PermitOpen 127.0.0.1:$PORT" >>$OBJ/sshd_config
25 echo "PermitOpen 127.0.0.1:1" >>$OBJ/sshd_proxy
26 echo "Match Address 127.0.0.1" >>$OBJ/sshd_proxy
27 echo "PermitOpen 127.0.0.1:$PORT" >>$OBJ/sshd_proxy
33 # Test Match + PermitOpen in sshd_config. This should be permitted
36 trace
"match permitopen localhost proto $p"
37 ${SSH} -$p $fwd -F $OBJ/ssh_config
-f somehost \
38 exec sh
-c \'"echo \$\$ > $pidfile; exec sleep 100"\' >>$TEST_SSH_LOGFILE 2>&1 ||\
39 fail
"match permitopen proto $p sshd failed"
41 ${SSH} -q -$p -p $fwdport -F $OBJ/ssh_config somehost true || \
42 fail
"match permitopen permit proto $p"
46 # Same but from different source. This should not be permitted
49 trace
"match permitopen proxy proto $p"
50 ${SSH} -q -$p $fwd -F $OBJ/ssh_proxy
-f somehost \
51 exec sh
-c \'"echo \$\$ > $pidfile; exec sleep 100"\' >>$TEST_SSH_LOGFILE 2>&1 ||\
52 fail
"match permitopen proxy proto $p sshd failed"
54 ${SSH} -q -$p -p $fwdport -F $OBJ/ssh_config somehost true
&& \
55 fail
"match permitopen deny proto $p"
59 # Retry previous with key option, should also be denied.
60 echo -n 'permitopen="127.0.0.1:'$PORT'" ' >$OBJ/authorized_keys_
$USER
61 cat $OBJ/rsa.pub
>> $OBJ/authorized_keys_
$USER
62 echo -n 'permitopen="127.0.0.1:'$PORT'" ' >>$OBJ/authorized_keys_
$USER
63 cat $OBJ/rsa1.pub
>> $OBJ/authorized_keys_
$USER
66 trace
"match permitopen proxy w/key opts proto $p"
67 ${SSH} -q -$p $fwd -F $OBJ/ssh_proxy
-f somehost \
68 exec sh
-c \'"echo \$\$ > $pidfile; exec sleep 100"\' >>$TEST_SSH_LOGFILE 2>&1 ||\
69 fail
"match permitopen w/key opt proto $p sshd failed"
71 ${SSH} -q -$p -p $fwdport -F $OBJ/ssh_config somehost true
&& \
72 fail
"match permitopen deny w/key opt proto $p"
76 # Test both sshd_config and key options permitting the same dst/port pair.
77 # Should be permitted.
80 trace
"match permitopen localhost proto $p"
81 ${SSH} -$p $fwd -F $OBJ/ssh_config
-f somehost \
82 exec sh
-c \'"echo \$\$ > $pidfile; exec sleep 100"\' >>$TEST_SSH_LOGFILE 2>&1 ||\
83 fail
"match permitopen proto $p sshd failed"
85 ${SSH} -q -$p -p $fwdport -F $OBJ/ssh_config somehost true || \
86 fail
"match permitopen permit proto $p"
90 cp $OBJ/sshd_proxy_bak
$OBJ/sshd_proxy
91 echo "PermitOpen 127.0.0.1:1 127.0.0.1:$PORT 127.0.0.2:2" >>$OBJ/sshd_proxy
92 echo "Match User $USER" >>$OBJ/sshd_proxy
93 echo "PermitOpen 127.0.0.1:1 127.0.0.1:2" >>$OBJ/sshd_proxy
95 # Test that a Match overrides a PermitOpen in the global section
98 trace
"match permitopen proxy w/key opts proto $p"
99 ${SSH} -q -$p $fwd -F $OBJ/ssh_proxy
-f somehost \
100 exec sh
-c \'"echo \$\$ > $pidfile; exec sleep 100"\' >>$TEST_SSH_LOGFILE 2>&1 ||\
101 fail
"match override permitopen proto $p sshd failed"
103 ${SSH} -q -$p -p $fwdport -F $OBJ/ssh_config somehost true
&& \
104 fail
"match override permitopen proto $p"
108 cp $OBJ/sshd_proxy_bak
$OBJ/sshd_proxy
109 echo "PermitOpen 127.0.0.1:1 127.0.0.1:$PORT 127.0.0.2:2" >>$OBJ/sshd_proxy
110 echo "Match User NoSuchUser" >>$OBJ/sshd_proxy
111 echo "PermitOpen 127.0.0.1:1 127.0.0.1:2" >>$OBJ/sshd_proxy
113 # Test that a rule that doesn't match doesn't override, plus test a
114 # PermitOpen entry that's not at the start of the list
117 trace
"nomatch permitopen proxy w/key opts proto $p"
118 ${SSH} -q -$p $fwd -F $OBJ/ssh_proxy
-f somehost \
119 exec sh
-c \'"echo \$\$ > $pidfile; exec sleep 100"\' >>$TEST_SSH_LOGFILE 2>&1 ||\
120 fail
"nomatch override permitopen proto $p sshd failed"
122 ${SSH} -q -$p -p $fwdport -F $OBJ/ssh_config somehost true || \
123 fail
"nomatch override permitopen proto $p"