addrmatch.sh revision 239849
1183724Ssos#	$OpenBSD: addrmatch.sh,v 1.4 2012/05/13 01:42:32 dtucker Exp $
2183724Ssos#	Placed in the Public Domain.
3183724Ssos
4183724Ssostid="address match"
5183724Ssos
6183724Ssosmv $OBJ/sshd_proxy $OBJ/sshd_proxy_bak
7183724Ssos
8183724Ssosrun_trial()
9183724Ssos{
10183724Ssos	user="$1"; addr="$2"; host="$3"; laddr="$4"; lport="$5"
11183724Ssos	expected="$6"; descr="$7"
12183724Ssos
13183724Ssos	verbose "test $descr for $user $addr $host"
14183724Ssos	result=`${SSHD} -f $OBJ/sshd_proxy -T \
15183724Ssos	    -C user=${user},addr=${addr},host=${host},laddr=${laddr},lport=${lport} | \
16183724Ssos	    awk '/^forcecommand/ {print $2}'`
17183724Ssos	if [ "$result" != "$expected" ]; then
18183724Ssos		fail "failed '$descr' expected $expected got $result"
19183724Ssos	fi
20183724Ssos}
21183724Ssos
22183724Ssoscp $OBJ/sshd_proxy_bak $OBJ/sshd_proxy
23183724Ssoscat >>$OBJ/sshd_proxy <<EOD
24183724SsosForceCommand nomatch
25183724SsosMatch Address 192.168.0.0/16,!192.168.30.0/24,10.0.0.0/8,host.example.com
26183724Ssos	ForceCommand match1
27183724SsosMatch Address 1.1.1.1,::1,!::3,2000::/16
28183724Ssos	ForceCommand match2
29183724SsosMatch LocalAddress 127.0.0.1,::1
30183724Ssos	ForceCommand match3
31183724SsosMatch LocalPort 5678
32183724Ssos	ForceCommand match4
33183724SsosEOD
34183724Ssos
35183724Ssosrun_trial user 192.168.0.1 somehost 1.2.3.4 1234 match1 "first entry"
36183724Ssosrun_trial user 192.168.30.1 somehost 1.2.3.4 1234 nomatch "negative match"
37183724Ssosrun_trial user 19.0.0.1 somehost 1.2.3.4 1234 nomatch "no match"
38183724Ssosrun_trial user 10.255.255.254 somehost 1.2.3.4 1234 match1 "list middle"
39183724Ssosrun_trial user 192.168.30.1 192.168.0.1 1.2.3.4 1234 nomatch "faked IP in hostname"
40183724Ssosrun_trial user 1.1.1.1 somehost.example.com 1.2.3.4 1234 match2 "bare IP4 address"
41183724Ssosrun_trial user 19.0.0.1 somehost 127.0.0.1 1234 match3 "localaddress"
42183724Ssosrun_trial user 19.0.0.1 somehost 1.2.3.4 5678 match4 "localport"
43183724Ssos
44183724Ssosif test "$TEST_SSH_IPV6" != "no"; then
45183724Ssosrun_trial user ::1 somehost.example.com ::2 1234 match2 "bare IP6 address"
46183724Ssosrun_trial user ::2 somehost.exaple.com ::2 1234 nomatch "deny IPv6"
47183724Ssosrun_trial user ::3 somehost ::2 1234 nomatch "IP6 negated"
48183724Ssosrun_trial user ::4 somehost ::2 1234 nomatch "IP6 no match"
49183724Ssosrun_trial user 2000::1 somehost ::2 1234 match2 "IP6 network"
50183724Ssosrun_trial user 2001::1 somehost ::2 1234 nomatch "IP6 network"
51183724Ssosrun_trial user ::5 somehost ::1 1234 match3 "IP6 localaddress"
52183724Ssosrun_trial user ::5 somehost ::2 5678 match4 "IP6 localport"
53183724Ssosfi
54183724Ssos
55183724Ssoscp $OBJ/sshd_proxy_bak $OBJ/sshd_proxy
56188765Smavrm $OBJ/sshd_proxy_bak
57183724Ssos