xref: /freebsd/crypto/openssh/regress/allow-deny-users.sh (revision cab6a39d7b343596a5823e65c0f7b426551ec22d)
1# Public Domain
2# Zev Weiss, 2016
3# $OpenBSD: allow-deny-users.sh,v 1.5 2018/07/13 02:13:50 djm Exp $
4
5tid="AllowUsers/DenyUsers"
6
7me="$LOGNAME"
8if [ "x$me" = "x" ]; then
9	me=`whoami`
10fi
11other="nobody"
12
13cp $OBJ/sshd_proxy $OBJ/sshd_proxy.orig
14
15test_auth()
16{
17	deny="$1"
18	allow="$2"
19	should_succeed="$3"
20	failmsg="$4"
21
22	cp $OBJ/sshd_proxy.orig $OBJ/sshd_proxy
23	echo DenyUsers="$deny" >> $OBJ/sshd_proxy
24	echo AllowUsers="$allow" >> $OBJ/sshd_proxy
25
26	start_sshd -oDenyUsers="$deny" -oAllowUsers="$allow"
27
28	${SSH} -F $OBJ/ssh_proxy "$me@somehost" true
29	status=$?
30
31	if (test $status -eq 0 && ! $should_succeed) \
32	    || (test $status -ne 0 && $should_succeed); then
33		fail "$failmsg"
34	fi
35}
36
37#         DenyUsers     AllowUsers    should_succeed  failure_message
38test_auth ""            ""            true            "user in neither DenyUsers nor AllowUsers denied"
39test_auth "$other $me"  ""            false           "user in DenyUsers allowed"
40test_auth "$me $other"  ""            false           "user in DenyUsers allowed"
41test_auth ""            "$other"      false           "user not in AllowUsers allowed"
42test_auth ""            "$other $me"  true            "user in AllowUsers denied"
43test_auth ""            "$me $other"  true            "user in AllowUsers denied"
44test_auth "$me $other"  "$me $other"  false           "user in both DenyUsers and AllowUsers allowed"
45test_auth "$other $me"  "$other $me"  false           "user in both DenyUsers and AllowUsers allowed"
46