From bfedd04199e1c74858ea7b6a073900c3c0e37005 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 22 Feb 2026 13:46:29 +0100 Subject: m fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/securetty | 91 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 45 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/securetty b/src/securetty index 3022b82..3e9c3ac 100755 --- a/src/securetty +++ b/src/securetty @@ -2,7 +2,7 @@ # cerberus-securetty – securetty support for cerberus # -# Copyright © 2015 Mattias Andrée (maandree@member.fsf.org) +# Copyright © 2015 Mattias Andrée (m@maandree.se) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -31,53 +31,52 @@ shift 1 hostname_on_next=0 dash=0 for arg in "$@"; do - if [ "${arg}" = "" ]; then - true - elif [ "${arg::1}" = "-" ] && [ ${dash} = 0 ]; then - arg="${arg:1}" - while [ ! "${arg}" = "" ]; do - c="${arg::1}" - arg="${arg:1}" - if [ "${c}" = "h" ]; then # hostname - if [ ! "${arg}" = "" ]; then - hostname="${arg}" - else - hostname_on_next=1 - fi - break - elif [ "${c}" = "f" ]; then # force - if [ ! "${arg}" = "" ]; then - username="${arg}" - fi - break - elif [ "${c}" = "-" ]; then # username - dash=1 - break - fi - done - elif [ ${hostname_on_next} = 1 ]; then - hostname="${arg}" - hostname_on_next=0 - else - username="${arg}" - fi + if test -z "${arg}"; then + : + elif test "${arg::1}" = "-" && test ${dash} = 0; then + arg="${arg:1}" + while test -z "${arg}"; do + c="${arg::1}" + arg="${arg:1}" + if test "${c}" = "h"; then # hostname + if test -n "${arg}"; then + hostname="${arg}" + else + hostname_on_next=1 + fi + break + elif test "${c}" = "f"; then # force + if test -n "${arg}"; then + username="${arg}" + fi + break + elif test "${c}" = "-"; then # username + dash=1 + break + fi + done + elif test ${hostname_on_next} = 1; then + hostname="${arg}" + hostname_on_next=0 + else + username="${arg}" + fi done # Verify that the user may log in -if [ "${hook}" = verify ]; then - if [ ! "${username}" = root ]; then - exit 0 # Not root: may log in - elif [ ! "${hostname}" = "" ]; then - echo "Sorry, root may not log in remotely" >&2 - exit 1 # Remote root: may not log in - elif [ ! -f "/etc/securetty" ]; then - exit 0 # /etc/securetty does not exist: may log in - elif grep "^${ttyname}$" < "/etc/securetty" > "/dev/null" 2> "/dev/null"; then - exit 0 # Root on whitelisted tty: may log in - else - echo "Sorry, root may not log in on ${ttyname}, see /etc/securetty available TTY:s" >&2 - exit 1 # Root on non-whitelisted tty: may not log in - fi +if test "${hook}" = verify; then + if test ! "${username}" = root; then + exit 0 # Not root: may log in + elif test -n "${hostname}"; then + printf '%s\n' "Sorry, root may not log in remotely" >&2 + exit 1 # Remote root: may not log in + elif test ! -f "/etc/securetty"; then + exit 0 # /etc/securetty does not exist: may log in + elif grep -q "^${ttyname}$" < "/etc/securetty" 2> "/dev/null"; then + exit 0 # Root on whitelisted tty: may log in + else + printf '%s\n' "Sorry, root may not log in on ${ttyname}, see /etc/securetty for available TTYs" >&2 + exit 1 # Root on non-whitelisted tty: may not log in + fi fi - -- cgit v1.2.3-70-g09d2