]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
2003-05-17 Havoc Pennington <hp@pobox.com>
authorHavoc Pennington <hp@redhat.com>
Sat, 17 May 2003 17:53:17 +0000 (17:53 +0000)
committerHavoc Pennington <hp@redhat.com>
Sat, 17 May 2003 17:53:17 +0000 (17:53 +0000)
* bus/config-parser.c (merge_included): merge in policies from
child configuration file.

* bus/policy.c (bus_policy_merge): function to merge two policies
together

ChangeLog
bus/config-parser.c
bus/policy.c
bus/policy.h
doc/TODO
glib/test-profile.c

index 496bdd26da0cab68dc68193acacd8ce3f584b632..1a4118323cd0c4db65ae32e90e20563949d95708 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2003-05-17  Havoc Pennington  <hp@pobox.com>
+
+       * bus/config-parser.c (merge_included): merge in policies from
+       child configuration file.
+
+       * bus/policy.c (bus_policy_merge): function to merge two policies 
+       together
+
 2003-05-16  Havoc Pennington  <hp@redhat.com>
 
        * dbus/dbus-connection.c: disable verbose lock spew
index d3f482ab005dee90f7653c7e5fc364b5c8d3e0ff..c42278e15d03743a729bcb67ad4f981d98c45e11 100644 (file)
@@ -231,6 +231,13 @@ merge_included (BusConfigParser *parser,
 {
   DBusList *link;
 
+  if (!bus_policy_merge (parser->policy,
+                         included->policy))
+    {
+      BUS_SET_OOM (error);
+      return FALSE;
+    }
+  
   if (included->user != NULL)
     {
       dbus_free (parser->user);
index 938f7daad950fa960513698747a743f1e1f2ae8d..2f8e2ca358e97c89dd19f1934b4219a51f014e63 100644 (file)
@@ -512,6 +512,87 @@ bus_policy_append_group_rule (BusPolicy      *policy,
   return TRUE;
 }
 
+static dbus_bool_t
+append_copy_of_policy_list (DBusList **list,
+                            DBusList **to_append)
+{
+  DBusList *link;
+  DBusList *tmp_list;
+
+  tmp_list = NULL;
+
+  /* Preallocate all our links */
+  link = _dbus_list_get_first_link (to_append);
+  while (link != NULL)
+    {
+      if (!_dbus_list_append (&tmp_list, link->data))
+        {
+          _dbus_list_clear (&tmp_list);
+          return FALSE;
+        }
+      
+      link = _dbus_list_get_next_link (to_append, link);
+    }
+
+  /* Now append them */
+  while ((link = _dbus_list_pop_first_link (&tmp_list)))
+    {
+      bus_policy_rule_ref (link->data);
+      _dbus_list_append_link (list, link);
+    }
+
+  return TRUE;
+}
+
+static dbus_bool_t
+merge_id_hash (DBusHashTable *dest,
+               DBusHashTable *to_absorb)
+{
+  DBusHashIter iter;
+  
+  _dbus_hash_iter_init (to_absorb, &iter);
+  while (_dbus_hash_iter_next (&iter))
+    {
+      unsigned long id = _dbus_hash_iter_get_ulong_key (&iter);
+      DBusList **list = _dbus_hash_iter_get_value (&iter);
+      DBusList **target = get_list (dest, id);
+
+      if (target == NULL)
+        return FALSE;
+
+      if (!append_copy_of_policy_list (target, list))
+        return FALSE;
+    }
+
+  return TRUE;
+}
+
+dbus_bool_t
+bus_policy_merge (BusPolicy *policy,
+                  BusPolicy *to_absorb)
+{
+  /* Not properly atomic, but as used for configuration files
+   * we don't rely on it.
+   */  
+  if (!append_copy_of_policy_list (&policy->default_rules,
+                                   &to_absorb->default_rules))
+    return FALSE;
+  
+  if (!append_copy_of_policy_list (&policy->mandatory_rules,
+                                   &to_absorb->mandatory_rules))
+    return FALSE;
+
+  if (!merge_id_hash (policy->rules_by_uid,
+                      to_absorb->rules_by_uid))
+    return FALSE;
+  
+  if (!merge_id_hash (policy->rules_by_gid,
+                      to_absorb->rules_by_gid))
+    return FALSE;
+
+  return TRUE;
+}
+
 struct BusClientPolicy
 {
   int refcount;
index c9b676e6e052bfcf1e06042c2977be430668bda8..940085ee09022afd8f30df6155f3b010e63bc520 100644 (file)
@@ -111,7 +111,8 @@ dbus_bool_t      bus_policy_append_user_rule      (BusPolicy        *policy,
 dbus_bool_t      bus_policy_append_group_rule     (BusPolicy        *policy,
                                                    dbus_gid_t        gid,
                                                    BusPolicyRule    *rule);
-
+dbus_bool_t      bus_policy_merge                 (BusPolicy        *policy,
+                                                   BusPolicy        *to_absorb);
 
 BusClientPolicy* bus_client_policy_new               (void);
 void             bus_client_policy_ref               (BusClientPolicy  *policy);
index 05bd25db024986129178a54b612c342d44ab3096..75ba7d868cd1c63054b1deed785a72835ef9a516 100644 (file)
--- a/doc/TODO
+++ b/doc/TODO
    will only be right for one of them. Probably need to just write() the serial 
    number, rather than putting it in the DBusMessage, or something.
 
+ - perhaps the bus driver should have properties that reflect attributes
+   of the session, such as hostname, architecture, operating system, 
+   etc. Could be useful for code that wants to special-case behavior 
+   for a particular host or class of hosts, for example.
+
  - currently the security policy stuff for messages to/from 
    the bus driver is kind of strange; basically it's hardcoded that 
    you can always talk to the driver, but the default config file 
    has rules for it anyway, or something. it's conceptually 
    screwy at the moment.
+
+ - <limit> elements are not merged in from included configuration 
+   files; they have to be in the toplevel file. when loading 
+   a child file, we could just init its DBusLimits from the parent, 
+   then after parsing copy its DBusLimits back to the parent
index d53f7626958aaeae9d68d770da6f057c4a34dffa..f213c676998149a5cf7c2937ed88d083328bd0d1 100644 (file)
@@ -27,8 +27,8 @@
 #include <stdlib.h>
 
 #define N_CLIENT_THREADS 1
-#define N_ITERATIONS 100
-#define PAYLOAD_SIZE 1000
+#define N_ITERATIONS 1000
+#define PAYLOAD_SIZE 30
 #define ECHO_MESSAGE "org.freedesktop.DBus.Test.EchoProfile"
 static const char *address;
 static unsigned char *payload;