diff options
author | wosch <wosch@FreeBSD.org> | 1998-06-07 18:38:32 +0000 |
---|---|---|
committer | wosch <wosch@FreeBSD.org> | 1998-06-07 18:38:32 +0000 |
commit | d0c6f6771ad19b91911772251de7954a790a3a8c (patch) | |
tree | b478e8f5e09d0d8f316861f2b11149879fd0bee5 /usr.sbin | |
parent | 1d5f38ac2264102518a09c66a7b285f57e81e67e (diff) | |
download | FreeBSD-src-d0c6f6771ad19b91911772251de7954a790a3a8c.zip FreeBSD-src-d0c6f6771ad19b91911772251de7954a790a3a8c.tar.gz |
Always ask for homedir.
PR: 6754
Submitted by: uhlar@netlab.sk
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/adduser/adduser.perl | 49 |
1 files changed, 38 insertions, 11 deletions
diff --git a/usr.sbin/adduser/adduser.perl b/usr.sbin/adduser/adduser.perl index 8e5dc53..6c4e51c 100644 --- a/usr.sbin/adduser/adduser.perl +++ b/usr.sbin/adduser/adduser.perl @@ -24,7 +24,7 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# $Id: adduser.perl,v 1.38 1997/12/24 11:44:14 wosch Exp $ +# $Id: adduser.perl,v 1.39 1998/01/10 17:27:21 wosch Exp $ # read variables @@ -173,7 +173,7 @@ sub shell_default_valid { return $s; } -# return default home partition (f.e. "/home") +# return default home partition (e.g. "/home") # create base directory if nesseccary sub home_partition { local($home) = @_; @@ -357,6 +357,20 @@ sub new_users_shell { return $shell{$sh}; } +# return home (full path) for user +# Note that the home path defaults to $home/$name for batch +sub new_users_home { + local($name) = @_; + local($userhome); + + while(1) { + $userhome = &confirm_list("Enter home directory (full path)", 1, "$home/$name", ""); + last if $userhome =~ /^\//; + warn qq{Home directory "$userhome" is not a full path\a\n}; + } + return $userhome; +} + # return free uid and gid sub new_users_id { local($name) = @_; @@ -536,7 +550,7 @@ Uid: $u_id Gid: $g_id ($group_login) Class: $class Groups: $group_login $new_groups -HOME: $home/$name +HOME: $userhome Shell: $sh EOF @@ -677,12 +691,14 @@ sub new_users { # name: Username # fullname: Full name # sh: shell + # userhome: home path for user # u_id: user id # g_id: group id # class: login class # group_login: groupname of g_id # new_groups: some other groups local($name, $group_login, $fullname, $sh, $u_id, $g_id, $class, $new_groups); + local($userhome); local($groupmembers_bak, $cryptpwd); local($new_users_ok) = 1; @@ -694,6 +710,7 @@ sub new_users { $name = &new_users_name; $fullname = &new_users_fullname($name); $sh = &new_users_shell; + $userhome = &new_users_home($name); ($u_id, $g_id) = &new_users_id($name); $class = &new_users_class($defaultclass); ($group_login, $defaultgroup) = @@ -712,14 +729,14 @@ sub new_users { $cryptpwd = crypt($password, &salt) if $password ne ""; # obscure perl bug $new_entry = "$name\:" . "$cryptpwd" . - "\:$u_id\:$g_id\:$class\:0:0:$fullname:$home/$name:$sh"; + "\:$u_id\:$g_id\:$class\:0:0:$fullname:$userhome:$sh"; &append_file($etc_passwd, "$new_entry"); &new_users_pwdmkdb("$new_entry"); &new_users_group_update; &new_users_passwd_update; print "Added user ``$name''\n"; &new_users_sendmessage; &adduser_log("$name:*:$u_id:$g_id($group_login):$fullname"); - &home_create($name, $group_login); + &home_create($userhome, $name, $group_login); } else { $new_users_ok = 0; } @@ -761,7 +778,7 @@ sub batch { &new_users_passwd_update; print "Added user ``$name''\n"; &sendmessage($name, @message_buffer) if $send_message ne "no"; &adduser_log("$name:*:$u_id:$g_id($group_login):$fullname"); - &home_create($name, $group_login); + &home_create("$home/$name", $name, $group_login); } # ask for password usage @@ -946,17 +963,28 @@ sub adduser_log { # create HOME directory, copy dotfiles from $dotdir to $HOME sub home_create { - local($name, $group) = @_; - local($homedir) = "$home/$name"; + local($homedir, $name, $group) = @_; + local($rootdir); if (-e "$homedir") { warn "HOME Directory ``$homedir'' already exist\a\n"; return 0; } + # if the home directory prefix doesn't exist, create it + # First, split the directory into a list; then remove the user's dir + @dir = split('/', $homedir); pop(@dir); + # Put back together & strip to get directory prefix + $rootdir = &stripdir(join('/', @dir)); + + if (!&mkdirhier("$rootdir")) { + # warn already displayed + return 0; + } + if ($dotdir eq 'no') { - if (!mkdir("$homedir",0755)) { - warn "mkdir $homedir: $!\n"; return 0; + if (!mkdir("$homedir", 0755)) { + warn "$dir: $!\n"; return 0; } system 'chown', "$name:$group", $homedir; return !$?; @@ -992,7 +1020,6 @@ sub mkdir_home { local($user_partition) = "/usr"; local($dirname) = &dirname($dir); - -e $dirname || &mkdirhier($dirname); if (((stat($dirname))[0]) == ((stat("/"))[0])){ |