allow-deny-users.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. tid="AllowUsers/DenyUsers"
  5. me="$LOGNAME"
  6. if [ "x$me" = "x" ]; then
  7. me=$(whoami)
  8. fi
  9. other="nobody"
  10. cp $OBJ/sshd_proxy $OBJ/sshd_proxy.orig
  11. test_auth()
  12. {
  13. deny="$1"
  14. allow="$2"
  15. should_succeed="$3"
  16. failmsg="$4"
  17. cp $OBJ/sshd_proxy.orig $OBJ/sshd_proxy
  18. echo DenyUsers="$deny" >> $OBJ/sshd_proxy
  19. echo AllowUsers="$allow" >> $OBJ/sshd_proxy
  20. start_sshd -oDenyUsers="$deny" -oAllowUsers="$allow"
  21. ${SSH} -F $OBJ/ssh_proxy "$me@somehost" true
  22. status=$?
  23. if (test $status -eq 0 && ! $should_succeed) ||
  24. ( test $status -ne 0 && $should_succeed); then
  25. fail "$failmsg"
  26. fi
  27. }
  28. # DenyUsers AllowUsers should_succeed failure_message
  29. test_auth "" "" true "user in neither DenyUsers nor AllowUsers denied"
  30. test_auth "$other $me" "" false "user in DenyUsers allowed"
  31. test_auth "$me $other" "" false "user in DenyUsers allowed"
  32. test_auth "" "$other" false "user not in AllowUsers allowed"
  33. test_auth "" "$other $me" true "user in AllowUsers denied"
  34. test_auth "" "$me $other" true "user in AllowUsers denied"
  35. test_auth "$me $other" "$me $other" false "user in both DenyUsers and AllowUsers allowed"
  36. test_auth "$other $me" "$other $me" false "user in both DenyUsers and AllowUsers allowed"