blob: 5c389512247c93cd62f14866ab29e6c400f93c24 [file] [log] [blame]
dtucker@openbsd.org0d2f8842016-12-16 03:51:19 +00001# Public Domain
2# Zev Weiss, 2016
djm@openbsd.org7449c172018-07-13 02:13:50 +00003# $OpenBSD: allow-deny-users.sh,v 1.5 2018/07/13 02:13:50 djm Exp $
dtucker@openbsd.org0d2f8842016-12-16 03:51:19 +00004
5tid="AllowUsers/DenyUsers"
6
dtucker@openbsd.orgeae735a2016-12-19 03:32:57 +00007me="$LOGNAME"
djm@openbsd.orgc8c60f32016-12-19 22:35:23 +00008if [ "x$me" = "x" ]; then
dtucker@openbsd.orgeae735a2016-12-19 03:32:57 +00009 me=`whoami`
10fi
dtucker@openbsd.org0d2f8842016-12-16 03:51:19 +000011other="nobody"
12
djm@openbsd.org7449c172018-07-13 02:13:50 +000013cp $OBJ/sshd_proxy $OBJ/sshd_proxy.orig
14
dtucker@openbsd.org0d2f8842016-12-16 03:51:19 +000015test_auth()
16{
17 deny="$1"
18 allow="$2"
19 should_succeed="$3"
20 failmsg="$4"
21
djm@openbsd.org7449c172018-07-13 02:13:50 +000022 cp $OBJ/sshd_proxy.orig $OBJ/sshd_proxy
23 echo DenyUsers="$deny" >> $OBJ/sshd_proxy
24 echo AllowUsers="$allow" >> $OBJ/sshd_proxy
25
dtucker@openbsd.org0d2f8842016-12-16 03:51:19 +000026 start_sshd -oDenyUsers="$deny" -oAllowUsers="$allow"
27
djm@openbsd.org7449c172018-07-13 02:13:50 +000028 ${SSH} -F $OBJ/ssh_proxy "$me@somehost" true
dtucker@openbsd.org0d2f8842016-12-16 03:51:19 +000029 status=$?
30
31 if (test $status -eq 0 && ! $should_succeed) \
32 || (test $status -ne 0 && $should_succeed); then
33 fail "$failmsg"
34 fi
dtucker@openbsd.org0d2f8842016-12-16 03:51:19 +000035}
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"