summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilan Bouchet-Valat <nalimilan@club.fr>2009-12-27 18:51:08 +0100
committerMilan Bouchet-Valat <nalimilan@club.fr>2010-01-11 17:37:43 +0100
commitd06c5f6c7ca7a324eb6bd88ac4931d822ed38997 (patch)
treec7a00a814fa3b75c6afcec65a4b3c3cf052fc4d8
parent73b1da98e7dce731bb30f86c45173c88b735be60 (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.
-rw-r--r--GroupConfig.pm91
-rw-r--r--GroupsConfig.pm7
-rw-r--r--Makefile.am1
-rw-r--r--Users/Groups.pm85
-rw-r--r--org.freedesktop.SystemToolsBackends.conf6
5 files changed, 144 insertions, 46 deletions
diff --git a/GroupConfig.pm b/GroupConfig.pm
new file mode 100644
index 0000000..7fbd0d1
--- /dev/null
+++ b/GroupConfig.pm
@@ -0,0 +1,91 @@
+#-*- Mode: perl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+# DBus object for the Groups list
+#
+# Copyright (C) 2009 Milan Bouchet-Valat
+#
+# Authors: Milan Bouchet-Valat <nalimilan@club.fr>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Library General Public License as published
+# by the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+
+package GroupConfig;
+
+use base qw(StbObject);
+use Net::DBus::Exporter ($Utils::Backend::DBUS_PREFIX);
+use Users::Groups;
+use Users::Users;
+
+my $OBJECT_NAME = "GroupConfig2";
+my $OBJECT_PATH = "$Utils::Backend::DBUS_PATH/$OBJECT_NAME";
+
+# name, password, GID, users
+our $GROUP_FORMAT = [ "struct", "string", "string", "uint32", [ "array", "string" ]];
+
+sub new
+{
+ my $class = shift;
+ my $self = $class->SUPER::new ($OBJECT_PATH, $OBJECT_NAME);
+
+ bless $self, $class;
+
+# Utils::Monitor::monitor_files (&Users::Groups::get_files (),
+# $self, $OBJECT_NAME, "changed");
+ return $self;
+}
+
+dbus_method ("get", [ "string" ], [ $GROUP_FORMAT ]);
+dbus_method ("set", [ $GROUP_FORMAT ], []);
+dbus_method ("add", [ $GROUP_FORMAT ], []);
+dbus_method ("del", [ $GROUP_FORMAT ], []);
+#dbus_signal ("changed", []);
+
+sub get
+{
+ my ($self, $name) = @_;
+
+ return Users::Groups::get_group ($name);
+}
+
+sub set
+{
+ my ($self, @config) = @_;
+
+ Users::Groups::set_group (@config);
+}
+
+sub add
+{
+ my ($self, @config) = @_;
+
+ Users::Groups::add_group (@config);
+}
+
+sub del
+{
+ my ($self, @config) = @_;
+
+ Users::Groups::del_group (@config);
+}
+
+sub getFiles
+{
+ my ($self) = @_;
+
+ return &Users::Groups::get_files ();
+}
+
+my $config = GroupConfig->new ();
+
+1;
diff --git a/GroupsConfig.pm b/GroupsConfig.pm
index 6198e43..727ed86 100644
--- a/GroupsConfig.pm
+++ b/GroupsConfig.pm
@@ -24,12 +24,15 @@ package GroupsConfig;
use base qw(StbObject);
use Net::DBus::Exporter ($Utils::Backend::DBUS_PREFIX);
+use GroupConfig;
use Users::Groups;
use Users::Users;
-my $OBJECT_NAME = "GroupsConfig";
+my $OBJECT_NAME = "GroupsConfig2";
my $OBJECT_PATH = "$Utils::Backend::DBUS_PATH/$OBJECT_NAME";
-my $format = [[ "array", [ "struct", "string", "string", "int32", [ "array", "string" ]]], "int32", "int32" ];
+
+# array of groups, min gid, max gid
+my $format = [ [ "array", $GroupConfig::GROUP_FORMAT ], "uint32", "uint32" ];
sub new
{
diff --git a/Makefile.am b/Makefile.am
index c2e52f6..6736b3e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -8,6 +8,7 @@ modulesdir = $(scriptsdir)
modules_DATA = \
Platform.pm \
StbObject.pm \
+ GroupConfig.pm \
GroupsConfig.pm \
HostsConfig.pm \
IfacesConfig.pm \
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);
}
}
diff --git a/org.freedesktop.SystemToolsBackends.conf b/org.freedesktop.SystemToolsBackends.conf
index 319ea51..e4b1b35 100644
--- a/org.freedesktop.SystemToolsBackends.conf
+++ b/org.freedesktop.SystemToolsBackends.conf
@@ -8,7 +8,7 @@
<!-- Uncomment this if you want to test configuration modules with a harmless user -->
<!--
- <allow own="org.freedesktop.SystemToolsBackends.GroupsConfig"/>
+ <allow own="org.freedesktop.SystemToolsBackends.GroupsConfig2"/>
<allow own="org.freedesktop.SystemToolsBackends.HostsConfig"/>
<allow own="org.freedesktop.SystemToolsBackends.IfacesConfig"/>
<allow own="org.freedesktop.SystemToolsBackends.NFSConfig"/>
@@ -32,7 +32,7 @@
<allow own="org.freedesktop.SystemToolsBackends"/>
<!-- also allow it to own the configuration modules -->
- <allow own="org.freedesktop.SystemToolsBackends.GroupsConfig"/>
+ <allow own="org.freedesktop.SystemToolsBackends.GroupsConfig2"/>
<allow own="org.freedesktop.SystemToolsBackends.HostsConfig"/>
<allow own="org.freedesktop.SystemToolsBackends.IfacesConfig"/>
<allow own="org.freedesktop.SystemToolsBackends.NFSConfig"/>
@@ -51,7 +51,7 @@
<allow send_interface="org.freedesktop.SystemToolsBackends.Platform"/>
<allow send_destination="org.freedesktop.SystemToolsBackends"/>
<allow send_destination="org.freedesktop.SystemToolsBackends.Platform"/>
- <allow send_destination="org.freedesktop.SystemToolsBackends.GroupsConfig"/>
+ <allow send_destination="org.freedesktop.SystemToolsBackends.GroupsConfig2"/>
<allow send_destination="org.freedesktop.SystemToolsBackends.HostsConfig"/>
<allow send_destination="org.freedesktop.SystemToolsBackends.IfacesConfig"/>
<allow send_destination="org.freedesktop.SystemToolsBackends.NFSConfig"/>