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 @@ -34,7 +34,7 @@ # err() { if [ -z "$quietflag" ]; then - echo 1>&2 ${THISCMD}: ERROR: $* + echo 1>&2 "${THISCMD}: ERROR: $*" fi } @@ -43,7 +43,7 @@ # info() { if [ -z "$quietflag" ]; then - echo ${THISCMD}: INFO: $* + echo "${THISCMD}: INFO: $*" fi } @@ -58,10 +58,10 @@ _nextuid= if [ -z "$_uid" ]; then - _nextuid="`${PWCMD} usernext | cut -f1 -d:`" + _nextuid="$(${PWCMD} usernext | cut -f1 -d:)" else while : ; do - ${PWCMD} usershow $_uid > /dev/null 2>&1 + ${PWCMD} usershow "$_uid" > /dev/null 2>&1 if [ ! "$?" -eq 0 ]; then _nextuid=$_uid break @@ -69,7 +69,7 @@ _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 \#*|'') ;; *) - echo -n "${_prefix}`basename $_path`" + echo -n "${_prefix}$(basename "$_path")" _prefix=' ' ;; esac @@ -140,15 +140,15 @@ return 0; fi - cat ${ETCSHELLS} | + cat "${ETCSHELLS}" | while read _path _junk ; do case "$_path" in \#*|'') ;; *) if [ "$_path" = "$_shell" -o \ - "`basename $_path`" = "$_shell" ]; then - echo $_path + "$(basename "$_path")" = "$_shell" ]; then + echo "$_path" return 0 fi ;; @@ -169,7 +169,7 @@ _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." @@ -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 @@ -288,7 +288,7 @@ _pwcmd="$_pwcmd $_shell $_class $_home $_dotdir $_passwdmethod $_passwd" _pwcmd="$_pwcmd $_expire $_pwexpire" - if ! _output=`eval $_pwcmd` ; then + if ! _output=$(eval "$_pwcmd") ; then err "There was an error adding user ($username)." return 1 else @@ -300,7 +300,7 @@ fi if [ -n "$disableflag" ]; then - if ${PWCMD} lock $username ; then + if ${PWCMD} lock "$username" ; then info "Account ($username) is locked." else info "Account ($username) could NOT be locked." @@ -317,10 +317,10 @@ # 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` + _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 @@ -328,7 +328,7 @@ cat "$msgfile" | while read _line ; do eval echo "$_line" - done | ${MAILCMD} -s"Welcome" ${username} + done | ${MAILCMD} -s"Welcome" "${username}" info "Sent welcome message to ($username)." } fi @@ -352,7 +352,7 @@ 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 @@ -363,7 +363,7 @@ err "You must enter a username!" [ -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 @@ -387,7 +387,7 @@ echo -n "Full name: " read _input else - _input="`echo "$fileline" | cut -f7 -d:`" + _input="$(echo "$fileline" | cut -f7 -d:)" fi ugecos="$_input" } @@ -404,23 +404,23 @@ # Make sure the current value of the shell is a valid one if [ -z "$Sflag" ]; then - if ! shell_exists $ushell ; then + if ! shell_exists "$ushell" ; then info "Using default shell ${defaultshell}." ushell="$defaultshell" fi fi if [ -z "$fflag" ]; then - echo -n "Shell ($shells) [`basename $ushell`]: " + 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" else - _fullpath=`fullpath_from_shell $_input` + _fullpath=$(fullpath_from_shell "$_input") if [ -n "$_fullpath" ]; then ushell="$_fullpath" else @@ -442,7 +442,7 @@ 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 @@ -451,7 +451,7 @@ # 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 @@ -490,7 +490,7 @@ _prompt= if [ -n "$uuid" ]; then - uuid=`get_nextuid $uuid` + uuid=$(get_nextuid "$uuid") _prompt="Uid [$uuid]: " else _prompt="Uid (Leave empty for default): " @@ -499,11 +499,11 @@ 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` + uuid=$(get_nextuid "$uuid") uidstart=$uuid } @@ -519,7 +519,7 @@ 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" @@ -540,7 +540,7 @@ 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 @@ -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 @@ -680,7 +680,7 @@ get_logingroup _logingroup_ok=yes if [ -n "$ulogingroup" -a "$username" != "$ulogingroup" ]; then - if ! ${PWCMD} show group $ulogingroup > /dev/null 2>&1; then + if ! ${PWCMD} show group "$ulogingroup" > /dev/null 2>&1; then echo "Group $ulogingroup does not exist!" _logingroup_ok=no fi @@ -691,7 +691,7 @@ _groups_ok=yes for i in $ugroups; do if [ "$username" != "$i" ]; then - if ! ${PWCMD} show group $i > /dev/null 2>&1; then + if ! ${PWCMD} show group "$i" > /dev/null 2>&1; then echo "Group $i does not exist!" _groups_ok=no fi @@ -786,12 +786,12 @@ 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 + [ -z "$configflag" ] && printf "%-10s : %s\n" Username "$username" case $passwdtype in yes) _pass='*****' @@ -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,7 +891,7 @@ # 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`} +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 @@ -912,10 +912,10 @@ 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 # @@ -999,7 +999,7 @@ shift ;; -s) - defaultshell="`fullpath_from_shell $2`" + defaultshell="$(fullpath_from_shell "$2")" shift; shift ;; -S) @@ -1021,7 +1021,7 @@ input_from_file elif [ -n "$infile" ]; then if [ -r "$infile" ]; then - input_from_file < $infile + input_from_file < "$infile" else err "File ($infile) is unreadable or does not exist." fi @@ -1037,7 +1037,7 @@ read _input case $_input in [Yy][Ee][Ss]|[Yy][Ee]|[Yy]) - uidstart=`get_nextuid $uidstart` + uidstart=$(get_nextuid "$uidstart") input_interactive continue ;;