From 009cce702749ffe93ef6ee4afa61831a0752b027 Mon Sep 17 00:00:00 2001 From: mtm Date: Fri, 20 Jun 2003 19:23:55 +0000 Subject: [PATCH] Add support for the special shell nologin. Prodded by: mikeh --- usr.sbin/adduser/adduser.8 | 2 ++ usr.sbin/adduser/adduser.sh | 47 +++++++++++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/usr.sbin/adduser/adduser.8 b/usr.sbin/adduser/adduser.8 index 69b51414db3d..ebd1c8d3e7e9 100644 --- a/usr.sbin/adduser/adduser.8 +++ b/usr.sbin/adduser/adduser.8 @@ -240,6 +240,8 @@ argument must be the base name of the shell, the full path. It must exist in .Pa /etc/shells +or be the special shell +.Em nologin to be considered a valid shell. .It Fl u Ar uid Use UIDs from diff --git a/usr.sbin/adduser/adduser.sh b/usr.sbin/adduser/adduser.sh index 588c6961ed4a..ab6f3b20d91f 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"