diff --git a/usr.sbin/adduser/adduser.sh b/usr.sbin/adduser/adduser.sh --- a/usr.sbin/adduser/adduser.sh +++ b/usr.sbin/adduser/adduser.sh @@ -33,8 +33,8 @@ # Display $msg on stderr, unless we're being quiet. # err() { - if [ -z "$quietflag" ]; then - echo 1>&2 ${THISCMD}: ERROR: $* + if [ -z "${quietflag}" ]; then + echo 1>&2 "${THISCMD}: ERROR: ${*}" fi } @@ -42,8 +42,8 @@ # Display $msg on stdout, unless we're being quiet. # info() { - if [ -z "$quietflag" ]; then - echo ${THISCMD}: INFO: $* + if [ -z "${quietflag}" ]; then + echo "${THISCMD}: INFO: ${*}" fi } @@ -54,22 +54,22 @@ # by pw(8). # get_nextuid () { - _uid=$1 + _uid="${1}" _nextuid= - if [ -z "$_uid" ]; then - _nextuid="`${PWCMD} usernext | cut -f1 -d:`" + if [ -z "${_uid}" ]; then + _nextuid="$(${PWCMD} usernext | cut -f1 -d:)" else while : ; do - ${PWCMD} usershow $_uid > /dev/null 2>&1 - if [ ! "$?" -eq 0 ]; then - _nextuid=$_uid + "${PWCMD}" usershow "${_uid}" > /dev/null 2>&1 + if [ ! "${?}" -eq 0 ]; then + _nextuid="${_uid}" break fi - _uid=$(($_uid + 1)) + _uid="$((${_uid} + 1))" done fi - echo $_nextuid + echo "${_nextuid}" } # show_usage @@ -104,13 +104,13 @@ # valid_shells() { _prefix= - cat ${ETCSHELLS} | + cat "${ETCSHELLS}" | while read _path _junk ; do - case $_path in + case "${_path}" in \#*|'') ;; *) - echo -n "${_prefix}`basename $_path`" + echo -n "${_prefix}$(basename "${_path}")" _prefix=' ' ;; esac @@ -126,29 +126,29 @@ # full path to the shell from the /etc/shells file. # fullpath_from_shell() { - _shell=$1 - [ -z "$_shell" ] && return 1 + _shell="${1}" + [ -z "${_shell}" ] && return 1 # /usr/sbin/nologin is a special case; it needs to be handled # before the cat | while loop, since a 'return' from within # a subshell will not terminate the function's execution, and # the path to the nologin shell might be printed out twice. # - if [ "$_shell" = "${NOLOGIN}" -o \ - "$_shell" = "${NOLOGIN_PATH}" ]; then - echo ${NOLOGIN_PATH} + if [ "${_shell}" = "${NOLOGIN}" -o \ + "${_shell}" = "${NOLOGIN_PATH}" ]; then + echo "${NOLOGIN_PATH}" return 0; fi - cat ${ETCSHELLS} | + cat "${ETCSHELLS}" | while read _path _junk ; do - case "$_path" in + case "${_path}" in \#*|'') ;; *) - if [ "$_path" = "$_shell" -o \ - "`basename $_path`" = "$_shell" ]; then - echo $_path + if [ "${_path}" = "${_shell}" -o \ + "$(basename "${_path}")" = "${_shell}" ]; then + echo "${_path}" return 0 fi ;; @@ -166,18 +166,18 @@ # will emit an informational message saying so. # shell_exists() { - _sh="$1" - _shellchk="${GREPCMD} '^$_sh$' ${ETCSHELLS} > /dev/null 2>&1" + _sh="${1}" + _shellchk="${GREPCMD} '^${_sh}$' ${ETCSHELLS} > /dev/null 2>&1" - if ! eval $_shellchk; then + 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." + if [ "${_sh}" != "${NOLOGIN_PATH}" ]; then + err "Invalid shell (${_sh}) for user ${username}." return 1 fi fi - ! [ -x "$_sh" ] && - info "The shell ($_sh) does not exist or is not executable." + ! [ -x "${_sh}" ] && + info "The shell (${_sh}) does not exist or is not executable." return 0 } @@ -188,21 +188,21 @@ # it makes sense to save. # save_config() { - echo "# Configuration file for adduser(8)." > ${ADDUSERCONF} - echo "# NOTE: only *some* variables are saved." >> ${ADDUSERCONF} - echo "# Last Modified on `${DATECMD}`." >> ${ADDUSERCONF} - echo '' >> ${ADDUSERCONF} - echo "defaultHomePerm=$uhomeperm" >> ${ADDUSERCONF} - echo "defaultLgroup=$ulogingroup" >> ${ADDUSERCONF} - echo "defaultclass=$uclass" >> ${ADDUSERCONF} - echo "defaultgroups=$ugroups" >> ${ADDUSERCONF} - echo "passwdtype=$passwdtype" >> ${ADDUSERCONF} - echo "homeprefix=$homeprefix" >> ${ADDUSERCONF} - echo "defaultshell=$ushell" >> ${ADDUSERCONF} - echo "udotdir=$udotdir" >> ${ADDUSERCONF} - echo "msgfile=$msgfile" >> ${ADDUSERCONF} - echo "disableflag=$disableflag" >> ${ADDUSERCONF} - echo "uidstart=$uidstart" >> ${ADDUSERCONF} + echo "# Configuration file for adduser(8)." > "${ADDUSERCONF}" + echo "# NOTE: only *some* variables are saved." >> "${ADDUSERCONF}" + echo "# Last Modified on $(${DATECMD})." >> "${ADDUSERCONF}" + echo '' >> "${ADDUSERCONF}" + echo "defaultHomePerm=${uhomeperm}" >> "${ADDUSERCONF}" + echo "defaultLgroup=${ulogingroup}" >> "${ADDUSERCONF}" + echo "defaultclass=${uclass}" >> "${ADDUSERCONF}" + echo "defaultgroups=${ugroups}" >> "${ADDUSERCONF}" + echo "passwdtype=${passwdtype}" >> "${ADDUSERCONF}" + echo "homeprefix=${homeprefix}" >> "${ADDUSERCONF}" + echo "defaultshell=${ushell}" >> "${ADDUSERCONF}" + echo "udotdir=${udotdir}" >> "${ADDUSERCONF}" + echo "msgfile=${msgfile}" >> "${ADDUSERCONF}" + echo "disableflag=${disableflag}" >> "${ADDUSERCONF}" + echo "uidstart=${uidstart}" >> "${ADDUSERCONF}" } # add_user @@ -213,7 +213,7 @@ # Is this a configuration run? If so, don't modify user database. # - if [ -n "$configflag" ]; then + if [ -n "${configflag}" ]; then save_config return fi @@ -234,33 +234,33 @@ _upasswd= _passwdmethod= - _name="-n '$username'" - [ -n "$uuid" ] && _uid='-u "$uuid"' - [ -n "$ulogingroup" ] && _group='-g "$ulogingroup"' - [ -n "$ugroups" ] && _grouplist='-G "$ugroups"' - [ -n "$ushell" ] && _shell='-s "$ushell"' - [ -n "$uclass" ] && _class='-L "$uclass"' - [ -n "$ugecos" ] && _comment='-c "$ugecos"' - [ -n "$udotdir" ] && _dotdir='-k "$udotdir"' - [ -n "$uexpire" ] && _expire='-e "$uexpire"' - [ -n "$upwexpire" ] && _pwexpire='-p "$upwexpire"' - if [ -z "$Dflag" -a -n "$uhome" ]; then + _name="-n '${username}'" + [ -n "${uuid}" ] && _uid='-u "${uuid}"' + [ -n "${ulogingroup}" ] && _group='-g "${ulogingroup}"' + [ -n "${ugroups}" ] && _grouplist='-G "${ugroups}"' + [ -n "${ushell}" ] && _shell='-s "${ushell}"' + [ -n "${uclass}" ] && _class='-L "${uclass}"' + [ -n "${ugecos}" ] && _comment='-c "${ugecos}"' + [ -n "${udotdir}" ] && _dotdir='-k "${udotdir}"' + [ -n "${uexpire}" ] && _expire='-e "${uexpire}"' + [ -n "${upwexpire}" ] && _pwexpire='-p "${upwexpire}"' + if [ -z "${Dflag}" -a -n "${uhome}" ]; then # The /nonexistent home directory is special. It # means the user has no home directory. - if [ "$uhome" = "$NOHOME" ]; then - _home='-d "$uhome"' + if [ "${uhome}" = "{$NOHOME}" ]; then + _home='-d "${uhome}"' else # Use home directory permissions if specified - if [ -n "$uhomeperm" ]; then - _home='-m -d "$uhome" -M "$uhomeperm"' + if [ -n "${uhomeperm}" ]; then + _home='-m -d "${uhome}" -M "${uhomeperm}"' else - _home='-m -d "$uhome"' + _home='-m -d "${uhome}"' fi fi - elif [ -n "$Dflag" -a -n "$uhome" ]; then - _home='-d "$uhome"' + elif [ -n "${Dflag}" -a -n "${uhome}" ]; then + _home='-d "${uhome}"' fi - case $passwdtype in + case "${passwdtype}" in no) _passwdmethod="-w no" _passwd="-h -" @@ -284,51 +284,51 @@ ;; esac - _pwcmd="$_upasswd ${PWCMD} useradd $_uid $_name $_group $_grouplist $_comment" - _pwcmd="$_pwcmd $_shell $_class $_home $_dotdir $_passwdmethod $_passwd" - _pwcmd="$_pwcmd $_expire $_pwexpire" + _pwcmd="${_upasswd} ${PWCMD} useradd ${_uid} ${_name} ${_group} ${_grouplist} ${_comment}" + _pwcmd="${_pwcmd} ${_shell} ${_class} ${_home} ${_dotdir} ${_passwdmethod} ${_passwd}" + _pwcmd="${_pwcmd} ${_expire} ${_pwexpire}" - if ! _output=`eval $_pwcmd` ; then - err "There was an error adding user ($username)." + if ! _output=$(eval "${_pwcmd}") ; then + err "There was an error adding user (${username})." return 1 else - info "Successfully added ($username) to the user database." - if [ "random" = "$passwdtype" ]; then - randompass="$_output" - info "Password for ($username) is: $randompass" + info "Successfully added (${username}) to the user database." + if [ "random" = "${passwdtype}" ]; then + randompass="${_output}" + info "Password for (${username}) is: ${randompass}" fi fi - if [ -n "$disableflag" ]; then - if ${PWCMD} lock $username ; then - info "Account ($username) is locked." + if [ -n "${disableflag}" ]; then + if ${PWCMD} lock "${username}" ; then + info "Account (${username}) is locked." else - info "Account ($username) could NOT be locked." + info "Account (${username}) could NOT be locked." fi fi _line= _owner= _perms= - if [ -n "$msgflag" ]; then - [ -r "$msgfile" ] && { + if [ -n "${msgflag}" ]; then + [ -r "${msgfile}" ] && { # We're evaluating the contents of an external file. # Let's not open ourselves up for attack. _perms will # be empty if it's writeable only by the owner. _owner # will *NOT* be empty if the file is owned by root. # - _dir="`dirname $msgfile`" - _file="`basename $msgfile`" - _perms=`/usr/bin/find $_dir -name $_file -perm +07022 -prune` - _owner=`/usr/bin/find $_dir -name $_file -user 0 -prune` - if [ -z "$_owner" -o -n "$_perms" ]; then - err "The message file ($msgfile) may be writeable only by root." + _dir="$(dirname "${msgfile}")" + _file="$(basename "${msgfile}")" + _perms="$(/usr/bin/find "${_dir}" -name "${_file}" -perm +07022 -prune)" + _owner="$(/usr/bin/find "${_dir}" -name "${_file}" -user 0 -prune)" + if [ -z "${_owner}" -o -n "${_perms}" ]; then + err "The message file (${msgfile}) may be writeable only by root." return 1 fi - cat "$msgfile" | + cat "${msgfile}" | while read _line ; do - eval echo "$_line" - done | ${MAILCMD} -s"Welcome" ${username} + eval echo "${_line}" + done | ${MAILCMD} -s"Welcome" "${username}" info "Sent welcome message to ($username)." } fi @@ -345,32 +345,32 @@ _input= # No need to take down user names if this is a configuration saving run. - [ -n "$configflag" ] && return + [ -n "${configflag}" ] && return while : ; do - if [ -z "$fflag" ]; then + if [ -z "${fflag}" ]; then echo -n "Username: " read _input else - _input="`echo "$fileline" | cut -f1 -d:`" + _input="$(echo "${fileline}" | cut -f1 -d:)" fi # There *must* be a username, and it must not exist. If # this is an interactive session give the user an # opportunity to retry. # - if [ -z "$_input" ]; then + if [ -z "${_input}" ]; then err "You must enter a username!" - [ -z "$fflag" ] && continue + [ -z "${fflag}" ] && continue fi - ${PWCMD} usershow $_input > /dev/null 2>&1 + ${PWCMD} usershow "${_input}" > /dev/null 2>&1 if [ "$?" -eq 0 ]; then err "User exists!" - [ -z "$fflag" ] && continue + [ -z "${fflag}" ] && continue fi break done - username="$_input" + username="${_input}" } # get_gecos @@ -381,15 +381,15 @@ _input= # No need to take down additional user information for a configuration run. - [ -n "$configflag" ] && return + [ -n "${configflag}" ] && return - if [ -z "$fflag" ]; then + if [ -z "${fflag}" ]; then echo -n "Full name: " read _input else - _input="`echo "$fileline" | cut -f7 -d:`" + _input="$(echo "${fileline}" | cut -f7 -d:)" fi - ugecos="$_input" + ugecos="${_input}" } # get_shell @@ -400,33 +400,33 @@ get_shell() { _input= _fullpath= - ushell="$defaultshell" + ushell="${defaultshell}" # Make sure the current value of the shell is a valid one - if [ -z "$Sflag" ]; then - if ! shell_exists $ushell ; then + if [ -z "${Sflag}" ]; then + if ! shell_exists "${ushell}" ; then info "Using default shell ${defaultshell}." - ushell="$defaultshell" + ushell="${defaultshell}" fi fi - if [ -z "$fflag" ]; then - echo -n "Shell ($shells) [`basename $ushell`]: " + if [ -z "${fflag}" ]; then + echo -n "Shell (${shells}) [$(basename "${ushell}")]: " read _input else - _input="`echo "$fileline" | cut -f9 -d:`" + _input="$(echo "${fileline}" | cut -f9 -d:)" fi - if [ -n "$_input" ]; then - if [ -n "$Sflag" ]; then - ushell="$_input" + if [ -n "${_input}" ]; then + if [ -n "${Sflag}" ]; then + ushell="${_input}" else - _fullpath=`fullpath_from_shell $_input` - if [ -n "$_fullpath" ]; then - ushell="$_fullpath" + _fullpath="$(fullpath_from_shell "${_input}")" + if [ -n "${_fullpath}" ]; then + ushell="${_fullpath}" else - err "Invalid shell ($_input) for user $username." + err "Invalid shell (${_input}) for user ${username}." info "Using default shell ${defaultshell}." - ushell="$defaultshell" + ushell="${defaultshell}" fi fi fi @@ -438,20 +438,20 @@ # get_homedir() { _input= - if [ -z "$fflag" ]; then + if [ -z "${fflag}" ]; then echo -n "Home directory [${homeprefix}/${username}]: " read _input else - _input="`echo "$fileline" | cut -f8 -d:`" + _input="$(echo "${fileline}" | cut -f8 -d:)" fi - if [ -n "$_input" ]; then - uhome="$_input" + if [ -n "${_input}" ]; then + uhome="${_input}" # if this is a configuration run, then user input is the home # directory prefix. Otherwise it is understood to # be $prefix/$user # - [ -z "$configflag" ] && homeprefix="`dirname $uhome`" || homeprefix="$uhome" + [ -z "${configflag}" ] && homeprefix="$(dirname "${uhome}")" || homeprefix="${uhome}" else uhome="${homeprefix}/${username}" fi @@ -461,22 +461,22 @@ # Reads the account's home directory permissions. # get_homeperm() { - uhomeperm=$defaultHomePerm + uhomeperm=${defaultHomePerm} _input= _prompt= - if [ -n "$uhomeperm" ]; then + if [ -n "${uhomeperm}" ]; then _prompt="Home directory permissions [${uhomeperm}]: " else _prompt="Home directory permissions (Leave empty for default): " fi - if [ -z "$fflag" ]; then - echo -n "$_prompt" + if [ -z "${fflag}" ]; then + echo -n "${_prompt}" read _input fi - if [ -n "$_input" ]; then - uhomeperm="$_input" + if [ -n "${_input}" ]; then + uhomeperm="${_input}" fi } @@ -489,40 +489,40 @@ _input= _prompt= - if [ -n "$uuid" ]; then - uuid=`get_nextuid $uuid` - _prompt="Uid [$uuid]: " + if [ -n "${uuid}" ]; then + uuid="$(get_nextuid "${uuid}")" + _prompt="Uid [${uuid}]: " else _prompt="Uid (Leave empty for default): " fi - if [ -z "$fflag" ]; then - echo -n "$_prompt" + if [ -z "${fflag}" ]; then + echo -n "${_prompt}" read _input else - _input="`echo "$fileline" | cut -f2 -d:`" + _input="$(echo "${fileline}" | cut -f2 -d:)" fi - [ -n "$_input" ] && uuid=$_input - uuid=`get_nextuid $uuid` - uidstart=$uuid + [ -n "${_input}" ] && uuid=${_input} + uuid="$(get_nextuid "${uuid}")" + uidstart=${uuid} } # get_class # Reads login class of account. Can be used in interactive or batch mode. # get_class() { - uclass="$defaultclass" + uclass="${defaultclass}" _input= _class=${uclass:-"default"} - if [ -z "$fflag" ]; then - echo -n "Login class [$_class]: " + if [ -z "${fflag}" ]; then + echo -n "Login class [${_class}]: " read _input else - _input="`echo "$fileline" | cut -f4 -d:`" + _input="$(echo "${fileline}" | cut -f4 -d:)" fi - [ -n "$_input" ] && uclass="$_input" + [ -n "${_input}" ] && uclass="${_input}" } # get_logingroup @@ -533,18 +533,18 @@ # will then provide a login group with the same name as the username. # get_logingroup() { - ulogingroup="$defaultLgroup" + ulogingroup="${defaultLgroup}" _input= - if [ -z "$fflag" ]; then + if [ -z "${fflag}" ]; then echo -n "Login group [${ulogingroup:-$username}]: " read _input else - _input="`echo "$fileline" | cut -f3 -d:`" + _input="$(echo "${fileline}" | cut -f3 -d:)" fi # Pw(8) will use the username as login group if it's left empty - [ -n "$_input" ] && ulogingroup="$_input" + [ -n "${_input}" ] && ulogingroup="${_input}" } # get_groups @@ -552,19 +552,19 @@ # and batch modes. # get_groups() { - ugroups="$defaultgroups" + ugroups="${defaultgroups}" _input= _group=${ulogingroup:-"${username}"} - if [ -z "$configflag" ]; then - [ -z "$fflag" ] && echo -n "Login group is $_group. Invite $username" - [ -z "$fflag" ] && echo -n " into other groups? [$ugroups]: " + if [ -z "${configflag}" ]; then + [ -z "${fflag}" ] && echo -n "Login group is ${_group}. Invite ${username}" + [ -z "${fflag}" ] && echo -n " into other groups? [${ugroups}]: " else - [ -z "$fflag" ] && echo -n "Enter additional groups [$ugroups]: " + [ -z "${fflag}" ] && echo -n "Enter additional groups [${ugroups}]: " fi read _input - [ -n "$_input" ] && ugroups="$_input" + [ -n "${_input}" ] && ugroups="${_input}" } # get_expire_dates @@ -572,8 +572,8 @@ # routine is used only from batch processing mode. # get_expire_dates() { - upwexpire="`echo "$fileline" | cut -f5 -d:`" - uexpire="`echo "$fileline" | cut -f6 -d:`" + upwexpire="$(echo "${fileline}" | cut -f5 -d:)" + uexpire="$(echo "${fileline}" | cut -f6 -d:)" } # get_password @@ -588,16 +588,16 @@ # We may temporarily change a password type. Make sure it's changed # back to whatever it was before we process the next account. # - [ -n "$savedpwtype" ] && { - passwdtype=$savedpwtype + [ -n "${savedpwtype}" ] && { + passwdtype=${savedpwtype} savedpwtype= } # There may be a ':' in the password upass=${fileline#*:*:*:*:*:*:*:*:*:} - if [ -z "$upass" ]; then - case $passwdtype in + if [ -z "${upass}" ]; then + case "${passwdtype}" in yes) # if it's empty, assume an empty password passwdtype=none @@ -605,7 +605,7 @@ ;; esac else - case $passwdtype in + case "${passwdtype}" in random) passwdtype=yes savedpwtype=random @@ -622,7 +622,7 @@ _field= while read -r fileline ; do - case "$fileline" in + case "${fileline}" in \#*|'') ;; *) @@ -636,7 +636,7 @@ get_homeperm get_password get_expire_dates - ugroups="$defaultgroups" + ugroups="${defaultgroups}" add_user ;; @@ -657,7 +657,7 @@ _usepass="yes" _logingroup_ok="no" _groups_ok="no" - case $passwdtype in + case "${passwdtype}" in none) _emptypass="yes" _usepass="yes" @@ -676,23 +676,23 @@ # The case where group = user is handled elsewhere, so # validate any other groups the user is invited to. - until [ "$_logingroup_ok" = yes ]; do + until [ "${_logingroup_ok}" = yes ]; do get_logingroup _logingroup_ok=yes - if [ -n "$ulogingroup" -a "$username" != "$ulogingroup" ]; then - if ! ${PWCMD} show group $ulogingroup > /dev/null 2>&1; then - echo "Group $ulogingroup does not exist!" + if [ -n "${ulogingroup}" -a "${username}" != "${ulogingroup}" ]; then + if ! ${PWCMD} show group "${ulogingroup}" > /dev/null 2>&1; then + echo "Group ${ulogingroup} does not exist!" _logingroup_ok=no fi fi done - until [ "$_groups_ok" = yes ]; do + until [ "${_groups_ok}" = yes ]; do get_groups _groups_ok=yes - for i in $ugroups; do - if [ "$username" != "$i" ]; then - if ! ${PWCMD} show group $i > /dev/null 2>&1; then - echo "Group $i does not exist!" + for i in ${ugroups}; do + if [ "${username}" != "$i" ]; then + if ! ${PWCMD} show group "$i" > /dev/null 2>&1; then + echo "Group ${i} does not exist!" _groups_ok=no fi fi @@ -705,31 +705,31 @@ get_homeperm while : ; do - echo -n "Use password-based authentication? [$_usepass]: " + echo -n "Use password-based authentication? [${_usepass}]: " read _input - [ -z "$_input" ] && _input=$_usepass - case $_input in + [ -z "${_input}" ] && _input=${_usepass} + case "${_input}" in [Nn][Oo]|[Nn]) passwdtype="no" ;; [Yy][Ee][Ss]|[Yy][Ee]|[Yy]) while : ; do - echo -n "Use an empty password? (yes/no) [$_emptypass]: " + echo -n "Use an empty password? (yes/no) [${_emptypass}]: " read _input - [ -n "$_input" ] && _emptypass=$_input - case $_emptypass in + [ -n "${_input}" ] && _emptypass=${_input} + case "${_emptypass}" in [Nn][Oo]|[Nn]) - echo -n "Use a random password? (yes/no) [$_random]: " + echo -n "Use a random password? (yes/no) [${_random}]: " read _input - [ -n "$_input" ] && _random="$_input" - case $_random in + [ -n "${_input}" ] && _random="${_input}" + case "${_random}" in [Yy][Ee][Ss]|[Yy][Ee]|[Yy]) passwdtype="random" break ;; esac passwdtype="yes" - [ -n "$configflag" ] && break + [ -n "${configflag}" ] && break trap 'stty echo; exit' 0 1 2 3 15 stty -echo echo -n "Enter password: " @@ -741,7 +741,7 @@ stty echo # if user entered a blank password # explicitly ask again. - [ -z "$upass" -a -z "$_passconfirm" ] \ + [ -z "${upass}" -a -z "${_passconfirm}" ] \ && continue ;; [Yy][Ee][Ss]|[Yy][Ee]|[Yy]) @@ -753,7 +753,7 @@ continue ;; esac - if [ "$upass" != "$_passconfirm" ]; then + if [ "${upass}" != "${_passconfirm}" ]; then echo "Passwords did not match!" continue fi @@ -769,10 +769,10 @@ done _disable=${disableflag:-"no"} while : ; do - echo -n "Lock out the account after creation? [$_disable]: " + echo -n "Lock out the account after creation? [${_disable}]: " read _input - [ -z "$_input" ] && _input=$_disable - case $_input in + [ -z "${_input}" ] && _input=${_disable} + case "${_input}" in [Nn][Oo]|[Nn]) disableflag= ;; @@ -786,13 +786,13 @@ esac break done - + # Display the information we have so far and prompt to # commit it. # _disable=${disableflag:-"no"} - [ -z "$configflag" ] && printf "%-10s : %s\n" Username $username - case $passwdtype in + [ -z "${configflag}" ] && printf "%-10s : %s\n" Username "${username}" + case "${passwdtype}" in yes) _pass='*****' ;; @@ -806,20 +806,20 @@ _pass='' ;; esac - [ -z "$configflag" ] && printf "%-10s : %s\n" "Password" "$_pass" - [ -n "$configflag" ] && printf "%-10s : %s\n" "Pass Type" "$passwdtype" - [ -z "$configflag" ] && printf "%-10s : %s\n" "Full Name" "$ugecos" - [ -z "$configflag" ] && printf "%-10s : %s\n" "Uid" "$uuid" - printf "%-10s : %s\n" "Class" "$uclass" - printf "%-10s : %s %s\n" "Groups" "${ulogingroup:-$username}" "$ugroups" - printf "%-10s : %s\n" "Home" "$uhome" - printf "%-10s : %s\n" "Home Mode" "$uhomeperm" - printf "%-10s : %s\n" "Shell" "$ushell" - printf "%-10s : %s\n" "Locked" "$_disable" + [ -z "${configflag}" ] && printf "%-10s : %s\n" "Password" "${_pass}" + [ -n "${configflag}" ] && printf "%-10s : %s\n" "Pass Type" "${passwdtype}" + [ -z "${configflag}" ] && printf "%-10s : %s\n" "Full Name" "${ugecos}" + [ -z "${configflag}" ] && printf "%-10s : %s\n" "Uid" "${uuid}" + printf "%-10s : %s\n" "Class" "${uclass}" + printf "%-10s : %s %s\n" "Groups" "${ulogingroup:-$username}" "${ugroups}" + printf "%-10s : %s\n" "Home" "${uhome}" + printf "%-10s : %s\n" "Home Mode" "${uhomeperm}" + printf "%-10s : %s\n" "Shell" "${ushell}" + printf "%-10s : %s\n" "Locked" "${_disable}" while : ; do echo -n "OK? (yes/no): " read _input - case $_input in + case "${_input}" in [Nn][Oo]|[Nn]) return 1 ;; @@ -837,7 +837,7 @@ #### END SUBROUTINE DEFINITION #### -THISCMD=`/usr/bin/basename $0` +THISCMD="$(/usr/bin/basename "$0")" DEFAULTSHELL=/bin/sh ADDUSERCONF="${ADDUSERCONF:-/etc/adduser.conf}" PWCMD="${PWCMD:-/usr/sbin/pw}" @@ -865,7 +865,7 @@ ugroups= uexpire= upwexpire= -shells="`valid_shells`" +shells="$(valid_shells)" passwdtype="yes" msgfile=/etc/adduser.msg msgflag= @@ -891,8 +891,8 @@ # measure as much as it is a useful method of reminding the user to # 'su -' before he/she wastes time entering data that won't be saved. # -procowner=${procowner:-`/usr/bin/id -u`} -if [ "$procowner" != "0" ]; then +procowner=${procowner:-$(/usr/bin/id -u)} +if [ "${procowner}" != "0" ]; then err 'you must be the super-user (uid 0) to use this utility.' exit 1 fi @@ -904,25 +904,25 @@ # should override configuration file). # for _i in $* ; do - if [ "$_i" = "-N" ]; then + if [ "${_i}" = "-N" ]; then readconfig= break; fi done -if [ -n "$readconfig" ]; then +if [ -n "${readconfig}" ]; then # On a long-lived system, the first time this script is run it # will barf upon reading the configuration file for its perl predecessor. - if ( . ${ADDUSERCONF} > /dev/null 2>&1 ); then - [ -r ${ADDUSERCONF} ] && . ${ADDUSERCONF} > /dev/null 2>&1 + if ( . "${ADDUSERCONF}" > /dev/null 2>&1 ); then + [ -r "${ADDUSERCONF}" ] && . "${ADDUSERCONF}" > /dev/null 2>&1 fi -fi +fi # Process command-line options # for _switch ; do - case $_switch in + case "${_switch}" in -L) - defaultclass="$2" + defaultclass="${2}" shift; shift ;; -C) @@ -938,20 +938,20 @@ shift ;; -k) - udotdir="$2" + udotdir="${2}" shift; shift ;; -f) - [ "$2" != "-" ] && infile="$2" + [ "${2}" != "-" ] && infile="${2}" fflag=yes shift; shift ;; -g) - defaultLgroup="$2" + defaultLgroup="${2}" shift; shift ;; -G) - defaultgroups="$2" + defaultgroups="${2}" shift; shift ;; -h) @@ -959,23 +959,23 @@ exit 0 ;; -d) - homeprefix="$2" + homeprefix="${2}" shift; shift ;; -m) - case "$2" in + case "${2}" in [Nn][Oo]) msgflag= ;; *) msgflag=yes - msgfile="$2" + msgfile="${2}" ;; esac shift; shift ;; -M) - defaultHomePerm=$2 + defaultHomePerm="${2}" shift; shift ;; -N) @@ -983,9 +983,9 @@ shift ;; -w) - case "$2" in + case "${2}" in no|none|random|yes) - passwdtype=$2 + passwdtype="${2}" ;; *) show_usage @@ -999,7 +999,7 @@ shift ;; -s) - defaultshell="`fullpath_from_shell $2`" + defaultshell="$(fullpath_from_shell "${2}")" shift; shift ;; -S) @@ -1007,7 +1007,7 @@ shift ;; -u) - uidstart=$2 + uidstart="${2}" shift; shift ;; esac @@ -1016,28 +1016,28 @@ # If the -f switch was used, get input from a file. Otherwise, # this is an interactive session. # -if [ -n "$fflag" ]; then - if [ -z "$infile" ]; then +if [ -n "${fflag}" ]; then + if [ -z "${infile}" ]; then input_from_file - elif [ -n "$infile" ]; then - if [ -r "$infile" ]; then - input_from_file < $infile + elif [ -n "${infile}" ]; then + if [ -r "${infile}" ]; then + input_from_file < "${infile}" else - err "File ($infile) is unreadable or does not exist." + err "File (${infile}) is unreadable or does not exist." fi fi else input_interactive while : ; do - if [ -z "$configflag" ]; then + if [ -z "${configflag}" ]; then echo -n "Add another user? (yes/no): " else echo -n "Re-edit the default configuration? (yes/no): " fi read _input - case $_input in + case "${_input}" in [Yy][Ee][Ss]|[Yy][Ee]|[Yy]) - uidstart=`get_nextuid $uidstart` + uidstart="$(get_nextuid "${uidstart}")" input_interactive continue ;;