dtucker@openbsd.org | 0d2f884 | 2016-12-16 03:51:19 +0000 | [diff] [blame] | 1 | # Public Domain |
| 2 | # Zev Weiss, 2016 |
djm@openbsd.org | 7449c17 | 2018-07-13 02:13:50 +0000 | [diff] [blame] | 3 | # $OpenBSD: allow-deny-users.sh,v 1.5 2018/07/13 02:13:50 djm Exp $ |
dtucker@openbsd.org | 0d2f884 | 2016-12-16 03:51:19 +0000 | [diff] [blame] | 4 | |
| 5 | tid="AllowUsers/DenyUsers" |
| 6 | |
dtucker@openbsd.org | eae735a | 2016-12-19 03:32:57 +0000 | [diff] [blame] | 7 | me="$LOGNAME" |
djm@openbsd.org | c8c60f3 | 2016-12-19 22:35:23 +0000 | [diff] [blame] | 8 | if [ "x$me" = "x" ]; then |
dtucker@openbsd.org | eae735a | 2016-12-19 03:32:57 +0000 | [diff] [blame] | 9 | me=`whoami` |
| 10 | fi |
dtucker@openbsd.org | 0d2f884 | 2016-12-16 03:51:19 +0000 | [diff] [blame] | 11 | other="nobody" |
| 12 | |
djm@openbsd.org | 7449c17 | 2018-07-13 02:13:50 +0000 | [diff] [blame] | 13 | cp $OBJ/sshd_proxy $OBJ/sshd_proxy.orig |
| 14 | |
dtucker@openbsd.org | 0d2f884 | 2016-12-16 03:51:19 +0000 | [diff] [blame] | 15 | test_auth() |
| 16 | { |
| 17 | deny="$1" |
| 18 | allow="$2" |
| 19 | should_succeed="$3" |
| 20 | failmsg="$4" |
| 21 | |
djm@openbsd.org | 7449c17 | 2018-07-13 02:13:50 +0000 | [diff] [blame] | 22 | 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.org | 0d2f884 | 2016-12-16 03:51:19 +0000 | [diff] [blame] | 26 | start_sshd -oDenyUsers="$deny" -oAllowUsers="$allow" |
| 27 | |
djm@openbsd.org | 7449c17 | 2018-07-13 02:13:50 +0000 | [diff] [blame] | 28 | ${SSH} -F $OBJ/ssh_proxy "$me@somehost" true |
dtucker@openbsd.org | 0d2f884 | 2016-12-16 03:51:19 +0000 | [diff] [blame] | 29 | 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.org | 0d2f884 | 2016-12-16 03:51:19 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | # DenyUsers AllowUsers should_succeed failure_message |
| 38 | test_auth "" "" true "user in neither DenyUsers nor AllowUsers denied" |
| 39 | test_auth "$other $me" "" false "user in DenyUsers allowed" |
| 40 | test_auth "$me $other" "" false "user in DenyUsers allowed" |
| 41 | test_auth "" "$other" false "user not in AllowUsers allowed" |
| 42 | test_auth "" "$other $me" true "user in AllowUsers denied" |
| 43 | test_auth "" "$me $other" true "user in AllowUsers denied" |
| 44 | test_auth "$me $other" "$me $other" false "user in both DenyUsers and AllowUsers allowed" |
| 45 | test_auth "$other $me" "$other $me" false "user in both DenyUsers and AllowUsers allowed" |