diff options
| author | Havoc Pennington <hp@redhat.com> | 2003-05-17 17:53:17 +0000 | 
|---|---|---|
| committer | Havoc Pennington <hp@redhat.com> | 2003-05-17 17:53:17 +0000 | 
| commit | 8826fea41716e30987511b7739f9cffab7b814c4 (patch) | |
| tree | e95c881807a59b3f355384ce83cd5e8cef2a7c54 | |
| parent | 306eab3e3d998472ad111146a12b7697ea96c9b9 (diff) | |
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
| -rw-r--r-- | ChangeLog | 8 | ||||
| -rw-r--r-- | bus/config-parser.c | 7 | ||||
| -rw-r--r-- | bus/policy.c | 81 | ||||
| -rw-r--r-- | bus/policy.h | 3 | ||||
| -rw-r--r-- | doc/TODO | 10 | ||||
| -rw-r--r-- | glib/test-profile.c | 4 | 
6 files changed, 110 insertions, 3 deletions
| @@ -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 diff --git a/bus/config-parser.c b/bus/config-parser.c index d3f482ab..c42278e1 100644 --- a/bus/config-parser.c +++ b/bus/config-parser.c @@ -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); diff --git a/bus/policy.c b/bus/policy.c index 938f7daa..2f8e2ca3 100644 --- a/bus/policy.c +++ b/bus/policy.c @@ -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; diff --git a/bus/policy.h b/bus/policy.h index c9b676e6..940085ee 100644 --- a/bus/policy.h +++ b/bus/policy.h @@ -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); @@ -56,8 +56,18 @@     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 diff --git a/glib/test-profile.c b/glib/test-profile.c index d53f7626..f213c676 100644 --- a/glib/test-profile.c +++ b/glib/test-profile.c @@ -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; | 
