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
25 #include "config-parser-common.h"
26 #include "config-parser.h"
31 #include <dbus/dbus-list.h>
32 #include <dbus/dbus-internals.h>
33 #include <dbus/dbus-sysdeps.h>
38 /* we ignore policies for unknown groups/users */
53 unsigned int had_content : 1;
59 unsigned int ignore_missing : 1;
60 unsigned int if_selinux_enabled : 1;
61 unsigned int selinux_root_relative : 1;
67 unsigned long gid_uid_or_at_console;
81 * Parser for bus configuration file.
83 struct BusConfigParser
85 int refcount; /**< Reference count */
87 DBusString basedir; /**< Directory we resolve paths relative to */
89 DBusList *stack; /**< stack of Element */
91 char *user; /**< user to run as */
93 char *servicehelper; /**< location of the setuid helper */
95 char *bus_type; /**< Message bus type */
97 DBusList *listen_on; /**< List of addresses to listen to */
99 DBusList *mechanisms; /**< Auth mechanisms */
101 DBusList *service_dirs; /**< Directories to look for session services in */
103 DBusList *conf_dirs; /**< Directories to look for policy configuration in */
105 BusPolicy *policy; /**< Security policy */
107 BusLimits limits; /**< Limits */
109 char *pidfile; /**< PID file */
111 DBusList *included_files; /**< Included files stack */
113 DBusHashTable *service_context_table; /**< Map service names to SELinux contexts */
115 unsigned int fork : 1; /**< TRUE to fork into daemon mode */
117 unsigned int syslog : 1; /**< TRUE to enable syslog */
118 unsigned int keep_umask : 1; /**< TRUE to keep original umask when forking */
120 unsigned int is_toplevel : 1; /**< FALSE if we are a sub-config-file inside another one */
122 unsigned int allow_anonymous : 1; /**< TRUE to allow anonymous connections */
126 push_element (BusConfigParser *parser,
131 _dbus_assert (type != ELEMENT_NONE);
133 e = dbus_new0 (Element, 1);
137 if (!_dbus_list_append (&parser->stack, e))
149 element_free (Element *e)
151 if (e->type == ELEMENT_LIMIT)
152 dbus_free (e->d.limit.name);
158 pop_element (BusConfigParser *parser)
162 e = _dbus_list_pop_last (&parser->stack);
168 peek_element (BusConfigParser *parser)
172 e = _dbus_list_get_last (&parser->stack);
178 top_element_type (BusConfigParser *parser)
182 e = _dbus_list_get_last (&parser->stack);
191 merge_service_context_hash (DBusHashTable *dest,
201 _dbus_hash_iter_init (from, &iter);
202 while (_dbus_hash_iter_next (&iter))
204 const char *service = _dbus_hash_iter_get_string_key (&iter);
205 const char *context = _dbus_hash_iter_get_value (&iter);
207 service_copy = _dbus_strdup (service);
208 if (service_copy == NULL)
210 context_copy = _dbus_strdup (context);
211 if (context_copy == NULL)
214 if (!_dbus_hash_table_insert_string (dest, service_copy, context_copy))
225 dbus_free (service_copy);
228 dbus_free (context_copy);
234 service_dirs_find_dir (DBusList **service_dirs,
239 _dbus_assert (dir != NULL);
241 for (link = *service_dirs; link; link = _dbus_list_get_next_link(service_dirs, link))
243 const char *link_dir;
245 link_dir = (const char *)link->data;
246 if (strcmp (dir, link_dir) == 0)
254 service_dirs_append_unique_or_free (DBusList **service_dirs,
257 if (!service_dirs_find_dir (service_dirs, dir))
258 return _dbus_list_append (service_dirs, dir);
265 service_dirs_append_link_unique_or_free (DBusList **service_dirs,
268 if (!service_dirs_find_dir (service_dirs, dir_link->data))
270 _dbus_list_append_link (service_dirs, dir_link);
274 dbus_free (dir_link->data);
275 _dbus_list_free_link (dir_link);
280 merge_included (BusConfigParser *parser,
281 BusConfigParser *included,
286 if (!bus_policy_merge (parser->policy,
293 if (!merge_service_context_hash (parser->service_context_table,
294 included->service_context_table))
300 if (included->user != NULL)
302 dbus_free (parser->user);
303 parser->user = included->user;
304 included->user = NULL;
307 if (included->bus_type != NULL)
309 dbus_free (parser->bus_type);
310 parser->bus_type = included->bus_type;
311 included->bus_type = NULL;
317 if (included->keep_umask)
318 parser->keep_umask = TRUE;
320 if (included->pidfile != NULL)
322 dbus_free (parser->pidfile);
323 parser->pidfile = included->pidfile;
324 included->pidfile = NULL;
327 while ((link = _dbus_list_pop_first_link (&included->listen_on)))
328 _dbus_list_append_link (&parser->listen_on, link);
330 while ((link = _dbus_list_pop_first_link (&included->mechanisms)))
331 _dbus_list_append_link (&parser->mechanisms, link);
333 while ((link = _dbus_list_pop_first_link (&included->service_dirs)))
334 service_dirs_append_link_unique_or_free (&parser->service_dirs, link);
336 while ((link = _dbus_list_pop_first_link (&included->conf_dirs)))
337 _dbus_list_append_link (&parser->conf_dirs, link);
343 seen_include (BusConfigParser *parser,
344 const DBusString *file)
348 iter = parser->included_files;
351 if (! strcmp (_dbus_string_get_const_data (file), iter->data))
354 iter = _dbus_list_get_next_link (&parser->included_files, iter);
361 bus_config_parser_new (const DBusString *basedir,
362 dbus_bool_t is_toplevel,
363 const BusConfigParser *parent)
365 BusConfigParser *parser;
367 parser = dbus_new0 (BusConfigParser, 1);
371 parser->is_toplevel = !!is_toplevel;
373 if (!_dbus_string_init (&parser->basedir))
379 if (((parser->policy = bus_policy_new ()) == NULL) ||
380 !_dbus_string_copy (basedir, 0, &parser->basedir, 0) ||
381 ((parser->service_context_table = _dbus_hash_table_new (DBUS_HASH_STRING,
383 dbus_free)) == NULL))
386 bus_policy_unref (parser->policy);
388 _dbus_string_free (&parser->basedir);
396 /* Initialize the parser's limits from the parent. */
397 parser->limits = parent->limits;
399 /* Use the parent's list of included_files to avoid
400 circular inclusions. */
401 parser->included_files = parent->included_files;
406 /* Make up some numbers! woot! */
407 parser->limits.max_incoming_bytes = _DBUS_ONE_MEGABYTE * 127;
408 parser->limits.max_outgoing_bytes = _DBUS_ONE_MEGABYTE * 127;
409 parser->limits.max_message_size = _DBUS_ONE_MEGABYTE * 32;
411 /* We set relatively conservative values here since due to the
412 way SCM_RIGHTS works we need to preallocate an array for the
413 maximum number of file descriptors we can receive. Picking a
414 high value here thus translates directly to more memory
416 parser->limits.max_incoming_unix_fds = 1024*4;
417 parser->limits.max_outgoing_unix_fds = 1024*4;
418 parser->limits.max_message_unix_fds = 1024;
420 /* Making this long means the user has to wait longer for an error
421 * message if something screws up, but making it too short means
422 * they might see a false failure.
424 parser->limits.activation_timeout = 25000; /* 25 seconds */
426 /* Making this long risks making a DOS attack easier, but too short
427 * and legitimate auth will fail. If interactive auth (ask user for
428 * password) is allowed, then potentially it has to be quite long.
430 parser->limits.auth_timeout = 30000; /* 30 seconds */
432 parser->limits.max_incomplete_connections = 64;
433 parser->limits.max_connections_per_user = 256;
435 /* Note that max_completed_connections / max_connections_per_user
436 * is the number of users that would have to work together to
437 * DOS all the other users.
439 parser->limits.max_completed_connections = 2048;
441 parser->limits.max_pending_activations = 512;
442 parser->limits.max_services_per_connection = 512;
444 /* For this one, keep in mind that it isn't only the memory used
445 * by the match rules, but slowdown from linearly walking a big
446 * list of them. A client adding more than this is almost
447 * certainly a bad idea for that reason, and should change to a
448 * smaller number of wider-net match rules - getting every last
449 * message to the bus is probably better than having a thousand
452 parser->limits.max_match_rules_per_connection = 512;
454 parser->limits.reply_timeout = -1; /* never */
456 /* this is effectively a limit on message queue size for messages
457 * that require a reply
459 parser->limits.max_replies_per_connection = 1024*8;
462 parser->refcount = 1;
468 bus_config_parser_ref (BusConfigParser *parser)
470 _dbus_assert (parser->refcount > 0);
472 parser->refcount += 1;
478 bus_config_parser_unref (BusConfigParser *parser)
480 _dbus_assert (parser->refcount > 0);
482 parser->refcount -= 1;
484 if (parser->refcount == 0)
486 while (parser->stack != NULL)
487 pop_element (parser);
489 dbus_free (parser->user);
490 dbus_free (parser->servicehelper);
491 dbus_free (parser->bus_type);
492 dbus_free (parser->pidfile);
494 _dbus_list_foreach (&parser->listen_on,
495 (DBusForeachFunction) dbus_free,
498 _dbus_list_clear (&parser->listen_on);
500 _dbus_list_foreach (&parser->service_dirs,
501 (DBusForeachFunction) dbus_free,
504 _dbus_list_clear (&parser->service_dirs);
506 _dbus_list_foreach (&parser->conf_dirs,
507 (DBusForeachFunction) dbus_free,
510 _dbus_list_clear (&parser->conf_dirs);
512 _dbus_list_foreach (&parser->mechanisms,
513 (DBusForeachFunction) dbus_free,
516 _dbus_list_clear (&parser->mechanisms);
518 _dbus_string_free (&parser->basedir);
521 bus_policy_unref (parser->policy);
523 if (parser->service_context_table)
524 _dbus_hash_table_unref (parser->service_context_table);
531 bus_config_parser_check_doctype (BusConfigParser *parser,
535 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
537 if (strcmp (doctype, "busconfig") != 0)
539 dbus_set_error (error,
541 "Configuration file has the wrong document type %s",
556 locate_attributes (BusConfigParser *parser,
557 const char *element_name,
558 const char **attribute_names,
559 const char **attribute_values,
561 const char *first_attribute_name,
562 const char **first_attribute_retloc,
570 LocateAttr attrs[MAX_ATTRS];
574 _dbus_assert (first_attribute_name != NULL);
575 _dbus_assert (first_attribute_retloc != NULL);
580 attrs[0].name = first_attribute_name;
581 attrs[0].retloc = first_attribute_retloc;
582 *first_attribute_retloc = NULL;
584 va_start (args, first_attribute_retloc);
586 name = va_arg (args, const char*);
587 retloc = va_arg (args, const char**);
591 _dbus_assert (retloc != NULL);
592 _dbus_assert (n_attrs < MAX_ATTRS);
594 attrs[n_attrs].name = name;
595 attrs[n_attrs].retloc = retloc;
599 name = va_arg (args, const char*);
600 retloc = va_arg (args, const char**);
606 while (attribute_names[i])
615 if (strcmp (attrs[j].name, attribute_names[i]) == 0)
617 retloc = attrs[j].retloc;
621 dbus_set_error (error, DBUS_ERROR_FAILED,
622 "Attribute \"%s\" repeated twice on the same <%s> element",
623 attrs[j].name, element_name);
628 *retloc = attribute_values[i];
637 dbus_set_error (error, DBUS_ERROR_FAILED,
638 "Attribute \"%s\" is invalid on <%s> element in this context",
639 attribute_names[i], element_name);
652 check_no_attributes (BusConfigParser *parser,
653 const char *element_name,
654 const char **attribute_names,
655 const char **attribute_values,
658 if (attribute_names[0] != NULL)
660 dbus_set_error (error, DBUS_ERROR_FAILED,
661 "Attribute \"%s\" is invalid on <%s> element in this context",
662 attribute_names[0], element_name);
670 start_busconfig_child (BusConfigParser *parser,
671 const char *element_name,
672 const char **attribute_names,
673 const char **attribute_values,
676 ElementType element_type;
678 element_type = bus_config_parser_element_name_to_type (element_name);
680 if (element_type == ELEMENT_USER)
682 if (!check_no_attributes (parser, "user", attribute_names, attribute_values, error))
685 if (push_element (parser, ELEMENT_USER) == NULL)
693 else if (element_type == ELEMENT_CONFIGTYPE)
695 if (!check_no_attributes (parser, "type", attribute_names, attribute_values, error))
698 if (push_element (parser, ELEMENT_CONFIGTYPE) == NULL)
706 else if (element_type == ELEMENT_FORK)
708 if (!check_no_attributes (parser, "fork", attribute_names, attribute_values, error))
711 if (push_element (parser, ELEMENT_FORK) == NULL)
721 else if (element_type == ELEMENT_SYSLOG)
723 if (!check_no_attributes (parser, "syslog", attribute_names, attribute_values, error))
726 if (push_element (parser, ELEMENT_SYSLOG) == NULL)
732 parser->syslog = TRUE;
736 else if (element_type == ELEMENT_KEEP_UMASK)
738 if (!check_no_attributes (parser, "keep_umask", attribute_names, attribute_values, error))
741 if (push_element (parser, ELEMENT_KEEP_UMASK) == NULL)
747 parser->keep_umask = TRUE;
751 else if (element_type == ELEMENT_PIDFILE)
753 if (!check_no_attributes (parser, "pidfile", attribute_names, attribute_values, error))
756 if (push_element (parser, ELEMENT_PIDFILE) == NULL)
764 else if (element_type == ELEMENT_LISTEN)
766 if (!check_no_attributes (parser, "listen", attribute_names, attribute_values, error))
769 if (push_element (parser, ELEMENT_LISTEN) == NULL)
777 else if (element_type == ELEMENT_AUTH)
779 if (!check_no_attributes (parser, "auth", attribute_names, attribute_values, error))
782 if (push_element (parser, ELEMENT_AUTH) == NULL)
790 else if (element_type == ELEMENT_SERVICEHELPER)
792 if (!check_no_attributes (parser, "servicehelper", attribute_names, attribute_values, error))
795 if (push_element (parser, ELEMENT_SERVICEHELPER) == NULL)
803 else if (element_type == ELEMENT_INCLUDEDIR)
805 if (!check_no_attributes (parser, "includedir", attribute_names, attribute_values, error))
808 if (push_element (parser, ELEMENT_INCLUDEDIR) == NULL)
816 else if (element_type == ELEMENT_STANDARD_SESSION_SERVICEDIRS)
822 if (!check_no_attributes (parser, "standard_session_servicedirs", attribute_names, attribute_values, error))
825 if (push_element (parser, ELEMENT_STANDARD_SESSION_SERVICEDIRS) == NULL)
831 if (!_dbus_get_standard_session_servicedirs (&dirs))
837 while ((link = _dbus_list_pop_first_link (&dirs)))
838 service_dirs_append_link_unique_or_free (&parser->service_dirs, link);
842 else if (element_type == ELEMENT_STANDARD_SYSTEM_SERVICEDIRS)
848 if (!check_no_attributes (parser, "standard_system_servicedirs", attribute_names, attribute_values, error))
851 if (push_element (parser, ELEMENT_STANDARD_SYSTEM_SERVICEDIRS) == NULL)
857 if (!_dbus_get_standard_system_servicedirs (&dirs))
863 while ((link = _dbus_list_pop_first_link (&dirs)))
864 service_dirs_append_link_unique_or_free (&parser->service_dirs, link);
868 else if (element_type == ELEMENT_ALLOW_ANONYMOUS)
870 if (!check_no_attributes (parser, "allow_anonymous", attribute_names, attribute_values, error))
873 if (push_element (parser, ELEMENT_ALLOW_ANONYMOUS) == NULL)
879 parser->allow_anonymous = TRUE;
882 else if (element_type == ELEMENT_SERVICEDIR)
884 if (!check_no_attributes (parser, "servicedir", attribute_names, attribute_values, error))
887 if (push_element (parser, ELEMENT_SERVICEDIR) == NULL)
895 else if (element_type == ELEMENT_INCLUDE)
898 const char *if_selinux_enabled;
899 const char *ignore_missing;
900 const char *selinux_root_relative;
902 if ((e = push_element (parser, ELEMENT_INCLUDE)) == NULL)
908 e->d.include.ignore_missing = FALSE;
909 e->d.include.if_selinux_enabled = FALSE;
910 e->d.include.selinux_root_relative = FALSE;
912 if (!locate_attributes (parser, "include",
916 "ignore_missing", &ignore_missing,
917 "if_selinux_enabled", &if_selinux_enabled,
918 "selinux_root_relative", &selinux_root_relative,
922 if (ignore_missing != NULL)
924 if (strcmp (ignore_missing, "yes") == 0)
925 e->d.include.ignore_missing = TRUE;
926 else if (strcmp (ignore_missing, "no") == 0)
927 e->d.include.ignore_missing = FALSE;
930 dbus_set_error (error, DBUS_ERROR_FAILED,
931 "ignore_missing attribute must have value \"yes\" or \"no\"");
936 if (if_selinux_enabled != NULL)
938 if (strcmp (if_selinux_enabled, "yes") == 0)
939 e->d.include.if_selinux_enabled = TRUE;
940 else if (strcmp (if_selinux_enabled, "no") == 0)
941 e->d.include.if_selinux_enabled = FALSE;
944 dbus_set_error (error, DBUS_ERROR_FAILED,
945 "if_selinux_enabled attribute must have value"
946 " \"yes\" or \"no\"");
951 if (selinux_root_relative != NULL)
953 if (strcmp (selinux_root_relative, "yes") == 0)
954 e->d.include.selinux_root_relative = TRUE;
955 else if (strcmp (selinux_root_relative, "no") == 0)
956 e->d.include.selinux_root_relative = FALSE;
959 dbus_set_error (error, DBUS_ERROR_FAILED,
960 "selinux_root_relative attribute must have value"
961 " \"yes\" or \"no\"");
968 else if (element_type == ELEMENT_POLICY)
974 const char *at_console;
976 if ((e = push_element (parser, ELEMENT_POLICY)) == NULL)
982 e->d.policy.type = POLICY_IGNORED;
984 if (!locate_attributes (parser, "policy",
991 "at_console", &at_console,
995 if (((context && user) ||
996 (context && group) ||
997 (context && at_console)) ||
999 (user && at_console)) ||
1000 (group && at_console) ||
1001 !(context || user || group || at_console))
1003 dbus_set_error (error, DBUS_ERROR_FAILED,
1004 "<policy> element must have exactly one of (context|user|group|at_console) attributes");
1008 if (context != NULL)
1010 if (strcmp (context, "default") == 0)
1012 e->d.policy.type = POLICY_DEFAULT;
1014 else if (strcmp (context, "mandatory") == 0)
1016 e->d.policy.type = POLICY_MANDATORY;
1020 dbus_set_error (error, DBUS_ERROR_FAILED,
1021 "context attribute on <policy> must have the value \"default\" or \"mandatory\", not \"%s\"",
1026 else if (user != NULL)
1028 DBusString username;
1029 _dbus_string_init_const (&username, user);
1031 if (_dbus_parse_unix_user_from_config (&username,
1032 &e->d.policy.gid_uid_or_at_console))
1033 e->d.policy.type = POLICY_USER;
1035 _dbus_warn ("Unknown username \"%s\" in message bus configuration file\n",
1038 else if (group != NULL)
1040 DBusString group_name;
1041 _dbus_string_init_const (&group_name, group);
1043 if (_dbus_parse_unix_group_from_config (&group_name,
1044 &e->d.policy.gid_uid_or_at_console))
1045 e->d.policy.type = POLICY_GROUP;
1047 _dbus_warn ("Unknown group \"%s\" in message bus configuration file\n",
1050 else if (at_console != NULL)
1053 t = (strcmp (at_console, "true") == 0);
1054 if (t || strcmp (at_console, "false") == 0)
1056 e->d.policy.gid_uid_or_at_console = t;
1057 e->d.policy.type = POLICY_CONSOLE;
1061 dbus_set_error (error, DBUS_ERROR_FAILED,
1062 "Unknown value \"%s\" for at_console in message bus configuration file",
1070 _dbus_assert_not_reached ("all <policy> attributes null and we didn't set error");
1075 else if (element_type == ELEMENT_LIMIT)
1080 if ((e = push_element (parser, ELEMENT_LIMIT)) == NULL)
1082 BUS_SET_OOM (error);
1086 if (!locate_attributes (parser, "limit",
1096 dbus_set_error (error, DBUS_ERROR_FAILED,
1097 "<limit> element must have a \"name\" attribute");
1101 e->d.limit.name = _dbus_strdup (name);
1102 if (e->d.limit.name == NULL)
1104 BUS_SET_OOM (error);
1110 else if (element_type == ELEMENT_SELINUX)
1112 if (!check_no_attributes (parser, "selinux", attribute_names, attribute_values, error))
1115 if (push_element (parser, ELEMENT_SELINUX) == NULL)
1117 BUS_SET_OOM (error);
1125 dbus_set_error (error, DBUS_ERROR_FAILED,
1126 "Element <%s> not allowed inside <%s> in configuration file",
1127 element_name, "busconfig");
1133 append_rule_from_element (BusConfigParser *parser,
1134 const char *element_name,
1135 const char **attribute_names,
1136 const char **attribute_values,
1141 const char *send_interface;
1142 const char *send_member;
1143 const char *send_error;
1144 const char *send_destination;
1145 const char *send_path;
1146 const char *send_type;
1147 const char *receive_interface;
1148 const char *receive_member;
1149 const char *receive_error;
1150 const char *receive_sender;
1151 const char *receive_path;
1152 const char *receive_type;
1153 const char *eavesdrop;
1154 const char *send_requested_reply;
1155 const char *receive_requested_reply;
1160 BusPolicyRule *rule;
1162 if (!locate_attributes (parser, element_name,
1166 "send_interface", &send_interface,
1167 "send_member", &send_member,
1168 "send_error", &send_error,
1169 "send_destination", &send_destination,
1170 "send_path", &send_path,
1171 "send_type", &send_type,
1172 "receive_interface", &receive_interface,
1173 "receive_member", &receive_member,
1174 "receive_error", &receive_error,
1175 "receive_sender", &receive_sender,
1176 "receive_path", &receive_path,
1177 "receive_type", &receive_type,
1178 "eavesdrop", &eavesdrop,
1179 "send_requested_reply", &send_requested_reply,
1180 "receive_requested_reply", &receive_requested_reply,
1188 if (!(send_interface || send_member || send_error || send_destination ||
1189 send_type || send_path ||
1190 receive_interface || receive_member || receive_error || receive_sender ||
1191 receive_type || receive_path || eavesdrop ||
1192 send_requested_reply || receive_requested_reply ||
1193 own || user || group))
1195 dbus_set_error (error, DBUS_ERROR_FAILED,
1196 "Element <%s> must have one or more attributes",
1201 if ((send_member && (send_interface == NULL && send_path == NULL)) ||
1202 (receive_member && (receive_interface == NULL && receive_path == NULL)))
1204 dbus_set_error (error, DBUS_ERROR_FAILED,
1205 "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.",
1210 /* Allowed combinations of elements are:
1212 * base, must be all send or all receive:
1215 * interface + member
1218 * base send_ can combine with send_destination, send_path, send_type, send_requested_reply
1219 * base receive_ with receive_sender, receive_path, receive_type, receive_requested_reply, eavesdrop
1221 * user, group, own must occur alone
1223 * Pretty sure the below stuff is broken, FIXME think about it more.
1226 if (((send_interface && send_error) ||
1227 (send_interface && receive_interface) ||
1228 (send_interface && receive_member) ||
1229 (send_interface && receive_error) ||
1230 (send_interface && receive_sender) ||
1231 (send_interface && receive_requested_reply) ||
1232 (send_interface && own) ||
1233 (send_interface && user) ||
1234 (send_interface && group)) ||
1236 ((send_member && send_error) ||
1237 (send_member && receive_interface) ||
1238 (send_member && receive_member) ||
1239 (send_member && receive_error) ||
1240 (send_member && receive_sender) ||
1241 (send_member && receive_requested_reply) ||
1242 (send_member && own) ||
1243 (send_member && user) ||
1244 (send_member && group)) ||
1246 ((send_error && receive_interface) ||
1247 (send_error && receive_member) ||
1248 (send_error && receive_error) ||
1249 (send_error && receive_sender) ||
1250 (send_error && receive_requested_reply) ||
1251 (send_error && own) ||
1252 (send_error && user) ||
1253 (send_error && group)) ||
1255 ((send_destination && receive_interface) ||
1256 (send_destination && receive_member) ||
1257 (send_destination && receive_error) ||
1258 (send_destination && receive_sender) ||
1259 (send_destination && receive_requested_reply) ||
1260 (send_destination && own) ||
1261 (send_destination && user) ||
1262 (send_destination && group)) ||
1264 ((send_type && receive_interface) ||
1265 (send_type && receive_member) ||
1266 (send_type && receive_error) ||
1267 (send_type && receive_sender) ||
1268 (send_type && receive_requested_reply) ||
1269 (send_type && own) ||
1270 (send_type && user) ||
1271 (send_type && group)) ||
1273 ((send_path && receive_interface) ||
1274 (send_path && receive_member) ||
1275 (send_path && receive_error) ||
1276 (send_path && receive_sender) ||
1277 (send_path && receive_requested_reply) ||
1278 (send_path && own) ||
1279 (send_path && user) ||
1280 (send_path && group)) ||
1282 ((send_requested_reply && receive_interface) ||
1283 (send_requested_reply && receive_member) ||
1284 (send_requested_reply && receive_error) ||
1285 (send_requested_reply && receive_sender) ||
1286 (send_requested_reply && receive_requested_reply) ||
1287 (send_requested_reply && own) ||
1288 (send_requested_reply && user) ||
1289 (send_requested_reply && group)) ||
1291 ((receive_interface && receive_error) ||
1292 (receive_interface && own) ||
1293 (receive_interface && user) ||
1294 (receive_interface && group)) ||
1296 ((receive_member && receive_error) ||
1297 (receive_member && own) ||
1298 (receive_member && user) ||
1299 (receive_member && group)) ||
1301 ((receive_error && own) ||
1302 (receive_error && user) ||
1303 (receive_error && group)) ||
1305 ((eavesdrop && own) ||
1306 (eavesdrop && user) ||
1307 (eavesdrop && group)) ||
1309 ((receive_requested_reply && own) ||
1310 (receive_requested_reply && user) ||
1311 (receive_requested_reply && group)) ||
1318 dbus_set_error (error, DBUS_ERROR_FAILED,
1319 "Invalid combination of attributes on element <%s>",
1326 /* In BusPolicyRule, NULL represents wildcard.
1327 * In the config file, '*' represents it.
1329 #define IS_WILDCARD(str) ((str) && ((str)[0]) == '*' && ((str)[1]) == '\0')
1331 if (send_interface || send_member || send_error || send_destination ||
1332 send_path || send_type || send_requested_reply)
1336 if (IS_WILDCARD (send_interface))
1337 send_interface = NULL;
1338 if (IS_WILDCARD (send_member))
1340 if (IS_WILDCARD (send_error))
1342 if (IS_WILDCARD (send_destination))
1343 send_destination = NULL;
1344 if (IS_WILDCARD (send_path))
1346 if (IS_WILDCARD (send_type))
1349 message_type = DBUS_MESSAGE_TYPE_INVALID;
1350 if (send_type != NULL)
1352 message_type = dbus_message_type_from_string (send_type);
1353 if (message_type == DBUS_MESSAGE_TYPE_INVALID)
1355 dbus_set_error (error, DBUS_ERROR_FAILED,
1356 "Bad message type \"%s\"",
1363 !(strcmp (eavesdrop, "true") == 0 ||
1364 strcmp (eavesdrop, "false") == 0))
1366 dbus_set_error (error, DBUS_ERROR_FAILED,
1367 "Bad value \"%s\" for %s attribute, must be true or false",
1368 "eavesdrop", eavesdrop);
1372 if (send_requested_reply &&
1373 !(strcmp (send_requested_reply, "true") == 0 ||
1374 strcmp (send_requested_reply, "false") == 0))
1376 dbus_set_error (error, DBUS_ERROR_FAILED,
1377 "Bad value \"%s\" for %s attribute, must be true or false",
1378 "send_requested_reply", send_requested_reply);
1382 rule = bus_policy_rule_new (BUS_POLICY_RULE_SEND, allow);
1387 rule->d.send.eavesdrop = (strcmp (eavesdrop, "true") == 0);
1390 rule->d.send.log = (strcmp (log, "true") == 0);
1392 if (send_requested_reply)
1393 rule->d.send.requested_reply = (strcmp (send_requested_reply, "true") == 0);
1395 rule->d.send.message_type = message_type;
1396 rule->d.send.path = _dbus_strdup (send_path);
1397 rule->d.send.interface = _dbus_strdup (send_interface);
1398 rule->d.send.member = _dbus_strdup (send_member);
1399 rule->d.send.error = _dbus_strdup (send_error);
1400 rule->d.send.destination = _dbus_strdup (send_destination);
1401 if (send_path && rule->d.send.path == NULL)
1403 if (send_interface && rule->d.send.interface == NULL)
1405 if (send_member && rule->d.send.member == NULL)
1407 if (send_error && rule->d.send.error == NULL)
1409 if (send_destination && rule->d.send.destination == NULL)
1412 else if (receive_interface || receive_member || receive_error || receive_sender ||
1413 receive_path || receive_type || eavesdrop || receive_requested_reply)
1417 if (IS_WILDCARD (receive_interface))
1418 receive_interface = NULL;
1419 if (IS_WILDCARD (receive_member))
1420 receive_member = NULL;
1421 if (IS_WILDCARD (receive_error))
1422 receive_error = NULL;
1423 if (IS_WILDCARD (receive_sender))
1424 receive_sender = NULL;
1425 if (IS_WILDCARD (receive_path))
1426 receive_path = NULL;
1427 if (IS_WILDCARD (receive_type))
1428 receive_type = NULL;
1430 message_type = DBUS_MESSAGE_TYPE_INVALID;
1431 if (receive_type != NULL)
1433 message_type = dbus_message_type_from_string (receive_type);
1434 if (message_type == DBUS_MESSAGE_TYPE_INVALID)
1436 dbus_set_error (error, DBUS_ERROR_FAILED,
1437 "Bad message type \"%s\"",
1445 !(strcmp (eavesdrop, "true") == 0 ||
1446 strcmp (eavesdrop, "false") == 0))
1448 dbus_set_error (error, DBUS_ERROR_FAILED,
1449 "Bad value \"%s\" for %s attribute, must be true or false",
1450 "eavesdrop", eavesdrop);
1454 if (receive_requested_reply &&
1455 !(strcmp (receive_requested_reply, "true") == 0 ||
1456 strcmp (receive_requested_reply, "false") == 0))
1458 dbus_set_error (error, DBUS_ERROR_FAILED,
1459 "Bad value \"%s\" for %s attribute, must be true or false",
1460 "receive_requested_reply", receive_requested_reply);
1464 rule = bus_policy_rule_new (BUS_POLICY_RULE_RECEIVE, allow);
1469 rule->d.receive.eavesdrop = (strcmp (eavesdrop, "true") == 0);
1471 if (receive_requested_reply)
1472 rule->d.receive.requested_reply = (strcmp (receive_requested_reply, "true") == 0);
1474 rule->d.receive.message_type = message_type;
1475 rule->d.receive.path = _dbus_strdup (receive_path);
1476 rule->d.receive.interface = _dbus_strdup (receive_interface);
1477 rule->d.receive.member = _dbus_strdup (receive_member);
1478 rule->d.receive.error = _dbus_strdup (receive_error);
1479 rule->d.receive.origin = _dbus_strdup (receive_sender);
1481 if (receive_path && rule->d.receive.path == NULL)
1483 if (receive_interface && rule->d.receive.interface == NULL)
1485 if (receive_member && rule->d.receive.member == NULL)
1487 if (receive_error && rule->d.receive.error == NULL)
1489 if (receive_sender && rule->d.receive.origin == NULL)
1494 rule = bus_policy_rule_new (BUS_POLICY_RULE_OWN, allow);
1498 if (IS_WILDCARD (own))
1501 rule->d.own.service_name = _dbus_strdup (own);
1502 if (own && rule->d.own.service_name == NULL)
1507 if (IS_WILDCARD (user))
1509 rule = bus_policy_rule_new (BUS_POLICY_RULE_USER, allow);
1513 rule->d.user.uid = DBUS_UID_UNSET;
1517 DBusString username;
1520 _dbus_string_init_const (&username, user);
1522 if (_dbus_parse_unix_user_from_config (&username, &uid))
1524 rule = bus_policy_rule_new (BUS_POLICY_RULE_USER, allow);
1528 rule->d.user.uid = uid;
1532 _dbus_warn ("Unknown username \"%s\" on element <%s>\n",
1533 user, element_name);
1539 if (IS_WILDCARD (group))
1541 rule = bus_policy_rule_new (BUS_POLICY_RULE_GROUP, allow);
1545 rule->d.group.gid = DBUS_GID_UNSET;
1549 DBusString groupname;
1552 _dbus_string_init_const (&groupname, group);
1554 if (_dbus_parse_unix_group_from_config (&groupname, &gid))
1556 rule = bus_policy_rule_new (BUS_POLICY_RULE_GROUP, allow);
1560 rule->d.group.gid = gid;
1564 _dbus_warn ("Unknown group \"%s\" on element <%s>\n",
1565 group, element_name);
1570 _dbus_assert_not_reached ("Did not handle some combination of attributes on <allow> or <deny>");
1576 pe = peek_element (parser);
1577 _dbus_assert (pe != NULL);
1578 _dbus_assert (pe->type == ELEMENT_POLICY);
1580 switch (pe->d.policy.type)
1582 case POLICY_IGNORED:
1583 /* drop the rule on the floor */
1586 case POLICY_DEFAULT:
1587 if (!bus_policy_append_default_rule (parser->policy, rule))
1590 case POLICY_MANDATORY:
1591 if (!bus_policy_append_mandatory_rule (parser->policy, rule))
1595 if (!BUS_POLICY_RULE_IS_PER_CLIENT (rule))
1597 dbus_set_error (error, DBUS_ERROR_FAILED,
1598 "<%s> rule cannot be per-user because it has bus-global semantics",
1603 if (!bus_policy_append_user_rule (parser->policy, pe->d.policy.gid_uid_or_at_console,
1608 if (!BUS_POLICY_RULE_IS_PER_CLIENT (rule))
1610 dbus_set_error (error, DBUS_ERROR_FAILED,
1611 "<%s> rule cannot be per-group because it has bus-global semantics",
1616 if (!bus_policy_append_group_rule (parser->policy, pe->d.policy.gid_uid_or_at_console,
1622 case POLICY_CONSOLE:
1623 if (!bus_policy_append_console_rule (parser->policy, pe->d.policy.gid_uid_or_at_console,
1629 bus_policy_rule_unref (rule);
1636 BUS_SET_OOM (error);
1639 bus_policy_rule_unref (rule);
1644 start_policy_child (BusConfigParser *parser,
1645 const char *element_name,
1646 const char **attribute_names,
1647 const char **attribute_values,
1650 if (strcmp (element_name, "allow") == 0)
1652 if (!append_rule_from_element (parser, element_name,
1653 attribute_names, attribute_values,
1657 if (push_element (parser, ELEMENT_ALLOW) == NULL)
1659 BUS_SET_OOM (error);
1665 else if (strcmp (element_name, "deny") == 0)
1667 if (!append_rule_from_element (parser, element_name,
1668 attribute_names, attribute_values,
1672 if (push_element (parser, ELEMENT_DENY) == NULL)
1674 BUS_SET_OOM (error);
1682 dbus_set_error (error, DBUS_ERROR_FAILED,
1683 "Element <%s> not allowed inside <%s> in configuration file",
1684 element_name, "policy");
1690 start_selinux_child (BusConfigParser *parser,
1691 const char *element_name,
1692 const char **attribute_names,
1693 const char **attribute_values,
1700 context_copy = NULL;
1702 if (strcmp (element_name, "associate") == 0)
1705 const char *context;
1707 if (!locate_attributes (parser, "associate",
1712 "context", &context,
1716 if (push_element (parser, ELEMENT_ASSOCIATE) == NULL)
1718 BUS_SET_OOM (error);
1722 if (own == NULL || context == NULL)
1724 dbus_set_error (error, DBUS_ERROR_FAILED,
1725 "Element <associate> must have attributes own=\"<servicename>\" and context=\"<selinux context>\"");
1729 own_copy = _dbus_strdup (own);
1730 if (own_copy == NULL)
1732 context_copy = _dbus_strdup (context);
1733 if (context_copy == NULL)
1736 if (!_dbus_hash_table_insert_string (parser->service_context_table,
1737 own_copy, context_copy))
1744 dbus_set_error (error, DBUS_ERROR_FAILED,
1745 "Element <%s> not allowed inside <%s> in configuration file",
1746 element_name, "selinux");
1752 dbus_free (own_copy);
1755 dbus_free (context_copy);
1757 BUS_SET_OOM (error);
1762 bus_config_parser_start_element (BusConfigParser *parser,
1763 const char *element_name,
1764 const char **attribute_names,
1765 const char **attribute_values,
1770 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1772 /* printf ("START: %s\n", element_name); */
1774 t = top_element_type (parser);
1776 if (t == ELEMENT_NONE)
1778 if (strcmp (element_name, "busconfig") == 0)
1780 if (!check_no_attributes (parser, "busconfig", attribute_names, attribute_values, error))
1783 if (push_element (parser, ELEMENT_BUSCONFIG) == NULL)
1785 BUS_SET_OOM (error);
1793 dbus_set_error (error, DBUS_ERROR_FAILED,
1794 "Unknown element <%s> at root of configuration file",
1799 else if (t == ELEMENT_BUSCONFIG)
1801 return start_busconfig_child (parser, element_name,
1802 attribute_names, attribute_values,
1805 else if (t == ELEMENT_POLICY)
1807 return start_policy_child (parser, element_name,
1808 attribute_names, attribute_values,
1811 else if (t == ELEMENT_SELINUX)
1813 return start_selinux_child (parser, element_name,
1814 attribute_names, attribute_values,
1819 dbus_set_error (error, DBUS_ERROR_FAILED,
1820 "Element <%s> is not allowed in this context",
1827 set_limit (BusConfigParser *parser,
1832 dbus_bool_t must_be_positive;
1833 dbus_bool_t must_be_int;
1835 must_be_int = FALSE;
1836 must_be_positive = FALSE;
1838 if (strcmp (name, "max_incoming_bytes") == 0)
1840 must_be_positive = TRUE;
1841 parser->limits.max_incoming_bytes = value;
1843 else if (strcmp (name, "max_incoming_unix_fds") == 0)
1845 must_be_positive = TRUE;
1846 parser->limits.max_incoming_unix_fds = value;
1848 else if (strcmp (name, "max_outgoing_bytes") == 0)
1850 must_be_positive = TRUE;
1851 parser->limits.max_outgoing_bytes = value;
1853 else if (strcmp (name, "max_outgoing_unix_fds") == 0)
1855 must_be_positive = TRUE;
1856 parser->limits.max_outgoing_unix_fds = value;
1858 else if (strcmp (name, "max_message_size") == 0)
1860 must_be_positive = TRUE;
1861 parser->limits.max_message_size = value;
1863 else if (strcmp (name, "max_message_unix_fds") == 0)
1865 must_be_positive = TRUE;
1866 parser->limits.max_message_unix_fds = value;
1868 else if (strcmp (name, "service_start_timeout") == 0)
1870 must_be_positive = TRUE;
1872 parser->limits.activation_timeout = value;
1874 else if (strcmp (name, "auth_timeout") == 0)
1876 must_be_positive = TRUE;
1878 parser->limits.auth_timeout = value;
1880 else if (strcmp (name, "reply_timeout") == 0)
1882 must_be_positive = TRUE;
1884 parser->limits.reply_timeout = value;
1886 else if (strcmp (name, "max_completed_connections") == 0)
1888 must_be_positive = TRUE;
1890 parser->limits.max_completed_connections = value;
1892 else if (strcmp (name, "max_incomplete_connections") == 0)
1894 must_be_positive = TRUE;
1896 parser->limits.max_incomplete_connections = value;
1898 else if (strcmp (name, "max_connections_per_user") == 0)
1900 must_be_positive = TRUE;
1902 parser->limits.max_connections_per_user = value;
1904 else if (strcmp (name, "max_pending_service_starts") == 0)
1906 must_be_positive = TRUE;
1908 parser->limits.max_pending_activations = value;
1910 else if (strcmp (name, "max_names_per_connection") == 0)
1912 must_be_positive = TRUE;
1914 parser->limits.max_services_per_connection = value;
1916 else if (strcmp (name, "max_match_rules_per_connection") == 0)
1918 must_be_positive = TRUE;
1920 parser->limits.max_match_rules_per_connection = value;
1922 else if (strcmp (name, "max_replies_per_connection") == 0)
1924 must_be_positive = TRUE;
1926 parser->limits.max_replies_per_connection = value;
1930 dbus_set_error (error, DBUS_ERROR_FAILED,
1931 "There is no limit called \"%s\"\n",
1936 if (must_be_positive && value < 0)
1938 dbus_set_error (error, DBUS_ERROR_FAILED,
1939 "<limit name=\"%s\"> must be a positive number\n",
1945 (value < _DBUS_INT_MIN || value > _DBUS_INT_MAX))
1947 dbus_set_error (error, DBUS_ERROR_FAILED,
1948 "<limit name=\"%s\"> value is too large\n",
1957 bus_config_parser_end_element (BusConfigParser *parser,
1958 const char *element_name,
1965 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1967 /* printf ("END: %s\n", element_name); */
1969 t = top_element_type (parser);
1971 if (t == ELEMENT_NONE)
1973 /* should probably be an assertion failure but
1974 * being paranoid about XML parsers
1976 dbus_set_error (error, DBUS_ERROR_FAILED,
1977 "XML parser ended element with no element on the stack");
1981 n = bus_config_parser_element_type_to_name (t);
1982 _dbus_assert (n != NULL);
1983 if (strcmp (n, element_name) != 0)
1985 /* should probably be an assertion failure but
1986 * being paranoid about XML parsers
1988 dbus_set_error (error, DBUS_ERROR_FAILED,
1989 "XML element <%s> ended but topmost element on the stack was <%s>",
1994 e = peek_element (parser);
1995 _dbus_assert (e != NULL);
2000 _dbus_assert_not_reached ("element in stack has no type");
2003 case ELEMENT_INCLUDE:
2005 case ELEMENT_CONFIGTYPE:
2006 case ELEMENT_LISTEN:
2007 case ELEMENT_PIDFILE:
2009 case ELEMENT_SERVICEDIR:
2010 case ELEMENT_SERVICEHELPER:
2011 case ELEMENT_INCLUDEDIR:
2013 if (!e->had_content)
2015 dbus_set_error (error, DBUS_ERROR_FAILED,
2016 "XML element <%s> was expected to have content inside it",
2017 bus_config_parser_element_type_to_name (e->type));
2021 if (e->type == ELEMENT_LIMIT)
2023 if (!set_limit (parser, e->d.limit.name, e->d.limit.value,
2029 case ELEMENT_BUSCONFIG:
2030 case ELEMENT_POLICY:
2034 case ELEMENT_SYSLOG:
2035 case ELEMENT_KEEP_UMASK:
2036 case ELEMENT_SELINUX:
2037 case ELEMENT_ASSOCIATE:
2038 case ELEMENT_STANDARD_SESSION_SERVICEDIRS:
2039 case ELEMENT_STANDARD_SYSTEM_SERVICEDIRS:
2040 case ELEMENT_ALLOW_ANONYMOUS:
2044 pop_element (parser);
2050 all_whitespace (const DBusString *str)
2054 _dbus_string_skip_white (str, 0, &i);
2056 return i == _dbus_string_get_length (str);
2060 make_full_path (const DBusString *basedir,
2061 const DBusString *filename,
2062 DBusString *full_path)
2064 if (_dbus_path_is_absolute (filename))
2066 return _dbus_string_copy (filename, 0, full_path, 0);
2070 if (!_dbus_string_copy (basedir, 0, full_path, 0))
2073 if (!_dbus_concat_dir_and_file (full_path, filename))
2081 include_file (BusConfigParser *parser,
2082 const DBusString *filename,
2083 dbus_bool_t ignore_missing,
2086 /* FIXME good test case for this would load each config file in the
2087 * test suite both alone, and as an include, and check
2088 * that the result is the same
2090 BusConfigParser *included;
2091 const char *filename_str;
2092 DBusError tmp_error;
2094 dbus_error_init (&tmp_error);
2096 filename_str = _dbus_string_get_const_data (filename);
2098 /* Check to make sure this file hasn't already been included. */
2099 if (seen_include (parser, filename))
2101 dbus_set_error (error, DBUS_ERROR_FAILED,
2102 "Circular inclusion of file '%s'",
2107 if (! _dbus_list_append (&parser->included_files, (void *) filename_str))
2109 BUS_SET_OOM (error);
2113 /* Since parser is passed in as the parent, included
2114 inherits parser's limits. */
2115 included = bus_config_load (filename, FALSE, parser, &tmp_error);
2117 _dbus_list_pop_last (&parser->included_files);
2119 if (included == NULL)
2121 _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
2123 if (dbus_error_has_name (&tmp_error, DBUS_ERROR_FILE_NOT_FOUND) &&
2126 dbus_error_free (&tmp_error);
2131 dbus_move_error (&tmp_error, error);
2137 _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
2139 if (!merge_included (parser, included, error))
2141 bus_config_parser_unref (included);
2145 /* Copy included's limits back to parser. */
2146 parser->limits = included->limits;
2148 bus_config_parser_unref (included);
2154 servicehelper_path (BusConfigParser *parser,
2155 const DBusString *filename,
2158 const char *filename_str;
2159 char *servicehelper;
2161 filename_str = _dbus_string_get_const_data (filename);
2163 /* copy to avoid overwriting with NULL on OOM */
2164 servicehelper = _dbus_strdup (filename_str);
2167 if (servicehelper == NULL)
2169 BUS_SET_OOM (error);
2173 /* save the latest servicehelper only if not OOM */
2174 dbus_free (parser->servicehelper);
2175 parser->servicehelper = servicehelper;
2177 /* We don't check whether the helper exists; instead we
2178 * would just fail to ever activate anything if it doesn't.
2179 * This allows an admin to fix the problem if it doesn't exist.
2180 * It also allows the parser test suite to successfully parse
2181 * test cases without installing the helper. ;-)
2188 include_dir (BusConfigParser *parser,
2189 const DBusString *dirname,
2192 DBusString filename;
2194 DBusError tmp_error;
2198 if (!_dbus_string_init (&filename))
2200 BUS_SET_OOM (error);
2206 dir = _dbus_directory_open (dirname, error);
2211 dbus_error_init (&tmp_error);
2212 while (_dbus_directory_get_next_file (dir, &filename, &tmp_error))
2214 DBusString full_path;
2216 if (!_dbus_string_init (&full_path))
2218 BUS_SET_OOM (error);
2222 if (!_dbus_string_copy (dirname, 0, &full_path, 0))
2224 BUS_SET_OOM (error);
2225 _dbus_string_free (&full_path);
2229 if (!_dbus_concat_dir_and_file (&full_path, &filename))
2231 BUS_SET_OOM (error);
2232 _dbus_string_free (&full_path);
2236 if (_dbus_string_ends_with_c_str (&full_path, ".conf"))
2238 if (!include_file (parser, &full_path, TRUE, error))
2240 if (dbus_error_is_set (error))
2242 /* We log to syslog unconditionally here, because this is
2243 * the configuration parser, so we don't yet know whether
2244 * this bus is going to want to write to syslog! (There's
2245 * also some layer inversion going on, if we want to use
2246 * the bus context.) */
2247 _dbus_system_log (DBUS_SYSTEM_LOG_INFO,
2248 "Encountered error '%s' while parsing '%s'\n",
2250 _dbus_string_get_const_data (&full_path));
2251 dbus_error_free (error);
2256 _dbus_string_free (&full_path);
2259 if (dbus_error_is_set (&tmp_error))
2261 dbus_move_error (&tmp_error, error);
2266 if (!_dbus_string_copy_data (dirname, &s))
2268 BUS_SET_OOM (error);
2272 if (!_dbus_list_append (&parser->conf_dirs, s))
2275 BUS_SET_OOM (error);
2282 _dbus_string_free (&filename);
2285 _dbus_directory_close (dir);
2291 bus_config_parser_content (BusConfigParser *parser,
2292 const DBusString *content,
2297 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
2303 _dbus_string_get_const_data (content, &c_str);
2305 printf ("CONTENT %d bytes: %s\n", _dbus_string_get_length (content), c_str);
2309 e = peek_element (parser);
2312 dbus_set_error (error, DBUS_ERROR_FAILED,
2313 "Text content outside of any XML element in configuration file");
2316 else if (e->had_content)
2318 _dbus_assert_not_reached ("Element had multiple content blocks");
2322 switch (top_element_type (parser))
2325 _dbus_assert_not_reached ("element at top of stack has no type");
2328 case ELEMENT_BUSCONFIG:
2329 case ELEMENT_POLICY:
2333 case ELEMENT_SYSLOG:
2334 case ELEMENT_KEEP_UMASK:
2335 case ELEMENT_STANDARD_SESSION_SERVICEDIRS:
2336 case ELEMENT_STANDARD_SYSTEM_SERVICEDIRS:
2337 case ELEMENT_ALLOW_ANONYMOUS:
2338 case ELEMENT_SELINUX:
2339 case ELEMENT_ASSOCIATE:
2340 if (all_whitespace (content))
2344 dbus_set_error (error, DBUS_ERROR_FAILED,
2345 "No text content expected inside XML element %s in configuration file",
2346 bus_config_parser_element_type_to_name (top_element_type (parser)));
2350 case ELEMENT_PIDFILE:
2354 e->had_content = TRUE;
2356 if (!_dbus_string_copy_data (content, &s))
2359 dbus_free (parser->pidfile);
2360 parser->pidfile = s;
2364 case ELEMENT_INCLUDE:
2366 DBusString full_path, selinux_policy_root;
2368 e->had_content = TRUE;
2370 if (e->d.include.if_selinux_enabled
2371 && !bus_selinux_enabled ())
2374 if (!_dbus_string_init (&full_path))
2377 if (e->d.include.selinux_root_relative)
2379 if (!bus_selinux_get_policy_root ())
2381 dbus_set_error (error, DBUS_ERROR_FAILED,
2382 "Could not determine SELinux policy root for relative inclusion");
2383 _dbus_string_free (&full_path);
2386 _dbus_string_init_const (&selinux_policy_root,
2387 bus_selinux_get_policy_root ());
2388 if (!make_full_path (&selinux_policy_root, content, &full_path))
2390 _dbus_string_free (&full_path);
2394 else if (!make_full_path (&parser->basedir, content, &full_path))
2396 _dbus_string_free (&full_path);
2400 if (!include_file (parser, &full_path,
2401 e->d.include.ignore_missing, error))
2403 _dbus_string_free (&full_path);
2407 _dbus_string_free (&full_path);
2411 case ELEMENT_SERVICEHELPER:
2413 DBusString full_path;
2415 e->had_content = TRUE;
2417 if (!_dbus_string_init (&full_path))
2420 if (!make_full_path (&parser->basedir, content, &full_path))
2422 _dbus_string_free (&full_path);
2426 if (!servicehelper_path (parser, &full_path, error))
2428 _dbus_string_free (&full_path);
2432 _dbus_string_free (&full_path);
2436 case ELEMENT_INCLUDEDIR:
2438 DBusString full_path;
2440 e->had_content = TRUE;
2442 if (!_dbus_string_init (&full_path))
2445 if (!make_full_path (&parser->basedir, content, &full_path))
2447 _dbus_string_free (&full_path);
2451 if (!include_dir (parser, &full_path, error))
2453 _dbus_string_free (&full_path);
2457 _dbus_string_free (&full_path);
2465 e->had_content = TRUE;
2467 if (!_dbus_string_copy_data (content, &s))
2470 dbus_free (parser->user);
2475 case ELEMENT_CONFIGTYPE:
2479 e->had_content = TRUE;
2481 if (!_dbus_string_copy_data (content, &s))
2484 dbus_free (parser->bus_type);
2485 parser->bus_type = s;
2489 case ELEMENT_LISTEN:
2493 e->had_content = TRUE;
2495 if (!_dbus_string_copy_data (content, &s))
2498 if (!_dbus_list_append (&parser->listen_on,
2511 e->had_content = TRUE;
2513 if (!_dbus_string_copy_data (content, &s))
2516 if (!_dbus_list_append (&parser->mechanisms,
2525 case ELEMENT_SERVICEDIR:
2528 DBusString full_path;
2530 e->had_content = TRUE;
2532 if (!_dbus_string_init (&full_path))
2535 if (!make_full_path (&parser->basedir, content, &full_path))
2537 _dbus_string_free (&full_path);
2541 if (!_dbus_string_copy_data (&full_path, &s))
2543 _dbus_string_free (&full_path);
2547 /* _only_ extra session directories can be specified */
2548 if (!service_dirs_append_unique_or_free (&parser->service_dirs, s))
2550 _dbus_string_free (&full_path);
2555 _dbus_string_free (&full_path);
2563 e->had_content = TRUE;
2566 if (!_dbus_string_parse_int (content, 0, &val, NULL))
2568 dbus_set_error (error, DBUS_ERROR_FAILED,
2569 "<limit name=\"%s\"> element has invalid value (could not parse as integer)",
2574 e->d.limit.value = val;
2576 _dbus_verbose ("Loaded value %ld for limit %s\n",
2583 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
2587 BUS_SET_OOM (error);
2592 bus_config_parser_finished (BusConfigParser *parser,
2595 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
2597 if (parser->stack != NULL)
2599 dbus_set_error (error, DBUS_ERROR_FAILED,
2600 "Element <%s> was not closed in configuration file",
2601 bus_config_parser_element_type_to_name (top_element_type (parser)));
2606 if (parser->is_toplevel && parser->listen_on == NULL)
2608 dbus_set_error (error, DBUS_ERROR_FAILED,
2609 "Configuration file needs one or more <listen> elements giving addresses");
2617 bus_config_parser_get_user (BusConfigParser *parser)
2619 return parser->user;
2623 bus_config_parser_get_type (BusConfigParser *parser)
2625 return parser->bus_type;
2629 bus_config_parser_get_addresses (BusConfigParser *parser)
2631 return &parser->listen_on;
2635 bus_config_parser_get_mechanisms (BusConfigParser *parser)
2637 return &parser->mechanisms;
2641 bus_config_parser_get_service_dirs (BusConfigParser *parser)
2643 return &parser->service_dirs;
2647 bus_config_parser_get_conf_dirs (BusConfigParser *parser)
2649 return &parser->conf_dirs;
2653 bus_config_parser_get_fork (BusConfigParser *parser)
2655 return parser->fork;
2659 bus_config_parser_get_syslog (BusConfigParser *parser)
2661 return parser->syslog;
2665 bus_config_parser_get_keep_umask (BusConfigParser *parser)
2667 return parser->keep_umask;
2671 bus_config_parser_get_allow_anonymous (BusConfigParser *parser)
2673 return parser->allow_anonymous;
2677 bus_config_parser_get_pidfile (BusConfigParser *parser)
2679 return parser->pidfile;
2683 bus_config_parser_get_servicehelper (BusConfigParser *parser)
2685 return parser->servicehelper;
2689 bus_config_parser_steal_policy (BusConfigParser *parser)
2693 _dbus_assert (parser->policy != NULL); /* can only steal the policy 1 time */
2695 policy = parser->policy;
2697 parser->policy = NULL;
2702 /* Overwrite any limits that were set in the configuration file */
2704 bus_config_parser_get_limits (BusConfigParser *parser,
2707 *limits = parser->limits;
2711 bus_config_parser_steal_service_context_table (BusConfigParser *parser)
2713 DBusHashTable *table;
2715 _dbus_assert (parser->service_context_table != NULL); /* can only steal once */
2717 table = parser->service_context_table;
2719 parser->service_context_table = NULL;
2724 #ifdef DBUS_BUILD_TESTS
2735 do_load (const DBusString *full_path,
2737 dbus_bool_t oom_possible)
2739 BusConfigParser *parser;
2742 dbus_error_init (&error);
2744 parser = bus_config_load (full_path, TRUE, NULL, &error);
2747 _DBUS_ASSERT_ERROR_IS_SET (&error);
2750 dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
2752 _dbus_verbose ("Failed to load valid file due to OOM\n");
2753 dbus_error_free (&error);
2756 else if (validity == VALID)
2758 _dbus_warn ("Failed to load valid file but still had memory: %s\n",
2761 dbus_error_free (&error);
2766 dbus_error_free (&error);
2772 _DBUS_ASSERT_ERROR_IS_CLEAR (&error);
2774 bus_config_parser_unref (parser);
2776 if (validity == INVALID)
2778 _dbus_warn ("Accepted invalid file\n");
2788 const DBusString *full_path;
2793 check_loader_oom_func (void *data)
2795 LoaderOomData *d = data;
2797 return do_load (d->full_path, d->validity, TRUE);
2801 process_test_valid_subdir (const DBusString *test_base_dir,
2805 DBusString test_directory;
2806 DBusString filename;
2814 if (!_dbus_string_init (&test_directory))
2815 _dbus_assert_not_reached ("didn't allocate test_directory\n");
2817 _dbus_string_init_const (&filename, subdir);
2819 if (!_dbus_string_copy (test_base_dir, 0,
2820 &test_directory, 0))
2821 _dbus_assert_not_reached ("couldn't copy test_base_dir to test_directory");
2823 if (!_dbus_concat_dir_and_file (&test_directory, &filename))
2824 _dbus_assert_not_reached ("couldn't allocate full path");
2826 _dbus_string_free (&filename);
2827 if (!_dbus_string_init (&filename))
2828 _dbus_assert_not_reached ("didn't allocate filename string\n");
2830 dbus_error_init (&error);
2831 dir = _dbus_directory_open (&test_directory, &error);
2834 _dbus_warn ("Could not open %s: %s\n",
2835 _dbus_string_get_const_data (&test_directory),
2837 dbus_error_free (&error);
2841 if (validity == VALID)
2842 printf ("Testing valid files:\n");
2843 else if (validity == INVALID)
2844 printf ("Testing invalid files:\n");
2846 printf ("Testing unknown files:\n");
2849 while (_dbus_directory_get_next_file (dir, &filename, &error))
2851 DBusString full_path;
2854 if (!_dbus_string_init (&full_path))
2855 _dbus_assert_not_reached ("couldn't init string");
2857 if (!_dbus_string_copy (&test_directory, 0, &full_path, 0))
2858 _dbus_assert_not_reached ("couldn't copy dir to full_path");
2860 if (!_dbus_concat_dir_and_file (&full_path, &filename))
2861 _dbus_assert_not_reached ("couldn't concat file to dir");
2863 if (!_dbus_string_ends_with_c_str (&full_path, ".conf"))
2865 _dbus_verbose ("Skipping non-.conf file %s\n",
2866 _dbus_string_get_const_data (&filename));
2867 _dbus_string_free (&full_path);
2871 printf (" %s\n", _dbus_string_get_const_data (&filename));
2873 _dbus_verbose (" expecting %s\n",
2874 validity == VALID ? "valid" :
2875 (validity == INVALID ? "invalid" :
2876 (validity == UNKNOWN ? "unknown" : "???")));
2878 d.full_path = &full_path;
2879 d.validity = validity;
2881 /* FIXME hackaround for an expat problem, see
2882 * https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=124747
2883 * http://freedesktop.org/pipermail/dbus/2004-May/001153.html
2885 /* if (!_dbus_test_oom_handling ("config-loader", check_loader_oom_func, &d)) */
2886 if (!check_loader_oom_func (&d))
2887 _dbus_assert_not_reached ("test failed");
2889 _dbus_string_free (&full_path);
2892 if (dbus_error_is_set (&error))
2894 _dbus_warn ("Could not get next file in %s: %s\n",
2895 _dbus_string_get_const_data (&test_directory),
2897 dbus_error_free (&error);
2906 _dbus_directory_close (dir);
2907 _dbus_string_free (&test_directory);
2908 _dbus_string_free (&filename);
2914 bools_equal (dbus_bool_t a,
2921 strings_equal_or_both_null (const char *a,
2924 if (a == NULL || b == NULL)
2927 return !strcmp (a, b);
2931 elements_equal (const Element *a,
2934 if (a->type != b->type)
2937 if (!bools_equal (a->had_content, b->had_content))
2943 case ELEMENT_INCLUDE:
2944 if (!bools_equal (a->d.include.ignore_missing,
2945 b->d.include.ignore_missing))
2949 case ELEMENT_POLICY:
2950 if (a->d.policy.type != b->d.policy.type)
2952 if (a->d.policy.gid_uid_or_at_console != b->d.policy.gid_uid_or_at_console)
2957 if (strcmp (a->d.limit.name, b->d.limit.name))
2959 if (a->d.limit.value != b->d.limit.value)
2973 lists_of_elements_equal (DBusList *a,
2982 while (ia != NULL && ib != NULL)
2984 if (elements_equal (ia->data, ib->data))
2986 ia = _dbus_list_get_next_link (&a, ia);
2987 ib = _dbus_list_get_next_link (&b, ib);
2990 return ia == NULL && ib == NULL;
2994 lists_of_c_strings_equal (DBusList *a,
3003 while (ia != NULL && ib != NULL)
3005 if (strcmp (ia->data, ib->data))
3007 ia = _dbus_list_get_next_link (&a, ia);
3008 ib = _dbus_list_get_next_link (&b, ib);
3011 return ia == NULL && ib == NULL;
3015 limits_equal (const BusLimits *a,
3019 (a->max_incoming_bytes == b->max_incoming_bytes
3020 || a->max_incoming_unix_fds == b->max_incoming_unix_fds
3021 || a->max_outgoing_bytes == b->max_outgoing_bytes
3022 || a->max_outgoing_unix_fds == b->max_outgoing_unix_fds
3023 || a->max_message_size == b->max_message_size
3024 || a->max_message_unix_fds == b->max_message_unix_fds
3025 || a->activation_timeout == b->activation_timeout
3026 || a->auth_timeout == b->auth_timeout
3027 || a->max_completed_connections == b->max_completed_connections
3028 || a->max_incomplete_connections == b->max_incomplete_connections
3029 || a->max_connections_per_user == b->max_connections_per_user
3030 || a->max_pending_activations == b->max_pending_activations
3031 || a->max_services_per_connection == b->max_services_per_connection
3032 || a->max_match_rules_per_connection == b->max_match_rules_per_connection
3033 || a->max_replies_per_connection == b->max_replies_per_connection
3034 || a->reply_timeout == b->reply_timeout);
3038 config_parsers_equal (const BusConfigParser *a,
3039 const BusConfigParser *b)
3041 if (!_dbus_string_equal (&a->basedir, &b->basedir))
3044 if (!lists_of_elements_equal (a->stack, b->stack))
3047 if (!strings_equal_or_both_null (a->user, b->user))
3050 if (!lists_of_c_strings_equal (a->listen_on, b->listen_on))
3053 if (!lists_of_c_strings_equal (a->mechanisms, b->mechanisms))
3056 if (!lists_of_c_strings_equal (a->service_dirs, b->service_dirs))
3059 /* FIXME: compare policy */
3061 /* FIXME: compare service selinux ID table */
3063 if (! limits_equal (&a->limits, &b->limits))
3066 if (!strings_equal_or_both_null (a->pidfile, b->pidfile))
3069 if (! bools_equal (a->fork, b->fork))
3072 if (! bools_equal (a->keep_umask, b->keep_umask))
3075 if (! bools_equal (a->is_toplevel, b->is_toplevel))
3082 all_are_equiv (const DBusString *target_directory)
3084 DBusString filename;
3086 BusConfigParser *first_parser;
3087 BusConfigParser *parser;
3093 first_parser = NULL;
3097 if (!_dbus_string_init (&filename))
3098 _dbus_assert_not_reached ("didn't allocate filename string");
3100 dbus_error_init (&error);
3101 dir = _dbus_directory_open (target_directory, &error);
3104 _dbus_warn ("Could not open %s: %s\n",
3105 _dbus_string_get_const_data (target_directory),
3107 dbus_error_free (&error);
3111 printf ("Comparing equivalent files:\n");
3114 while (_dbus_directory_get_next_file (dir, &filename, &error))
3116 DBusString full_path;
3118 if (!_dbus_string_init (&full_path))
3119 _dbus_assert_not_reached ("couldn't init string");
3121 if (!_dbus_string_copy (target_directory, 0, &full_path, 0))
3122 _dbus_assert_not_reached ("couldn't copy dir to full_path");
3124 if (!_dbus_concat_dir_and_file (&full_path, &filename))
3125 _dbus_assert_not_reached ("couldn't concat file to dir");
3127 if (!_dbus_string_ends_with_c_str (&full_path, ".conf"))
3129 _dbus_verbose ("Skipping non-.conf file %s\n",
3130 _dbus_string_get_const_data (&filename));
3131 _dbus_string_free (&full_path);
3135 printf (" %s\n", _dbus_string_get_const_data (&filename));
3137 parser = bus_config_load (&full_path, TRUE, NULL, &error);
3141 _dbus_warn ("Could not load file %s: %s\n",
3142 _dbus_string_get_const_data (&full_path),
3144 _dbus_string_free (&full_path);
3145 dbus_error_free (&error);
3148 else if (first_parser == NULL)
3150 _dbus_string_free (&full_path);
3151 first_parser = parser;
3155 _dbus_string_free (&full_path);
3156 equal = config_parsers_equal (first_parser, parser);
3157 bus_config_parser_unref (parser);
3166 _dbus_string_free (&filename);
3168 bus_config_parser_unref (first_parser);
3170 _dbus_directory_close (dir);
3177 process_test_equiv_subdir (const DBusString *test_base_dir,
3180 DBusString test_directory;
3181 DBusString filename;
3190 if (!_dbus_string_init (&test_directory))
3191 _dbus_assert_not_reached ("didn't allocate test_directory");
3193 _dbus_string_init_const (&filename, subdir);
3195 if (!_dbus_string_copy (test_base_dir, 0,
3196 &test_directory, 0))
3197 _dbus_assert_not_reached ("couldn't copy test_base_dir to test_directory");
3199 if (!_dbus_concat_dir_and_file (&test_directory, &filename))
3200 _dbus_assert_not_reached ("couldn't allocate full path");
3202 _dbus_string_free (&filename);
3203 if (!_dbus_string_init (&filename))
3204 _dbus_assert_not_reached ("didn't allocate filename string");
3206 dbus_error_init (&error);
3207 dir = _dbus_directory_open (&test_directory, &error);
3210 _dbus_warn ("Could not open %s: %s\n",
3211 _dbus_string_get_const_data (&test_directory),
3213 dbus_error_free (&error);
3217 while (_dbus_directory_get_next_file (dir, &filename, &error))
3219 DBusString full_path;
3221 /* Skip CVS's magic directories! */
3222 if (_dbus_string_equal_c_str (&filename, "CVS"))
3225 if (!_dbus_string_init (&full_path))
3226 _dbus_assert_not_reached ("couldn't init string");
3228 if (!_dbus_string_copy (&test_directory, 0, &full_path, 0))
3229 _dbus_assert_not_reached ("couldn't copy dir to full_path");
3231 if (!_dbus_concat_dir_and_file (&full_path, &filename))
3232 _dbus_assert_not_reached ("couldn't concat file to dir");
3234 equal = all_are_equiv (&full_path);
3235 _dbus_string_free (&full_path);
3244 _dbus_string_free (&test_directory);
3245 _dbus_string_free (&filename);
3247 _dbus_directory_close (dir);
3253 static const char *test_session_service_dir_matches[] =
3256 "/testhome/foo/.testlocal/testshare/dbus-1/services",
3257 "/testusr/testlocal/testshare/dbus-1/services",
3258 "/testusr/testshare/dbus-1/services",
3259 DBUS_DATADIR"/dbus-1/services",
3261 /* will be filled in test_default_session_servicedirs() */
3270 test_default_session_servicedirs (void)
3275 const char *common_progs;
3280 if (_dbus_get_install_root(buffer, sizeof(buffer)))
3282 strcat(buffer,DBUS_DATADIR);
3283 strcat(buffer,"/dbus-1/services");
3284 test_session_service_dir_matches[0] = buffer;
3288 /* On Unix we don't actually use this variable, but it's easier to handle the
3289 * deallocation if we always allocate it, whether needed or not */
3290 if (!_dbus_string_init (&progs))
3291 _dbus_assert_not_reached ("OOM allocating progs");
3293 common_progs = _dbus_getenv ("CommonProgramFiles");
3297 if (!_dbus_string_append (&progs, common_progs))
3299 _dbus_string_free (&progs);
3303 if (!_dbus_string_append (&progs, "/dbus-1/services"))
3305 _dbus_string_free (&progs);
3308 test_session_service_dir_matches[1] = _dbus_string_get_const_data(&progs);
3313 printf ("Testing retrieving the default session service directories\n");
3314 if (!_dbus_get_standard_session_servicedirs (&dirs))
3315 _dbus_assert_not_reached ("couldn't get stardard dirs");
3317 /* make sure our defaults end with share/dbus-1/service */
3318 while ((link = _dbus_list_pop_first_link (&dirs)))
3322 printf (" default service dir: %s\n", (char *)link->data);
3323 _dbus_string_init_const (&path, (char *)link->data);
3324 if (!_dbus_string_ends_with_c_str (&path, "dbus-1/services"))
3326 printf ("error with default session service directories\n");
3327 dbus_free (link->data);
3328 _dbus_list_free_link (link);
3329 _dbus_string_free (&progs);
3333 dbus_free (link->data);
3334 _dbus_list_free_link (link);
3338 if (!_dbus_setenv ("XDG_DATA_HOME", "/testhome/foo/.testlocal/testshare"))
3339 _dbus_assert_not_reached ("couldn't setenv XDG_DATA_HOME");
3341 if (!_dbus_setenv ("XDG_DATA_DIRS", ":/testusr/testlocal/testshare: :/testusr/testshare:"))
3342 _dbus_assert_not_reached ("couldn't setenv XDG_DATA_DIRS");
3344 if (!_dbus_get_standard_session_servicedirs (&dirs))
3345 _dbus_assert_not_reached ("couldn't get stardard dirs");
3347 /* make sure we read and parse the env variable correctly */
3349 while ((link = _dbus_list_pop_first_link (&dirs)))
3351 printf (" test service dir: %s\n", (char *)link->data);
3352 if (test_session_service_dir_matches[i] == NULL)
3354 printf ("more directories parsed than in match set\n");
3355 dbus_free (link->data);
3356 _dbus_list_free_link (link);
3357 _dbus_string_free (&progs);
3361 if (strcmp (test_session_service_dir_matches[i],
3362 (char *)link->data) != 0)
3364 printf ("%s directory does not match %s in the match set\n",
3366 test_session_service_dir_matches[i]);
3367 dbus_free (link->data);
3368 _dbus_list_free_link (link);
3369 _dbus_string_free (&progs);
3375 dbus_free (link->data);
3376 _dbus_list_free_link (link);
3379 if (test_session_service_dir_matches[i] != NULL)
3381 printf ("extra data %s in the match set was not matched\n",
3382 test_session_service_dir_matches[i]);
3384 _dbus_string_free (&progs);
3388 _dbus_string_free (&progs);
3392 static const char *test_system_service_dir_matches[] =
3395 "/testusr/testlocal/testshare/dbus-1/system-services",
3396 "/testusr/testshare/dbus-1/system-services",
3398 DBUS_DATADIR"/dbus-1/system-services",
3406 test_default_system_servicedirs (void)
3411 const char *common_progs;
3414 /* On Unix we don't actually use this variable, but it's easier to handle the
3415 * deallocation if we always allocate it, whether needed or not */
3416 if (!_dbus_string_init (&progs))
3417 _dbus_assert_not_reached ("OOM allocating progs");
3419 common_progs = _dbus_getenv ("CommonProgramFiles");
3423 if (!_dbus_string_append (&progs, common_progs))
3425 _dbus_string_free (&progs);
3429 if (!_dbus_string_append (&progs, "/dbus-1/system-services"))
3431 _dbus_string_free (&progs);
3434 test_system_service_dir_matches[1] = _dbus_string_get_const_data(&progs);
3439 printf ("Testing retrieving the default system service directories\n");
3440 if (!_dbus_get_standard_system_servicedirs (&dirs))
3441 _dbus_assert_not_reached ("couldn't get stardard dirs");
3443 /* make sure our defaults end with share/dbus-1/system-service */
3444 while ((link = _dbus_list_pop_first_link (&dirs)))
3448 printf (" default service dir: %s\n", (char *)link->data);
3449 _dbus_string_init_const (&path, (char *)link->data);
3450 if (!_dbus_string_ends_with_c_str (&path, "dbus-1/system-services"))
3452 printf ("error with default system service directories\n");
3453 dbus_free (link->data);
3454 _dbus_list_free_link (link);
3455 _dbus_string_free (&progs);
3459 dbus_free (link->data);
3460 _dbus_list_free_link (link);
3464 if (!_dbus_setenv ("XDG_DATA_HOME", "/testhome/foo/.testlocal/testshare"))
3465 _dbus_assert_not_reached ("couldn't setenv XDG_DATA_HOME");
3467 if (!_dbus_setenv ("XDG_DATA_DIRS", ":/testusr/testlocal/testshare: :/testusr/testshare:"))
3468 _dbus_assert_not_reached ("couldn't setenv XDG_DATA_DIRS");
3470 if (!_dbus_get_standard_system_servicedirs (&dirs))
3471 _dbus_assert_not_reached ("couldn't get stardard dirs");
3473 /* make sure we read and parse the env variable correctly */
3475 while ((link = _dbus_list_pop_first_link (&dirs)))
3477 printf (" test service dir: %s\n", (char *)link->data);
3478 if (test_system_service_dir_matches[i] == NULL)
3480 printf ("more directories parsed than in match set\n");
3481 dbus_free (link->data);
3482 _dbus_list_free_link (link);
3483 _dbus_string_free (&progs);
3487 if (strcmp (test_system_service_dir_matches[i],
3488 (char *)link->data) != 0)
3490 printf ("%s directory does not match %s in the match set\n",
3492 test_system_service_dir_matches[i]);
3493 dbus_free (link->data);
3494 _dbus_list_free_link (link);
3495 _dbus_string_free (&progs);
3501 dbus_free (link->data);
3502 _dbus_list_free_link (link);
3505 if (test_system_service_dir_matches[i] != NULL)
3507 printf ("extra data %s in the match set was not matched\n",
3508 test_system_service_dir_matches[i]);
3510 _dbus_string_free (&progs);
3514 _dbus_string_free (&progs);
3519 bus_config_parser_test (const DBusString *test_data_dir)
3521 if (test_data_dir == NULL ||
3522 _dbus_string_get_length (test_data_dir) == 0)
3524 printf ("No test data\n");
3528 if (!test_default_session_servicedirs())
3532 printf("default system service dir skipped\n");
3534 if (!test_default_system_servicedirs())
3538 if (!process_test_valid_subdir (test_data_dir, "valid-config-files", VALID))
3541 if (!process_test_valid_subdir (test_data_dir, "invalid-config-files", INVALID))
3544 if (!process_test_equiv_subdir (test_data_dir, "equiv-config-files"))
3550 #endif /* DBUS_BUILD_TESTS */