From: Sascha Wildner Date: Mon, 31 Oct 2011 15:43:37 +0000 (+0100) Subject: adduser(8): Sync with FreeBSD. X-Git-Tag: v3.0.0~768 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/9ed5bb8ac3273f3a5493b92ab5dc3a6b15f7a87c adduser(8): Sync with FreeBSD. Submitted-by: Juan Francisco Cantero Hurtado Dragonfly-bug: --- diff --git a/usr.sbin/adduser/Makefile b/usr.sbin/adduser/Makefile index f1e2ac401a..c22cf3a921 100644 --- a/usr.sbin/adduser/Makefile +++ b/usr.sbin/adduser/Makefile @@ -1,5 +1,4 @@ # $FreeBSD: src/usr.sbin/adduser/Makefile,v 1.19 2004/03/30 21:50:42 trhodes Exp $ -# $DragonFly: src/usr.sbin/adduser/Makefile,v 1.4 2004/06/21 17:47:12 cpressey Exp $ SCRIPTS=adduser.sh rmuser.sh MAN= adduser.conf.5 adduser.8 rmuser.8 diff --git a/usr.sbin/adduser/adduser.8 b/usr.sbin/adduser/adduser.8 index aad06be630..fd95ec2c73 100644 --- a/usr.sbin/adduser/adduser.8 +++ b/usr.sbin/adduser/adduser.8 @@ -24,10 +24,9 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD: src/usr.sbin/adduser/adduser.8,v 1.60 2007/10/20 00:45:31 mtm Exp $ -.\" $DragonFly: src/usr.sbin/adduser/adduser.8,v 1.5 2007/12/28 16:37:10 matthias Exp $ +.\" $FreeBSD: src/usr.sbin/adduser/adduser.8,v 1.62 2008/03/16 21:36:05 brueffer Exp $ .\" -.Dd June 7, 2006 +.Dd October 31, 2011 .Dt ADDUSER 8 .Os .Sh NAME @@ -38,6 +37,7 @@ .Op Fl CDENShq .Op Fl G Ar groups .Op Fl L Ar login_class +.Op Fl M Ar mode .Op Fl d Ar partition .Op Fl f Ar file .Op Fl g Ar login_group @@ -240,6 +240,9 @@ Please note that the message file can reference the internal variables of the .Nm script. +.It Fl M Ar mode +Create the home directory with permissions set to +.Ar mode . .It Fl N Do not read the default configuration file. .It Fl q @@ -393,7 +396,7 @@ and this field is empty, its contents will be used as a password. This field will be ignored if the -.Fl p +.Fl w option is used with a .Cm no or diff --git a/usr.sbin/adduser/adduser.conf.5 b/usr.sbin/adduser/adduser.conf.5 index 9eea06d01e..9dccac7182 100644 --- a/usr.sbin/adduser/adduser.conf.5 +++ b/usr.sbin/adduser/adduser.conf.5 @@ -23,8 +23,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD: src/usr.sbin/adduser/adduser.conf.5,v 1.6 2007/04/12 08:39:13 ceri Exp $ -.\" $DragonFly: src/usr.sbin/adduser/adduser.conf.5,v 1.3 2007/12/29 18:18:00 swildner Exp $ +.\" $FreeBSD: src/usr.sbin/adduser/adduser.conf.5,v 1.7 2010/05/13 12:07:55 uqs Exp $ .\" .Dd April 12, 2007 .Dt ADDUSER.CONF 5 diff --git a/usr.sbin/adduser/adduser.sh b/usr.sbin/adduser/adduser.sh index 3a8a9d3d59..4623bcb124 100644 --- a/usr.sbin/adduser/adduser.sh +++ b/usr.sbin/adduser/adduser.sh @@ -24,25 +24,24 @@ # # Email: Mike Makonnen # -# $FreeBSD: src/usr.sbin/adduser/adduser.sh,v 1.31 2007/10/20 00:45:31 mtm Exp $ -# $DragonFly: src/usr.sbin/adduser/adduser.sh,v 1.4 2008/07/21 23:42:02 swildner Exp $ +# $FreeBSD: src/usr.sbin/adduser/adduser.sh,v 1.33 2010/01/14 22:04:08 joel Exp $ # # err msg -# Display $msg on stderr, unless we're being quiet. -# +# Display $msg on stderr, unless we're being quiet. +# err() { if [ -z "$quietflag" ]; then - echo 1>&2 ${THISCMD}: ERROR: $* + echo 1>&2 ${THISCMD}: ERROR: $* fi } # info msg -# Display $msg on stdout, unless we're being quiet. -# +# Display $msg on stdout, unless we're being quiet. +# info() { if [ -z "$quietflag" ]; then - echo ${THISCMD}: INFO: $* + echo ${THISCMD}: INFO: $* fi } @@ -51,7 +50,7 @@ info() { # is not, output the value of the next higher uid that is available. # If a uid is not specified, output the first available uid, as indicated # by pw(8). -# +# get_nextuid () { _uid=$1 _nextuid= @@ -82,6 +81,7 @@ show_usage() { echo " -E disable this account after creation" echo " -G additional groups to add accounts to" echo " -L login class of the user" + echo " -M file permission for home directory" echo " -N do not read configuration file" echo " -S a nonexistent shell is not an error" echo " -d home directory" @@ -163,8 +163,7 @@ fullpath_from_shell() { # the path is invalid or it is not executable it # will emit an informational message saying so. # -shell_exists() -{ +shell_exists() { _sh="$1" _shellchk="${GREPCMD} '^$_sh$' ${ETCSHELLS} > /dev/null 2>&1" @@ -191,6 +190,7 @@ save_config() { 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} @@ -248,7 +248,12 @@ add_user() { if [ "$uhome" = "$NOHOME" ]; then _home='-d "$uhome"' else - _home='-m -d "$uhome"' + # Use home directory permissions if specified + if [ -n "$uhomeperm" ]; then + _home='-m -d "$uhome" -M "$uhomeperm"' + else + _home='-m -d "$uhome"' + fi fi elif [ -n "$Dflag" -a -n "$uhome" ]; then _home='-d "$uhome"' @@ -450,6 +455,29 @@ get_homedir() { fi } +# get_homeperm +# Reads the account's home directory permissions. +# +get_homeperm() { + uhomeperm=$defaultHomePerm + _input= + _prompt= + + 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" + read _input + fi + + if [ -n "$_input" ]; then + uhomeperm="$_input" + fi +} + # get_uid # Reads a numeric userid in an interactive or batch session. Automatically # allocates one if it is not specified. @@ -602,6 +630,7 @@ input_from_file() { get_class get_shell get_homedir + get_homeperm get_password get_expire_dates ugroups="$defaultgroups" @@ -617,7 +646,6 @@ input_from_file() { # the user database. # input_interactive() { - _disable= _pass= _passconfirm= @@ -671,6 +699,7 @@ input_interactive() { get_class get_shell get_homedir + get_homeperm while : ; do echo -n "Use password-based authentication? [$_usepass]: " @@ -781,6 +810,7 @@ input_interactive() { 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 @@ -825,6 +855,7 @@ ugecos= ulogingroup= uclass= uhome= +uhomeperm= upass= ushell= udotdir=/usr/share/skel @@ -851,6 +882,7 @@ defaultclass= defaultLgroup= defaultgroups= defaultshell="${DEFAULTSHELL}" +defaultHomePerm= # Make sure the user running this program is root. This isn't a security # measure as much as it is a useful method of reminding the user to @@ -939,6 +971,10 @@ for _switch ; do esac shift; shift ;; + -M) + defaultHomePerm=$2 + shift; shift + ;; -N) readconfig= shift diff --git a/usr.sbin/adduser/rmuser.8 b/usr.sbin/adduser/rmuser.8 index cb10476f81..dd1869917e 100644 --- a/usr.sbin/adduser/rmuser.8 +++ b/usr.sbin/adduser/rmuser.8 @@ -25,7 +25,6 @@ .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" $FreeBSD: src/usr.sbin/adduser/rmuser.8,v 1.25 2006/12/05 23:20:14 ceri Exp $ -.\" $DragonFly: src/usr.sbin/adduser/rmuser.8,v 1.5 2007/12/28 16:37:10 matthias Exp $ .\" .Dd May 10, 2002 .Dt RMUSER 8 diff --git a/usr.sbin/adduser/rmuser.sh b/usr.sbin/adduser/rmuser.sh index fa2f4cf3fd..7cbf350894 100644 --- a/usr.sbin/adduser/rmuser.sh +++ b/usr.sbin/adduser/rmuser.sh @@ -24,8 +24,7 @@ # # Email: Mike Makonnen # -# $FreeBSD: src/usr.sbin/adduser/rmuser.sh,v 1.8 2004/02/29 09:54:15 schweikh Exp $ -# $DragonFly: src/usr.sbin/adduser/rmuser.sh,v 1.1 2004/06/21 17:47:12 cpressey Exp $ +# $FreeBSD: src/usr.sbin/adduser/rmuser.sh,v 1.11 2008/07/30 18:37:21 jhb Exp $ # ATJOBDIR="/var/at/jobs" @@ -34,6 +33,7 @@ MAILSPOOL="/var/mail" SIGKILL="-KILL" TEMPDIRS="/tmp /var/tmp" THISCMD=`/usr/bin/basename $0` +PWCMD="${PWCMD:-/usr/sbin/pw}" # err msg # Display $msg on stderr. @@ -87,10 +87,10 @@ rm_mail() { echo -n " mailspool" rm ${MAILSPOOL}/$login fi - if [ -f ${MAILSPOOL}/${login}.pop ]; then - verbose && echo -n " ${MAILSPOOL}/${login}.pop" || + if [ -f ${MAILSPOOL}/.${login}.pop ]; then + verbose && echo -n " ${MAILSPOOL}/.${login}.pop" || echo -n " pop3" - rm ${MAILSPOOL}/${login}.pop + rm ${MAILSPOOL}/.${login}.pop fi verbose && echo '.' } @@ -179,7 +179,7 @@ rm_user() { } ! verbose && echo -n " passwd" verbose && echo -n " from the system:" - pw userdel -n $login $pw_rswitch + ${PWCMD} userdel -n $login $pw_rswitch verbose && echo ' Done.' } @@ -302,7 +302,7 @@ if [ ! "$userlist" ]; then show_usage exit 1 else - echo -n "Please enter one or more user name's: " + echo -n "Please enter one or more user names: " read userlist fi fi @@ -313,7 +313,7 @@ for _user in $userlist ; do # Make sure the name exists in the passwd database and that it # does not have a uid of 0 # - userrec=`pw 2>/dev/null usershow -n $_user` + userrec=`${PWCMD} 2>/dev/null usershow -n $_user` if [ "$?" != "0" ]; then err "user ($_user) does not exist in the password database." continue @@ -344,7 +344,7 @@ for _user in $userlist ; do fi # Disable any further attempts to log into this account - pw 2>/dev/null lock $_user + ${PWCMD} 2>/dev/null lock $_user # Remove crontab, mail spool, etc. Then obliterate the user from # the passwd and group database.