SC=/usr/bin/systemctl may() { local u=$1; shift; sudo -l -U "$u" "$@" >/dev/null 2>&1; } # Drop-ins sudo reads (no dot, no ~) that weren't there at setup and name alice. alice_dropin() { local f for f in /etc/sudoers.d/*; do [ -f "$f" ] || continue case ${f##*/} in *.* | *~) continue ;; esac grep -qxF "${f##*/}" "$LAB_STATE/sudoers-d" && continue grep -qw alice "$f" && return 0 done return 1 } only_ssh() { ! may alice /usr/bin/id && ! may alice /bin/bash && ! may alice $SC stop ssh && ! may alice $SC restart cron && ! may alice $SC restart ssh.socket && ! may alice $SC edit ssh } no_password() { local l l=$(sudo -l -U alice | sed -n '/may run the following/,$p') grep -q NOPASSWD <<<"$l" && ! grep -Eq '(^|[^O])PASSWD:' <<<"$l" && ! runuser -u alice -- sudo -n $SC status ssh 2>&1 >/dev/null