diff options
author | Milan Bouchet-Valat <nalimilan@club.fr> | 2009-12-27 18:51:08 +0100 |
---|---|---|
committer | Milan Bouchet-Valat <nalimilan@club.fr> | 2010-01-11 17:37:43 +0100 |
commit | d06c5f6c7ca7a324eb6bd88ac4931d822ed38997 (patch) | |
tree | c7a00a814fa3b75c6afcec65a4b3c3cf052fc4d8 /Users | |
parent | 73b1da98e7dce731bb30f86c45173c88b735be60 (diff) |
New groups protocol
GroupsConfig is now only used to fetch list of groups and settings. All commit operations now go through GroupConfig: set(), add() and del() methods. This avoids problems when committing the whole list, which could lead to removing all groups on the system.
Diffstat (limited to 'Users')
-rw-r--r-- | Users/Groups.pm | 85 |
1 files changed, 44 insertions, 41 deletions
diff --git a/Users/Groups.pm b/Users/Groups.pm index facb7a6..4f5d718 100644 --- a/Users/Groups.pm +++ b/Users/Groups.pm @@ -50,6 +50,9 @@ sub del_group { my ($group) = @_; + # Make backups manually, otherwise they don't get backed up. + &Utils::File::do_backup ($group_names); + if ($Utils::Backend::tool{"system"} eq "FreeBSD") { @command = ($cmd_pw, "groupdel", "-n", $$group[$LOGIN]); @@ -129,6 +132,9 @@ sub add_group my ($group) = @_; my ($u, $user, @users); + # Make backups manually, otherwise they don't get backed up. + &Utils::File::do_backup ($group_names); + $u = $$group[$USERS]; if ($Utils::Backend::tool{"system"} eq "FreeBSD") @@ -215,6 +221,38 @@ sub change_group } } +sub get_group +{ + my ($login) = @_; + my ($groups) = &get (); + + foreach $group (@$groups) + { + next if ($login != $$group[$LOGIN]); + return $group; + } + + return NULL; +} + +sub set_group +{ + my ($new_group) = @_; + my ($groups) = &get (); + + # Make backups manually, otherwise they don't get backed up. + &Utils::File::do_backup ($group_names); + + foreach $group (@$groups) + { + if ($$new_group[$GID] == $$group[$GID]) + { + &change_group ($group, $new_group); + return; + } + } +} + sub get { my ($ifh, @groups, $group_last_modified); @@ -256,49 +294,14 @@ sub get_files sub set { my ($config) = @_; - my ($old_config, %groups); - my (%config_hash, %old_config_hash); - if ($config) - { - # Make backup manually, otherwise they don't get backed up. - &Utils::File::do_backup ($group_names); - - $old_config = &get (); - - foreach $i (@$config) - { - $groups{$$i[$LOGIN]} |= 1; - $config_hash{$$i[$LOGIN]} = $i; - } - - foreach $i (@$old_config) - { - $groups{$$i[$LOGIN]} |= 2; - $old_config_hash{$$i[$LOGIN]} = $i; - } - - # Delete all groups that only appeared in the old configuration - foreach $i (sort (keys (%groups))) - { - $state = $groups{$i}; + return if (!$config); - if ($state == 1) - { - # Groups with state 1 have been added to the config - &add_group ($config_hash{$i}); - } - elsif ($state == 2) - { - # Groups with state 2 have been deleted from the config - &del_group ($old_config_hash{$i}); - } - elsif (($state == 3) && - (!Utils::Util::struct_eq ($config_hash{$i}, $old_config_hash{$i}))) - { - &change_group ($old_config_hash{$i}, $config_hash{$i}); - } - } + # Change groups that are present in both old and new config. + # Groups won't be removed or added this way, for more safety. + foreach $group (@$config) + { + set_group ($group); } } |