1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* config-parser.c XML-library-agnostic configuration file parser
4 * Copyright (C) 2003, 2004 Red Hat, Inc.
6 * Licensed under the Academic Free License version 2.1
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "config-parser-common.h"
24 #include "config-parser.h"
29 #include <dbus/dbus-list.h>
30 #include <dbus/dbus-internals.h>
35 /* we ignore policies for unknown groups/users */
50 unsigned int had_content : 1;
56 unsigned int ignore_missing : 1;
57 unsigned int if_selinux_enabled : 1;
58 unsigned int selinux_root_relative : 1;
64 unsigned long gid_uid_or_at_console;
78 * Parser for bus configuration file.
80 struct BusConfigParser
82 int refcount; /**< Reference count */
84 DBusString basedir; /**< Directory we resolve paths relative to */
86 DBusList *stack; /**< stack of Element */
88 char *user; /**< user to run as */
90 char *servicehelper; /**< location of the setuid helper */
92 char *bus_type; /**< Message bus type */
94 DBusList *listen_on; /**< List of addresses to listen to */
96 DBusList *mechanisms; /**< Auth mechanisms */
98 DBusList *service_dirs; /**< Directories to look for session services in */
100 DBusList *conf_dirs; /**< Directories to look for policy configuration in */
102 BusPolicy *policy; /**< Security policy */
104 BusLimits limits; /**< Limits */
106 char *pidfile; /**< PID file */
108 DBusList *included_files; /**< Included files stack */
110 DBusHashTable *service_context_table; /**< Map service names to SELinux contexts */
112 unsigned int fork : 1; /**< TRUE to fork into daemon mode */
114 unsigned int syslog : 1; /**< TRUE to enable syslog */
115 unsigned int keep_umask : 1; /**< TRUE to keep original umask when forking */
117 unsigned int is_toplevel : 1; /**< FALSE if we are a sub-config-file inside another one */
119 unsigned int allow_anonymous : 1; /**< TRUE to allow anonymous connections */
123 push_element (BusConfigParser *parser,
128 _dbus_assert (type != ELEMENT_NONE);
130 e = dbus_new0 (Element, 1);
134 if (!_dbus_list_append (&parser->stack, e))
146 element_free (Element *e)
148 if (e->type == ELEMENT_LIMIT)
149 dbus_free (e->d.limit.name);
155 pop_element (BusConfigParser *parser)
159 e = _dbus_list_pop_last (&parser->stack);
165 peek_element (BusConfigParser *parser)
169 e = _dbus_list_get_last (&parser->stack);
175 top_element_type (BusConfigParser *parser)
179 e = _dbus_list_get_last (&parser->stack);
188 merge_service_context_hash (DBusHashTable *dest,
198 _dbus_hash_iter_init (from, &iter);
199 while (_dbus_hash_iter_next (&iter))
201 const char *service = _dbus_hash_iter_get_string_key (&iter);
202 const char *context = _dbus_hash_iter_get_value (&iter);
204 service_copy = _dbus_strdup (service);
205 if (service_copy == NULL)
207 context_copy = _dbus_strdup (context);
208 if (context_copy == NULL)
211 if (!_dbus_hash_table_insert_string (dest, service_copy, context_copy))
222 dbus_free (service_copy);
225 dbus_free (context_copy);
231 service_dirs_find_dir (DBusList **service_dirs,
236 _dbus_assert (dir != NULL);
238 for (link = *service_dirs; link; link = _dbus_list_get_next_link(service_dirs, link))
240 const char *link_dir;
242 link_dir = (const char *)link->data;
243 if (strcmp (dir, link_dir) == 0)
251 service_dirs_append_unique_or_free (DBusList **service_dirs,
254 if (!service_dirs_find_dir (service_dirs, dir))
255 return _dbus_list_append (service_dirs, dir);
262 service_dirs_append_link_unique_or_free (DBusList **service_dirs,
265 if (!service_dirs_find_dir (service_dirs, dir_link->data))
267 _dbus_list_append_link (service_dirs, dir_link);
271 dbus_free (dir_link->data);
272 _dbus_list_free_link (dir_link);
277 merge_included (BusConfigParser *parser,
278 BusConfigParser *included,
283 if (!bus_policy_merge (parser->policy,
290 if (!merge_service_context_hash (parser->service_context_table,
291 included->service_context_table))
297 if (included->user != NULL)
299 dbus_free (parser->user);
300 parser->user = included->user;
301 included->user = NULL;
304 if (included->bus_type != NULL)
306 dbus_free (parser->bus_type);
307 parser->bus_type = included->bus_type;
308 included->bus_type = NULL;
314 if (included->keep_umask)
315 parser->keep_umask = TRUE;
317 if (included->pidfile != NULL)
319 dbus_free (parser->pidfile);
320 parser->pidfile = included->pidfile;
321 included->pidfile = NULL;
324 while ((link = _dbus_list_pop_first_link (&included->listen_on)))
325 _dbus_list_append_link (&parser->listen_on, link);
327 while ((link = _dbus_list_pop_first_link (&included->mechanisms)))
328 _dbus_list_append_link (&parser->mechanisms, link);
330 while ((link = _dbus_list_pop_first_link (&included->service_dirs)))
331 service_dirs_append_link_unique_or_free (&parser->service_dirs, link);
333 while ((link = _dbus_list_pop_first_link (&included->conf_dirs)))
334 _dbus_list_append_link (&parser->conf_dirs, link);
340 seen_include (BusConfigParser *parser,
341 const DBusString *file)
345 iter = parser->included_files;
348 if (! strcmp (_dbus_string_get_const_data (file), iter->data))
351 iter = _dbus_list_get_next_link (&parser->included_files, iter);
358 bus_config_parser_new (const DBusString *basedir,
359 dbus_bool_t is_toplevel,
360 const BusConfigParser *parent)
362 BusConfigParser *parser;
364 parser = dbus_new0 (BusConfigParser, 1);
368 parser->is_toplevel = !!is_toplevel;
370 if (!_dbus_string_init (&parser->basedir))
376 if (((parser->policy = bus_policy_new ()) == NULL) ||
377 !_dbus_string_copy (basedir, 0, &parser->basedir, 0) ||
378 ((parser->service_context_table = _dbus_hash_table_new (DBUS_HASH_STRING,
380 dbus_free)) == NULL))
383 bus_policy_unref (parser->policy);
385 _dbus_string_free (&parser->basedir);
393 /* Initialize the parser's limits from the parent. */
394 parser->limits = parent->limits;
396 /* Use the parent's list of included_files to avoid
397 circular inclusions. */
398 parser->included_files = parent->included_files;
403 /* Make up some numbers! woot! */
404 parser->limits.max_incoming_bytes = _DBUS_ONE_MEGABYTE * 127;
405 parser->limits.max_outgoing_bytes = _DBUS_ONE_MEGABYTE * 127;
406 parser->limits.max_message_size = _DBUS_ONE_MEGABYTE * 32;
408 /* We set relatively conservative values here since due to the
409 way SCM_RIGHTS works we need to preallocate an array for the
410 maximum number of file descriptors we can receive. Picking a
411 high value here thus translates directly to more memory
413 parser->limits.max_incoming_unix_fds = 1024*4;
414 parser->limits.max_outgoing_unix_fds = 1024*4;
415 parser->limits.max_message_unix_fds = 1024;
417 /* Making this long means the user has to wait longer for an error
418 * message if something screws up, but making it too short means
419 * they might see a false failure.
421 parser->limits.activation_timeout = 25000; /* 25 seconds */
423 /* Making this long risks making a DOS attack easier, but too short
424 * and legitimate auth will fail. If interactive auth (ask user for
425 * password) is allowed, then potentially it has to be quite long.
427 parser->limits.auth_timeout = 30000; /* 30 seconds */
429 parser->limits.max_incomplete_connections = 64;
430 parser->limits.max_connections_per_user = 256;
432 /* Note that max_completed_connections / max_connections_per_user
433 * is the number of users that would have to work together to
434 * DOS all the other users.
436 parser->limits.max_completed_connections = 2048;
438 parser->limits.max_pending_activations = 512;
439 parser->limits.max_services_per_connection = 512;
441 /* For this one, keep in mind that it isn't only the memory used
442 * by the match rules, but slowdown from linearly walking a big
443 * list of them. A client adding more than this is almost
444 * certainly a bad idea for that reason, and should change to a
445 * smaller number of wider-net match rules - getting every last
446 * message to the bus is probably better than having a thousand
449 parser->limits.max_match_rules_per_connection = 512;
451 parser->limits.reply_timeout = -1; /* never */
453 /* this is effectively a limit on message queue size for messages
454 * that require a reply
456 parser->limits.max_replies_per_connection = 1024*8;
459 parser->refcount = 1;
465 bus_config_parser_ref (BusConfigParser *parser)
467 _dbus_assert (parser->refcount > 0);
469 parser->refcount += 1;
475 bus_config_parser_unref (BusConfigParser *parser)
477 _dbus_assert (parser->refcount > 0);
479 parser->refcount -= 1;
481 if (parser->refcount == 0)
483 while (parser->stack != NULL)
484 pop_element (parser);
486 dbus_free (parser->user);
487 dbus_free (parser->servicehelper);
488 dbus_free (parser->bus_type);
489 dbus_free (parser->pidfile);
491 _dbus_list_foreach (&parser->listen_on,
492 (DBusForeachFunction) dbus_free,
495 _dbus_list_clear (&parser->listen_on);
497 _dbus_list_foreach (&parser->service_dirs,
498 (DBusForeachFunction) dbus_free,
501 _dbus_list_clear (&parser->service_dirs);
503 _dbus_list_foreach (&parser->conf_dirs,
504 (DBusForeachFunction) dbus_free,
507 _dbus_list_clear (&parser->conf_dirs);
509 _dbus_list_foreach (&parser->mechanisms,
510 (DBusForeachFunction) dbus_free,
513 _dbus_list_clear (&parser->mechanisms);
515 _dbus_string_free (&parser->basedir);
518 bus_policy_unref (parser->policy);
520 if (parser->service_context_table)
521 _dbus_hash_table_unref (parser->service_context_table);
528 bus_config_parser_check_doctype (BusConfigParser *parser,
532 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
534 if (strcmp (doctype, "busconfig") != 0)
536 dbus_set_error (error,
538 "Configuration file has the wrong document type %s",
553 locate_attributes (BusConfigParser *parser,
554 const char *element_name,
555 const char **attribute_names,
556 const char **attribute_values,
558 const char *first_attribute_name,
559 const char **first_attribute_retloc,
567 LocateAttr attrs[MAX_ATTRS];
571 _dbus_assert (first_attribute_name != NULL);
572 _dbus_assert (first_attribute_retloc != NULL);
577 attrs[0].name = first_attribute_name;
578 attrs[0].retloc = first_attribute_retloc;
579 *first_attribute_retloc = NULL;
581 va_start (args, first_attribute_retloc);
583 name = va_arg (args, const char*);
584 retloc = va_arg (args, const char**);
588 _dbus_assert (retloc != NULL);
589 _dbus_assert (n_attrs < MAX_ATTRS);
591 attrs[n_attrs].name = name;
592 attrs[n_attrs].retloc = retloc;
596 name = va_arg (args, const char*);
597 retloc = va_arg (args, const char**);
603 while (attribute_names[i])
612 if (strcmp (attrs[j].name, attribute_names[i]) == 0)
614 retloc = attrs[j].retloc;
618 dbus_set_error (error, DBUS_ERROR_FAILED,
619 "Attribute \"%s\" repeated twice on the same <%s> element",
620 attrs[j].name, element_name);
625 *retloc = attribute_values[i];
634 dbus_set_error (error, DBUS_ERROR_FAILED,
635 "Attribute \"%s\" is invalid on <%s> element in this context",
636 attribute_names[i], element_name);
649 check_no_attributes (BusConfigParser *parser,
650 const char *element_name,
651 const char **attribute_names,
652 const char **attribute_values,
655 if (attribute_names[0] != NULL)
657 dbus_set_error (error, DBUS_ERROR_FAILED,
658 "Attribute \"%s\" is invalid on <%s> element in this context",
659 attribute_names[0], element_name);
667 start_busconfig_child (BusConfigParser *parser,
668 const char *element_name,
669 const char **attribute_names,
670 const char **attribute_values,
673 ElementType element_type;
675 element_type = bus_config_parser_element_name_to_type (element_name);
677 if (element_type == ELEMENT_USER)
679 if (!check_no_attributes (parser, "user", attribute_names, attribute_values, error))
682 if (push_element (parser, ELEMENT_USER) == NULL)
690 else if (element_type == ELEMENT_TYPE)
692 if (!check_no_attributes (parser, "type", attribute_names, attribute_values, error))
695 if (push_element (parser, ELEMENT_TYPE) == NULL)
703 else if (element_type == ELEMENT_FORK)
705 if (!check_no_attributes (parser, "fork", attribute_names, attribute_values, error))
708 if (push_element (parser, ELEMENT_FORK) == NULL)
718 else if (element_type == ELEMENT_SYSLOG)
720 if (!check_no_attributes (parser, "syslog", attribute_names, attribute_values, error))
723 if (push_element (parser, ELEMENT_SYSLOG) == NULL)
729 parser->syslog = TRUE;
733 else if (element_type == ELEMENT_KEEP_UMASK)
735 if (!check_no_attributes (parser, "keep_umask", attribute_names, attribute_values, error))
738 if (push_element (parser, ELEMENT_KEEP_UMASK) == NULL)
744 parser->keep_umask = TRUE;
748 else if (element_type == ELEMENT_PIDFILE)
750 if (!check_no_attributes (parser, "pidfile", attribute_names, attribute_values, error))
753 if (push_element (parser, ELEMENT_PIDFILE) == NULL)
761 else if (element_type == ELEMENT_LISTEN)
763 if (!check_no_attributes (parser, "listen", attribute_names, attribute_values, error))
766 if (push_element (parser, ELEMENT_LISTEN) == NULL)
774 else if (element_type == ELEMENT_AUTH)
776 if (!check_no_attributes (parser, "auth", attribute_names, attribute_values, error))
779 if (push_element (parser, ELEMENT_AUTH) == NULL)
787 else if (element_type == ELEMENT_SERVICEHELPER)
789 if (!check_no_attributes (parser, "servicehelper", attribute_names, attribute_values, error))
792 if (push_element (parser, ELEMENT_SERVICEHELPER) == NULL)
800 else if (element_type == ELEMENT_INCLUDEDIR)
802 if (!check_no_attributes (parser, "includedir", attribute_names, attribute_values, error))
805 if (push_element (parser, ELEMENT_INCLUDEDIR) == NULL)
813 else if (element_type == ELEMENT_STANDARD_SESSION_SERVICEDIRS)
819 if (!check_no_attributes (parser, "standard_session_servicedirs", attribute_names, attribute_values, error))
822 if (push_element (parser, ELEMENT_STANDARD_SESSION_SERVICEDIRS) == NULL)
828 if (!_dbus_get_standard_session_servicedirs (&dirs))
834 while ((link = _dbus_list_pop_first_link (&dirs)))
835 service_dirs_append_link_unique_or_free (&parser->service_dirs, link);
839 else if (element_type == ELEMENT_STANDARD_SYSTEM_SERVICEDIRS)
845 if (!check_no_attributes (parser, "standard_system_servicedirs", attribute_names, attribute_values, error))
848 if (push_element (parser, ELEMENT_STANDARD_SYSTEM_SERVICEDIRS) == NULL)
854 if (!_dbus_get_standard_system_servicedirs (&dirs))
860 while ((link = _dbus_list_pop_first_link (&dirs)))
861 service_dirs_append_link_unique_or_free (&parser->service_dirs, link);
865 else if (element_type == ELEMENT_ALLOW_ANONYMOUS)
867 if (!check_no_attributes (parser, "allow_anonymous", attribute_names, attribute_values, error))
870 if (push_element (parser, ELEMENT_ALLOW_ANONYMOUS) == NULL)
876 parser->allow_anonymous = TRUE;
879 else if (element_type == ELEMENT_SERVICEDIR)
881 if (!check_no_attributes (parser, "servicedir", attribute_names, attribute_values, error))
884 if (push_element (parser, ELEMENT_SERVICEDIR) == NULL)
892 else if (element_type == ELEMENT_INCLUDE)
895 const char *if_selinux_enabled;
896 const char *ignore_missing;
897 const char *selinux_root_relative;
899 if ((e = push_element (parser, ELEMENT_INCLUDE)) == NULL)
905 e->d.include.ignore_missing = FALSE;
906 e->d.include.if_selinux_enabled = FALSE;
907 e->d.include.selinux_root_relative = FALSE;
909 if (!locate_attributes (parser, "include",
913 "ignore_missing", &ignore_missing,
914 "if_selinux_enabled", &if_selinux_enabled,
915 "selinux_root_relative", &selinux_root_relative,
919 if (ignore_missing != NULL)
921 if (strcmp (ignore_missing, "yes") == 0)
922 e->d.include.ignore_missing = TRUE;
923 else if (strcmp (ignore_missing, "no") == 0)
924 e->d.include.ignore_missing = FALSE;
927 dbus_set_error (error, DBUS_ERROR_FAILED,
928 "ignore_missing attribute must have value \"yes\" or \"no\"");
933 if (if_selinux_enabled != NULL)
935 if (strcmp (if_selinux_enabled, "yes") == 0)
936 e->d.include.if_selinux_enabled = TRUE;
937 else if (strcmp (if_selinux_enabled, "no") == 0)
938 e->d.include.if_selinux_enabled = FALSE;
941 dbus_set_error (error, DBUS_ERROR_FAILED,
942 "if_selinux_enabled attribute must have value"
943 " \"yes\" or \"no\"");
948 if (selinux_root_relative != NULL)
950 if (strcmp (selinux_root_relative, "yes") == 0)
951 e->d.include.selinux_root_relative = TRUE;
952 else if (strcmp (selinux_root_relative, "no") == 0)
953 e->d.include.selinux_root_relative = FALSE;
956 dbus_set_error (error, DBUS_ERROR_FAILED,
957 "selinux_root_relative attribute must have value"
958 " \"yes\" or \"no\"");
965 else if (element_type == ELEMENT_POLICY)
971 const char *at_console;
973 if ((e = push_element (parser, ELEMENT_POLICY)) == NULL)
979 e->d.policy.type = POLICY_IGNORED;
981 if (!locate_attributes (parser, "policy",
988 "at_console", &at_console,
992 if (((context && user) ||
993 (context && group) ||
994 (context && at_console)) ||
996 (user && at_console)) ||
997 (group && at_console) ||
998 !(context || user || group || at_console))
1000 dbus_set_error (error, DBUS_ERROR_FAILED,
1001 "<policy> element must have exactly one of (context|user|group|at_console) attributes");
1005 if (context != NULL)
1007 if (strcmp (context, "default") == 0)
1009 e->d.policy.type = POLICY_DEFAULT;
1011 else if (strcmp (context, "mandatory") == 0)
1013 e->d.policy.type = POLICY_MANDATORY;
1017 dbus_set_error (error, DBUS_ERROR_FAILED,
1018 "context attribute on <policy> must have the value \"default\" or \"mandatory\", not \"%s\"",
1023 else if (user != NULL)
1025 DBusString username;
1026 _dbus_string_init_const (&username, user);
1028 if (_dbus_parse_unix_user_from_config (&username,
1029 &e->d.policy.gid_uid_or_at_console))
1030 e->d.policy.type = POLICY_USER;
1032 _dbus_warn ("Unknown username \"%s\" in message bus configuration file\n",
1035 else if (group != NULL)
1037 DBusString group_name;
1038 _dbus_string_init_const (&group_name, group);
1040 if (_dbus_parse_unix_group_from_config (&group_name,
1041 &e->d.policy.gid_uid_or_at_console))
1042 e->d.policy.type = POLICY_GROUP;
1044 _dbus_warn ("Unknown group \"%s\" in message bus configuration file\n",
1047 else if (at_console != NULL)
1050 t = (strcmp (at_console, "true") == 0);
1051 if (t || strcmp (at_console, "false") == 0)
1053 e->d.policy.gid_uid_or_at_console = t;
1054 e->d.policy.type = POLICY_CONSOLE;
1058 dbus_set_error (error, DBUS_ERROR_FAILED,
1059 "Unknown value \"%s\" for at_console in message bus configuration file",
1067 _dbus_assert_not_reached ("all <policy> attributes null and we didn't set error");
1072 else if (element_type == ELEMENT_LIMIT)
1077 if ((e = push_element (parser, ELEMENT_LIMIT)) == NULL)
1079 BUS_SET_OOM (error);
1083 if (!locate_attributes (parser, "limit",
1093 dbus_set_error (error, DBUS_ERROR_FAILED,
1094 "<limit> element must have a \"name\" attribute");
1098 e->d.limit.name = _dbus_strdup (name);
1099 if (e->d.limit.name == NULL)
1101 BUS_SET_OOM (error);
1107 else if (element_type == ELEMENT_SELINUX)
1109 if (!check_no_attributes (parser, "selinux", attribute_names, attribute_values, error))
1112 if (push_element (parser, ELEMENT_SELINUX) == NULL)
1114 BUS_SET_OOM (error);
1122 dbus_set_error (error, DBUS_ERROR_FAILED,
1123 "Element <%s> not allowed inside <%s> in configuration file",
1124 element_name, "busconfig");
1130 append_rule_from_element (BusConfigParser *parser,
1131 const char *element_name,
1132 const char **attribute_names,
1133 const char **attribute_values,
1138 const char *send_interface;
1139 const char *send_member;
1140 const char *send_error;
1141 const char *send_destination;
1142 const char *send_path;
1143 const char *send_type;
1144 const char *receive_interface;
1145 const char *receive_member;
1146 const char *receive_error;
1147 const char *receive_sender;
1148 const char *receive_path;
1149 const char *receive_type;
1150 const char *eavesdrop;
1151 const char *send_requested_reply;
1152 const char *receive_requested_reply;
1157 BusPolicyRule *rule;
1159 if (!locate_attributes (parser, element_name,
1163 "send_interface", &send_interface,
1164 "send_member", &send_member,
1165 "send_error", &send_error,
1166 "send_destination", &send_destination,
1167 "send_path", &send_path,
1168 "send_type", &send_type,
1169 "receive_interface", &receive_interface,
1170 "receive_member", &receive_member,
1171 "receive_error", &receive_error,
1172 "receive_sender", &receive_sender,
1173 "receive_path", &receive_path,
1174 "receive_type", &receive_type,
1175 "eavesdrop", &eavesdrop,
1176 "send_requested_reply", &send_requested_reply,
1177 "receive_requested_reply", &receive_requested_reply,
1185 if (!(send_interface || send_member || send_error || send_destination ||
1186 send_type || send_path ||
1187 receive_interface || receive_member || receive_error || receive_sender ||
1188 receive_type || receive_path || eavesdrop ||
1189 send_requested_reply || receive_requested_reply ||
1190 own || user || group))
1192 dbus_set_error (error, DBUS_ERROR_FAILED,
1193 "Element <%s> must have one or more attributes",
1198 if ((send_member && (send_interface == NULL && send_path == NULL)) ||
1199 (receive_member && (receive_interface == NULL && receive_path == NULL)))
1201 dbus_set_error (error, DBUS_ERROR_FAILED,
1202 "On element <%s>, if you specify a member you must specify an interface or a path. Keep in mind that not all messages have an interface field.",
1207 /* Allowed combinations of elements are:
1209 * base, must be all send or all receive:
1212 * interface + member
1215 * base send_ can combine with send_destination, send_path, send_type, send_requested_reply
1216 * base receive_ with receive_sender, receive_path, receive_type, receive_requested_reply, eavesdrop
1218 * user, group, own must occur alone
1220 * Pretty sure the below stuff is broken, FIXME think about it more.
1223 if (((send_interface && send_error) ||
1224 (send_interface && receive_interface) ||
1225 (send_interface && receive_member) ||
1226 (send_interface && receive_error) ||
1227 (send_interface && receive_sender) ||
1228 (send_interface && receive_requested_reply) ||
1229 (send_interface && own) ||
1230 (send_interface && user) ||
1231 (send_interface && group)) ||
1233 ((send_member && send_error) ||
1234 (send_member && receive_interface) ||
1235 (send_member && receive_member) ||
1236 (send_member && receive_error) ||
1237 (send_member && receive_sender) ||
1238 (send_member && receive_requested_reply) ||
1239 (send_member && own) ||
1240 (send_member && user) ||
1241 (send_member && group)) ||
1243 ((send_error && receive_interface) ||
1244 (send_error && receive_member) ||
1245 (send_error && receive_error) ||
1246 (send_error && receive_sender) ||
1247 (send_error && receive_requested_reply) ||
1248 (send_error && own) ||
1249 (send_error && user) ||
1250 (send_error && group)) ||
1252 ((send_destination && receive_interface) ||
1253 (send_destination && receive_member) ||
1254 (send_destination && receive_error) ||
1255 (send_destination && receive_sender) ||
1256 (send_destination && receive_requested_reply) ||
1257 (send_destination && own) ||
1258 (send_destination && user) ||
1259 (send_destination && group)) ||
1261 ((send_type && receive_interface) ||
1262 (send_type && receive_member) ||
1263 (send_type && receive_error) ||
1264 (send_type && receive_sender) ||
1265 (send_type && receive_requested_reply) ||
1266 (send_type && own) ||
1267 (send_type && user) ||
1268 (send_type && group)) ||
1270 ((send_path && receive_interface) ||
1271 (send_path && receive_member) ||
1272 (send_path && receive_error) ||
1273 (send_path && receive_sender) ||
1274 (send_path && receive_requested_reply) ||
1275 (send_path && own) ||
1276 (send_path && user) ||
1277 (send_path && group)) ||
1279 ((send_requested_reply && receive_interface) ||
1280 (send_requested_reply && receive_member) ||
1281 (send_requested_reply && receive_error) ||
1282 (send_requested_reply && receive_sender) ||
1283 (send_requested_reply && receive_requested_reply) ||
1284 (send_requested_reply && own) ||
1285 (send_requested_reply && user) ||
1286 (send_requested_reply && group)) ||
1288 ((receive_interface && receive_error) ||
1289 (receive_interface && own) ||
1290 (receive_interface && user) ||
1291 (receive_interface && group)) ||
1293 ((receive_member && receive_error) ||
1294 (receive_member && own) ||
1295 (receive_member && user) ||
1296 (receive_member && group)) ||
1298 ((receive_error && own) ||
1299 (receive_error && user) ||
1300 (receive_error && group)) ||
1302 ((eavesdrop && own) ||
1303 (eavesdrop && user) ||
1304 (eavesdrop && group)) ||
1306 ((receive_requested_reply && own) ||
1307 (receive_requested_reply && user) ||
1308 (receive_requested_reply && group)) ||
1315 dbus_set_error (error, DBUS_ERROR_FAILED,
1316 "Invalid combination of attributes on element <%s>",
1323 /* In BusPolicyRule, NULL represents wildcard.
1324 * In the config file, '*' represents it.
1326 #define IS_WILDCARD(str) ((str) && ((str)[0]) == '*' && ((str)[1]) == '\0')
1328 if (send_interface || send_member || send_error || send_destination ||
1329 send_path || send_type || send_requested_reply)
1333 if (IS_WILDCARD (send_interface))
1334 send_interface = NULL;
1335 if (IS_WILDCARD (send_member))
1337 if (IS_WILDCARD (send_error))
1339 if (IS_WILDCARD (send_destination))
1340 send_destination = NULL;
1341 if (IS_WILDCARD (send_path))
1343 if (IS_WILDCARD (send_type))
1346 message_type = DBUS_MESSAGE_TYPE_INVALID;
1347 if (send_type != NULL)
1349 message_type = dbus_message_type_from_string (send_type);
1350 if (message_type == DBUS_MESSAGE_TYPE_INVALID)
1352 dbus_set_error (error, DBUS_ERROR_FAILED,
1353 "Bad message type \"%s\"",
1360 !(strcmp (eavesdrop, "true") == 0 ||
1361 strcmp (eavesdrop, "false") == 0))
1363 dbus_set_error (error, DBUS_ERROR_FAILED,
1364 "Bad value \"%s\" for %s attribute, must be true or false",
1365 "eavesdrop", eavesdrop);
1369 if (send_requested_reply &&
1370 !(strcmp (send_requested_reply, "true") == 0 ||
1371 strcmp (send_requested_reply, "false") == 0))
1373 dbus_set_error (error, DBUS_ERROR_FAILED,
1374 "Bad value \"%s\" for %s attribute, must be true or false",
1375 "send_requested_reply", send_requested_reply);
1379 rule = bus_policy_rule_new (BUS_POLICY_RULE_SEND, allow);
1384 rule->d.send.eavesdrop = (strcmp (eavesdrop, "true") == 0);
1387 rule->d.send.log = (strcmp (log, "true") == 0);
1389 if (send_requested_reply)
1390 rule->d.send.requested_reply = (strcmp (send_requested_reply, "true") == 0);
1392 rule->d.send.message_type = message_type;
1393 rule->d.send.path = _dbus_strdup (send_path);
1394 rule->d.send.interface = _dbus_strdup (send_interface);
1395 rule->d.send.member = _dbus_strdup (send_member);
1396 rule->d.send.error = _dbus_strdup (send_error);
1397 rule->d.send.destination = _dbus_strdup (send_destination);
1398 if (send_path && rule->d.send.path == NULL)
1400 if (send_interface && rule->d.send.interface == NULL)
1402 if (send_member && rule->d.send.member == NULL)
1404 if (send_error && rule->d.send.error == NULL)
1406 if (send_destination && rule->d.send.destination == NULL)
1409 else if (receive_interface || receive_member || receive_error || receive_sender ||
1410 receive_path || receive_type || eavesdrop || receive_requested_reply)
1414 if (IS_WILDCARD (receive_interface))
1415 receive_interface = NULL;
1416 if (IS_WILDCARD (receive_member))
1417 receive_member = NULL;
1418 if (IS_WILDCARD (receive_error))
1419 receive_error = NULL;
1420 if (IS_WILDCARD (receive_sender))
1421 receive_sender = NULL;
1422 if (IS_WILDCARD (receive_path))
1423 receive_path = NULL;
1424 if (IS_WILDCARD (receive_type))
1425 receive_type = NULL;
1427 message_type = DBUS_MESSAGE_TYPE_INVALID;
1428 if (receive_type != NULL)
1430 message_type = dbus_message_type_from_string (receive_type);
1431 if (message_type == DBUS_MESSAGE_TYPE_INVALID)
1433 dbus_set_error (error, DBUS_ERROR_FAILED,
1434 "Bad message type \"%s\"",
1442 !(strcmp (eavesdrop, "true") == 0 ||
1443 strcmp (eavesdrop, "false") == 0))
1445 dbus_set_error (error, DBUS_ERROR_FAILED,
1446 "Bad value \"%s\" for %s attribute, must be true or false",
1447 "eavesdrop", eavesdrop);
1451 if (receive_requested_reply &&
1452 !(strcmp (receive_requested_reply, "true") == 0 ||
1453 strcmp (receive_requested_reply, "false") == 0))
1455 dbus_set_error (error, DBUS_ERROR_FAILED,
1456 "Bad value \"%s\" for %s attribute, must be true or false",
1457 "receive_requested_reply", receive_requested_reply);
1461 rule = bus_policy_rule_new (BUS_POLICY_RULE_RECEIVE, allow);
1466 rule->d.receive.eavesdrop = (strcmp (eavesdrop, "true") == 0);
1468 if (receive_requested_reply)
1469 rule->d.receive.requested_reply = (strcmp (receive_requested_reply, "true") == 0);
1471 rule->d.receive.message_type = message_type;
1472 rule->d.receive.path = _dbus_strdup (receive_path);
1473 rule->d.receive.interface = _dbus_strdup (receive_interface);
1474 rule->d.receive.member = _dbus_strdup (receive_member);
1475 rule->d.receive.error = _dbus_strdup (receive_error);
1476 rule->d.receive.origin = _dbus_strdup (receive_sender);
1478 if (receive_path && rule->d.receive.path == NULL)
1480 if (receive_interface && rule->d.receive.interface == NULL)
1482 if (receive_member && rule->d.receive.member == NULL)
1484 if (receive_error && rule->d.receive.error == NULL)
1486 if (receive_sender && rule->d.receive.origin == NULL)
1491 rule = bus_policy_rule_new (BUS_POLICY_RULE_OWN, allow);
1495 if (IS_WILDCARD (own))
1498 rule->d.own.service_name = _dbus_strdup (own);
1499 if (own && rule->d.own.service_name == NULL)
1504 if (IS_WILDCARD (user))
1506 rule = bus_policy_rule_new (BUS_POLICY_RULE_USER, allow);
1510 rule->d.user.uid = DBUS_UID_UNSET;
1514 DBusString username;
1517 _dbus_string_init_const (&username, user);
1519 if (_dbus_parse_unix_user_from_config (&username, &uid))
1521 rule = bus_policy_rule_new (BUS_POLICY_RULE_USER, allow);
1525 rule->d.user.uid = uid;
1529 _dbus_warn ("Unknown username \"%s\" on element <%s>\n",
1530 user, element_name);
1536 if (IS_WILDCARD (group))
1538 rule = bus_policy_rule_new (BUS_POLICY_RULE_GROUP, allow);
1542 rule->d.group.gid = DBUS_GID_UNSET;
1546 DBusString groupname;
1549 _dbus_string_init_const (&groupname, group);
1551 if (_dbus_parse_unix_group_from_config (&groupname, &gid))
1553 rule = bus_policy_rule_new (BUS_POLICY_RULE_GROUP, allow);
1557 rule->d.group.gid = gid;
1561 _dbus_warn ("Unknown group \"%s\" on element <%s>\n",
1562 group, element_name);
1567 _dbus_assert_not_reached ("Did not handle some combination of attributes on <allow> or <deny>");
1573 pe = peek_element (parser);
1574 _dbus_assert (pe != NULL);
1575 _dbus_assert (pe->type == ELEMENT_POLICY);
1577 switch (pe->d.policy.type)
1579 case POLICY_IGNORED:
1580 /* drop the rule on the floor */
1583 case POLICY_DEFAULT:
1584 if (!bus_policy_append_default_rule (parser->policy, rule))
1587 case POLICY_MANDATORY:
1588 if (!bus_policy_append_mandatory_rule (parser->policy, rule))
1592 if (!BUS_POLICY_RULE_IS_PER_CLIENT (rule))
1594 dbus_set_error (error, DBUS_ERROR_FAILED,
1595 "<%s> rule cannot be per-user because it has bus-global semantics",
1600 if (!bus_policy_append_user_rule (parser->policy, pe->d.policy.gid_uid_or_at_console,
1605 if (!BUS_POLICY_RULE_IS_PER_CLIENT (rule))
1607 dbus_set_error (error, DBUS_ERROR_FAILED,
1608 "<%s> rule cannot be per-group because it has bus-global semantics",
1613 if (!bus_policy_append_group_rule (parser->policy, pe->d.policy.gid_uid_or_at_console,
1619 case POLICY_CONSOLE:
1620 if (!bus_policy_append_console_rule (parser->policy, pe->d.policy.gid_uid_or_at_console,
1626 bus_policy_rule_unref (rule);
1633 BUS_SET_OOM (error);
1636 bus_policy_rule_unref (rule);
1641 start_policy_child (BusConfigParser *parser,
1642 const char *element_name,
1643 const char **attribute_names,
1644 const char **attribute_values,
1647 if (strcmp (element_name, "allow") == 0)
1649 if (!append_rule_from_element (parser, element_name,
1650 attribute_names, attribute_values,
1654 if (push_element (parser, ELEMENT_ALLOW) == NULL)
1656 BUS_SET_OOM (error);
1662 else if (strcmp (element_name, "deny") == 0)
1664 if (!append_rule_from_element (parser, element_name,
1665 attribute_names, attribute_values,
1669 if (push_element (parser, ELEMENT_DENY) == NULL)
1671 BUS_SET_OOM (error);
1679 dbus_set_error (error, DBUS_ERROR_FAILED,
1680 "Element <%s> not allowed inside <%s> in configuration file",
1681 element_name, "policy");
1687 start_selinux_child (BusConfigParser *parser,
1688 const char *element_name,
1689 const char **attribute_names,
1690 const char **attribute_values,
1697 context_copy = NULL;
1699 if (strcmp (element_name, "associate") == 0)
1702 const char *context;
1704 if (!locate_attributes (parser, "associate",
1709 "context", &context,
1713 if (push_element (parser, ELEMENT_ASSOCIATE) == NULL)
1715 BUS_SET_OOM (error);
1719 if (own == NULL || context == NULL)
1721 dbus_set_error (error, DBUS_ERROR_FAILED,
1722 "Element <associate> must have attributes own=\"<servicename>\" and context=\"<selinux context>\"");
1726 own_copy = _dbus_strdup (own);
1727 if (own_copy == NULL)
1729 context_copy = _dbus_strdup (context);
1730 if (context_copy == NULL)
1733 if (!_dbus_hash_table_insert_string (parser->service_context_table,
1734 own_copy, context_copy))
1741 dbus_set_error (error, DBUS_ERROR_FAILED,
1742 "Element <%s> not allowed inside <%s> in configuration file",
1743 element_name, "selinux");
1749 dbus_free (own_copy);
1752 dbus_free (context_copy);
1754 BUS_SET_OOM (error);
1759 bus_config_parser_start_element (BusConfigParser *parser,
1760 const char *element_name,
1761 const char **attribute_names,
1762 const char **attribute_values,
1767 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1769 /* printf ("START: %s\n", element_name); */
1771 t = top_element_type (parser);
1773 if (t == ELEMENT_NONE)
1775 if (strcmp (element_name, "busconfig") == 0)
1777 if (!check_no_attributes (parser, "busconfig", attribute_names, attribute_values, error))
1780 if (push_element (parser, ELEMENT_BUSCONFIG) == NULL)
1782 BUS_SET_OOM (error);
1790 dbus_set_error (error, DBUS_ERROR_FAILED,
1791 "Unknown element <%s> at root of configuration file",
1796 else if (t == ELEMENT_BUSCONFIG)
1798 return start_busconfig_child (parser, element_name,
1799 attribute_names, attribute_values,
1802 else if (t == ELEMENT_POLICY)
1804 return start_policy_child (parser, element_name,
1805 attribute_names, attribute_values,
1808 else if (t == ELEMENT_SELINUX)
1810 return start_selinux_child (parser, element_name,
1811 attribute_names, attribute_values,
1816 dbus_set_error (error, DBUS_ERROR_FAILED,
1817 "Element <%s> is not allowed in this context",
1824 set_limit (BusConfigParser *parser,
1829 dbus_bool_t must_be_positive;
1830 dbus_bool_t must_be_int;
1832 must_be_int = FALSE;
1833 must_be_positive = FALSE;
1835 if (strcmp (name, "max_incoming_bytes") == 0)
1837 must_be_positive = TRUE;
1838 parser->limits.max_incoming_bytes = value;
1840 else if (strcmp (name, "max_incoming_unix_fds") == 0)
1842 must_be_positive = TRUE;
1843 parser->limits.max_incoming_unix_fds = value;
1845 else if (strcmp (name, "max_outgoing_bytes") == 0)
1847 must_be_positive = TRUE;
1848 parser->limits.max_outgoing_bytes = value;
1850 else if (strcmp (name, "max_outgoing_unix_fds") == 0)
1852 must_be_positive = TRUE;
1853 parser->limits.max_outgoing_unix_fds = value;
1855 else if (strcmp (name, "max_message_size") == 0)
1857 must_be_positive = TRUE;
1858 parser->limits.max_message_size = value;
1860 else if (strcmp (name, "max_message_unix_fds") == 0)
1862 must_be_positive = TRUE;
1863 parser->limits.max_message_unix_fds = value;
1865 else if (strcmp (name, "service_start_timeout") == 0)
1867 must_be_positive = TRUE;
1869 parser->limits.activation_timeout = value;
1871 else if (strcmp (name, "auth_timeout") == 0)
1873 must_be_positive = TRUE;
1875 parser->limits.auth_timeout = value;
1877 else if (strcmp (name, "reply_timeout") == 0)
1879 must_be_positive = TRUE;
1881 parser->limits.reply_timeout = value;
1883 else if (strcmp (name, "max_completed_connections") == 0)
1885 must_be_positive = TRUE;
1887 parser->limits.max_completed_connections = value;
1889 else if (strcmp (name, "max_incomplete_connections") == 0)
1891 must_be_positive = TRUE;
1893 parser->limits.max_incomplete_connections = value;
1895 else if (strcmp (name, "max_connections_per_user") == 0)
1897 must_be_positive = TRUE;
1899 parser->limits.max_connections_per_user = value;
1901 else if (strcmp (name, "max_pending_service_starts") == 0)
1903 must_be_positive = TRUE;
1905 parser->limits.max_pending_activations = value;
1907 else if (strcmp (name, "max_names_per_connection") == 0)
1909 must_be_positive = TRUE;
1911 parser->limits.max_services_per_connection = value;
1913 else if (strcmp (name, "max_match_rules_per_connection") == 0)
1915 must_be_positive = TRUE;
1917 parser->limits.max_match_rules_per_connection = value;
1919 else if (strcmp (name, "max_replies_per_connection") == 0)
1921 must_be_positive = TRUE;
1923 parser->limits.max_replies_per_connection = value;
1927 dbus_set_error (error, DBUS_ERROR_FAILED,
1928 "There is no limit called \"%s\"\n",
1933 if (must_be_positive && value < 0)
1935 dbus_set_error (error, DBUS_ERROR_FAILED,
1936 "<limit name=\"%s\"> must be a positive number\n",
1942 (value < _DBUS_INT_MIN || value > _DBUS_INT_MAX))
1944 dbus_set_error (error, DBUS_ERROR_FAILED,
1945 "<limit name=\"%s\"> value is too large\n",
1954 bus_config_parser_end_element (BusConfigParser *parser,
1955 const char *element_name,
1962 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1964 /* printf ("END: %s\n", element_name); */
1966 t = top_element_type (parser);
1968 if (t == ELEMENT_NONE)
1970 /* should probably be an assertion failure but
1971 * being paranoid about XML parsers
1973 dbus_set_error (error, DBUS_ERROR_FAILED,
1974 "XML parser ended element with no element on the stack");
1978 n = bus_config_parser_element_type_to_name (t);
1979 _dbus_assert (n != NULL);
1980 if (strcmp (n, element_name) != 0)
1982 /* should probably be an assertion failure but
1983 * being paranoid about XML parsers
1985 dbus_set_error (error, DBUS_ERROR_FAILED,
1986 "XML element <%s> ended but topmost element on the stack was <%s>",
1991 e = peek_element (parser);
1992 _dbus_assert (e != NULL);
1997 _dbus_assert_not_reached ("element in stack has no type");
2000 case ELEMENT_INCLUDE:
2003 case ELEMENT_LISTEN:
2004 case ELEMENT_PIDFILE:
2006 case ELEMENT_SERVICEDIR:
2007 case ELEMENT_SERVICEHELPER:
2008 case ELEMENT_INCLUDEDIR:
2010 if (!e->had_content)
2012 dbus_set_error (error, DBUS_ERROR_FAILED,
2013 "XML element <%s> was expected to have content inside it",
2014 bus_config_parser_element_type_to_name (e->type));
2018 if (e->type == ELEMENT_LIMIT)
2020 if (!set_limit (parser, e->d.limit.name, e->d.limit.value,
2026 case ELEMENT_BUSCONFIG:
2027 case ELEMENT_POLICY:
2031 case ELEMENT_SYSLOG:
2032 case ELEMENT_KEEP_UMASK:
2033 case ELEMENT_SELINUX:
2034 case ELEMENT_ASSOCIATE:
2035 case ELEMENT_STANDARD_SESSION_SERVICEDIRS:
2036 case ELEMENT_STANDARD_SYSTEM_SERVICEDIRS:
2037 case ELEMENT_ALLOW_ANONYMOUS:
2041 pop_element (parser);
2047 all_whitespace (const DBusString *str)
2051 _dbus_string_skip_white (str, 0, &i);
2053 return i == _dbus_string_get_length (str);
2057 make_full_path (const DBusString *basedir,
2058 const DBusString *filename,
2059 DBusString *full_path)
2061 if (_dbus_path_is_absolute (filename))
2063 return _dbus_string_copy (filename, 0, full_path, 0);
2067 if (!_dbus_string_copy (basedir, 0, full_path, 0))
2070 if (!_dbus_concat_dir_and_file (full_path, filename))
2078 include_file (BusConfigParser *parser,
2079 const DBusString *filename,
2080 dbus_bool_t ignore_missing,
2083 /* FIXME good test case for this would load each config file in the
2084 * test suite both alone, and as an include, and check
2085 * that the result is the same
2087 BusConfigParser *included;
2088 const char *filename_str;
2089 DBusError tmp_error;
2091 dbus_error_init (&tmp_error);
2093 filename_str = _dbus_string_get_const_data (filename);
2095 /* Check to make sure this file hasn't already been included. */
2096 if (seen_include (parser, filename))
2098 dbus_set_error (error, DBUS_ERROR_FAILED,
2099 "Circular inclusion of file '%s'",
2104 if (! _dbus_list_append (&parser->included_files, (void *) filename_str))
2106 BUS_SET_OOM (error);
2110 /* Since parser is passed in as the parent, included
2111 inherits parser's limits. */
2112 included = bus_config_load (filename, FALSE, parser, &tmp_error);
2114 _dbus_list_pop_last (&parser->included_files);
2116 if (included == NULL)
2118 _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
2120 if (dbus_error_has_name (&tmp_error, DBUS_ERROR_FILE_NOT_FOUND) &&
2123 dbus_error_free (&tmp_error);
2128 dbus_move_error (&tmp_error, error);
2134 _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
2136 if (!merge_included (parser, included, error))
2138 bus_config_parser_unref (included);
2142 /* Copy included's limits back to parser. */
2143 parser->limits = included->limits;
2145 bus_config_parser_unref (included);
2151 servicehelper_path (BusConfigParser *parser,
2152 const DBusString *filename,
2155 const char *filename_str;
2156 char *servicehelper;
2158 filename_str = _dbus_string_get_const_data (filename);
2160 /* copy to avoid overwriting with NULL on OOM */
2161 servicehelper = _dbus_strdup (filename_str);
2164 if (servicehelper == NULL)
2166 BUS_SET_OOM (error);
2170 /* save the latest servicehelper only if not OOM */
2171 dbus_free (parser->servicehelper);
2172 parser->servicehelper = servicehelper;
2174 /* We don't check whether the helper exists; instead we
2175 * would just fail to ever activate anything if it doesn't.
2176 * This allows an admin to fix the problem if it doesn't exist.
2177 * It also allows the parser test suite to successfully parse
2178 * test cases without installing the helper. ;-)
2185 include_dir (BusConfigParser *parser,
2186 const DBusString *dirname,
2189 DBusString filename;
2191 DBusError tmp_error;
2195 if (!_dbus_string_init (&filename))
2197 BUS_SET_OOM (error);
2203 dir = _dbus_directory_open (dirname, error);
2208 dbus_error_init (&tmp_error);
2209 while (_dbus_directory_get_next_file (dir, &filename, &tmp_error))
2211 DBusString full_path;
2213 if (!_dbus_string_init (&full_path))
2215 BUS_SET_OOM (error);
2219 if (!_dbus_string_copy (dirname, 0, &full_path, 0))
2221 BUS_SET_OOM (error);
2222 _dbus_string_free (&full_path);
2226 if (!_dbus_concat_dir_and_file (&full_path, &filename))
2228 BUS_SET_OOM (error);
2229 _dbus_string_free (&full_path);
2233 if (_dbus_string_ends_with_c_str (&full_path, ".conf"))
2235 if (!include_file (parser, &full_path, TRUE, error))
2237 _dbus_string_free (&full_path);
2242 _dbus_string_free (&full_path);
2245 if (dbus_error_is_set (&tmp_error))
2247 dbus_move_error (&tmp_error, error);
2252 if (!_dbus_string_copy_data (dirname, &s))
2254 BUS_SET_OOM (error);
2258 if (!_dbus_list_append (&parser->conf_dirs, s))
2261 BUS_SET_OOM (error);
2268 _dbus_string_free (&filename);
2271 _dbus_directory_close (dir);
2277 bus_config_parser_content (BusConfigParser *parser,
2278 const DBusString *content,
2283 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
2289 _dbus_string_get_const_data (content, &c_str);
2291 printf ("CONTENT %d bytes: %s\n", _dbus_string_get_length (content), c_str);
2295 e = peek_element (parser);
2298 dbus_set_error (error, DBUS_ERROR_FAILED,
2299 "Text content outside of any XML element in configuration file");
2302 else if (e->had_content)
2304 _dbus_assert_not_reached ("Element had multiple content blocks");
2308 switch (top_element_type (parser))
2311 _dbus_assert_not_reached ("element at top of stack has no type");
2314 case ELEMENT_BUSCONFIG:
2315 case ELEMENT_POLICY:
2319 case ELEMENT_SYSLOG:
2320 case ELEMENT_KEEP_UMASK:
2321 case ELEMENT_STANDARD_SESSION_SERVICEDIRS:
2322 case ELEMENT_STANDARD_SYSTEM_SERVICEDIRS:
2323 case ELEMENT_ALLOW_ANONYMOUS:
2324 case ELEMENT_SELINUX:
2325 case ELEMENT_ASSOCIATE:
2326 if (all_whitespace (content))
2330 dbus_set_error (error, DBUS_ERROR_FAILED,
2331 "No text content expected inside XML element %s in configuration file",
2332 bus_config_parser_element_type_to_name (top_element_type (parser)));
2336 case ELEMENT_PIDFILE:
2340 e->had_content = TRUE;
2342 if (!_dbus_string_copy_data (content, &s))
2345 dbus_free (parser->pidfile);
2346 parser->pidfile = s;
2350 case ELEMENT_INCLUDE:
2352 DBusString full_path, selinux_policy_root;
2354 e->had_content = TRUE;
2356 if (e->d.include.if_selinux_enabled
2357 && !bus_selinux_enabled ())
2360 if (!_dbus_string_init (&full_path))
2363 if (e->d.include.selinux_root_relative)
2365 if (!bus_selinux_get_policy_root ())
2367 dbus_set_error (error, DBUS_ERROR_FAILED,
2368 "Could not determine SELinux policy root for relative inclusion");
2369 _dbus_string_free (&full_path);
2372 _dbus_string_init_const (&selinux_policy_root,
2373 bus_selinux_get_policy_root ());
2374 if (!make_full_path (&selinux_policy_root, content, &full_path))
2376 _dbus_string_free (&full_path);
2380 else if (!make_full_path (&parser->basedir, content, &full_path))
2382 _dbus_string_free (&full_path);
2386 if (!include_file (parser, &full_path,
2387 e->d.include.ignore_missing, error))
2389 _dbus_string_free (&full_path);
2393 _dbus_string_free (&full_path);
2397 case ELEMENT_SERVICEHELPER:
2399 DBusString full_path;
2401 e->had_content = TRUE;
2403 if (!_dbus_string_init (&full_path))
2406 if (!make_full_path (&parser->basedir, content, &full_path))
2408 _dbus_string_free (&full_path);
2412 if (!servicehelper_path (parser, &full_path, error))
2414 _dbus_string_free (&full_path);
2418 _dbus_string_free (&full_path);
2422 case ELEMENT_INCLUDEDIR:
2424 DBusString full_path;
2426 e->had_content = TRUE;
2428 if (!_dbus_string_init (&full_path))
2431 if (!make_full_path (&parser->basedir, content, &full_path))
2433 _dbus_string_free (&full_path);
2437 if (!include_dir (parser, &full_path, error))
2439 _dbus_string_free (&full_path);
2443 _dbus_string_free (&full_path);
2451 e->had_content = TRUE;
2453 if (!_dbus_string_copy_data (content, &s))
2456 dbus_free (parser->user);
2465 e->had_content = TRUE;
2467 if (!_dbus_string_copy_data (content, &s))
2470 dbus_free (parser->bus_type);
2471 parser->bus_type = s;
2475 case ELEMENT_LISTEN:
2479 e->had_content = TRUE;
2481 if (!_dbus_string_copy_data (content, &s))
2484 if (!_dbus_list_append (&parser->listen_on,
2497 e->had_content = TRUE;
2499 if (!_dbus_string_copy_data (content, &s))
2502 if (!_dbus_list_append (&parser->mechanisms,
2511 case ELEMENT_SERVICEDIR:
2514 DBusString full_path;
2516 e->had_content = TRUE;
2518 if (!_dbus_string_init (&full_path))
2521 if (!make_full_path (&parser->basedir, content, &full_path))
2523 _dbus_string_free (&full_path);
2527 if (!_dbus_string_copy_data (&full_path, &s))
2529 _dbus_string_free (&full_path);
2533 /* _only_ extra session directories can be specified */
2534 if (!service_dirs_append_unique_or_free (&parser->service_dirs, s))
2536 _dbus_string_free (&full_path);
2541 _dbus_string_free (&full_path);
2549 e->had_content = TRUE;
2552 if (!_dbus_string_parse_int (content, 0, &val, NULL))
2554 dbus_set_error (error, DBUS_ERROR_FAILED,
2555 "<limit name=\"%s\"> element has invalid value (could not parse as integer)",
2560 e->d.limit.value = val;
2562 _dbus_verbose ("Loaded value %ld for limit %s\n",
2569 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
2573 BUS_SET_OOM (error);
2578 bus_config_parser_finished (BusConfigParser *parser,
2581 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
2583 if (parser->stack != NULL)
2585 dbus_set_error (error, DBUS_ERROR_FAILED,
2586 "Element <%s> was not closed in configuration file",
2587 bus_config_parser_element_type_to_name (top_element_type (parser)));
2592 if (parser->is_toplevel && parser->listen_on == NULL)
2594 dbus_set_error (error, DBUS_ERROR_FAILED,
2595 "Configuration file needs one or more <listen> elements giving addresses");
2603 bus_config_parser_get_user (BusConfigParser *parser)
2605 return parser->user;
2609 bus_config_parser_get_type (BusConfigParser *parser)
2611 return parser->bus_type;
2615 bus_config_parser_get_addresses (BusConfigParser *parser)
2617 return &parser->listen_on;
2621 bus_config_parser_get_mechanisms (BusConfigParser *parser)
2623 return &parser->mechanisms;
2627 bus_config_parser_get_service_dirs (BusConfigParser *parser)
2629 return &parser->service_dirs;
2633 bus_config_parser_get_conf_dirs (BusConfigParser *parser)
2635 return &parser->conf_dirs;
2639 bus_config_parser_get_fork (BusConfigParser *parser)
2641 return parser->fork;
2645 bus_config_parser_get_syslog (BusConfigParser *parser)
2647 return parser->syslog;
2651 bus_config_parser_get_keep_umask (BusConfigParser *parser)
2653 return parser->keep_umask;
2657 bus_config_parser_get_allow_anonymous (BusConfigParser *parser)
2659 return parser->allow_anonymous;
2663 bus_config_parser_get_pidfile (BusConfigParser *parser)
2665 return parser->pidfile;
2669 bus_config_parser_get_servicehelper (BusConfigParser *parser)
2671 return parser->servicehelper;
2675 bus_config_parser_steal_policy (BusConfigParser *parser)
2679 _dbus_assert (parser->policy != NULL); /* can only steal the policy 1 time */
2681 policy = parser->policy;
2683 parser->policy = NULL;
2688 /* Overwrite any limits that were set in the configuration file */
2690 bus_config_parser_get_limits (BusConfigParser *parser,
2693 *limits = parser->limits;
2697 bus_config_parser_steal_service_context_table (BusConfigParser *parser)
2699 DBusHashTable *table;
2701 _dbus_assert (parser->service_context_table != NULL); /* can only steal once */
2703 table = parser->service_context_table;
2705 parser->service_context_table = NULL;
2710 #ifdef DBUS_BUILD_TESTS
2721 do_load (const DBusString *full_path,
2723 dbus_bool_t oom_possible)
2725 BusConfigParser *parser;
2728 dbus_error_init (&error);
2730 parser = bus_config_load (full_path, TRUE, NULL, &error);
2733 _DBUS_ASSERT_ERROR_IS_SET (&error);
2736 dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
2738 _dbus_verbose ("Failed to load valid file due to OOM\n");
2739 dbus_error_free (&error);
2742 else if (validity == VALID)
2744 _dbus_warn ("Failed to load valid file but still had memory: %s\n",
2747 dbus_error_free (&error);
2752 dbus_error_free (&error);
2758 _DBUS_ASSERT_ERROR_IS_CLEAR (&error);
2760 bus_config_parser_unref (parser);
2762 if (validity == INVALID)
2764 _dbus_warn ("Accepted invalid file\n");
2774 const DBusString *full_path;
2779 check_loader_oom_func (void *data)
2781 LoaderOomData *d = data;
2783 return do_load (d->full_path, d->validity, TRUE);
2787 process_test_valid_subdir (const DBusString *test_base_dir,
2791 DBusString test_directory;
2792 DBusString filename;
2800 if (!_dbus_string_init (&test_directory))
2801 _dbus_assert_not_reached ("didn't allocate test_directory\n");
2803 _dbus_string_init_const (&filename, subdir);
2805 if (!_dbus_string_copy (test_base_dir, 0,
2806 &test_directory, 0))
2807 _dbus_assert_not_reached ("couldn't copy test_base_dir to test_directory");
2809 if (!_dbus_concat_dir_and_file (&test_directory, &filename))
2810 _dbus_assert_not_reached ("couldn't allocate full path");
2812 _dbus_string_free (&filename);
2813 if (!_dbus_string_init (&filename))
2814 _dbus_assert_not_reached ("didn't allocate filename string\n");
2816 dbus_error_init (&error);
2817 dir = _dbus_directory_open (&test_directory, &error);
2820 _dbus_warn ("Could not open %s: %s\n",
2821 _dbus_string_get_const_data (&test_directory),
2823 dbus_error_free (&error);
2827 if (validity == VALID)
2828 printf ("Testing valid files:\n");
2829 else if (validity == INVALID)
2830 printf ("Testing invalid files:\n");
2832 printf ("Testing unknown files:\n");
2835 while (_dbus_directory_get_next_file (dir, &filename, &error))
2837 DBusString full_path;
2840 if (!_dbus_string_init (&full_path))
2841 _dbus_assert_not_reached ("couldn't init string");
2843 if (!_dbus_string_copy (&test_directory, 0, &full_path, 0))
2844 _dbus_assert_not_reached ("couldn't copy dir to full_path");
2846 if (!_dbus_concat_dir_and_file (&full_path, &filename))
2847 _dbus_assert_not_reached ("couldn't concat file to dir");
2849 if (!_dbus_string_ends_with_c_str (&full_path, ".conf"))
2851 _dbus_verbose ("Skipping non-.conf file %s\n",
2852 _dbus_string_get_const_data (&filename));
2853 _dbus_string_free (&full_path);
2857 printf (" %s\n", _dbus_string_get_const_data (&filename));
2859 _dbus_verbose (" expecting %s\n",
2860 validity == VALID ? "valid" :
2861 (validity == INVALID ? "invalid" :
2862 (validity == UNKNOWN ? "unknown" : "???")));
2864 d.full_path = &full_path;
2865 d.validity = validity;
2867 /* FIXME hackaround for an expat problem, see
2868 * https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=124747
2869 * http://freedesktop.org/pipermail/dbus/2004-May/001153.html
2871 /* if (!_dbus_test_oom_handling ("config-loader", check_loader_oom_func, &d)) */
2872 if (!check_loader_oom_func (&d))
2873 _dbus_assert_not_reached ("test failed");
2875 _dbus_string_free (&full_path);
2878 if (dbus_error_is_set (&error))
2880 _dbus_warn ("Could not get next file in %s: %s\n",
2881 _dbus_string_get_const_data (&test_directory),
2883 dbus_error_free (&error);
2892 _dbus_directory_close (dir);
2893 _dbus_string_free (&test_directory);
2894 _dbus_string_free (&filename);
2900 bools_equal (dbus_bool_t a,
2907 strings_equal_or_both_null (const char *a,
2910 if (a == NULL || b == NULL)
2913 return !strcmp (a, b);
2917 elements_equal (const Element *a,
2920 if (a->type != b->type)
2923 if (!bools_equal (a->had_content, b->had_content))
2929 case ELEMENT_INCLUDE:
2930 if (!bools_equal (a->d.include.ignore_missing,
2931 b->d.include.ignore_missing))
2935 case ELEMENT_POLICY:
2936 if (a->d.policy.type != b->d.policy.type)
2938 if (a->d.policy.gid_uid_or_at_console != b->d.policy.gid_uid_or_at_console)
2943 if (strcmp (a->d.limit.name, b->d.limit.name))
2945 if (a->d.limit.value != b->d.limit.value)
2959 lists_of_elements_equal (DBusList *a,
2968 while (ia != NULL && ib != NULL)
2970 if (elements_equal (ia->data, ib->data))
2972 ia = _dbus_list_get_next_link (&a, ia);
2973 ib = _dbus_list_get_next_link (&b, ib);
2976 return ia == NULL && ib == NULL;
2980 lists_of_c_strings_equal (DBusList *a,
2989 while (ia != NULL && ib != NULL)
2991 if (strcmp (ia->data, ib->data))
2993 ia = _dbus_list_get_next_link (&a, ia);
2994 ib = _dbus_list_get_next_link (&b, ib);
2997 return ia == NULL && ib == NULL;
3001 limits_equal (const BusLimits *a,
3005 (a->max_incoming_bytes == b->max_incoming_bytes
3006 || a->max_incoming_unix_fds == b->max_incoming_unix_fds
3007 || a->max_outgoing_bytes == b->max_outgoing_bytes
3008 || a->max_outgoing_unix_fds == b->max_outgoing_unix_fds
3009 || a->max_message_size == b->max_message_size
3010 || a->max_message_unix_fds == b->max_message_unix_fds
3011 || a->activation_timeout == b->activation_timeout
3012 || a->auth_timeout == b->auth_timeout
3013 || a->max_completed_connections == b->max_completed_connections
3014 || a->max_incomplete_connections == b->max_incomplete_connections
3015 || a->max_connections_per_user == b->max_connections_per_user
3016 || a->max_pending_activations == b->max_pending_activations
3017 || a->max_services_per_connection == b->max_services_per_connection
3018 || a->max_match_rules_per_connection == b->max_match_rules_per_connection
3019 || a->max_replies_per_connection == b->max_replies_per_connection
3020 || a->reply_timeout == b->reply_timeout);
3024 config_parsers_equal (const BusConfigParser *a,
3025 const BusConfigParser *b)
3027 if (!_dbus_string_equal (&a->basedir, &b->basedir))
3030 if (!lists_of_elements_equal (a->stack, b->stack))
3033 if (!strings_equal_or_both_null (a->user, b->user))
3036 if (!lists_of_c_strings_equal (a->listen_on, b->listen_on))
3039 if (!lists_of_c_strings_equal (a->mechanisms, b->mechanisms))
3042 if (!lists_of_c_strings_equal (a->service_dirs, b->service_dirs))
3045 /* FIXME: compare policy */
3047 /* FIXME: compare service selinux ID table */
3049 if (! limits_equal (&a->limits, &b->limits))
3052 if (!strings_equal_or_both_null (a->pidfile, b->pidfile))
3055 if (! bools_equal (a->fork, b->fork))
3058 if (! bools_equal (a->keep_umask, b->keep_umask))
3061 if (! bools_equal (a->is_toplevel, b->is_toplevel))
3068 all_are_equiv (const DBusString *target_directory)
3070 DBusString filename;
3072 BusConfigParser *first_parser;
3073 BusConfigParser *parser;
3079 first_parser = NULL;
3083 if (!_dbus_string_init (&filename))
3084 _dbus_assert_not_reached ("didn't allocate filename string");
3086 dbus_error_init (&error);
3087 dir = _dbus_directory_open (target_directory, &error);
3090 _dbus_warn ("Could not open %s: %s\n",
3091 _dbus_string_get_const_data (target_directory),
3093 dbus_error_free (&error);
3097 printf ("Comparing equivalent files:\n");
3100 while (_dbus_directory_get_next_file (dir, &filename, &error))
3102 DBusString full_path;
3104 if (!_dbus_string_init (&full_path))
3105 _dbus_assert_not_reached ("couldn't init string");
3107 if (!_dbus_string_copy (target_directory, 0, &full_path, 0))
3108 _dbus_assert_not_reached ("couldn't copy dir to full_path");
3110 if (!_dbus_concat_dir_and_file (&full_path, &filename))
3111 _dbus_assert_not_reached ("couldn't concat file to dir");
3113 if (!_dbus_string_ends_with_c_str (&full_path, ".conf"))
3115 _dbus_verbose ("Skipping non-.conf file %s\n",
3116 _dbus_string_get_const_data (&filename));
3117 _dbus_string_free (&full_path);
3121 printf (" %s\n", _dbus_string_get_const_data (&filename));
3123 parser = bus_config_load (&full_path, TRUE, NULL, &error);
3127 _dbus_warn ("Could not load file %s: %s\n",
3128 _dbus_string_get_const_data (&full_path),
3130 _dbus_string_free (&full_path);
3131 dbus_error_free (&error);
3134 else if (first_parser == NULL)
3136 _dbus_string_free (&full_path);
3137 first_parser = parser;
3141 _dbus_string_free (&full_path);
3142 equal = config_parsers_equal (first_parser, parser);
3143 bus_config_parser_unref (parser);
3152 _dbus_string_free (&filename);
3154 bus_config_parser_unref (first_parser);
3156 _dbus_directory_close (dir);
3163 process_test_equiv_subdir (const DBusString *test_base_dir,
3166 DBusString test_directory;
3167 DBusString filename;
3176 if (!_dbus_string_init (&test_directory))
3177 _dbus_assert_not_reached ("didn't allocate test_directory");
3179 _dbus_string_init_const (&filename, subdir);
3181 if (!_dbus_string_copy (test_base_dir, 0,
3182 &test_directory, 0))
3183 _dbus_assert_not_reached ("couldn't copy test_base_dir to test_directory");
3185 if (!_dbus_concat_dir_and_file (&test_directory, &filename))
3186 _dbus_assert_not_reached ("couldn't allocate full path");
3188 _dbus_string_free (&filename);
3189 if (!_dbus_string_init (&filename))
3190 _dbus_assert_not_reached ("didn't allocate filename string");
3192 dbus_error_init (&error);
3193 dir = _dbus_directory_open (&test_directory, &error);
3196 _dbus_warn ("Could not open %s: %s\n",
3197 _dbus_string_get_const_data (&test_directory),
3199 dbus_error_free (&error);
3203 while (_dbus_directory_get_next_file (dir, &filename, &error))
3205 DBusString full_path;
3207 /* Skip CVS's magic directories! */
3208 if (_dbus_string_equal_c_str (&filename, "CVS"))
3211 if (!_dbus_string_init (&full_path))
3212 _dbus_assert_not_reached ("couldn't init string");
3214 if (!_dbus_string_copy (&test_directory, 0, &full_path, 0))
3215 _dbus_assert_not_reached ("couldn't copy dir to full_path");
3217 if (!_dbus_concat_dir_and_file (&full_path, &filename))
3218 _dbus_assert_not_reached ("couldn't concat file to dir");
3220 equal = all_are_equiv (&full_path);
3221 _dbus_string_free (&full_path);
3230 _dbus_string_free (&test_directory);
3231 _dbus_string_free (&filename);
3233 _dbus_directory_close (dir);
3239 static const char *test_session_service_dir_matches[] =
3242 "/testusr/testlocal/testshare/dbus-1/services",
3243 "/testusr/testshare/dbus-1/services",
3245 DBUS_DATADIR"/dbus-1/services",
3247 "/testhome/foo/.testlocal/testshare/dbus-1/services",
3253 test_default_session_servicedirs (void)
3258 const char *common_progs;
3261 /* On Unix we don't actually use this variable, but it's easier to handle the
3262 * deallocation if we always allocate it, whether needed or not */
3263 if (!_dbus_string_init (&progs))
3264 _dbus_assert_not_reached ("OOM allocating progs");
3266 common_progs = _dbus_getenv ("CommonProgramFiles");
3270 if (!_dbus_string_append (&progs, common_progs))
3272 _dbus_string_free (&progs);
3276 if (!_dbus_string_append (&progs, "/dbus-1/services"))
3278 _dbus_string_free (&progs);
3281 test_session_service_dir_matches[1] = _dbus_string_get_const_data(&progs);
3286 printf ("Testing retrieving the default session service directories\n");
3287 if (!_dbus_get_standard_session_servicedirs (&dirs))
3288 _dbus_assert_not_reached ("couldn't get stardard dirs");
3290 /* make sure our defaults end with share/dbus-1/service */
3291 while ((link = _dbus_list_pop_first_link (&dirs)))
3295 printf (" default service dir: %s\n", (char *)link->data);
3296 _dbus_string_init_const (&path, (char *)link->data);
3297 if (!_dbus_string_ends_with_c_str (&path, "dbus-1/services"))
3299 printf ("error with default session service directories\n");
3300 dbus_free (link->data);
3301 _dbus_list_free_link (link);
3302 _dbus_string_free (&progs);
3306 dbus_free (link->data);
3307 _dbus_list_free_link (link);
3311 if (!_dbus_setenv ("XDG_DATA_HOME", "/testhome/foo/.testlocal/testshare"))
3312 _dbus_assert_not_reached ("couldn't setenv XDG_DATA_HOME");
3314 if (!_dbus_setenv ("XDG_DATA_DIRS", ":/testusr/testlocal/testshare: :/testusr/testshare:"))
3315 _dbus_assert_not_reached ("couldn't setenv XDG_DATA_DIRS");
3317 if (!_dbus_get_standard_session_servicedirs (&dirs))
3318 _dbus_assert_not_reached ("couldn't get stardard dirs");
3320 /* make sure we read and parse the env variable correctly */
3322 while ((link = _dbus_list_pop_first_link (&dirs)))
3324 printf (" test service dir: %s\n", (char *)link->data);
3325 if (test_session_service_dir_matches[i] == NULL)
3327 printf ("more directories parsed than in match set\n");
3328 dbus_free (link->data);
3329 _dbus_list_free_link (link);
3330 _dbus_string_free (&progs);
3334 if (strcmp (test_session_service_dir_matches[i],
3335 (char *)link->data) != 0)
3337 printf ("%s directory does not match %s in the match set\n",
3339 test_session_service_dir_matches[i]);
3340 dbus_free (link->data);
3341 _dbus_list_free_link (link);
3342 _dbus_string_free (&progs);
3348 dbus_free (link->data);
3349 _dbus_list_free_link (link);
3352 if (test_session_service_dir_matches[i] != NULL)
3354 printf ("extra data %s in the match set was not matched\n",
3355 test_session_service_dir_matches[i]);
3357 _dbus_string_free (&progs);
3361 _dbus_string_free (&progs);
3365 static const char *test_system_service_dir_matches[] =
3368 "/testusr/testlocal/testshare/dbus-1/system-services",
3369 "/testusr/testshare/dbus-1/system-services",
3371 DBUS_DATADIR"/dbus-1/system-services",
3376 test_default_system_servicedirs (void)
3381 const char *common_progs;
3384 /* On Unix we don't actually use this variable, but it's easier to handle the
3385 * deallocation if we always allocate it, whether needed or not */
3386 if (!_dbus_string_init (&progs))
3387 _dbus_assert_not_reached ("OOM allocating progs");
3389 common_progs = _dbus_getenv ("CommonProgramFiles");
3393 if (!_dbus_string_append (&progs, common_progs))
3395 _dbus_string_free (&progs);
3399 if (!_dbus_string_append (&progs, "/dbus-1/system-services"))
3401 _dbus_string_free (&progs);
3404 test_system_service_dir_matches[1] = _dbus_string_get_const_data(&progs);
3409 printf ("Testing retrieving the default system service directories\n");
3410 if (!_dbus_get_standard_system_servicedirs (&dirs))
3411 _dbus_assert_not_reached ("couldn't get stardard dirs");
3413 /* make sure our defaults end with share/dbus-1/system-service */
3414 while ((link = _dbus_list_pop_first_link (&dirs)))
3418 printf (" default service dir: %s\n", (char *)link->data);
3419 _dbus_string_init_const (&path, (char *)link->data);
3420 if (!_dbus_string_ends_with_c_str (&path, "dbus-1/system-services"))
3422 printf ("error with default system service directories\n");
3423 dbus_free (link->data);
3424 _dbus_list_free_link (link);
3425 _dbus_string_free (&progs);
3429 dbus_free (link->data);
3430 _dbus_list_free_link (link);
3434 if (!_dbus_setenv ("XDG_DATA_HOME", "/testhome/foo/.testlocal/testshare"))
3435 _dbus_assert_not_reached ("couldn't setenv XDG_DATA_HOME");
3437 if (!_dbus_setenv ("XDG_DATA_DIRS", ":/testusr/testlocal/testshare: :/testusr/testshare:"))
3438 _dbus_assert_not_reached ("couldn't setenv XDG_DATA_DIRS");
3440 if (!_dbus_get_standard_system_servicedirs (&dirs))
3441 _dbus_assert_not_reached ("couldn't get stardard dirs");
3443 /* make sure we read and parse the env variable correctly */
3445 while ((link = _dbus_list_pop_first_link (&dirs)))
3447 printf (" test service dir: %s\n", (char *)link->data);
3448 if (test_system_service_dir_matches[i] == NULL)
3450 printf ("more directories parsed than in match set\n");
3451 dbus_free (link->data);
3452 _dbus_list_free_link (link);
3453 _dbus_string_free (&progs);
3457 if (strcmp (test_system_service_dir_matches[i],
3458 (char *)link->data) != 0)
3460 printf ("%s directory does not match %s in the match set\n",
3462 test_system_service_dir_matches[i]);
3463 dbus_free (link->data);
3464 _dbus_list_free_link (link);
3465 _dbus_string_free (&progs);
3471 dbus_free (link->data);
3472 _dbus_list_free_link (link);
3475 if (test_system_service_dir_matches[i] != NULL)
3477 printf ("extra data %s in the match set was not matched\n",
3478 test_system_service_dir_matches[i]);
3480 _dbus_string_free (&progs);
3484 _dbus_string_free (&progs);
3489 bus_config_parser_test (const DBusString *test_data_dir)
3491 if (test_data_dir == NULL ||
3492 _dbus_string_get_length (test_data_dir) == 0)
3494 printf ("No test data\n");
3498 if (!test_default_session_servicedirs())
3501 if (!test_default_system_servicedirs())
3504 if (!process_test_valid_subdir (test_data_dir, "valid-config-files", VALID))
3507 if (!process_test_valid_subdir (test_data_dir, "invalid-config-files", INVALID))
3510 if (!process_test_equiv_subdir (test_data_dir, "equiv-config-files"))
3516 #endif /* DBUS_BUILD_TESTS */