diff options
author | carlosg <carlosg> | 2006-05-26 11:22:04 +0000 |
---|---|---|
committer | carlosg <carlosg> | 2006-05-26 11:22:04 +0000 |
commit | 611a79ec13e3e462cf7f37bdcdfba848d69d221e (patch) | |
tree | e2307f86bed8e031892945f99563cc65648c035a /Users/Users.pm | |
parent | b27e89369ba7a86e668a74c6e75262c333a07f35 (diff) |
2006-05-26 Carlos Garnacho <carlosg@gnome.org>
* UsersConfig.pm: added default group. -1 will mean "create new group
for the user"
* Users/Groups.pm: use addgroup/delgroup if available
* Users/Users.pm: use adduser/deluser if available, translate default
group to GIDs. Do not use a global variable getting the configuration,
some values may survive several get() calls
Diffstat (limited to 'Users/Users.pm')
-rw-r--r-- | Users/Users.pm | 87 |
1 files changed, 60 insertions, 27 deletions
diff --git a/Users/Users.pm b/Users/Users.pm index ae40d42..f64bc39 100644 --- a/Users/Users.pm +++ b/Users/Users.pm @@ -64,7 +64,11 @@ use Utils::Replace; # Where are the tools? $cmd_usermod = &Utils::File::locate_tool ("usermod"); $cmd_userdel = &Utils::File::locate_tool ("userdel"); -$cmd_useradd = &Utils::File::locate_tool ("useradd"); +$cmd_useradd = &Utils::File::locate_tool ("useradd"); + +$cmd_adduser = &Utils::File::locate_tool ("adduser"); +$cmd_deluser = &Utils::File::locate_tool ("deluser"); + $cmd_chfn = &Utils::File::locate_tool ("chfn"); $cmd_pw = &Utils::File::locate_tool ("pw"); @@ -203,21 +207,21 @@ sub get_profiles_prop_array } my $rh_logindefs_defaults = { - 'shell' => '/bin/bash', - 'group' => '$user', - 'skel_dir' => '/etc/skel/', + 'shell' => '/bin/bash', + 'group' => -1, + 'skel_dir' => '/etc/skel/', }; my $gentoo_logindefs_defaults = { - 'shell' => '/bin/bash', - 'group' => 'users', - 'skel_dir' => '/etc/skel/', + 'shell' => '/bin/bash', + 'group' => 100, + 'skel_dir' => '/etc/skel/', }; my $freebsd_logindefs_defaults = { - 'shell' => '/bin/sh', - 'group' => '$user', - 'skel_dir' => '/etc/skel/', + 'shell' => '/bin/sh', + 'group' => -1, + 'skel_dir' => '/etc/skel/', }; my $logindefs_dist_map = { @@ -405,14 +409,12 @@ sub get_logindefs sub get { my ($ifh, @users, %users_hash); - my (@line); + my (@line, @users); # Find the passwd file. $ifh = &Utils::File::open_read_from_names(@passwd_names); return unless ($ifh); - %users_hash = (); - while (<$ifh>) { chomp; @@ -428,7 +430,7 @@ sub get push @comment, "" while (scalar (@comment) < 5); $line[$COMMENT] = [@comment]; - $$users_hash{$login} = [@line]; + $users_hash{$login} = [@line]; } &Utils::File::close_file ($ifh); @@ -447,7 +449,7 @@ sub get $login = shift @line; $passwd = shift @line; - $$users_hash{$login}[$PASSWD] = $passwd; + $users_hash{$login}[$PASSWD] = $passwd; # FIXME: add the rest of the fields? #push @{$$users_hash{$login}}, @line; @@ -457,9 +459,9 @@ sub get } # transform the hash into an array - foreach $login (keys %$users_hash) + foreach $login (keys %users_hash) { - push @users, $$users_hash{$login}; + push @users, $users_hash{$login}; } return \@users; @@ -487,7 +489,14 @@ sub del_user } else { - $command = "$cmd_userdel \'" . $$user[$LOGIN] . "\'"; + if ($cmd_deluser) + { + $command = "$cmd_deluser '". $$user[$LOGIN] . "'"; + } + else + { + $command = "$cmd_userdel \'" . $$user[$LOGIN] . "\'"; + } } &Utils::File::run ($command); @@ -569,15 +578,39 @@ sub add_user $home_parents =~ s/\/+[^\/]+\/*$//; &Utils::File::run ("$tool_mkdir -p $home_parents"); - $command = "$cmd_useradd -m" . - " -d \'" . $$user[$HOME] . "\'" . - " -g \'" . $$user[$GID] . "\'" . - " -p \'" . $$user[$PASSWD] . "\'" . - " -s \'" . $$user[$SHELL] . "\'" . - " -u \'" . $$user[$UID] . "\'" . - " \'" . $$user[$LOGIN] . "\'"; - - &Utils::File::run ($command); + if ($cmd_adduser) + { + # use adduser if available, set empty gecos fields + # and password, they will be filled out later + $command = "$cmd_adduser --gecos '' --disabled-password" . + " --home \'" . $$user[$HOME] . "\'" . + " --gid \'" . $$user[$GID] . "\'" . + " --shell \'" . $$user[$SHELL] . "\'" . + " --uid \'" . $$user[$UID] . "\'" . + " \'" . $$user[$LOGIN] . "\'"; + + &Utils::File::run ($command); + + # password can't be set in non-interactive + # mode with adduser, call usermod instead + $command = "$cmd_usermod " . + "' -p '" . $$user[$PASSWD] . "' " . $$user[$LOGIN]; + + &Utils::File::run ($command); + } + else + { + # fallback to useradd + $command = "$cmd_useradd -m" . + " --home \'" . $$user[$HOME] . "\'" . + " --gid \'" . $$user[$GID] . "\'" . + " --password \'" . $$user[$PASSWD] . "\'" . + " --shell \'" . $$user[$SHELL] . "\'" . + " --uid \'" . $$user[$UID] . "\'" . + " \'" . $$user[$LOGIN] . "\'"; + + &Utils::File::run ($command); + } } &change_user_chfn ($$user[$LOGIN], undef, $$user[$COMMENT]); |