diff options
author | carlosg <carlosg> | 2006-10-05 12:27:21 +0000 |
---|---|---|
committer | carlosg <carlosg> | 2006-10-05 12:27:21 +0000 |
commit | f47a9349484ace8adec505c846b54da36b7321d8 (patch) | |
tree | 10da5bfaa0d1367f18b18d1f7c4b87c6cf4655ed /Users/Groups.pm | |
parent | 416f7fa1c0224f5ff2cada729b6238d23d6f00ec (diff) |
2006-10-05 Carlos Garnacho <carlosg@gnome.org>
Ported to 1.9.x a huge and incredible patch by Darren Kenny
<Darren.Kenny@Sun.COM> and Erast Benson <erast@gnusolaris.com>
to make s-t-b recognize and configure SunOS based systems.
* Utils/Platform.pm: recognize OpenSolaris and Nexenta properly.
* Utils/File.pm (read_joined_lines): added.
* Users/Shells.pm, Users.pm, Groups.pm: add SunOS case paths.
* Time/NTP.pm, TimeDate.pm: ditto.
* Shares/NFS.pm: parse/modify dfstab in the SunOS case
* Network/Hosts.pm, Ifaces.pm: add code to deal with SunOS network
configuration.
* Init/Services.pm: deal with SMF init system.
Diffstat (limited to 'Users/Groups.pm')
-rw-r--r-- | Users/Groups.pm | 82 |
1 files changed, 69 insertions, 13 deletions
diff --git a/Users/Groups.pm b/Users/Groups.pm index 118ad66..8b13f00 100644 --- a/Users/Groups.pm +++ b/Users/Groups.pm @@ -41,6 +41,7 @@ $cmd_groupmod = &Utils::File::locate_tool ("groupmod"); $cmd_delgroup = &Utils::File::locate_tool ("delgroup"); $cmd_addgroup = &Utils::File::locate_tool ("addgroup"); +$cmd_usermod = &Utils::File::locate_tool ("usermod"); $cmd_gpasswd = &Utils::File::locate_tool ("gpasswd"); $cmd_pw = &Utils::File::locate_tool ("pw"); @@ -61,6 +62,70 @@ sub del_group &Utils::File::run ($command); } +# This is only for Linux and SunOS, +# pw groupadd manages this in FreeBSD +sub add_user_to_group +{ + my ($group, $user) = @_; + my ($command); + + if ($Utils::Backend::tool{"system"} eq "SunOS") + { + my ($groups, @arr); + + $groups = &Utils::File::run_backtick ("groups $user"); + $groups =~ s/.*://; + chomp ($groups); + + @arr = split (/ /, $groups); + push @arr, $group; + $groups = join (',', @arr); + $groups =~ s/^,//; + $groups =~ s/,$//; + + $command = "$cmd_usermod -G $groups $user"; + } + else + { + $command = "$cmd_gpasswd -a \'" . $user . "\' " . $group; + } + + &Utils::File::run ($command); +} + +# This is only for Linux and SunOS, +# pw groupdel manages this in FreeBSD +sub delete_user_from_group +{ + my ($group, $user) = @_; + my ($command); + + if ($Utils::Backend::tool{"system"} eq "SunOS") + { + my ($groups, @arr); + + $groups = &Utils::File::run_backtick ("groups $user"); + $groups =~ s/.*://; + chomp ($groups); + + # delete the user + $groups =~ s/[ \t]+$group//; + + @arr = split (/ /, $groups); + $groups = join (',', @arr); + $groups =~ s/^,//; + $groups =~ s/,$//; + + $command = "$cmd_usermod -G $groups $user"; + } + else + { + $command = "$cmd_gpasswd -d \'" . $user . "\' \'" . $group . "\'"; + } + + &Utils::File::run ($command); +} + sub add_group { my ($group) = @_; @@ -95,10 +160,7 @@ sub add_group foreach $user (sort @$u) { - $command = "$cmd_gpasswd -a \'" . $user . - "\' " . $$group[$LOGIN]; - - &Utils::File::run ($command); + &add_user_to_group ($$group[$LOGIN], $user); } } } @@ -144,19 +206,13 @@ sub change_group { # users with state 2 are those that only appeared # in the old group configuration, so we must delete them - $command = "$cmd_gpasswd -d \'" . $user . "\' \'" . - $$new_group[$LOGIN] . "\'"; - - &Utils::File::run ($command); + &delete_user_from_group ($$new_group [$LOGIN], $user); } - else + elsif ($state == 1) { # users with state 1 are those who were added # to the new group configuration - $command = "$cmd_gpasswd -a \'" . $user . "\' \'" . - $$new_group[$LOGIN] . "\'"; - - &Utils::File::run ($command); + &add_user_to_group ($$new_group[$LOGIN], $user); } } } |