Index: usr.sbin/adduser/adduser.8 =================================================================== --- usr.sbin/adduser/adduser.8 +++ usr.sbin/adduser/adduser.8 @@ -26,7 +26,7 @@ .\" .\" $FreeBSD$ .\" -.Dd September 15, 2012 +.Dd April 9, 2015 .Dt ADDUSER 8 .Os .Sh NAME @@ -46,6 +46,7 @@ .Op Fl s Ar shell .Op Fl u Ar uid_start .Op Fl w Ar type +.Op Fl z Ar dataset .Sh DESCRIPTION The .Nm @@ -244,6 +245,10 @@ .Ar mode . .It Fl N Do not read the default configuration file. +.It Fl o Ar properties +ZFS properties for home directory dataset. +A comma separated list of ZFS properties to set on each users' home +directory when it is created. .It Fl q Minimal user feedback. In particular, the random password will not be echoed to @@ -297,6 +302,15 @@ .Va randompass variable. .El +.It Fl z Ar dataset +Create ZFS dataset for home directory. +Create a ZFS dataset for each users' home directory, under the +.Ar dataset +parent dataset. +The +.Fl o +argument can be used to specify a comma separated list of properties +to set on the dataset. .El .Sh FORMAT When the Index: usr.sbin/adduser/adduser.conf.5 =================================================================== --- usr.sbin/adduser/adduser.conf.5 +++ usr.sbin/adduser/adduser.conf.5 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd April 12, 2007 +.Dd April 9, 2015 .Dt ADDUSER.CONF 5 .Os .Sh NAME @@ -173,6 +173,14 @@ .It Va uidstart The default user ID setting. This must be a number above 1000 and fewer than 65534. +.It Va zfshome +Set to +.Cm yes +to create a ZFS dataset for each users' home directory. +.It Va zfshome_dataset +The ZFS dataset to be the parent of the newly created datasets. +.It Va zfshome_properties +The ZFS properties to set on each new dataset. .El .Sh EXAMPLES The following is an example @@ -196,6 +204,9 @@ msgfile=/etc/adduser.msg disableflag= upwexpire=91d # Expire passwords 91 days after creation. +zfshome=yes +zfshome_dataset=zroot/usr/home +zfshome_properties=compress=lz4,quota=2G .Ed .Sh SEE ALSO .Xr group 5 , Index: usr.sbin/adduser/adduser.sh =================================================================== --- usr.sbin/adduser/adduser.sh +++ usr.sbin/adduser/adduser.sh @@ -1,6 +1,7 @@ #!/bin/sh # # Copyright (c) 2002-2004 Michael Telahun Makonnen. All rights reserved. +# Copyright (c) 2015 Allan Jude # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -94,6 +95,7 @@ echo " -s shell" echo " -u uid to start at" echo " -w password type: no, none, yes or random" + echo " -z create ZFS dataset for home directory" } # valid_shells @@ -231,6 +233,7 @@ _passwd= _upasswd= _passwdmethod= + _zfsopt= _name="-n '$username'" [ -n "$uuid" ] && _uid='-u "$uuid"' @@ -282,6 +285,18 @@ ;; esac + if [ -n "$zfshome" ]; then + oIFS="$IFS"; IFS=',' + for _z in $zfshome_options; do + _zfsopt="$_zfsopt -o $_z" + done + IFS="$oIFS" + if ! _output=`${ZFSCMD} create ${_zfsopt} -o mountpoint=$uhome ${zfshome_dataset}/${username}`; then + err "There was an error creating the ZFS dataset (${zfshome_dataset}/${username})." + return 1 + fi + fi + _pwcmd="$_upasswd ${PWCMD} useradd $_uid $_name $_group $_grouplist $_comment" _pwcmd="$_pwcmd $_shell $_class $_home $_dotdir $_passwdmethod $_passwd" _pwcmd="$_pwcmd $_expire $_pwexpire" @@ -839,6 +854,7 @@ DEFAULTSHELL=/bin/sh ADDUSERCONF="${ADDUSERCONF:-/etc/adduser.conf}" PWCMD="${PWCMD:-/usr/sbin/pw}" +ZFSCMD="${ZFSCMD:-/sbin/zfs}" MAILCMD="${MAILCMD:-mail}" ETCSHELLS="${ETCSHELLS:-/etc/shells}" NOHOME="/nonexistent" @@ -913,7 +929,7 @@ if ( . ${ADDUSERCONF} > /dev/null 2>&1 ); then [ -r ${ADDUSERCONF} ] && . ${ADDUSERCONF} > /dev/null 2>&1 fi -fi +fi # Process command-line options # @@ -980,6 +996,10 @@ readconfig= shift ;; + -o) + zfshome_options=$2 + shift; shift + ;; -w) case "$2" in no|none|random|yes) @@ -1008,6 +1028,11 @@ uidstart=$2 shift; shift ;; + -z) + zfshome=yes + zfshome_dataset=$2 + shift; shift + ;; esac done Index: usr.sbin/adduser/rmuser.sh =================================================================== --- usr.sbin/adduser/rmuser.sh +++ usr.sbin/adduser/rmuser.sh @@ -1,6 +1,7 @@ #!/bin/sh # # Copyright (c) 2002, 2003 Michael Telahun Makonnen. All rights reserved. +# Copyright (c) 2015 Allan Jude # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -34,6 +35,7 @@ TEMPDIRS="/tmp /var/tmp" THISCMD=`/usr/bin/basename $0` PWCMD="${PWCMD:-/usr/sbin/pw}" +ZFSCMD="${ZFSCMD:-/sbin/zfs}" # err msg # Display $msg on stderr. @@ -177,6 +179,17 @@ verbose && echo -n " (including home directory)" ! verbose && echo -n " home" } + if [ -n "$pw_rswitch" -a -c /dev/zfs ]; then + _homedir=`eval echo ~${login}` + if [ -n "$_homedir" ]; then + _dataset=`${ZFSCMD} list -H -o name $_homedir` + if [ -n "$_dataset" ]; then + verbose && echo -n " (manually remove ZFS dataset)" + ! verbose && echo -n " not-removing-zfs" + fi + fi + fi + ! verbose && echo -n " passwd" verbose && echo -n " from the system:" ${PWCMD} userdel -n $login $pw_rswitch