Bug 18446: Keep umask for session bus
[platform/upstream/dbus.git] / bus / config-parser.c
index acf4022..5bb34f1 100644 (file)
@@ -1,4 +1,4 @@
-/* -*- mode: C; c-file-style: "gnu" -*- */
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
 /* config-parser.c  XML-library-agnostic configuration file parser
  *
  * Copyright (C) 2003, 2004 Red Hat, Inc.
@@ -20,6 +20,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  */
+#include "config-parser-common.h"
 #include "config-parser.h"
 #include "test.h"
 #include "utils.h"
 
 typedef enum
 {
-  ELEMENT_NONE,
-  ELEMENT_BUSCONFIG,
-  ELEMENT_INCLUDE,
-  ELEMENT_USER,
-  ELEMENT_LISTEN,
-  ELEMENT_AUTH,
-  ELEMENT_POLICY,
-  ELEMENT_LIMIT,
-  ELEMENT_ALLOW,
-  ELEMENT_DENY,
-  ELEMENT_FORK,
-  ELEMENT_PIDFILE,
-  ELEMENT_SERVICEDIR,
-  ELEMENT_INCLUDEDIR,
-  ELEMENT_TYPE,
-  ELEMENT_SELINUX,
-  ELEMENT_ASSOCIATE
-} ElementType;
-
-typedef enum
-{
   /* we ignore policies for unknown groups/users */
   POLICY_IGNORED,
 
@@ -59,7 +39,8 @@ typedef enum
   POLICY_DEFAULT,
   POLICY_MANDATORY,
   POLICY_USER,
-  POLICY_GROUP
+  POLICY_GROUP,
+  POLICY_CONSOLE
 } PolicyType;
 
 typedef struct
@@ -73,12 +54,14 @@ typedef struct
     struct
     {
       unsigned int ignore_missing : 1;
+      unsigned int if_selinux_enabled : 1;
+      unsigned int selinux_root_relative : 1;
     } include;
 
     struct
     {
       PolicyType type;
-      unsigned long gid_or_uid;      
+      unsigned long gid_uid_or_at_console;      
     } policy;
 
     struct
@@ -104,13 +87,17 @@ struct BusConfigParser
 
   char *user;          /**< user to run as */
 
+  char *servicehelper; /**< location of the setuid helper */
+
   char *bus_type;          /**< Message bus type */
   
   DBusList *listen_on; /**< List of addresses to listen to */
 
   DBusList *mechanisms; /**< Auth mechanisms */
 
-  DBusList *service_dirs; /**< Directories to look for services in */
+  DBusList *service_dirs; /**< Directories to look for session services in */
+
+  DBusList *conf_dirs;   /**< Directories to look for policy configuration in */
 
   BusPolicy *policy;     /**< Security policy */
 
@@ -120,59 +107,15 @@ struct BusConfigParser
 
   DBusList *included_files;  /**< Included files stack */
 
-  DBusHashTable *service_sid_table; /**< Map service names to SELinux contexts */
+  DBusHashTable *service_context_table; /**< Map service names to SELinux contexts */
 
   unsigned int fork : 1; /**< TRUE to fork into daemon mode */
 
+  unsigned int keep_umask : 1; /**< TRUE to keep original umask when forking */
+
   unsigned int is_toplevel : 1; /**< FALSE if we are a sub-config-file inside another one */
 };
 
-static const char*
-element_type_to_name (ElementType type)
-{
-  switch (type)
-    {
-    case ELEMENT_NONE:
-      return NULL;
-    case ELEMENT_BUSCONFIG:
-      return "busconfig";
-    case ELEMENT_INCLUDE:
-      return "include";
-    case ELEMENT_USER:
-      return "user";
-    case ELEMENT_LISTEN:
-      return "listen";
-    case ELEMENT_AUTH:
-      return "auth";
-    case ELEMENT_POLICY:
-      return "policy";
-    case ELEMENT_LIMIT:
-      return "limit";
-    case ELEMENT_ALLOW:
-      return "allow";
-    case ELEMENT_DENY:
-      return "deny";
-    case ELEMENT_FORK:
-      return "fork";
-    case ELEMENT_PIDFILE:
-      return "pidfile";
-    case ELEMENT_SERVICEDIR:
-      return "servicedir";
-    case ELEMENT_INCLUDEDIR:
-      return "includedir";
-    case ELEMENT_TYPE:
-      return "type";
-    case ELEMENT_SELINUX:
-      return "selinux";
-    case ELEMENT_ASSOCIATE:
-      return "associate";
-    }
-
-  _dbus_assert_not_reached ("bad element type");
-
-  return NULL;
-}
-
 static Element*
 push_element (BusConfigParser *parser,
               ElementType      type)
@@ -239,12 +182,100 @@ top_element_type (BusConfigParser *parser)
 }
 
 static dbus_bool_t
+merge_service_context_hash (DBusHashTable *dest,
+                           DBusHashTable *from)
+{
+  DBusHashIter iter;
+  char *service_copy;
+  char *context_copy;
+
+  service_copy = NULL;
+  context_copy = NULL;
+
+  _dbus_hash_iter_init (from, &iter);
+  while (_dbus_hash_iter_next (&iter))
+    {
+      const char *service = _dbus_hash_iter_get_string_key (&iter);
+      const char *context = _dbus_hash_iter_get_value (&iter);
+
+      service_copy = _dbus_strdup (service);
+      if (service_copy == NULL)
+        goto fail;
+      context_copy = _dbus_strdup (context);
+      if (context_copy == NULL)
+        goto fail; 
+      
+      if (!_dbus_hash_table_insert_string (dest, service_copy, context_copy))
+        goto fail;
+
+      service_copy = NULL;
+      context_copy = NULL;    
+    }
+
+  return TRUE;
+
+ fail:
+  if (service_copy)
+    dbus_free (service_copy);
+
+  if (context_copy)
+    dbus_free (context_copy);
+
+  return FALSE;
+}
+
+static dbus_bool_t
+service_dirs_find_dir (DBusList **service_dirs,
+                       const char *dir)
+{
+  DBusList *link;
+
+  _dbus_assert (dir != NULL);
+
+  for (link = *service_dirs; link; link = _dbus_list_get_next_link(service_dirs, link))
+    {
+      const char *link_dir;
+      
+      link_dir = (const char *)link->data;
+      if (strcmp (dir, link_dir) == 0)
+        return TRUE;
+    }
+
+  return FALSE;
+}
+
+static dbus_bool_t
+service_dirs_append_unique_or_free (DBusList **service_dirs,
+                                    char *dir)
+{
+  if (!service_dirs_find_dir (service_dirs, dir))
+    return _dbus_list_append (service_dirs, dir);  
+
+  dbus_free (dir);
+  return TRUE;
+}
+
+static void 
+service_dirs_append_link_unique_or_free (DBusList **service_dirs,
+                                         DBusList *dir_link)
+{
+  if (!service_dirs_find_dir (service_dirs, dir_link->data))
+    {
+      _dbus_list_append_link (service_dirs, dir_link);
+    }
+  else
+    {
+      dbus_free (dir_link->data);
+      _dbus_list_free_link (dir_link);
+    }
+}
+
+static dbus_bool_t
 merge_included (BusConfigParser *parser,
                 BusConfigParser *included,
                 DBusError       *error)
 {
   DBusList *link;
-  DBusHashTable *table;
 
   if (!bus_policy_merge (parser->policy,
                          included->policy))
@@ -253,16 +284,12 @@ merge_included (BusConfigParser *parser,
       return FALSE;
     }
 
-  table = bus_selinux_id_table_union (parser->service_sid_table,
-                                      included->service_sid_table);
-  if (table == NULL)
+  if (!merge_service_context_hash (parser->service_context_table,
+                                  included->service_context_table))
     {
       BUS_SET_OOM (error);
       return FALSE;
     }
-
-  _dbus_hash_table_unref (parser->service_sid_table);
-  parser->service_sid_table = table;
   
   if (included->user != NULL)
     {
@@ -281,6 +308,9 @@ merge_included (BusConfigParser *parser,
   if (included->fork)
     parser->fork = TRUE;
 
+  if (included->keep_umask)
+    parser->keep_umask = TRUE;
+
   if (included->pidfile != NULL)
     {
       dbus_free (parser->pidfile);
@@ -295,7 +325,10 @@ merge_included (BusConfigParser *parser,
     _dbus_list_append_link (&parser->mechanisms, link);
 
   while ((link = _dbus_list_pop_first_link (&included->service_dirs)))
-    _dbus_list_append_link (&parser->service_dirs, link);
+    service_dirs_append_link_unique_or_free (&parser->service_dirs, link);
+
+  while ((link = _dbus_list_pop_first_link (&included->conf_dirs)))
+    _dbus_list_append_link (&parser->conf_dirs, link);
   
   return TRUE;
 }
@@ -339,7 +372,9 @@ bus_config_parser_new (const DBusString      *basedir,
 
   if (((parser->policy = bus_policy_new ()) == NULL) ||
       !_dbus_string_copy (basedir, 0, &parser->basedir, 0) ||
-      ((parser->service_sid_table = bus_selinux_id_table_new ()) == NULL))
+      ((parser->service_context_table = _dbus_hash_table_new (DBUS_HASH_STRING,
+                                                             dbus_free,
+                                                             dbus_free)) == NULL))
     {
       if (parser->policy)
         bus_policy_unref (parser->policy);
@@ -363,8 +398,8 @@ bus_config_parser_new (const DBusString      *basedir,
     {
 
       /* Make up some numbers! woot! */
-      parser->limits.max_incoming_bytes = _DBUS_ONE_MEGABYTE * 63;
-      parser->limits.max_outgoing_bytes = _DBUS_ONE_MEGABYTE * 63;
+      parser->limits.max_incoming_bytes = _DBUS_ONE_MEGABYTE * 127;
+      parser->limits.max_outgoing_bytes = _DBUS_ONE_MEGABYTE * 127;
       parser->limits.max_message_size = _DBUS_ONE_MEGABYTE * 32;
       
       /* Making this long means the user has to wait longer for an error
@@ -379,22 +414,34 @@ bus_config_parser_new (const DBusString      *basedir,
        */
       parser->limits.auth_timeout = 30000; /* 30 seconds */
       
-      parser->limits.max_incomplete_connections = 32;
-      parser->limits.max_connections_per_user = 128;
+      parser->limits.max_incomplete_connections = 64;
+      parser->limits.max_connections_per_user = 256;
       
       /* Note that max_completed_connections / max_connections_per_user
        * is the number of users that would have to work together to
        * DOS all the other users.
        */
-      parser->limits.max_completed_connections = 1024;
-      
-      parser->limits.max_pending_activations = 256;
-      parser->limits.max_services_per_connection = 256;
+      parser->limits.max_completed_connections = 2048;
       
-      parser->limits.max_match_rules_per_connection = 128;
+      parser->limits.max_pending_activations = 512;
+      parser->limits.max_services_per_connection = 512;
+
+      /* For this one, keep in mind that it isn't only the memory used
+       * by the match rules, but slowdown from linearly walking a big
+       * list of them. A client adding more than this is almost
+       * certainly a bad idea for that reason, and should change to a
+       * smaller number of wider-net match rules - getting every last
+       * message to the bus is probably better than having a thousand
+       * match rules.
+       */
+      parser->limits.max_match_rules_per_connection = 512;
       
       parser->limits.reply_timeout = 5 * 60 * 1000; /* 5 minutes */
-      parser->limits.max_replies_per_connection = 32;
+
+      /* this is effectively a limit on message queue size for messages
+       * that require a reply
+       */
+      parser->limits.max_replies_per_connection = 1024*8;
     }
       
   parser->refcount = 1;
@@ -425,6 +472,7 @@ bus_config_parser_unref (BusConfigParser *parser)
         pop_element (parser);
 
       dbus_free (parser->user);
+      dbus_free (parser->servicehelper);
       dbus_free (parser->bus_type);
       dbus_free (parser->pidfile);
       
@@ -440,6 +488,12 @@ bus_config_parser_unref (BusConfigParser *parser)
 
       _dbus_list_clear (&parser->service_dirs);
 
+      _dbus_list_foreach (&parser->conf_dirs,
+                          (DBusForeachFunction) dbus_free,
+                          NULL);
+
+      _dbus_list_clear (&parser->conf_dirs);
+
       _dbus_list_foreach (&parser->mechanisms,
                           (DBusForeachFunction) dbus_free,
                           NULL);
@@ -451,8 +505,8 @@ bus_config_parser_unref (BusConfigParser *parser)
       if (parser->policy)
         bus_policy_unref (parser->policy);
 
-      if (parser->service_sid_table)
-        _dbus_hash_table_unref (parser->service_sid_table);
+      if (parser->service_context_table)
+        _dbus_hash_table_unref (parser->service_context_table);
       
       dbus_free (parser);
     }
@@ -533,9 +587,6 @@ locate_attributes (BusConfigParser  *parser,
 
   va_end (args);
 
-  if (!retval)
-    return retval;
-
   i = 0;
   while (attribute_names[i])
     {
@@ -607,7 +658,11 @@ start_busconfig_child (BusConfigParser   *parser,
                        const char       **attribute_values,
                        DBusError         *error)
 {
-  if (strcmp (element_name, "user") == 0)
+  ElementType element_type;
+
+  element_type = bus_config_parser_element_name_to_type (element_name);
+
+  if (element_type == ELEMENT_USER)
     {
       if (!check_no_attributes (parser, "user", attribute_names, attribute_values, error))
         return FALSE;
@@ -620,7 +675,7 @@ start_busconfig_child (BusConfigParser   *parser,
 
       return TRUE;
     }
-  else if (strcmp (element_name, "type") == 0)
+  else if (element_type == ELEMENT_TYPE)
     {
       if (!check_no_attributes (parser, "type", attribute_names, attribute_values, error))
         return FALSE;
@@ -633,7 +688,7 @@ start_busconfig_child (BusConfigParser   *parser,
 
       return TRUE;
     }
-  else if (strcmp (element_name, "fork") == 0)
+  else if (element_type == ELEMENT_FORK)
     {
       if (!check_no_attributes (parser, "fork", attribute_names, attribute_values, error))
         return FALSE;
@@ -648,7 +703,22 @@ start_busconfig_child (BusConfigParser   *parser,
       
       return TRUE;
     }
-  else if (strcmp (element_name, "pidfile") == 0)
+  else if (element_type == ELEMENT_KEEP_UMASK)
+    {
+      if (!check_no_attributes (parser, "keep_umask", attribute_names, attribute_values, error))
+        return FALSE;
+
+      if (push_element (parser, ELEMENT_KEEP_UMASK) == NULL)
+        {
+          BUS_SET_OOM (error);
+          return FALSE;
+        }
+
+      parser->keep_umask = TRUE;
+      
+      return TRUE;
+    }
+  else if (element_type == ELEMENT_PIDFILE)
     {
       if (!check_no_attributes (parser, "pidfile", attribute_names, attribute_values, error))
         return FALSE;
@@ -661,7 +731,7 @@ start_busconfig_child (BusConfigParser   *parser,
 
       return TRUE;
     }
-  else if (strcmp (element_name, "listen") == 0)
+  else if (element_type == ELEMENT_LISTEN)
     {
       if (!check_no_attributes (parser, "listen", attribute_names, attribute_values, error))
         return FALSE;
@@ -674,7 +744,7 @@ start_busconfig_child (BusConfigParser   *parser,
 
       return TRUE;
     }
-  else if (strcmp (element_name, "auth") == 0)
+  else if (element_type == ELEMENT_AUTH)
     {
       if (!check_no_attributes (parser, "auth", attribute_names, attribute_values, error))
         return FALSE;
@@ -687,7 +757,20 @@ start_busconfig_child (BusConfigParser   *parser,
       
       return TRUE;
     }
-  else if (strcmp (element_name, "includedir") == 0)
+  else if (element_type == ELEMENT_SERVICEHELPER)
+    {
+      if (!check_no_attributes (parser, "servicehelper", attribute_names, attribute_values, error))
+        return FALSE;
+
+      if (push_element (parser, ELEMENT_SERVICEHELPER) == NULL)
+        {
+          BUS_SET_OOM (error);
+          return FALSE;
+        }
+
+      return TRUE;
+    }
+  else if (element_type == ELEMENT_INCLUDEDIR)
     {
       if (!check_no_attributes (parser, "includedir", attribute_names, attribute_values, error))
         return FALSE;
@@ -700,7 +783,59 @@ start_busconfig_child (BusConfigParser   *parser,
 
       return TRUE;
     }
-  else if (strcmp (element_name, "servicedir") == 0)
+  else if (element_type == ELEMENT_STANDARD_SESSION_SERVICEDIRS)
+    {
+      DBusList *link;
+      DBusList *dirs;
+      dirs = NULL;
+
+      if (!check_no_attributes (parser, "standard_session_servicedirs", attribute_names, attribute_values, error))
+        return FALSE;
+
+      if (push_element (parser, ELEMENT_STANDARD_SESSION_SERVICEDIRS) == NULL)
+        {
+          BUS_SET_OOM (error);
+          return FALSE;
+        }
+
+      if (!_dbus_get_standard_session_servicedirs (&dirs))
+        {
+          BUS_SET_OOM (error);
+          return FALSE;
+        }
+
+        while ((link = _dbus_list_pop_first_link (&dirs)))
+          service_dirs_append_link_unique_or_free (&parser->service_dirs, link);
+
+      return TRUE;
+    }
+  else if (element_type == ELEMENT_STANDARD_SYSTEM_SERVICEDIRS)
+    {
+      DBusList *link;
+      DBusList *dirs;
+      dirs = NULL;
+
+      if (!check_no_attributes (parser, "standard_system_servicedirs", attribute_names, attribute_values, error))
+        return FALSE;
+
+      if (push_element (parser, ELEMENT_STANDARD_SYSTEM_SERVICEDIRS) == NULL)
+        {
+          BUS_SET_OOM (error);
+          return FALSE;
+        }
+
+      if (!_dbus_get_standard_system_servicedirs (&dirs))
+        {
+          BUS_SET_OOM (error);
+          return FALSE;
+        }
+
+        while ((link = _dbus_list_pop_first_link (&dirs)))
+          service_dirs_append_link_unique_or_free (&parser->service_dirs, link);
+
+      return TRUE;
+    }
+  else if (element_type == ELEMENT_SERVICEDIR)
     {
       if (!check_no_attributes (parser, "servicedir", attribute_names, attribute_values, error))
         return FALSE;
@@ -713,10 +848,12 @@ start_busconfig_child (BusConfigParser   *parser,
 
       return TRUE;
     }
-  else if (strcmp (element_name, "include") == 0)
+  else if (element_type == ELEMENT_INCLUDE)
     {
       Element *e;
+      const char *if_selinux_enabled;
       const char *ignore_missing;
+      const char *selinux_root_relative;
 
       if ((e = push_element (parser, ELEMENT_INCLUDE)) == NULL)
         {
@@ -725,12 +862,16 @@ start_busconfig_child (BusConfigParser   *parser,
         }
 
       e->d.include.ignore_missing = FALSE;
+      e->d.include.if_selinux_enabled = FALSE;
+      e->d.include.selinux_root_relative = FALSE;
 
       if (!locate_attributes (parser, "include",
                               attribute_names,
                               attribute_values,
                               error,
                               "ignore_missing", &ignore_missing,
+                              "if_selinux_enabled", &if_selinux_enabled,
+                              "selinux_root_relative", &selinux_root_relative,
                               NULL))
         return FALSE;
 
@@ -748,14 +889,45 @@ start_busconfig_child (BusConfigParser   *parser,
             }
         }
 
+      if (if_selinux_enabled != NULL)
+        {
+          if (strcmp (if_selinux_enabled, "yes") == 0)
+            e->d.include.if_selinux_enabled = TRUE;
+          else if (strcmp (if_selinux_enabled, "no") == 0)
+            e->d.include.if_selinux_enabled = FALSE;
+          else
+            {
+              dbus_set_error (error, DBUS_ERROR_FAILED,
+                              "if_selinux_enabled attribute must have value"
+                              " \"yes\" or \"no\"");
+              return FALSE;
+           }
+        }
+      
+      if (selinux_root_relative != NULL)
+        {
+          if (strcmp (selinux_root_relative, "yes") == 0)
+            e->d.include.selinux_root_relative = TRUE;
+          else if (strcmp (selinux_root_relative, "no") == 0)
+            e->d.include.selinux_root_relative = FALSE;
+          else
+            {
+              dbus_set_error (error, DBUS_ERROR_FAILED,
+                              "selinux_root_relative attribute must have value"
+                              " \"yes\" or \"no\"");
+              return FALSE;
+           }
+        }
+
       return TRUE;
     }
-  else if (strcmp (element_name, "policy") == 0)
+  else if (element_type == ELEMENT_POLICY)
     {
       Element *e;
       const char *context;
       const char *user;
       const char *group;
+      const char *at_console;
 
       if ((e = push_element (parser, ELEMENT_POLICY)) == NULL)
         {
@@ -772,16 +944,20 @@ start_busconfig_child (BusConfigParser   *parser,
                               "context", &context,
                               "user", &user,
                               "group", &group,
+                              "at_console", &at_console,
                               NULL))
         return FALSE;
 
       if (((context && user) ||
-           (context && group)) ||
-          (user && group) ||
-          !(context || user || group))
+           (context && group) ||
+           (context && at_console)) ||
+           ((user && group) ||
+           (user && at_console)) ||
+           (group && at_console) ||
+          !(context || user || group || at_console))
         {
           dbus_set_error (error, DBUS_ERROR_FAILED,
-                          "<policy> element must have exactly one of (context|user|group) attributes");
+                          "<policy> element must have exactly one of (context|user|group|at_console) attributes");
           return FALSE;
         }
 
@@ -808,8 +984,8 @@ start_busconfig_child (BusConfigParser   *parser,
           DBusString username;
           _dbus_string_init_const (&username, user);
 
-          if (_dbus_get_user_id (&username,
-                                 &e->d.policy.gid_or_uid))
+          if (_dbus_parse_unix_user_from_config (&username,
+                                                 &e->d.policy.gid_uid_or_at_console))
             e->d.policy.type = POLICY_USER;
           else
             _dbus_warn ("Unknown username \"%s\" in message bus configuration file\n",
@@ -820,13 +996,31 @@ start_busconfig_child (BusConfigParser   *parser,
           DBusString group_name;
           _dbus_string_init_const (&group_name, group);
 
-          if (_dbus_get_group_id (&group_name,
-                                  &e->d.policy.gid_or_uid))
+          if (_dbus_parse_unix_group_from_config (&group_name,
+                                                  &e->d.policy.gid_uid_or_at_console))
             e->d.policy.type = POLICY_GROUP;
           else
             _dbus_warn ("Unknown group \"%s\" in message bus configuration file\n",
                         group);          
         }
+      else if (at_console != NULL)
+        {
+           dbus_bool_t t;
+           t = (strcmp (at_console, "true") == 0);
+           if (t || strcmp (at_console, "false") == 0)
+             {
+               e->d.policy.gid_uid_or_at_console = t; 
+               e->d.policy.type = POLICY_CONSOLE;
+             }  
+           else
+             {
+               dbus_set_error (error, DBUS_ERROR_FAILED,
+                              "Unknown value \"%s\" for at_console in message bus configuration file",
+                              at_console);
+
+               return FALSE;
+             }
+        }
       else
         {
           _dbus_assert_not_reached ("all <policy> attributes null and we didn't set error");
@@ -834,7 +1028,7 @@ start_busconfig_child (BusConfigParser   *parser,
       
       return TRUE;
     }
-  else if (strcmp (element_name, "limit") == 0)
+  else if (element_type == ELEMENT_LIMIT)
     {
       Element *e;
       const char *name;
@@ -869,11 +1063,8 @@ start_busconfig_child (BusConfigParser   *parser,
 
       return TRUE;
     }
-  else if (strcmp (element_name, "selinux") == 0)
+  else if (element_type == ELEMENT_SELINUX)
     {
-      Element *e;
-      const char *name;
-
       if (!check_no_attributes (parser, "selinux", attribute_names, attribute_values, error))
         return FALSE;
 
@@ -920,6 +1111,7 @@ append_rule_from_element (BusConfigParser   *parser,
   const char *own;
   const char *user;
   const char *group;
+
   BusPolicyRule *rule;
   
   if (!locate_attributes (parser, element_name,
@@ -990,7 +1182,6 @@ append_rule_from_element (BusConfigParser   *parser,
        (send_interface && receive_member) ||
        (send_interface && receive_error) ||
        (send_interface && receive_sender) ||
-       (send_interface && eavesdrop) ||
        (send_interface && receive_requested_reply) ||
        (send_interface && own) ||
        (send_interface && user) ||
@@ -1001,7 +1192,6 @@ append_rule_from_element (BusConfigParser   *parser,
        (send_member && receive_member) ||
        (send_member && receive_error) ||
        (send_member && receive_sender) ||
-       (send_member && eavesdrop) ||
        (send_member && receive_requested_reply) ||
        (send_member && own) ||
        (send_member && user) ||
@@ -1011,7 +1201,6 @@ append_rule_from_element (BusConfigParser   *parser,
        (send_error && receive_member) ||
        (send_error && receive_error) ||
        (send_error && receive_sender) ||
-       (send_error && eavesdrop) ||
        (send_error && receive_requested_reply) ||
        (send_error && own) ||
        (send_error && user) ||
@@ -1021,7 +1210,6 @@ append_rule_from_element (BusConfigParser   *parser,
        (send_destination && receive_member) ||
        (send_destination && receive_error) ||
        (send_destination && receive_sender) ||
-       (send_destination && eavesdrop) ||
        (send_destination && receive_requested_reply) ||
        (send_destination && own) ||
        (send_destination && user) ||
@@ -1031,7 +1219,6 @@ append_rule_from_element (BusConfigParser   *parser,
        (send_type && receive_member) ||
        (send_type && receive_error) ||
        (send_type && receive_sender) ||
-       (send_type && eavesdrop) ||
        (send_type && receive_requested_reply) ||
        (send_type && own) ||
        (send_type && user) ||
@@ -1041,7 +1228,6 @@ append_rule_from_element (BusConfigParser   *parser,
        (send_path && receive_member) ||
        (send_path && receive_error) ||
        (send_path && receive_sender) ||
-       (send_path && eavesdrop) ||
        (send_path && receive_requested_reply) ||
        (send_path && own) ||
        (send_path && user) ||
@@ -1051,7 +1237,6 @@ append_rule_from_element (BusConfigParser   *parser,
        (send_requested_reply && receive_member) ||
        (send_requested_reply && receive_error) ||
        (send_requested_reply && receive_sender) ||
-       (send_requested_reply && eavesdrop) ||
        (send_requested_reply && receive_requested_reply) ||
        (send_requested_reply && own) ||
        (send_requested_reply && user) ||
@@ -1128,6 +1313,16 @@ append_rule_from_element (BusConfigParser   *parser,
             }
         }
 
+      if (eavesdrop &&
+          !(strcmp (eavesdrop, "true") == 0 ||
+            strcmp (eavesdrop, "false") == 0))
+        {
+          dbus_set_error (error, DBUS_ERROR_FAILED,
+                          "Bad value \"%s\" for %s attribute, must be true or false",
+                          "eavesdrop", eavesdrop);
+          return FALSE;
+        }
+
       if (send_requested_reply &&
           !(strcmp (send_requested_reply, "true") == 0 ||
             strcmp (send_requested_reply, "false") == 0))
@@ -1142,9 +1337,12 @@ append_rule_from_element (BusConfigParser   *parser,
       if (rule == NULL)
         goto nomem;
       
+      if (eavesdrop)
+        rule->d.send.eavesdrop = (strcmp (eavesdrop, "true") == 0);
+
       if (send_requested_reply)
         rule->d.send.requested_reply = (strcmp (send_requested_reply, "true") == 0);
-      
+
       rule->d.send.message_type = message_type;
       rule->d.send.path = _dbus_strdup (send_path);
       rule->d.send.interface = _dbus_strdup (send_interface);
@@ -1272,7 +1470,7 @@ append_rule_from_element (BusConfigParser   *parser,
           
           _dbus_string_init_const (&username, user);
       
-          if (_dbus_get_user_id (&username, &uid))
+          if (_dbus_parse_unix_user_from_config (&username, &uid))
             {
               rule = bus_policy_rule_new (BUS_POLICY_RULE_USER, allow); 
               if (rule == NULL)
@@ -1304,7 +1502,7 @@ append_rule_from_element (BusConfigParser   *parser,
           
           _dbus_string_init_const (&groupname, group);
           
-          if (_dbus_get_user_id (&groupname, &gid))
+          if (_dbus_parse_unix_group_from_config (&groupname, &gid))
             {
               rule = bus_policy_rule_new (BUS_POLICY_RULE_GROUP, allow); 
               if (rule == NULL)
@@ -1353,7 +1551,7 @@ append_rule_from_element (BusConfigParser   *parser,
               goto failed;
             }
           
-          if (!bus_policy_append_user_rule (parser->policy, pe->d.policy.gid_or_uid,
+          if (!bus_policy_append_user_rule (parser->policy, pe->d.policy.gid_uid_or_at_console,
                                             rule))
             goto nomem;
           break;
@@ -1366,12 +1564,19 @@ append_rule_from_element (BusConfigParser   *parser,
               goto failed;
             }
           
-          if (!bus_policy_append_group_rule (parser->policy, pe->d.policy.gid_or_uid,
+          if (!bus_policy_append_group_rule (parser->policy, pe->d.policy.gid_uid_or_at_console,
                                              rule))
             goto nomem;
           break;
+        
+
+        case POLICY_CONSOLE:
+          if (!bus_policy_append_console_rule (parser->policy, pe->d.policy.gid_uid_or_at_console,
+                                               rule))
+            goto nomem;
+          break;
         }
-      
       bus_policy_rule_unref (rule);
       rule = NULL;
     }
@@ -1439,6 +1644,12 @@ start_selinux_child (BusConfigParser   *parser,
                      const char       **attribute_values,
                      DBusError         *error)
 {
+  char *own_copy;
+  char *context_copy;
+
+  own_copy = NULL;
+  context_copy = NULL;
+
   if (strcmp (element_name, "associate") == 0)
     {
       const char *own;
@@ -1466,13 +1677,17 @@ start_selinux_child (BusConfigParser   *parser,
           return FALSE;
         }
 
-      if (!bus_selinux_id_table_insert (parser->service_sid_table,
-                                        own, context))
-        {
-          BUS_SET_OOM (error);
-          return FALSE;
-        }
-      
+      own_copy = _dbus_strdup (own);
+      if (own_copy == NULL)
+        goto oom;
+      context_copy = _dbus_strdup (context);
+      if (context_copy == NULL)
+        goto oom;
+
+      if (!_dbus_hash_table_insert_string (parser->service_context_table,
+                                          own_copy, context_copy))
+        goto oom;
+
       return TRUE;
     }
   else
@@ -1482,6 +1697,16 @@ start_selinux_child (BusConfigParser   *parser,
                       element_name, "selinux");
       return FALSE;
     }
+
+ oom:
+  if (own_copy)
+    dbus_free (own_copy);
+
+  if (context_copy)  
+    dbus_free (context_copy);
+
+  BUS_SET_OOM (error);
+  return FALSE;
 }
 
 dbus_bool_t
@@ -1576,7 +1801,7 @@ set_limit (BusConfigParser *parser,
       must_be_positive = TRUE;
       parser->limits.max_message_size = value;
     }
-  else if (strcmp (name, "activation_timeout") == 0)
+  else if (strcmp (name, "service_start_timeout") == 0)
     {
       must_be_positive = TRUE;
       must_be_int = TRUE;
@@ -1612,18 +1837,24 @@ set_limit (BusConfigParser *parser,
       must_be_int = TRUE;
       parser->limits.max_connections_per_user = value;
     }
-  else if (strcmp (name, "max_pending_activations") == 0)
+  else if (strcmp (name, "max_pending_service_starts") == 0)
     {
       must_be_positive = TRUE;
       must_be_int = TRUE;
       parser->limits.max_pending_activations = value;
     }
-  else if (strcmp (name, "max_services_per_connection") == 0)
+  else if (strcmp (name, "max_names_per_connection") == 0)
     {
       must_be_positive = TRUE;
       must_be_int = TRUE;
       parser->limits.max_services_per_connection = value;
     }
+  else if (strcmp (name, "max_match_rules_per_connection") == 0)
+    {
+      must_be_positive = TRUE;
+      must_be_int = TRUE;
+      parser->limits.max_match_rules_per_connection = value;
+    }
   else if (strcmp (name, "max_replies_per_connection") == 0)
     {
       must_be_positive = TRUE;
@@ -1683,7 +1914,7 @@ bus_config_parser_end_element (BusConfigParser   *parser,
       return FALSE;
     }
 
-  n = element_type_to_name (t);
+  n = bus_config_parser_element_type_to_name (t);
   _dbus_assert (n != NULL);
   if (strcmp (n, element_name) != 0)
     {
@@ -1712,13 +1943,14 @@ bus_config_parser_end_element (BusConfigParser   *parser,
     case ELEMENT_PIDFILE:
     case ELEMENT_AUTH:
     case ELEMENT_SERVICEDIR:
+    case ELEMENT_SERVICEHELPER:
     case ELEMENT_INCLUDEDIR:
     case ELEMENT_LIMIT:
       if (!e->had_content)
         {
           dbus_set_error (error, DBUS_ERROR_FAILED,
                           "XML element <%s> was expected to have content inside it",
-                          element_type_to_name (e->type));
+                          bus_config_parser_element_type_to_name (e->type));
           return FALSE;
         }
 
@@ -1735,8 +1967,11 @@ bus_config_parser_end_element (BusConfigParser   *parser,
     case ELEMENT_ALLOW:
     case ELEMENT_DENY:
     case ELEMENT_FORK:
+    case ELEMENT_KEEP_UMASK:
     case ELEMENT_SELINUX:
     case ELEMENT_ASSOCIATE:
+    case ELEMENT_STANDARD_SESSION_SERVICEDIRS:
+    case ELEMENT_STANDARD_SYSTEM_SERVICEDIRS:
       break;
     }
 
@@ -1850,6 +2085,40 @@ include_file (BusConfigParser   *parser,
 }
 
 static dbus_bool_t
+servicehelper_path (BusConfigParser   *parser,
+                    const DBusString  *filename,
+                    DBusError         *error)
+{
+  const char *filename_str;
+  char *servicehelper;
+
+  filename_str = _dbus_string_get_const_data (filename);
+
+  /* copy to avoid overwriting with NULL on OOM */
+  servicehelper = _dbus_strdup (filename_str);
+
+  /* check for OOM */
+  if (servicehelper == NULL)
+    {
+      BUS_SET_OOM (error);
+      return FALSE;
+    }
+
+  /* save the latest servicehelper only if not OOM */
+  dbus_free (parser->servicehelper);
+  parser->servicehelper = servicehelper;
+
+  /* We don't check whether the helper exists; instead we
+   * would just fail to ever activate anything if it doesn't.
+   * This allows an admin to fix the problem if it doesn't exist.
+   * It also allows the parser test suite to successfully parse
+   * test cases without installing the helper. ;-)
+   */
+  
+  return TRUE;
+}
+
+static dbus_bool_t
 include_dir (BusConfigParser   *parser,
              const DBusString  *dirname,
              DBusError         *error)
@@ -1858,6 +2127,7 @@ include_dir (BusConfigParser   *parser,
   dbus_bool_t retval;
   DBusError tmp_error;
   DBusDirIter *dir;
+  char *s;
   
   if (!_dbus_string_init (&filename))
     {
@@ -1914,7 +2184,21 @@ include_dir (BusConfigParser   *parser,
       dbus_move_error (&tmp_error, error);
       goto failed;
     }
-  
+
+
+  if (!_dbus_string_copy_data (dirname, &s))
+    {
+      BUS_SET_OOM (error);
+      goto failed;
+    }
+
+  if (!_dbus_list_append (&parser->conf_dirs, s))
+    {
+      dbus_free (s);
+      BUS_SET_OOM (error);
+      goto failed;
+    }
+
   retval = TRUE;
   
  failed:
@@ -1969,6 +2253,9 @@ bus_config_parser_content (BusConfigParser   *parser,
     case ELEMENT_ALLOW:
     case ELEMENT_DENY:
     case ELEMENT_FORK:
+    case ELEMENT_KEEP_UMASK:
+    case ELEMENT_STANDARD_SESSION_SERVICEDIRS:    
+    case ELEMENT_STANDARD_SYSTEM_SERVICEDIRS:    
     case ELEMENT_SELINUX:
     case ELEMENT_ASSOCIATE:
       if (all_whitespace (content))
@@ -1977,7 +2264,7 @@ bus_config_parser_content (BusConfigParser   *parser,
         {
           dbus_set_error (error, DBUS_ERROR_FAILED,
                           "No text content expected inside XML element %s in configuration file",
-                          element_type_to_name (top_element_type (parser)));
+                          bus_config_parser_element_type_to_name (top_element_type (parser)));
           return FALSE;
         }
 
@@ -1997,6 +2284,53 @@ bus_config_parser_content (BusConfigParser   *parser,
 
     case ELEMENT_INCLUDE:
       {
+        DBusString full_path, selinux_policy_root;
+
+        e->had_content = TRUE;
+
+       if (e->d.include.if_selinux_enabled
+           && !bus_selinux_enabled ())
+         break;
+
+        if (!_dbus_string_init (&full_path))
+          goto nomem;
+
+        if (e->d.include.selinux_root_relative)
+         {
+            if (!bus_selinux_get_policy_root ())
+             {
+               dbus_set_error (error, DBUS_ERROR_FAILED,
+                               "Could not determine SELinux policy root for relative inclusion");
+               _dbus_string_free (&full_path);
+               return FALSE;
+             }
+            _dbus_string_init_const (&selinux_policy_root,
+                                     bus_selinux_get_policy_root ());
+            if (!make_full_path (&selinux_policy_root, content, &full_path))
+              {
+                _dbus_string_free (&full_path);
+                goto nomem;
+              }
+          }
+        else if (!make_full_path (&parser->basedir, content, &full_path))
+          {
+            _dbus_string_free (&full_path);
+            goto nomem;
+          }
+
+        if (!include_file (parser, &full_path,
+                           e->d.include.ignore_missing, error))
+          {
+            _dbus_string_free (&full_path);
+            return FALSE;
+          }
+
+        _dbus_string_free (&full_path);
+      }
+      break;
+
+    case ELEMENT_SERVICEHELPER:
+      {
         DBusString full_path;
         
         e->had_content = TRUE;
@@ -2009,9 +2343,8 @@ bus_config_parser_content (BusConfigParser   *parser,
             _dbus_string_free (&full_path);
             goto nomem;
           }
-        
-        if (!include_file (parser, &full_path,
-                           e->d.include.ignore_missing, error))
+
+        if (!servicehelper_path (parser, &full_path, error))
           {
             _dbus_string_free (&full_path);
             return FALSE;
@@ -2020,7 +2353,7 @@ bus_config_parser_content (BusConfigParser   *parser,
         _dbus_string_free (&full_path);
       }
       break;
-
+      
     case ELEMENT_INCLUDEDIR:
       {
         DBusString full_path;
@@ -2132,7 +2465,8 @@ bus_config_parser_content (BusConfigParser   *parser,
             goto nomem;
           }
 
-        if (!_dbus_list_append (&parser->service_dirs, s))
+        /* _only_ extra session directories can be specified */
+        if (!service_dirs_append_unique_or_free (&parser->service_dirs, s))
           {
             _dbus_string_free (&full_path);
             dbus_free (s);
@@ -2185,7 +2519,7 @@ bus_config_parser_finished (BusConfigParser   *parser,
     {
       dbus_set_error (error, DBUS_ERROR_FAILED,
                       "Element <%s> was not closed in configuration file",
-                      element_type_to_name (top_element_type (parser)));
+                      bus_config_parser_element_type_to_name (top_element_type (parser)));
 
       return FALSE;
     }
@@ -2230,18 +2564,36 @@ bus_config_parser_get_service_dirs (BusConfigParser *parser)
   return &parser->service_dirs;
 }
 
+DBusList**
+bus_config_parser_get_conf_dirs (BusConfigParser *parser)
+{
+  return &parser->conf_dirs;
+}
+
 dbus_bool_t
 bus_config_parser_get_fork (BusConfigParser   *parser)
 {
   return parser->fork;
 }
 
+dbus_bool_t
+bus_config_parser_get_keep_umask (BusConfigParser   *parser)
+{
+  return parser->keep_umask;
+}
+
 const char *
 bus_config_parser_get_pidfile (BusConfigParser   *parser)
 {
   return parser->pidfile;
 }
 
+const char *
+bus_config_parser_get_servicehelper (BusConfigParser   *parser)
+{
+  return parser->servicehelper;
+}
+
 BusPolicy*
 bus_config_parser_steal_policy (BusConfigParser *parser)
 {
@@ -2265,15 +2617,15 @@ bus_config_parser_get_limits (BusConfigParser *parser,
 }
 
 DBusHashTable*
-bus_config_parser_steal_service_sid_table (BusConfigParser *parser)
+bus_config_parser_steal_service_context_table (BusConfigParser *parser)
 {
   DBusHashTable *table;
 
-  _dbus_assert (parser->service_sid_table != NULL); /* can only steal once */
+  _dbus_assert (parser->service_context_table != NULL); /* can only steal once */
 
-  table = parser->service_sid_table;
+  table = parser->service_context_table;
 
-  parser->service_sid_table = NULL;
+  parser->service_context_table = NULL;
 
   return table;
 }
@@ -2506,7 +2858,7 @@ elements_equal (const Element *a,
     case ELEMENT_POLICY:
       if (a->d.policy.type != b->d.policy.type)
        return FALSE;
-      if (a->d.policy.gid_or_uid != b->d.policy.gid_or_uid)
+      if (a->d.policy.gid_uid_or_at_console != b->d.policy.gid_uid_or_at_console)
        return FALSE;
       break;
 
@@ -2623,6 +2975,9 @@ config_parsers_equal (const BusConfigParser *a,
   if (! bools_equal (a->fork, b->fork))
     return FALSE;
 
+  if (! bools_equal (a->keep_umask, b->keep_umask))
+    return FALSE;
+
   if (! bools_equal (a->is_toplevel, b->is_toplevel))
     return FALSE;
 
@@ -2686,28 +3041,29 @@ all_are_equiv (const DBusString *target_directory)
       printf ("    %s\n", _dbus_string_get_const_data (&filename));
 
       parser = bus_config_load (&full_path, TRUE, NULL, &error);
-      _dbus_string_free (&full_path);
 
       if (parser == NULL)
        {
          _dbus_warn ("Could not load file %s: %s\n",
                      _dbus_string_get_const_data (&full_path),
                      error.message);
+          _dbus_string_free (&full_path);
          dbus_error_free (&error);
          goto finished;
        }
       else if (first_parser == NULL)
        {
+          _dbus_string_free (&full_path);
          first_parser = parser;
        }
       else
        {
+          _dbus_string_free (&full_path);
          equal = config_parsers_equal (first_parser, parser);
          bus_config_parser_unref (parser);
          if (! equal)
            goto finished;
        }
-
     }
 
   retval = TRUE;
@@ -2799,7 +3155,256 @@ process_test_equiv_subdir (const DBusString *test_base_dir,
   return retval;
   
 }
-                          
+
+static const char *test_session_service_dir_matches[] = 
+        {
+#ifdef DBUS_UNIX
+         "/testusr/testlocal/testshare/dbus-1/services",
+         "/testusr/testshare/dbus-1/services",
+#endif
+         DBUS_DATADIR"/dbus-1/services",
+#ifdef DBUS_UNIX
+         "/testhome/foo/.testlocal/testshare/dbus-1/services",
+#endif
+         NULL
+        };
+
+static dbus_bool_t
+test_default_session_servicedirs (void)
+{
+  DBusList *dirs;
+  DBusList *link;
+  DBusString progs;
+  const char *common_progs;
+  int i;
+
+  /* On Unix we don't actually use this variable, but it's easier to handle the
+   * deallocation if we always allocate it, whether needed or not */
+  if (!_dbus_string_init (&progs))
+    _dbus_assert_not_reached ("OOM allocating progs");
+
+  common_progs = _dbus_getenv ("CommonProgramFiles");
+#ifndef DBUS_UNIX
+  if (common_progs) 
+    {
+      if (!_dbus_string_append (&progs, common_progs)) 
+        {
+          _dbus_string_free (&progs);
+          return FALSE;
+        }
+
+      if (!_dbus_string_append (&progs, "/dbus-1/services")) 
+        {
+          _dbus_string_free (&progs);
+          return FALSE;
+        }
+      test_session_service_dir_matches[1] = _dbus_string_get_const_data(&progs);
+    }
+#endif
+  dirs = NULL;
+
+  printf ("Testing retrieving the default session service directories\n");
+  if (!_dbus_get_standard_session_servicedirs (&dirs))
+    _dbus_assert_not_reached ("couldn't get stardard dirs");
+
+  /* make sure our defaults end with share/dbus-1/service */
+  while ((link = _dbus_list_pop_first_link (&dirs)))
+    {
+      DBusString path;
+      
+      printf ("    default service dir: %s\n", (char *)link->data);
+      _dbus_string_init_const (&path, (char *)link->data);
+      if (!_dbus_string_ends_with_c_str (&path, "dbus-1/services"))
+        {
+          printf ("error with default session service directories\n");
+             dbus_free (link->data);
+         _dbus_list_free_link (link);
+          _dbus_string_free (&progs);
+          return FALSE;
+        }
+      dbus_free (link->data);
+      _dbus_list_free_link (link);
+    }
+
+#ifdef DBUS_UNIX
+  if (!_dbus_setenv ("XDG_DATA_HOME", "/testhome/foo/.testlocal/testshare"))
+    _dbus_assert_not_reached ("couldn't setenv XDG_DATA_HOME");
+
+  if (!_dbus_setenv ("XDG_DATA_DIRS", ":/testusr/testlocal/testshare: :/testusr/testshare:"))
+    _dbus_assert_not_reached ("couldn't setenv XDG_DATA_DIRS");
+#endif
+  if (!_dbus_get_standard_session_servicedirs (&dirs))
+    _dbus_assert_not_reached ("couldn't get stardard dirs");
+
+  /* make sure we read and parse the env variable correctly */
+  i = 0;
+  while ((link = _dbus_list_pop_first_link (&dirs)))
+    {
+      printf ("    test service dir: %s\n", (char *)link->data);
+      if (test_session_service_dir_matches[i] == NULL)
+        {
+          printf ("more directories parsed than in match set\n");
+          dbus_free (link->data);
+          _dbus_list_free_link (link);
+          _dbus_string_free (&progs);
+          return FALSE;
+        }
+      if (strcmp (test_session_service_dir_matches[i], 
+                  (char *)link->data) != 0)
+        {
+          printf ("%s directory does not match %s in the match set\n", 
+                  (char *)link->data,
+                  test_session_service_dir_matches[i]);
+          dbus_free (link->data);
+          _dbus_list_free_link (link);
+          _dbus_string_free (&progs);
+          return FALSE;
+        }
+
+      ++i;
+
+      dbus_free (link->data);
+      _dbus_list_free_link (link);
+    }
+  
+  if (test_session_service_dir_matches[i] != NULL)
+    {
+      printf ("extra data %s in the match set was not matched\n",
+              test_session_service_dir_matches[i]);
+
+      _dbus_string_free (&progs);
+      return FALSE;
+    }
+    
+  _dbus_string_free (&progs);
+  return TRUE;
+}
+
+static const char *test_system_service_dir_matches[] = 
+        {
+#ifdef DBUS_UNIX
+         "/testusr/testlocal/testshare/dbus-1/system-services",
+         "/testusr/testshare/dbus-1/system-services",
+#endif
+         DBUS_DATADIR"/dbus-1/system-services",
+         NULL
+        };
+
+static dbus_bool_t
+test_default_system_servicedirs (void)
+{
+  DBusList *dirs;
+  DBusList *link;
+  DBusString progs;
+  const char *common_progs;
+  int i;
+
+  /* On Unix we don't actually use this variable, but it's easier to handle the
+   * deallocation if we always allocate it, whether needed or not */
+  if (!_dbus_string_init (&progs))
+    _dbus_assert_not_reached ("OOM allocating progs");
+
+  common_progs = _dbus_getenv ("CommonProgramFiles");
+#ifndef DBUS_UNIX
+  if (common_progs) 
+    {
+      if (!_dbus_string_append (&progs, common_progs)) 
+        {
+          _dbus_string_free (&progs);
+          return FALSE;
+        }
+
+      if (!_dbus_string_append (&progs, "/dbus-1/system-services")) 
+        {
+          _dbus_string_free (&progs);
+          return FALSE;
+        }
+      test_system_service_dir_matches[1] = _dbus_string_get_const_data(&progs);
+    }
+#endif
+  dirs = NULL;
+
+  printf ("Testing retrieving the default system service directories\n");
+  if (!_dbus_get_standard_system_servicedirs (&dirs))
+    _dbus_assert_not_reached ("couldn't get stardard dirs");
+
+  /* make sure our defaults end with share/dbus-1/system-service */
+  while ((link = _dbus_list_pop_first_link (&dirs)))
+    {
+      DBusString path;
+      
+      printf ("    default service dir: %s\n", (char *)link->data);
+      _dbus_string_init_const (&path, (char *)link->data);
+      if (!_dbus_string_ends_with_c_str (&path, "dbus-1/system-services"))
+        {
+          printf ("error with default system service directories\n");
+             dbus_free (link->data);
+         _dbus_list_free_link (link);
+          _dbus_string_free (&progs);
+          return FALSE;
+        }
+      dbus_free (link->data);
+      _dbus_list_free_link (link);
+    }
+
+#ifdef DBUS_UNIX
+  if (!_dbus_setenv ("XDG_DATA_HOME", "/testhome/foo/.testlocal/testshare"))
+    _dbus_assert_not_reached ("couldn't setenv XDG_DATA_HOME");
+
+  if (!_dbus_setenv ("XDG_DATA_DIRS", ":/testusr/testlocal/testshare: :/testusr/testshare:"))
+    _dbus_assert_not_reached ("couldn't setenv XDG_DATA_DIRS");
+#endif
+  if (!_dbus_get_standard_system_servicedirs (&dirs))
+    _dbus_assert_not_reached ("couldn't get stardard dirs");
+
+  /* make sure we read and parse the env variable correctly */
+  i = 0;
+  while ((link = _dbus_list_pop_first_link (&dirs)))
+    {
+      printf ("    test service dir: %s\n", (char *)link->data);
+      if (test_system_service_dir_matches[i] == NULL)
+        {
+          printf ("more directories parsed than in match set\n");
+          dbus_free (link->data);
+          _dbus_list_free_link (link);
+          _dbus_string_free (&progs);
+          return FALSE;
+        }
+      if (strcmp (test_system_service_dir_matches[i], 
+                  (char *)link->data) != 0)
+        {
+          printf ("%s directory does not match %s in the match set\n", 
+                  (char *)link->data,
+                  test_system_service_dir_matches[i]);
+          dbus_free (link->data);
+          _dbus_list_free_link (link);
+          _dbus_string_free (&progs);
+          return FALSE;
+        }
+
+      ++i;
+
+      dbus_free (link->data);
+      _dbus_list_free_link (link);
+    }
+  
+  if (test_system_service_dir_matches[i] != NULL)
+    {
+      printf ("extra data %s in the match set was not matched\n",
+              test_system_service_dir_matches[i]);
+
+      _dbus_string_free (&progs);
+      return FALSE;
+    }
+    
+  _dbus_string_free (&progs);
+  return TRUE;
+}
+                  
 dbus_bool_t
 bus_config_parser_test (const DBusString *test_data_dir)
 {
@@ -2810,6 +3415,12 @@ bus_config_parser_test (const DBusString *test_data_dir)
       return TRUE;
     }
 
+  if (!test_default_session_servicedirs())
+    return FALSE;
+
+  if (!test_default_system_servicedirs())
+    return FALSE;
+
   if (!process_test_valid_subdir (test_data_dir, "valid-config-files", VALID))
     return FALSE;