1 # $OpenBSD: cfgmatch.sh,v 1.2 2006/07/22 01:50:00 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
18 cp $OBJ/sshd_proxy $OBJ/sshd_proxy_bak
20 echo "PermitOpen 127.0.0.1:1" >>$OBJ/sshd_config
21 echo "Match Address 127.0.0.1" >>$OBJ/sshd_config
22 echo "PermitOpen 127.0.0.1:$PORT" >>$OBJ/sshd_config
24 echo "PermitOpen 127.0.0.1:1" >>$OBJ/sshd_proxy
25 echo "Match Address 127.0.0.1" >>$OBJ/sshd_proxy
26 echo "PermitOpen 127.0.0.1:$PORT" >>$OBJ/sshd_proxy
32 # Test Match + PermitOpen in sshd_config. This should be permitted
35 trace "match permitopen localhost proto $p"
36 ${SSH} -$p $fwd -F $OBJ/ssh_config -f somehost \
37 "echo \$\$ > $pidfile; exec sleep 100" >>$TEST_SSH_LOGFILE 2>&1 ||\
38 fail "match permitopen proto $p sshd failed"
40 ${SSH} -q -$p -p $fwdport -F $OBJ/ssh_config somehost true || \
41 fail "match permitopen permit proto $p"
45 # Same but from different source. This should not be permitted
48 trace "match permitopen proxy proto $p"
49 ${SSH} -q -$p $fwd -F $OBJ/ssh_proxy -f somehost \
50 "echo \$\$ > $pidfile; exec sleep 100" >>$TEST_SSH_LOGFILE 2>&1 ||\
51 fail "match permitopen proxy proto $p sshd failed"
53 ${SSH} -q -$p -p $fwdport -F $OBJ/ssh_config somehost true && \
54 fail "match permitopen deny proto $p"
58 # Retry previous with key option, should also be denied.
59 echo -n 'permitopen="127.0.0.1:'$PORT'" ' >$OBJ/authorized_keys_$USER
60 cat $OBJ/rsa.pub >> $OBJ/authorized_keys_$USER
61 echo -n 'permitopen="127.0.0.1:'$PORT'" ' >>$OBJ/authorized_keys_$USER
62 cat $OBJ/rsa1.pub >> $OBJ/authorized_keys_$USER
65 trace "match permitopen proxy w/key opts proto $p"
66 ${SSH} -q -$p $fwd -F $OBJ/ssh_proxy -f somehost \
67 "echo \$\$ > $pidfile; exec sleep 100" >>$TEST_SSH_LOGFILE 2>&1 ||\
68 fail "match permitopen w/key opt proto $p sshd failed"
70 ${SSH} -q -$p -p $fwdport -F $OBJ/ssh_config somehost true && \
71 fail "match permitopen deny w/key opt proto $p"
75 # Test both sshd_config and key options permitting the same dst/port pair.
76 # Should be permitted.
79 trace "match permitopen localhost proto $p"
80 ${SSH} -$p $fwd -F $OBJ/ssh_config -f somehost \
81 "echo \$\$ > $pidfile; exec sleep 100" >>$TEST_SSH_LOGFILE 2>&1 ||\
82 fail "match permitopen proto $p sshd failed"
84 ${SSH} -q -$p -p $fwdport -F $OBJ/ssh_config somehost true || \
85 fail "match permitopen permit proto $p"
89 cp $OBJ/sshd_proxy_bak $OBJ/sshd_proxy
90 echo "PermitOpen 127.0.0.1:1 127.0.0.1:$PORT 127.0.0.2:2" >>$OBJ/sshd_proxy
91 echo "Match User $USER" >>$OBJ/sshd_proxy
92 echo "PermitOpen 127.0.0.1:1 127.0.0.1:2" >>$OBJ/sshd_proxy
94 # Test that a Match overrides a PermitOpen in the global section
97 trace "match permitopen proxy w/key opts proto $p"
98 ${SSH} -q -$p $fwd -F $OBJ/ssh_proxy -f somehost \
99 "echo \$\$ > $pidfile; exec sleep 100" >>$TEST_SSH_LOGFILE 2>&1 ||\
100 fail "match override permitopen proto $p sshd failed"
102 ${SSH} -q -$p -p $fwdport -F $OBJ/ssh_config somehost true && \
103 fail "match override permitopen proto $p"