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