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 | |
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
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | Users/Groups.pm | 19 | ||||
-rw-r--r-- | Users/Users.pm | 87 | ||||
-rw-r--r-- | UsersConfig.pm | 10 |
4 files changed, 91 insertions, 34 deletions
@@ -1,3 +1,12 @@ +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 + 2006-05-20 Carlos Garnacho <carlosg@gnome.org> * configure.in: fix problem expanding paths, detect Net::DBus, and diff --git a/Users/Groups.pm b/Users/Groups.pm index e2935f4..bd228de 100644 --- a/Users/Groups.pm +++ b/Users/Groups.pm @@ -37,6 +37,10 @@ $group_names = "/etc/group"; $cmd_groupdel = &Utils::File::locate_tool ("groupdel"); $cmd_groupadd = &Utils::File::locate_tool ("groupadd"); $cmd_groupmod = &Utils::File::locate_tool ("groupmod"); + +$cmd_delgroup = &Utils::File::locate_tool ("delgroup"); +$cmd_addgroup = &Utils::File::locate_tool ("addgroup"); + $cmd_gpasswd = &Utils::File::locate_tool ("gpasswd"); $cmd_pw = &Utils::File::locate_tool ("pw"); @@ -50,7 +54,8 @@ sub del_group } else { - $command = "$cmd_groupdel \'" . $$group[$LOGIN] . "\'"; + $command = ($cmd_delgroup) ? $cmd_delgroup : $cmd_groupdel; + $command .= " \'" . $$group[$LOGIN] . "\'"; } &Utils::File::run ($command); @@ -75,8 +80,16 @@ sub add_group } else { - $command = "$cmd_groupadd -g \'" . $$group[$GID] . - "\' " . $$group[$LOGIN]; + if ($cmd_addgroup) + { + $command = "$cmd_addgroup " . + "--gid \'" . $$group[$GID] . "\' " . $$group[$LOGIN]; + } + else + { + $command = "$cmd_groupadd -g \'" . $$group[$GID] . + "\' " . $$group[$LOGIN]; + } &Utils::File::run ($command); 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]); diff --git a/UsersConfig.pm b/UsersConfig.pm index b582a6e..6107cdd 100644 --- a/UsersConfig.pm +++ b/UsersConfig.pm @@ -47,10 +47,10 @@ sub new dbus_method ("get", [], [[ "array", [ "struct", "string", "string", "int32", "int32", [ "array", "string"], "string", "string" ]], - ["array", "string" ], "int32", "int32", "int32", "string", "string" ]); + ["array", "string" ], "int32", "int32", "int32", "string", "string", "int32" ]); dbus_method ("set", [[ "array", [ "struct", "string", "string", "int32", "int32", [ "array", "string"], "string", "string" ]], - ["array", "string" ], "int32", "int32", "int32", "string", "string" ], []); + ["array", "string" ], "int32", "int32", "int32", "string", "string", "int32" ], []); dbus_signal ("changed", []); sub get @@ -64,7 +64,8 @@ sub get $shells = &Users::Shells::get (); return ($users, $shells, $use_md5, $$logindefs{"umin"}, - $$logindefs{"umax"}, $$logindefs{"home_prefix"}, $$logindefs{"shell"}); + $$logindefs{"umax"}, $$logindefs{"home_prefix"}, + $$logindefs{"shell"}, $$logindefs{"group"}); } sub set @@ -76,7 +77,8 @@ sub set Users::Users::set_logindefs ({"umin" => $config[3], "umax" => $config[4], "home_prefix" => $config[5], - "shell" => $config[6]}); + "shell" => $config[6], + "group" => $config[7]}); } 1; |