diff options
author | mtm <mtm@FreeBSD.org> | 2003-06-20 19:23:55 +0000 |
---|---|---|
committer | mtm <mtm@FreeBSD.org> | 2003-06-20 19:23:55 +0000 |
commit | 009cce702749ffe93ef6ee4afa61831a0752b027 (patch) | |
tree | 83cf5c7887c8137628c50bcb831a7cfe70299859 /usr.sbin/adduser/adduser.sh | |
parent | 65d4714c1b4145a37f2b1435b1e9708b23cb5e2c (diff) | |
download | FreeBSD-src-009cce702749ffe93ef6ee4afa61831a0752b027.zip FreeBSD-src-009cce702749ffe93ef6ee4afa61831a0752b027.tar.gz |
Add support for the special shell nologin.
Prodded by: mikeh
Diffstat (limited to 'usr.sbin/adduser/adduser.sh')
-rw-r--r-- | usr.sbin/adduser/adduser.sh | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/usr.sbin/adduser/adduser.sh b/usr.sbin/adduser/adduser.sh index 588c696..ab6f3b2 100644 --- a/usr.sbin/adduser/adduser.sh +++ b/usr.sbin/adduser/adduser.sh @@ -110,6 +110,9 @@ valid_shells() { ;; esac done + + # /sbin/nologin is a special case + [ -x "${NOLOGIN_PATH}" ] && echo -n " ${NOLOGIN}" } # fullpath_from_shell shell @@ -133,9 +136,41 @@ fullpath_from_shell() { ;; esac done + + # /sbin/nologin is a special case + if [ "$_shell" = "${NOLOGIN}" ]; then + echo ${NOLOGIN_PATH} + return 0; + fi + return 1 } +# shell_exists shell +# If the given shell is listed in ${ETCSHELLS} or it is +# the nologin shell this function will return 0. +# Otherwise, it will return 1. If shell is valid but +# the path is invalid or it is not executable it +# will emit an informational message saying so. +# +shell_exists() +{ + _sh="$1" + _shellchk="${GREPCMD} '^$_sh$' ${ETCSHELLS} > /dev/null 2>&1" + + if ! eval $_shellchk; then + # The nologin shell is not listed in /etc/shells. + if [ "$_sh" != "${NOLOGIN_PATH}" ]; then + err "Invalid shell ($_sh) for user $username." + return 1 + fi + fi + ! [ -x "$_sh" ] && + warn "The shell ($_sh) does not exist or is not executable." + + return 0 +} + # save_config # Save some variables to a configuration file. # Note: not all script variables are saved, only those that @@ -334,11 +369,10 @@ get_shell() { ushell="$defaultshell" # Make sure the current value of the shell is a valid one - _shellchk="${GREPCMD} '^$ushell$' ${ETCSHELLS} > /dev/null 2>&1" - eval $_shellchk || { - err "Invalid shell ($ushell). Using default shell ${defaultshell}." + if ! shell_exists $ushell ; then + info "Using default shell ${defaultshell}." ushell="$defaultshell" - } + fi if [ -z "$fflag" ]; then echo -n "Shell ($shells) [`basename $ushell`]: " @@ -351,7 +385,8 @@ get_shell() { if [ -n "$_fullpath" ]; then ushell="$_fullpath" else - err "Invalid shell selection. Using default shell ${defaultshell}." + err "Invalid shell ($_input) for user $username." + info "Using default shell ${defaultshell}." ushell="$defaultshell" fi fi @@ -744,6 +779,8 @@ ADDUSERCONF="${ADDUSERCONF:-/etc/adduser.conf}" PWCMD="${PWCMD:-/usr/sbin/pw}" MAILCMD="${MAILCMD:-mail}" ETCSHELLS="${ETCSHELLS:-/etc/shells}" +NOLOGIN="nologin" +NOLOGIN_PATH="/sbin/nologin" GREPCMD="/usr/bin/grep" DATECMD="/bin/date" |