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"
32 #include <dbus/dbus-list.h>
33 #include <dbus/dbus-internals.h>
34 #include <dbus/dbus-misc.h>
35 #include <dbus/dbus-sysdeps.h>
40 /* we ignore policies for unknown groups/users */
55 unsigned int had_content : 1;
61 unsigned int ignore_missing : 1;
62 unsigned int if_selinux_enabled : 1;
63 unsigned int selinux_root_relative : 1;
69 unsigned long gid_uid_or_at_console;
83 * Parser for bus configuration file.
85 struct BusConfigParser
87 int refcount; /**< Reference count */
89 DBusString basedir; /**< Directory we resolve paths relative to */
91 DBusList *stack; /**< stack of Element */
93 char *user; /**< user to run as */
95 char *servicehelper; /**< location of the setuid helper */
97 char *bus_type; /**< Message bus type */
99 DBusList *listen_on; /**< List of addresses to listen to */
101 DBusList *mechanisms; /**< Auth mechanisms */
103 DBusList *service_dirs; /**< Directories to look for session services in */
105 DBusList *conf_dirs; /**< Directories to look for policy configuration in */
107 BusPolicy *policy; /**< Security policy */
109 BusLimits limits; /**< Limits */
111 char *pidfile; /**< PID file */
113 DBusList *included_files; /**< Included files stack */
115 DBusHashTable *service_context_table; /**< Map service names to SELinux contexts */
117 unsigned int fork : 1; /**< TRUE to fork into daemon mode */
119 unsigned int syslog : 1; /**< TRUE to enable syslog */
120 unsigned int keep_umask : 1; /**< TRUE to keep original umask when forking */
122 unsigned int is_toplevel : 1; /**< FALSE if we are a sub-config-file inside another one */
124 unsigned int allow_anonymous : 1; /**< TRUE to allow anonymous connections */
128 push_element (BusConfigParser *parser,
133 _dbus_assert (type != ELEMENT_NONE);
135 e = dbus_new0 (Element, 1);
139 if (!_dbus_list_append (&parser->stack, e))
151 element_free (Element *e)
153 if (e->type == ELEMENT_LIMIT)
154 dbus_free (e->d.limit.name);
160 pop_element (BusConfigParser *parser)
164 e = _dbus_list_pop_last (&parser->stack);
170 peek_element (BusConfigParser *parser)
174 e = _dbus_list_get_last (&parser->stack);
180 top_element_type (BusConfigParser *parser)
184 e = _dbus_list_get_last (&parser->stack);
193 merge_service_context_hash (DBusHashTable *dest,
203 _dbus_hash_iter_init (from, &iter);
204 while (_dbus_hash_iter_next (&iter))
206 const char *service = _dbus_hash_iter_get_string_key (&iter);
207 const char *context = _dbus_hash_iter_get_value (&iter);
209 service_copy = _dbus_strdup (service);
210 if (service_copy == NULL)
212 context_copy = _dbus_strdup (context);
213 if (context_copy == NULL)
216 if (!_dbus_hash_table_insert_string (dest, service_copy, context_copy))
227 dbus_free (service_copy);
230 dbus_free (context_copy);
236 service_dirs_find_dir (DBusList **service_dirs,
241 _dbus_assert (dir != NULL);
243 for (link = *service_dirs; link; link = _dbus_list_get_next_link(service_dirs, link))
245 const char *link_dir;
247 link_dir = (const char *)link->data;
248 if (strcmp (dir, link_dir) == 0)
256 service_dirs_append_link_unique_or_free (DBusList **service_dirs,
259 if (!service_dirs_find_dir (service_dirs, dir_link->data))
261 _dbus_list_append_link (service_dirs, dir_link);
265 dbus_free (dir_link->data);
266 _dbus_list_free_link (dir_link);
271 merge_included (BusConfigParser *parser,
272 BusConfigParser *included,
277 if (!bus_policy_merge (parser->policy,
284 if (!merge_service_context_hash (parser->service_context_table,
285 included->service_context_table))
291 if (included->user != NULL)
293 dbus_free (parser->user);
294 parser->user = included->user;
295 included->user = NULL;
298 if (included->bus_type != NULL)
300 dbus_free (parser->bus_type);
301 parser->bus_type = included->bus_type;
302 included->bus_type = NULL;
308 if (included->keep_umask)
309 parser->keep_umask = TRUE;
311 if (included->allow_anonymous)
312 parser->allow_anonymous = TRUE;
314 if (included->pidfile != NULL)
316 dbus_free (parser->pidfile);
317 parser->pidfile = included->pidfile;
318 included->pidfile = NULL;
321 if (included->servicehelper != NULL)
323 dbus_free (parser->servicehelper);
324 parser->servicehelper = included->servicehelper;
325 included->servicehelper = NULL;
328 while ((link = _dbus_list_pop_first_link (&included->listen_on)))
329 _dbus_list_append_link (&parser->listen_on, link);
331 while ((link = _dbus_list_pop_first_link (&included->mechanisms)))
332 _dbus_list_append_link (&parser->mechanisms, link);
334 while ((link = _dbus_list_pop_first_link (&included->service_dirs)))
335 service_dirs_append_link_unique_or_free (&parser->service_dirs, link);
337 while ((link = _dbus_list_pop_first_link (&included->conf_dirs)))
338 _dbus_list_append_link (&parser->conf_dirs, link);
344 seen_include (BusConfigParser *parser,
345 const DBusString *file)
349 iter = parser->included_files;
352 if (! strcmp (_dbus_string_get_const_data (file), iter->data))
355 iter = _dbus_list_get_next_link (&parser->included_files, iter);
362 bus_config_parser_new (const DBusString *basedir,
363 dbus_bool_t is_toplevel,
364 const BusConfigParser *parent)
366 BusConfigParser *parser;
368 parser = dbus_new0 (BusConfigParser, 1);
372 parser->is_toplevel = !!is_toplevel;
374 if (!_dbus_string_init (&parser->basedir))
380 if (((parser->policy = bus_policy_new ()) == NULL) ||
381 !_dbus_string_copy (basedir, 0, &parser->basedir, 0) ||
382 ((parser->service_context_table = _dbus_hash_table_new (DBUS_HASH_STRING,
384 dbus_free)) == NULL))
387 bus_policy_unref (parser->policy);
389 _dbus_string_free (&parser->basedir);
397 /* Initialize the parser's limits from the parent. */
398 parser->limits = parent->limits;
400 /* Use the parent's list of included_files to avoid
401 circular inclusions. */
402 parser->included_files = parent->included_files;
407 /* Make up some numbers! woot! */
408 parser->limits.max_incoming_bytes = _DBUS_ONE_MEGABYTE * 127;
409 parser->limits.max_outgoing_bytes = _DBUS_ONE_MEGABYTE * 127;
410 parser->limits.max_message_size = _DBUS_ONE_MEGABYTE * 32;
412 /* We set relatively conservative values here since due to the
413 way SCM_RIGHTS works we need to preallocate an array for the
414 maximum number of file descriptors we can receive. Picking a
415 high value here thus translates directly to more memory
417 parser->limits.max_incoming_unix_fds = DBUS_DEFAULT_MESSAGE_UNIX_FDS*4;
418 parser->limits.max_outgoing_unix_fds = DBUS_DEFAULT_MESSAGE_UNIX_FDS*4;
419 parser->limits.max_message_unix_fds = DBUS_DEFAULT_MESSAGE_UNIX_FDS;
421 /* Making this long means the user has to wait longer for an error
422 * message if something screws up, but making it too short means
423 * they might see a false failure.
425 parser->limits.activation_timeout = 25000; /* 25 seconds */
427 /* Making this long risks making a DOS attack easier, but too short
428 * and legitimate auth will fail. If interactive auth (ask user for
429 * password) is allowed, then potentially it has to be quite long.
431 parser->limits.auth_timeout = 30000; /* 30 seconds */
433 /* Do not allow a fd to stay forever in dbus-daemon
434 * https://bugs.freedesktop.org/show_bug.cgi?id=80559
436 parser->limits.pending_fd_timeout = 150000; /* 2.5 minutes */
438 parser->limits.max_incomplete_connections = 64;
439 parser->limits.max_connections_per_user = 256;
441 /* Note that max_completed_connections / max_connections_per_user
442 * is the number of users that would have to work together to
443 * DOS all the other users.
445 parser->limits.max_completed_connections = 2048;
447 parser->limits.max_pending_activations = 512;
448 parser->limits.max_services_per_connection = 512;
450 /* For this one, keep in mind that it isn't only the memory used
451 * by the match rules, but slowdown from linearly walking a big
452 * list of them. A client adding more than this is almost
453 * certainly a bad idea for that reason, and should change to a
454 * smaller number of wider-net match rules - getting every last
455 * message to the bus is probably better than having a thousand
458 parser->limits.max_match_rules_per_connection = 512;
460 parser->limits.reply_timeout = -1; /* never */
462 /* this is effectively a limit on message queue size for messages
463 * that require a reply
465 parser->limits.max_replies_per_connection = 128;
468 parser->refcount = 1;
474 bus_config_parser_ref (BusConfigParser *parser)
476 _dbus_assert (parser->refcount > 0);
478 parser->refcount += 1;
484 bus_config_parser_unref (BusConfigParser *parser)
486 _dbus_assert (parser->refcount > 0);
488 parser->refcount -= 1;
490 if (parser->refcount == 0)
492 while (parser->stack != NULL)
493 pop_element (parser);
495 dbus_free (parser->user);
496 dbus_free (parser->servicehelper);
497 dbus_free (parser->bus_type);
498 dbus_free (parser->pidfile);
500 _dbus_list_foreach (&parser->listen_on,
501 (DBusForeachFunction) dbus_free,
504 _dbus_list_clear (&parser->listen_on);
506 _dbus_list_foreach (&parser->service_dirs,
507 (DBusForeachFunction) dbus_free,
510 _dbus_list_clear (&parser->service_dirs);
512 _dbus_list_foreach (&parser->conf_dirs,
513 (DBusForeachFunction) dbus_free,
516 _dbus_list_clear (&parser->conf_dirs);
518 _dbus_list_foreach (&parser->mechanisms,
519 (DBusForeachFunction) dbus_free,
522 _dbus_list_clear (&parser->mechanisms);
524 _dbus_string_free (&parser->basedir);
527 bus_policy_unref (parser->policy);
529 if (parser->service_context_table)
530 _dbus_hash_table_unref (parser->service_context_table);
537 bus_config_parser_check_doctype (BusConfigParser *parser,
541 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
543 if (strcmp (doctype, "busconfig") != 0)
545 dbus_set_error (error,
547 "Configuration file has the wrong document type %s",
562 locate_attributes (BusConfigParser *parser,
563 const char *element_name,
564 const char **attribute_names,
565 const char **attribute_values,
567 const char *first_attribute_name,
568 const char **first_attribute_retloc,
576 LocateAttr attrs[MAX_ATTRS];
580 _dbus_assert (first_attribute_name != NULL);
581 _dbus_assert (first_attribute_retloc != NULL);
586 attrs[0].name = first_attribute_name;
587 attrs[0].retloc = first_attribute_retloc;
588 *first_attribute_retloc = NULL;
590 va_start (args, first_attribute_retloc);
592 name = va_arg (args, const char*);
593 retloc = va_arg (args, const char**);
597 _dbus_assert (retloc != NULL);
598 _dbus_assert (n_attrs < MAX_ATTRS);
600 attrs[n_attrs].name = name;
601 attrs[n_attrs].retloc = retloc;
605 name = va_arg (args, const char*);
606 retloc = va_arg (args, const char**);
612 while (attribute_names[i])
621 if (strcmp (attrs[j].name, attribute_names[i]) == 0)
623 retloc = attrs[j].retloc;
627 dbus_set_error (error, DBUS_ERROR_FAILED,
628 "Attribute \"%s\" repeated twice on the same <%s> element",
629 attrs[j].name, element_name);
634 *retloc = attribute_values[i];
643 dbus_set_error (error, DBUS_ERROR_FAILED,
644 "Attribute \"%s\" is invalid on <%s> element in this context",
645 attribute_names[i], element_name);
658 check_no_attributes (BusConfigParser *parser,
659 const char *element_name,
660 const char **attribute_names,
661 const char **attribute_values,
664 if (attribute_names[0] != NULL)
666 dbus_set_error (error, DBUS_ERROR_FAILED,
667 "Attribute \"%s\" is invalid on <%s> element in this context",
668 attribute_names[0], element_name);
676 start_busconfig_child (BusConfigParser *parser,
677 const char *element_name,
678 const char **attribute_names,
679 const char **attribute_values,
682 ElementType element_type;
684 element_type = bus_config_parser_element_name_to_type (element_name);
686 if (element_type == ELEMENT_USER)
688 if (!check_no_attributes (parser, "user", attribute_names, attribute_values, error))
691 if (push_element (parser, ELEMENT_USER) == NULL)
699 else if (element_type == ELEMENT_CONFIGTYPE)
701 if (!check_no_attributes (parser, "type", attribute_names, attribute_values, error))
704 if (push_element (parser, ELEMENT_CONFIGTYPE) == NULL)
712 else if (element_type == ELEMENT_FORK)
714 if (!check_no_attributes (parser, "fork", attribute_names, attribute_values, error))
717 if (push_element (parser, ELEMENT_FORK) == NULL)
727 else if (element_type == ELEMENT_SYSLOG)
729 if (!check_no_attributes (parser, "syslog", attribute_names, attribute_values, error))
732 if (push_element (parser, ELEMENT_SYSLOG) == NULL)
738 parser->syslog = TRUE;
742 else if (element_type == ELEMENT_KEEP_UMASK)
744 if (!check_no_attributes (parser, "keep_umask", attribute_names, attribute_values, error))
747 if (push_element (parser, ELEMENT_KEEP_UMASK) == NULL)
753 parser->keep_umask = TRUE;
757 else if (element_type == ELEMENT_PIDFILE)
759 if (!check_no_attributes (parser, "pidfile", attribute_names, attribute_values, error))
762 if (push_element (parser, ELEMENT_PIDFILE) == NULL)
770 else if (element_type == ELEMENT_LISTEN)
772 if (!check_no_attributes (parser, "listen", attribute_names, attribute_values, error))
775 if (push_element (parser, ELEMENT_LISTEN) == NULL)
783 else if (element_type == ELEMENT_AUTH)
785 if (!check_no_attributes (parser, "auth", attribute_names, attribute_values, error))
788 if (push_element (parser, ELEMENT_AUTH) == NULL)
796 else if (element_type == ELEMENT_SERVICEHELPER)
798 if (!check_no_attributes (parser, "servicehelper", attribute_names, attribute_values, error))
801 if (push_element (parser, ELEMENT_SERVICEHELPER) == NULL)
809 else if (element_type == ELEMENT_INCLUDEDIR)
811 if (!check_no_attributes (parser, "includedir", attribute_names, attribute_values, error))
814 if (push_element (parser, ELEMENT_INCLUDEDIR) == NULL)
822 else if (element_type == ELEMENT_STANDARD_SESSION_SERVICEDIRS)
828 if (!check_no_attributes (parser, "standard_session_servicedirs", attribute_names, attribute_values, error))
831 if (push_element (parser, ELEMENT_STANDARD_SESSION_SERVICEDIRS) == NULL)
837 if (!_dbus_get_standard_session_servicedirs (&dirs))
843 while ((link = _dbus_list_pop_first_link (&dirs)))
844 service_dirs_append_link_unique_or_free (&parser->service_dirs, link);
848 else if (element_type == ELEMENT_STANDARD_SYSTEM_SERVICEDIRS)
854 if (!check_no_attributes (parser, "standard_system_servicedirs", attribute_names, attribute_values, error))
857 if (push_element (parser, ELEMENT_STANDARD_SYSTEM_SERVICEDIRS) == NULL)
863 if (!_dbus_get_standard_system_servicedirs (&dirs))
869 while ((link = _dbus_list_pop_first_link (&dirs)))
870 service_dirs_append_link_unique_or_free (&parser->service_dirs, link);
874 else if (element_type == ELEMENT_ALLOW_ANONYMOUS)
876 if (!check_no_attributes (parser, "allow_anonymous", attribute_names, attribute_values, error))
879 if (push_element (parser, ELEMENT_ALLOW_ANONYMOUS) == NULL)
885 parser->allow_anonymous = TRUE;
888 else if (element_type == ELEMENT_SERVICEDIR)
890 if (!check_no_attributes (parser, "servicedir", attribute_names, attribute_values, error))
893 if (push_element (parser, ELEMENT_SERVICEDIR) == NULL)
901 else if (element_type == ELEMENT_INCLUDE)
904 const char *if_selinux_enabled;
905 const char *ignore_missing;
906 const char *selinux_root_relative;
908 if ((e = push_element (parser, ELEMENT_INCLUDE)) == NULL)
914 e->d.include.ignore_missing = FALSE;
915 e->d.include.if_selinux_enabled = FALSE;
916 e->d.include.selinux_root_relative = FALSE;
918 if (!locate_attributes (parser, "include",
922 "ignore_missing", &ignore_missing,
923 "if_selinux_enabled", &if_selinux_enabled,
924 "selinux_root_relative", &selinux_root_relative,
928 if (ignore_missing != NULL)
930 if (strcmp (ignore_missing, "yes") == 0)
931 e->d.include.ignore_missing = TRUE;
932 else if (strcmp (ignore_missing, "no") == 0)
933 e->d.include.ignore_missing = FALSE;
936 dbus_set_error (error, DBUS_ERROR_FAILED,
937 "ignore_missing attribute must have value \"yes\" or \"no\"");
942 if (if_selinux_enabled != NULL)
944 if (strcmp (if_selinux_enabled, "yes") == 0)
945 e->d.include.if_selinux_enabled = TRUE;
946 else if (strcmp (if_selinux_enabled, "no") == 0)
947 e->d.include.if_selinux_enabled = FALSE;
950 dbus_set_error (error, DBUS_ERROR_FAILED,
951 "if_selinux_enabled attribute must have value"
952 " \"yes\" or \"no\"");
957 if (selinux_root_relative != NULL)
959 if (strcmp (selinux_root_relative, "yes") == 0)
960 e->d.include.selinux_root_relative = TRUE;
961 else if (strcmp (selinux_root_relative, "no") == 0)
962 e->d.include.selinux_root_relative = FALSE;
965 dbus_set_error (error, DBUS_ERROR_FAILED,
966 "selinux_root_relative attribute must have value"
967 " \"yes\" or \"no\"");
974 else if (element_type == ELEMENT_POLICY)
980 const char *at_console;
982 if ((e = push_element (parser, ELEMENT_POLICY)) == NULL)
988 e->d.policy.type = POLICY_IGNORED;
990 if (!locate_attributes (parser, "policy",
997 "at_console", &at_console,
1001 if (((context && user) ||
1002 (context && group) ||
1003 (context && at_console)) ||
1005 (user && at_console)) ||
1006 (group && at_console) ||
1007 !(context || user || group || at_console))
1009 dbus_set_error (error, DBUS_ERROR_FAILED,
1010 "<policy> element must have exactly one of (context|user|group|at_console) attributes");
1014 if (context != NULL)
1016 if (strcmp (context, "default") == 0)
1018 e->d.policy.type = POLICY_DEFAULT;
1020 else if (strcmp (context, "mandatory") == 0)
1022 e->d.policy.type = POLICY_MANDATORY;
1026 dbus_set_error (error, DBUS_ERROR_FAILED,
1027 "context attribute on <policy> must have the value \"default\" or \"mandatory\", not \"%s\"",
1032 else if (user != NULL)
1034 DBusString username;
1035 _dbus_string_init_const (&username, user);
1037 if (_dbus_parse_unix_user_from_config (&username,
1038 &e->d.policy.gid_uid_or_at_console))
1039 e->d.policy.type = POLICY_USER;
1041 _dbus_warn ("Unknown username \"%s\" in message bus configuration file",
1044 else if (group != NULL)
1046 DBusString group_name;
1047 _dbus_string_init_const (&group_name, group);
1049 if (_dbus_parse_unix_group_from_config (&group_name,
1050 &e->d.policy.gid_uid_or_at_console))
1051 e->d.policy.type = POLICY_GROUP;
1053 _dbus_warn ("Unknown group \"%s\" in message bus configuration file",
1056 else if (at_console != NULL)
1059 t = (strcmp (at_console, "true") == 0);
1060 if (t || strcmp (at_console, "false") == 0)
1062 e->d.policy.gid_uid_or_at_console = t;
1063 e->d.policy.type = POLICY_CONSOLE;
1067 dbus_set_error (error, DBUS_ERROR_FAILED,
1068 "Unknown value \"%s\" for at_console in message bus configuration file",
1076 _dbus_assert_not_reached ("all <policy> attributes null and we didn't set error");
1081 else if (element_type == ELEMENT_LIMIT)
1086 if ((e = push_element (parser, ELEMENT_LIMIT)) == NULL)
1088 BUS_SET_OOM (error);
1092 if (!locate_attributes (parser, "limit",
1102 dbus_set_error (error, DBUS_ERROR_FAILED,
1103 "<limit> element must have a \"name\" attribute");
1107 e->d.limit.name = _dbus_strdup (name);
1108 if (e->d.limit.name == NULL)
1110 BUS_SET_OOM (error);
1116 else if (element_type == ELEMENT_SELINUX)
1118 if (!check_no_attributes (parser, "selinux", attribute_names, attribute_values, error))
1121 if (push_element (parser, ELEMENT_SELINUX) == NULL)
1123 BUS_SET_OOM (error);
1129 else if (element_type == ELEMENT_APPARMOR)
1134 if ((e = push_element (parser, ELEMENT_APPARMOR)) == NULL)
1136 BUS_SET_OOM (error);
1140 if (!locate_attributes (parser, "apparmor",
1148 return bus_apparmor_set_mode_from_config (mode, error);
1152 dbus_set_error (error, DBUS_ERROR_FAILED,
1153 "Element <%s> not allowed inside <%s> in configuration file",
1154 element_name, "busconfig");
1160 append_rule_from_element (BusConfigParser *parser,
1161 const char *element_name,
1162 const char **attribute_names,
1163 const char **attribute_values,
1168 const char *send_interface;
1169 const char *send_member;
1170 const char *send_error;
1171 const char *send_destination;
1172 const char *send_path;
1173 const char *send_type;
1174 const char *receive_interface;
1175 const char *receive_member;
1176 const char *receive_error;
1177 const char *receive_sender;
1178 const char *receive_path;
1179 const char *receive_type;
1180 const char *eavesdrop;
1181 const char *send_requested_reply;
1182 const char *receive_requested_reply;
1184 const char *own_prefix;
1188 BusPolicyRule *rule;
1190 if (!locate_attributes (parser, element_name,
1194 "send_interface", &send_interface,
1195 "send_member", &send_member,
1196 "send_error", &send_error,
1197 "send_destination", &send_destination,
1198 "send_path", &send_path,
1199 "send_type", &send_type,
1200 "receive_interface", &receive_interface,
1201 "receive_member", &receive_member,
1202 "receive_error", &receive_error,
1203 "receive_sender", &receive_sender,
1204 "receive_path", &receive_path,
1205 "receive_type", &receive_type,
1206 "eavesdrop", &eavesdrop,
1207 "send_requested_reply", &send_requested_reply,
1208 "receive_requested_reply", &receive_requested_reply,
1210 "own_prefix", &own_prefix,
1217 if (!(send_interface || send_member || send_error || send_destination ||
1218 send_type || send_path ||
1219 receive_interface || receive_member || receive_error || receive_sender ||
1220 receive_type || receive_path || eavesdrop ||
1221 send_requested_reply || receive_requested_reply ||
1222 own || own_prefix || user || group))
1224 dbus_set_error (error, DBUS_ERROR_FAILED,
1225 "Element <%s> must have one or more attributes",
1230 if ((send_member && (send_interface == NULL && send_path == NULL)) ||
1231 (receive_member && (receive_interface == NULL && receive_path == NULL)))
1233 dbus_set_error (error, DBUS_ERROR_FAILED,
1234 "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.",
1239 /* Allowed combinations of elements are:
1241 * base, must be all send or all receive:
1244 * interface + member
1247 * base send_ can combine with send_destination, send_path, send_type, send_requested_reply
1248 * base receive_ with receive_sender, receive_path, receive_type, receive_requested_reply, eavesdrop
1250 * user, group, own, own_prefix must occur alone
1252 * Pretty sure the below stuff is broken, FIXME think about it more.
1255 if ((send_interface && (send_error ||
1256 receive_interface ||
1260 receive_requested_reply ||
1261 own || own_prefix ||
1265 (send_member && (send_error ||
1266 receive_interface ||
1270 receive_requested_reply ||
1271 own || own_prefix ||
1275 (send_error && (receive_interface ||
1279 receive_requested_reply ||
1280 own || own_prefix ||
1284 (send_destination && (receive_interface ||
1288 receive_requested_reply ||
1289 own || own_prefix ||
1293 (send_type && (receive_interface ||
1297 receive_requested_reply ||
1298 own || own_prefix ||
1302 (send_path && (receive_interface ||
1306 receive_requested_reply ||
1307 own || own_prefix ||
1311 (send_requested_reply && (receive_interface ||
1315 receive_requested_reply ||
1316 own || own_prefix ||
1320 (receive_interface && (receive_error ||
1321 own || own_prefix ||
1325 (receive_member && (receive_error ||
1326 own || own_prefix ||
1330 (receive_error && (own || own_prefix ||
1334 (eavesdrop && (own || own_prefix ||
1338 (receive_requested_reply && (own || own_prefix ||
1342 (own && (own_prefix || user || group)) ||
1344 (own_prefix && (own || user || group)) ||
1348 dbus_set_error (error, DBUS_ERROR_FAILED,
1349 "Invalid combination of attributes on element <%s>",
1356 /* In BusPolicyRule, NULL represents wildcard.
1357 * In the config file, '*' represents it.
1359 #define IS_WILDCARD(str) ((str) && ((str)[0]) == '*' && ((str)[1]) == '\0')
1361 if (send_interface || send_member || send_error || send_destination ||
1362 send_path || send_type || send_requested_reply)
1366 if (IS_WILDCARD (send_interface))
1367 send_interface = NULL;
1368 if (IS_WILDCARD (send_member))
1370 if (IS_WILDCARD (send_error))
1372 if (IS_WILDCARD (send_destination))
1373 send_destination = NULL;
1374 if (IS_WILDCARD (send_path))
1376 if (IS_WILDCARD (send_type))
1379 message_type = DBUS_MESSAGE_TYPE_INVALID;
1380 if (send_type != NULL)
1382 message_type = dbus_message_type_from_string (send_type);
1383 if (message_type == DBUS_MESSAGE_TYPE_INVALID)
1385 dbus_set_error (error, DBUS_ERROR_FAILED,
1386 "Bad message type \"%s\"",
1393 !(strcmp (eavesdrop, "true") == 0 ||
1394 strcmp (eavesdrop, "false") == 0))
1396 dbus_set_error (error, DBUS_ERROR_FAILED,
1397 "Bad value \"%s\" for %s attribute, must be true or false",
1398 "eavesdrop", eavesdrop);
1402 if (send_requested_reply &&
1403 !(strcmp (send_requested_reply, "true") == 0 ||
1404 strcmp (send_requested_reply, "false") == 0))
1406 dbus_set_error (error, DBUS_ERROR_FAILED,
1407 "Bad value \"%s\" for %s attribute, must be true or false",
1408 "send_requested_reply", send_requested_reply);
1412 rule = bus_policy_rule_new (BUS_POLICY_RULE_SEND, allow);
1417 rule->d.send.eavesdrop = (strcmp (eavesdrop, "true") == 0);
1420 rule->d.send.log = (strcmp (log, "true") == 0);
1422 if (send_requested_reply)
1423 rule->d.send.requested_reply = (strcmp (send_requested_reply, "true") == 0);
1425 rule->d.send.message_type = message_type;
1426 rule->d.send.path = _dbus_strdup (send_path);
1427 rule->d.send.interface = _dbus_strdup (send_interface);
1428 rule->d.send.member = _dbus_strdup (send_member);
1429 rule->d.send.error = _dbus_strdup (send_error);
1430 rule->d.send.destination = _dbus_strdup (send_destination);
1431 if (send_path && rule->d.send.path == NULL)
1433 if (send_interface && rule->d.send.interface == NULL)
1435 if (send_member && rule->d.send.member == NULL)
1437 if (send_error && rule->d.send.error == NULL)
1439 if (send_destination && rule->d.send.destination == NULL)
1442 else if (receive_interface || receive_member || receive_error || receive_sender ||
1443 receive_path || receive_type || eavesdrop || receive_requested_reply)
1447 if (IS_WILDCARD (receive_interface))
1448 receive_interface = NULL;
1449 if (IS_WILDCARD (receive_member))
1450 receive_member = NULL;
1451 if (IS_WILDCARD (receive_error))
1452 receive_error = NULL;
1453 if (IS_WILDCARD (receive_sender))
1454 receive_sender = NULL;
1455 if (IS_WILDCARD (receive_path))
1456 receive_path = NULL;
1457 if (IS_WILDCARD (receive_type))
1458 receive_type = NULL;
1460 message_type = DBUS_MESSAGE_TYPE_INVALID;
1461 if (receive_type != NULL)
1463 message_type = dbus_message_type_from_string (receive_type);
1464 if (message_type == DBUS_MESSAGE_TYPE_INVALID)
1466 dbus_set_error (error, DBUS_ERROR_FAILED,
1467 "Bad message type \"%s\"",
1475 !(strcmp (eavesdrop, "true") == 0 ||
1476 strcmp (eavesdrop, "false") == 0))
1478 dbus_set_error (error, DBUS_ERROR_FAILED,
1479 "Bad value \"%s\" for %s attribute, must be true or false",
1480 "eavesdrop", eavesdrop);
1484 if (receive_requested_reply &&
1485 !(strcmp (receive_requested_reply, "true") == 0 ||
1486 strcmp (receive_requested_reply, "false") == 0))
1488 dbus_set_error (error, DBUS_ERROR_FAILED,
1489 "Bad value \"%s\" for %s attribute, must be true or false",
1490 "receive_requested_reply", receive_requested_reply);
1494 rule = bus_policy_rule_new (BUS_POLICY_RULE_RECEIVE, allow);
1499 rule->d.receive.eavesdrop = (strcmp (eavesdrop, "true") == 0);
1501 if (receive_requested_reply)
1502 rule->d.receive.requested_reply = (strcmp (receive_requested_reply, "true") == 0);
1504 rule->d.receive.message_type = message_type;
1505 rule->d.receive.path = _dbus_strdup (receive_path);
1506 rule->d.receive.interface = _dbus_strdup (receive_interface);
1507 rule->d.receive.member = _dbus_strdup (receive_member);
1508 rule->d.receive.error = _dbus_strdup (receive_error);
1509 rule->d.receive.origin = _dbus_strdup (receive_sender);
1511 if (receive_path && rule->d.receive.path == NULL)
1513 if (receive_interface && rule->d.receive.interface == NULL)
1515 if (receive_member && rule->d.receive.member == NULL)
1517 if (receive_error && rule->d.receive.error == NULL)
1519 if (receive_sender && rule->d.receive.origin == NULL)
1522 else if (own || own_prefix)
1524 rule = bus_policy_rule_new (BUS_POLICY_RULE_OWN, allow);
1530 if (IS_WILDCARD (own))
1533 rule->d.own.prefix = 0;
1534 rule->d.own.service_name = _dbus_strdup (own);
1535 if (own && rule->d.own.service_name == NULL)
1540 rule->d.own.prefix = 1;
1541 rule->d.own.service_name = _dbus_strdup (own_prefix);
1542 if (rule->d.own.service_name == NULL)
1548 if (IS_WILDCARD (user))
1550 rule = bus_policy_rule_new (BUS_POLICY_RULE_USER, allow);
1554 rule->d.user.uid = DBUS_UID_UNSET;
1558 DBusString username;
1561 _dbus_string_init_const (&username, user);
1563 if (_dbus_parse_unix_user_from_config (&username, &uid))
1565 rule = bus_policy_rule_new (BUS_POLICY_RULE_USER, allow);
1569 rule->d.user.uid = uid;
1573 _dbus_warn ("Unknown username \"%s\" on element <%s>",
1574 user, element_name);
1580 if (IS_WILDCARD (group))
1582 rule = bus_policy_rule_new (BUS_POLICY_RULE_GROUP, allow);
1586 rule->d.group.gid = DBUS_GID_UNSET;
1590 DBusString groupname;
1593 _dbus_string_init_const (&groupname, group);
1595 if (_dbus_parse_unix_group_from_config (&groupname, &gid))
1597 rule = bus_policy_rule_new (BUS_POLICY_RULE_GROUP, allow);
1601 rule->d.group.gid = gid;
1605 _dbus_warn ("Unknown group \"%s\" on element <%s>",
1606 group, element_name);
1611 _dbus_assert_not_reached ("Did not handle some combination of attributes on <allow> or <deny>");
1617 pe = peek_element (parser);
1618 _dbus_assert (pe != NULL);
1619 _dbus_assert (pe->type == ELEMENT_POLICY);
1621 switch (pe->d.policy.type)
1623 case POLICY_IGNORED:
1624 /* drop the rule on the floor */
1627 case POLICY_DEFAULT:
1628 if (!bus_policy_append_default_rule (parser->policy, rule))
1631 case POLICY_MANDATORY:
1632 if (!bus_policy_append_mandatory_rule (parser->policy, rule))
1636 if (!BUS_POLICY_RULE_IS_PER_CLIENT (rule))
1638 dbus_set_error (error, DBUS_ERROR_FAILED,
1639 "<%s> rule cannot be per-user because it has bus-global semantics",
1644 if (!bus_policy_append_user_rule (parser->policy, pe->d.policy.gid_uid_or_at_console,
1649 if (!BUS_POLICY_RULE_IS_PER_CLIENT (rule))
1651 dbus_set_error (error, DBUS_ERROR_FAILED,
1652 "<%s> rule cannot be per-group because it has bus-global semantics",
1657 if (!bus_policy_append_group_rule (parser->policy, pe->d.policy.gid_uid_or_at_console,
1663 case POLICY_CONSOLE:
1664 if (!bus_policy_append_console_rule (parser->policy, pe->d.policy.gid_uid_or_at_console,
1670 bus_policy_rule_unref (rule);
1677 BUS_SET_OOM (error);
1680 bus_policy_rule_unref (rule);
1685 start_policy_child (BusConfigParser *parser,
1686 const char *element_name,
1687 const char **attribute_names,
1688 const char **attribute_values,
1691 if (strcmp (element_name, "allow") == 0)
1693 if (!append_rule_from_element (parser, element_name,
1694 attribute_names, attribute_values,
1698 if (push_element (parser, ELEMENT_ALLOW) == NULL)
1700 BUS_SET_OOM (error);
1706 else if (strcmp (element_name, "deny") == 0)
1708 if (!append_rule_from_element (parser, element_name,
1709 attribute_names, attribute_values,
1713 if (push_element (parser, ELEMENT_DENY) == NULL)
1715 BUS_SET_OOM (error);
1723 dbus_set_error (error, DBUS_ERROR_FAILED,
1724 "Element <%s> not allowed inside <%s> in configuration file",
1725 element_name, "policy");
1731 start_selinux_child (BusConfigParser *parser,
1732 const char *element_name,
1733 const char **attribute_names,
1734 const char **attribute_values,
1741 context_copy = NULL;
1743 if (strcmp (element_name, "associate") == 0)
1746 const char *context;
1748 if (!locate_attributes (parser, "associate",
1753 "context", &context,
1757 if (push_element (parser, ELEMENT_ASSOCIATE) == NULL)
1759 BUS_SET_OOM (error);
1763 if (own == NULL || context == NULL)
1765 dbus_set_error (error, DBUS_ERROR_FAILED,
1766 "Element <associate> must have attributes own=\"<servicename>\" and context=\"<selinux context>\"");
1770 own_copy = _dbus_strdup (own);
1771 if (own_copy == NULL)
1773 context_copy = _dbus_strdup (context);
1774 if (context_copy == NULL)
1777 if (!_dbus_hash_table_insert_string (parser->service_context_table,
1778 own_copy, context_copy))
1785 dbus_set_error (error, DBUS_ERROR_FAILED,
1786 "Element <%s> not allowed inside <%s> in configuration file",
1787 element_name, "selinux");
1793 dbus_free (own_copy);
1796 dbus_free (context_copy);
1798 BUS_SET_OOM (error);
1803 bus_config_parser_start_element (BusConfigParser *parser,
1804 const char *element_name,
1805 const char **attribute_names,
1806 const char **attribute_values,
1811 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1813 /* printf ("START: %s\n", element_name); */
1815 t = top_element_type (parser);
1817 if (t == ELEMENT_NONE)
1819 if (strcmp (element_name, "busconfig") == 0)
1821 if (!check_no_attributes (parser, "busconfig", attribute_names, attribute_values, error))
1824 if (push_element (parser, ELEMENT_BUSCONFIG) == NULL)
1826 BUS_SET_OOM (error);
1834 dbus_set_error (error, DBUS_ERROR_FAILED,
1835 "Unknown element <%s> at root of configuration file",
1840 else if (t == ELEMENT_BUSCONFIG)
1842 return start_busconfig_child (parser, element_name,
1843 attribute_names, attribute_values,
1846 else if (t == ELEMENT_POLICY)
1848 return start_policy_child (parser, element_name,
1849 attribute_names, attribute_values,
1852 else if (t == ELEMENT_SELINUX)
1854 return start_selinux_child (parser, element_name,
1855 attribute_names, attribute_values,
1860 dbus_set_error (error, DBUS_ERROR_FAILED,
1861 "Element <%s> is not allowed in this context",
1868 set_limit (BusConfigParser *parser,
1873 dbus_bool_t must_be_positive;
1874 dbus_bool_t must_be_int;
1876 must_be_int = FALSE;
1877 must_be_positive = FALSE;
1879 if (strcmp (name, "max_incoming_bytes") == 0)
1881 must_be_positive = TRUE;
1882 parser->limits.max_incoming_bytes = value;
1884 else if (strcmp (name, "max_incoming_unix_fds") == 0)
1886 must_be_positive = TRUE;
1887 parser->limits.max_incoming_unix_fds = value;
1889 else if (strcmp (name, "max_outgoing_bytes") == 0)
1891 must_be_positive = TRUE;
1892 parser->limits.max_outgoing_bytes = value;
1894 else if (strcmp (name, "max_outgoing_unix_fds") == 0)
1896 must_be_positive = TRUE;
1897 parser->limits.max_outgoing_unix_fds = value;
1899 else if (strcmp (name, "max_message_size") == 0)
1901 must_be_positive = TRUE;
1902 parser->limits.max_message_size = value;
1904 else if (strcmp (name, "max_message_unix_fds") == 0)
1906 must_be_positive = TRUE;
1907 parser->limits.max_message_unix_fds = value;
1909 else if (strcmp (name, "service_start_timeout") == 0)
1911 must_be_positive = TRUE;
1913 parser->limits.activation_timeout = value;
1915 else if (strcmp (name, "auth_timeout") == 0)
1917 must_be_positive = TRUE;
1919 parser->limits.auth_timeout = value;
1921 else if (strcmp (name, "pending_fd_timeout") == 0)
1923 must_be_positive = TRUE;
1925 parser->limits.pending_fd_timeout = value;
1927 else if (strcmp (name, "reply_timeout") == 0)
1929 must_be_positive = TRUE;
1931 parser->limits.reply_timeout = value;
1933 else if (strcmp (name, "max_completed_connections") == 0)
1935 must_be_positive = TRUE;
1937 parser->limits.max_completed_connections = value;
1939 else if (strcmp (name, "max_incomplete_connections") == 0)
1941 must_be_positive = TRUE;
1943 parser->limits.max_incomplete_connections = value;
1945 else if (strcmp (name, "max_connections_per_user") == 0)
1947 must_be_positive = TRUE;
1949 parser->limits.max_connections_per_user = value;
1951 else if (strcmp (name, "max_pending_service_starts") == 0)
1953 must_be_positive = TRUE;
1955 parser->limits.max_pending_activations = value;
1957 else if (strcmp (name, "max_names_per_connection") == 0)
1959 must_be_positive = TRUE;
1961 parser->limits.max_services_per_connection = value;
1963 else if (strcmp (name, "max_match_rules_per_connection") == 0)
1965 must_be_positive = TRUE;
1967 parser->limits.max_match_rules_per_connection = value;
1969 else if (strcmp (name, "max_replies_per_connection") == 0)
1971 must_be_positive = TRUE;
1973 parser->limits.max_replies_per_connection = value;
1977 dbus_set_error (error, DBUS_ERROR_FAILED,
1978 "There is no limit called \"%s\"\n",
1983 if (must_be_positive && value < 0)
1985 dbus_set_error (error, DBUS_ERROR_FAILED,
1986 "<limit name=\"%s\"> must be a positive number\n",
1992 (value < _DBUS_INT_MIN || value > _DBUS_INT_MAX))
1994 dbus_set_error (error, DBUS_ERROR_FAILED,
1995 "<limit name=\"%s\"> value is too large\n",
2004 bus_config_parser_end_element (BusConfigParser *parser,
2005 const char *element_name,
2012 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
2014 /* printf ("END: %s\n", element_name); */
2016 t = top_element_type (parser);
2018 if (t == ELEMENT_NONE)
2020 /* should probably be an assertion failure but
2021 * being paranoid about XML parsers
2023 dbus_set_error (error, DBUS_ERROR_FAILED,
2024 "XML parser ended element with no element on the stack");
2028 n = bus_config_parser_element_type_to_name (t);
2029 _dbus_assert (n != NULL);
2030 if (strcmp (n, element_name) != 0)
2032 /* should probably be an assertion failure but
2033 * being paranoid about XML parsers
2035 dbus_set_error (error, DBUS_ERROR_FAILED,
2036 "XML element <%s> ended but topmost element on the stack was <%s>",
2041 e = peek_element (parser);
2042 _dbus_assert (e != NULL);
2047 _dbus_assert_not_reached ("element in stack has no type");
2050 case ELEMENT_INCLUDE:
2052 case ELEMENT_CONFIGTYPE:
2053 case ELEMENT_LISTEN:
2054 case ELEMENT_PIDFILE:
2056 case ELEMENT_SERVICEDIR:
2057 case ELEMENT_SERVICEHELPER:
2058 case ELEMENT_INCLUDEDIR:
2060 if (!e->had_content)
2062 dbus_set_error (error, DBUS_ERROR_FAILED,
2063 "XML element <%s> was expected to have content inside it",
2064 bus_config_parser_element_type_to_name (e->type));
2068 if (e->type == ELEMENT_LIMIT)
2070 if (!set_limit (parser, e->d.limit.name, e->d.limit.value,
2076 case ELEMENT_BUSCONFIG:
2077 case ELEMENT_POLICY:
2081 case ELEMENT_SYSLOG:
2082 case ELEMENT_KEEP_UMASK:
2083 case ELEMENT_SELINUX:
2084 case ELEMENT_ASSOCIATE:
2085 case ELEMENT_STANDARD_SESSION_SERVICEDIRS:
2086 case ELEMENT_STANDARD_SYSTEM_SERVICEDIRS:
2087 case ELEMENT_ALLOW_ANONYMOUS:
2088 case ELEMENT_APPARMOR:
2092 pop_element (parser);
2098 all_whitespace (const DBusString *str)
2102 _dbus_string_skip_white (str, 0, &i);
2104 return i == _dbus_string_get_length (str);
2108 make_full_path (const DBusString *basedir,
2109 const DBusString *filename,
2110 DBusString *full_path)
2112 if (_dbus_path_is_absolute (filename))
2114 if (!_dbus_string_copy (filename, 0, full_path, 0))
2119 if (!_dbus_string_copy (basedir, 0, full_path, 0))
2122 if (!_dbus_concat_dir_and_file (full_path, filename))
2126 if (!_dbus_replace_install_prefix (full_path))
2133 include_file (BusConfigParser *parser,
2134 const DBusString *filename,
2135 dbus_bool_t ignore_missing,
2138 /* FIXME good test case for this would load each config file in the
2139 * test suite both alone, and as an include, and check
2140 * that the result is the same
2142 BusConfigParser *included;
2143 const char *filename_str;
2144 DBusError tmp_error;
2146 dbus_error_init (&tmp_error);
2148 filename_str = _dbus_string_get_const_data (filename);
2150 /* Check to make sure this file hasn't already been included. */
2151 if (seen_include (parser, filename))
2153 dbus_set_error (error, DBUS_ERROR_FAILED,
2154 "Circular inclusion of file '%s'",
2159 if (! _dbus_list_append (&parser->included_files, (void *) filename_str))
2161 BUS_SET_OOM (error);
2165 /* Since parser is passed in as the parent, included
2166 inherits parser's limits. */
2167 included = bus_config_load (filename, FALSE, parser, &tmp_error);
2169 _dbus_list_pop_last (&parser->included_files);
2171 if (included == NULL)
2173 _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
2175 if (dbus_error_has_name (&tmp_error, DBUS_ERROR_FILE_NOT_FOUND) &&
2178 dbus_error_free (&tmp_error);
2183 dbus_move_error (&tmp_error, error);
2189 _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
2191 if (!merge_included (parser, included, error))
2193 bus_config_parser_unref (included);
2197 /* Copy included's limits back to parser. */
2198 parser->limits = included->limits;
2200 bus_config_parser_unref (included);
2206 servicehelper_path (BusConfigParser *parser,
2207 const DBusString *filename,
2210 const char *filename_str;
2211 char *servicehelper;
2213 filename_str = _dbus_string_get_const_data (filename);
2215 /* copy to avoid overwriting with NULL on OOM */
2216 servicehelper = _dbus_strdup (filename_str);
2219 if (servicehelper == NULL)
2221 BUS_SET_OOM (error);
2225 /* save the latest servicehelper only if not OOM */
2226 dbus_free (parser->servicehelper);
2227 parser->servicehelper = servicehelper;
2229 /* We don't check whether the helper exists; instead we
2230 * would just fail to ever activate anything if it doesn't.
2231 * This allows an admin to fix the problem if it doesn't exist.
2232 * It also allows the parser test suite to successfully parse
2233 * test cases without installing the helper. ;-)
2240 include_dir (BusConfigParser *parser,
2241 const DBusString *dirname,
2244 DBusString filename;
2246 DBusError tmp_error;
2250 if (!_dbus_string_init (&filename))
2252 BUS_SET_OOM (error);
2258 dir = _dbus_directory_open (dirname, error);
2262 if (dbus_error_has_name (error, DBUS_ERROR_FILE_NOT_FOUND))
2264 dbus_error_free (error);
2271 dbus_error_init (&tmp_error);
2272 while (_dbus_directory_get_next_file (dir, &filename, &tmp_error))
2274 DBusString full_path;
2276 if (!_dbus_string_init (&full_path))
2278 BUS_SET_OOM (error);
2282 if (!_dbus_string_copy (dirname, 0, &full_path, 0))
2284 BUS_SET_OOM (error);
2285 _dbus_string_free (&full_path);
2289 if (!_dbus_concat_dir_and_file (&full_path, &filename))
2291 BUS_SET_OOM (error);
2292 _dbus_string_free (&full_path);
2296 if (_dbus_string_ends_with_c_str (&full_path, ".conf"))
2298 if (!include_file (parser, &full_path, TRUE, error))
2300 if (dbus_error_is_set (error))
2302 /* We use both syslog and stderr here, because this is
2303 * the configuration parser, so we don't yet know whether
2304 * this bus is going to want to write to syslog! Err on
2305 * the side of making sure the message gets to the sysadmin
2307 _dbus_init_system_log ("dbus-daemon",
2308 DBUS_LOG_FLAGS_STDERR | DBUS_LOG_FLAGS_SYSTEM_LOG);
2309 _dbus_log (DBUS_SYSTEM_LOG_INFO,
2310 "Encountered error '%s' while parsing '%s'",
2312 _dbus_string_get_const_data (&full_path));
2313 dbus_error_free (error);
2318 _dbus_string_free (&full_path);
2321 if (dbus_error_is_set (&tmp_error))
2323 dbus_move_error (&tmp_error, error);
2328 if (!_dbus_string_copy_data (dirname, &s))
2330 BUS_SET_OOM (error);
2334 if (!_dbus_list_append (&parser->conf_dirs, s))
2337 BUS_SET_OOM (error);
2345 _dbus_string_free (&filename);
2348 _dbus_directory_close (dir);
2354 bus_config_parser_content (BusConfigParser *parser,
2355 const DBusString *content,
2360 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
2366 _dbus_string_get_const_data (content, &c_str);
2368 printf ("CONTENT %d bytes: %s\n", _dbus_string_get_length (content), c_str);
2372 e = peek_element (parser);
2375 dbus_set_error (error, DBUS_ERROR_FAILED,
2376 "Text content outside of any XML element in configuration file");
2379 else if (e->had_content)
2381 _dbus_assert_not_reached ("Element had multiple content blocks");
2385 switch (top_element_type (parser))
2388 _dbus_assert_not_reached ("element at top of stack has no type");
2391 case ELEMENT_BUSCONFIG:
2392 case ELEMENT_POLICY:
2396 case ELEMENT_SYSLOG:
2397 case ELEMENT_KEEP_UMASK:
2398 case ELEMENT_STANDARD_SESSION_SERVICEDIRS:
2399 case ELEMENT_STANDARD_SYSTEM_SERVICEDIRS:
2400 case ELEMENT_ALLOW_ANONYMOUS:
2401 case ELEMENT_SELINUX:
2402 case ELEMENT_ASSOCIATE:
2403 case ELEMENT_APPARMOR:
2404 if (all_whitespace (content))
2408 dbus_set_error (error, DBUS_ERROR_FAILED,
2409 "No text content expected inside XML element %s in configuration file",
2410 bus_config_parser_element_type_to_name (top_element_type (parser)));
2414 case ELEMENT_PIDFILE:
2418 e->had_content = TRUE;
2420 if (!_dbus_string_copy_data (content, &s))
2423 dbus_free (parser->pidfile);
2424 parser->pidfile = s;
2428 case ELEMENT_INCLUDE:
2430 DBusString full_path, selinux_policy_root;
2432 e->had_content = TRUE;
2434 if (e->d.include.if_selinux_enabled
2435 && !bus_selinux_enabled ())
2438 if (!_dbus_string_init (&full_path))
2441 if (e->d.include.selinux_root_relative)
2443 if (!bus_selinux_get_policy_root ())
2445 dbus_set_error (error, DBUS_ERROR_FAILED,
2446 "Could not determine SELinux policy root for relative inclusion");
2447 _dbus_string_free (&full_path);
2450 _dbus_string_init_const (&selinux_policy_root,
2451 bus_selinux_get_policy_root ());
2452 if (!make_full_path (&selinux_policy_root, content, &full_path))
2454 _dbus_string_free (&full_path);
2458 else if (!make_full_path (&parser->basedir, content, &full_path))
2460 _dbus_string_free (&full_path);
2464 if (!include_file (parser, &full_path,
2465 e->d.include.ignore_missing, error))
2467 _dbus_string_free (&full_path);
2471 _dbus_string_free (&full_path);
2475 case ELEMENT_SERVICEHELPER:
2477 DBusString full_path;
2479 e->had_content = TRUE;
2481 if (!_dbus_string_init (&full_path))
2484 if (!make_full_path (&parser->basedir, content, &full_path))
2486 _dbus_string_free (&full_path);
2490 if (!servicehelper_path (parser, &full_path, error))
2492 _dbus_string_free (&full_path);
2496 _dbus_string_free (&full_path);
2500 case ELEMENT_INCLUDEDIR:
2502 DBusString full_path;
2504 e->had_content = TRUE;
2506 if (!_dbus_string_init (&full_path))
2509 if (!make_full_path (&parser->basedir, content, &full_path))
2511 _dbus_string_free (&full_path);
2515 if (!include_dir (parser, &full_path, error))
2517 _dbus_string_free (&full_path);
2521 _dbus_string_free (&full_path);
2529 e->had_content = TRUE;
2531 if (!_dbus_string_copy_data (content, &s))
2534 dbus_free (parser->user);
2539 case ELEMENT_CONFIGTYPE:
2543 e->had_content = TRUE;
2545 if (!_dbus_string_copy_data (content, &s))
2548 dbus_free (parser->bus_type);
2549 parser->bus_type = s;
2553 case ELEMENT_LISTEN:
2557 e->had_content = TRUE;
2559 if (!_dbus_string_copy_data (content, &s))
2562 if (!_dbus_list_append (&parser->listen_on,
2575 e->had_content = TRUE;
2577 if (!_dbus_string_copy_data (content, &s))
2580 if (!_dbus_list_append (&parser->mechanisms,
2589 case ELEMENT_SERVICEDIR:
2592 DBusString full_path;
2595 e->had_content = TRUE;
2597 if (!_dbus_string_init (&full_path))
2600 if (!make_full_path (&parser->basedir, content, &full_path))
2602 _dbus_string_free (&full_path);
2606 if (!_dbus_string_copy_data (&full_path, &s))
2608 _dbus_string_free (&full_path);
2612 link = _dbus_list_alloc_link (s);
2616 _dbus_string_free (&full_path);
2622 service_dirs_append_link_unique_or_free (&parser->service_dirs, link);
2623 _dbus_string_free (&full_path);
2631 e->had_content = TRUE;
2634 if (!_dbus_string_parse_int (content, 0, &val, NULL))
2636 dbus_set_error (error, DBUS_ERROR_FAILED,
2637 "<limit name=\"%s\"> element has invalid value (could not parse as integer)",
2642 e->d.limit.value = val;
2644 _dbus_verbose ("Loaded value %ld for limit %s\n",
2651 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
2655 BUS_SET_OOM (error);
2660 bus_config_parser_finished (BusConfigParser *parser,
2663 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
2665 if (parser->stack != NULL)
2667 dbus_set_error (error, DBUS_ERROR_FAILED,
2668 "Element <%s> was not closed in configuration file",
2669 bus_config_parser_element_type_to_name (top_element_type (parser)));
2674 if (parser->is_toplevel && parser->listen_on == NULL)
2676 dbus_set_error (error, DBUS_ERROR_FAILED,
2677 "Configuration file needs one or more <listen> elements giving addresses");
2685 bus_config_parser_get_user (BusConfigParser *parser)
2687 return parser->user;
2691 bus_config_parser_get_type (BusConfigParser *parser)
2693 return parser->bus_type;
2697 bus_config_parser_get_addresses (BusConfigParser *parser)
2699 return &parser->listen_on;
2703 bus_config_parser_get_mechanisms (BusConfigParser *parser)
2705 return &parser->mechanisms;
2709 bus_config_parser_get_service_dirs (BusConfigParser *parser)
2711 return &parser->service_dirs;
2715 bus_config_parser_get_conf_dirs (BusConfigParser *parser)
2717 return &parser->conf_dirs;
2721 bus_config_parser_get_fork (BusConfigParser *parser)
2723 return parser->fork;
2727 bus_config_parser_get_syslog (BusConfigParser *parser)
2729 return parser->syslog;
2733 bus_config_parser_get_keep_umask (BusConfigParser *parser)
2735 return parser->keep_umask;
2739 bus_config_parser_get_allow_anonymous (BusConfigParser *parser)
2741 return parser->allow_anonymous;
2745 bus_config_parser_get_pidfile (BusConfigParser *parser)
2747 return parser->pidfile;
2751 bus_config_parser_get_servicehelper (BusConfigParser *parser)
2753 return parser->servicehelper;
2757 bus_config_parser_steal_policy (BusConfigParser *parser)
2761 _dbus_assert (parser->policy != NULL); /* can only steal the policy 1 time */
2763 policy = parser->policy;
2765 parser->policy = NULL;
2770 /* Overwrite any limits that were set in the configuration file */
2772 bus_config_parser_get_limits (BusConfigParser *parser,
2775 *limits = parser->limits;
2779 bus_config_parser_steal_service_context_table (BusConfigParser *parser)
2781 DBusHashTable *table;
2783 _dbus_assert (parser->service_context_table != NULL); /* can only steal once */
2785 table = parser->service_context_table;
2787 parser->service_context_table = NULL;
2792 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
2803 do_check_own_rules (BusPolicy *policy)
2807 dbus_bool_t allowed;
2809 {"org.freedesktop", FALSE},
2810 {"org.freedesktop.ManySystem", FALSE},
2811 {"org.freedesktop.ManySystems", TRUE},
2812 {"org.freedesktop.ManySystems.foo", TRUE},
2813 {"org.freedesktop.ManySystems.foo.bar", TRUE},
2814 {"org.freedesktop.ManySystems2", FALSE},
2815 {"org.freedesktop.ManySystems2.foo", FALSE},
2816 {"org.freedesktop.ManySystems2.foo.bar", FALSE},
2821 while (checks[i].name)
2823 DBusString service_name;
2826 if (!_dbus_string_init (&service_name))
2827 _dbus_assert_not_reached ("couldn't init string");
2828 if (!_dbus_string_append (&service_name, checks[i].name))
2829 _dbus_assert_not_reached ("couldn't append string");
2831 ret = bus_policy_check_can_own (policy, &service_name);
2832 printf (" Check name %s: %s\n", checks[i].name,
2833 ret ? "allowed" : "not allowed");
2834 if (checks[i].allowed && !ret)
2836 _dbus_warn ("Cannot own %s", checks[i].name);
2839 if (!checks[i].allowed && ret)
2841 _dbus_warn ("Can own %s", checks[i].name);
2844 _dbus_string_free (&service_name);
2853 do_load (const DBusString *full_path,
2855 dbus_bool_t oom_possible,
2856 dbus_bool_t check_own_rules)
2858 BusConfigParser *parser;
2861 dbus_error_init (&error);
2863 parser = bus_config_load (full_path, TRUE, NULL, &error);
2866 _DBUS_ASSERT_ERROR_IS_SET (&error);
2869 dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
2871 _dbus_verbose ("Failed to load valid file due to OOM\n");
2872 dbus_error_free (&error);
2875 else if (validity == VALID)
2877 _dbus_warn ("Failed to load valid file but still had memory: %s",
2880 dbus_error_free (&error);
2885 dbus_error_free (&error);
2891 _DBUS_ASSERT_ERROR_IS_CLEAR (&error);
2893 if (check_own_rules && do_check_own_rules (parser->policy) == FALSE)
2898 bus_config_parser_unref (parser);
2900 if (validity == INVALID)
2902 _dbus_warn ("Accepted invalid file");
2912 const DBusString *full_path;
2914 dbus_bool_t check_own_rules;
2918 check_loader_oom_func (void *data)
2920 LoaderOomData *d = data;
2922 return do_load (d->full_path, d->validity, TRUE, d->check_own_rules);
2926 process_test_valid_subdir (const DBusString *test_base_dir,
2930 DBusString test_directory;
2931 DBusString filename;
2939 if (!_dbus_string_init (&test_directory))
2940 _dbus_assert_not_reached ("didn't allocate test_directory");
2942 _dbus_string_init_const (&filename, subdir);
2944 if (!_dbus_string_copy (test_base_dir, 0,
2945 &test_directory, 0))
2946 _dbus_assert_not_reached ("couldn't copy test_base_dir to test_directory");
2948 if (!_dbus_concat_dir_and_file (&test_directory, &filename))
2949 _dbus_assert_not_reached ("couldn't allocate full path");
2951 _dbus_string_free (&filename);
2952 if (!_dbus_string_init (&filename))
2953 _dbus_assert_not_reached ("didn't allocate filename string");
2955 dbus_error_init (&error);
2956 dir = _dbus_directory_open (&test_directory, &error);
2959 _dbus_warn ("Could not open %s: %s",
2960 _dbus_string_get_const_data (&test_directory),
2962 dbus_error_free (&error);
2966 if (validity == VALID)
2967 printf ("Testing valid files:\n");
2968 else if (validity == INVALID)
2969 printf ("Testing invalid files:\n");
2971 printf ("Testing unknown files:\n");
2974 while (_dbus_directory_get_next_file (dir, &filename, &error))
2976 DBusString full_path;
2979 if (!_dbus_string_init (&full_path))
2980 _dbus_assert_not_reached ("couldn't init string");
2982 if (!_dbus_string_copy (&test_directory, 0, &full_path, 0))
2983 _dbus_assert_not_reached ("couldn't copy dir to full_path");
2985 if (!_dbus_concat_dir_and_file (&full_path, &filename))
2986 _dbus_assert_not_reached ("couldn't concat file to dir");
2988 if (!_dbus_string_ends_with_c_str (&full_path, ".conf"))
2990 _dbus_verbose ("Skipping non-.conf file %s\n",
2991 _dbus_string_get_const_data (&filename));
2992 _dbus_string_free (&full_path);
2996 printf (" %s\n", _dbus_string_get_const_data (&filename));
2998 _dbus_verbose (" expecting %s\n",
2999 validity == VALID ? "valid" :
3000 (validity == INVALID ? "invalid" :
3001 (validity == UNKNOWN ? "unknown" : "???")));
3003 d.full_path = &full_path;
3004 d.validity = validity;
3005 d.check_own_rules = _dbus_string_ends_with_c_str (&full_path,
3006 "check-own-rules.conf");
3008 /* FIXME hackaround for an expat problem, see
3009 * https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=124747
3010 * http://freedesktop.org/pipermail/dbus/2004-May/001153.html
3012 /* if (!_dbus_test_oom_handling ("config-loader", check_loader_oom_func, &d)) */
3013 if (!check_loader_oom_func (&d))
3014 _dbus_assert_not_reached ("test failed");
3016 _dbus_string_free (&full_path);
3019 if (dbus_error_is_set (&error))
3021 _dbus_warn ("Could not get next file in %s: %s",
3022 _dbus_string_get_const_data (&test_directory),
3024 dbus_error_free (&error);
3033 _dbus_directory_close (dir);
3034 _dbus_string_free (&test_directory);
3035 _dbus_string_free (&filename);
3041 bools_equal (dbus_bool_t a,
3048 strings_equal_or_both_null (const char *a,
3051 if (a == NULL || b == NULL)
3054 return !strcmp (a, b);
3058 elements_equal (const Element *a,
3061 if (a->type != b->type)
3064 if (!bools_equal (a->had_content, b->had_content))
3070 case ELEMENT_INCLUDE:
3071 if (!bools_equal (a->d.include.ignore_missing,
3072 b->d.include.ignore_missing))
3076 case ELEMENT_POLICY:
3077 if (a->d.policy.type != b->d.policy.type)
3079 if (a->d.policy.gid_uid_or_at_console != b->d.policy.gid_uid_or_at_console)
3084 if (strcmp (a->d.limit.name, b->d.limit.name))
3086 if (a->d.limit.value != b->d.limit.value)
3100 lists_of_elements_equal (DBusList *a,
3109 while (ia != NULL && ib != NULL)
3111 if (elements_equal (ia->data, ib->data))
3113 ia = _dbus_list_get_next_link (&a, ia);
3114 ib = _dbus_list_get_next_link (&b, ib);
3117 return ia == NULL && ib == NULL;
3121 lists_of_c_strings_equal (DBusList *a,
3130 while (ia != NULL && ib != NULL)
3132 if (strcmp (ia->data, ib->data))
3134 ia = _dbus_list_get_next_link (&a, ia);
3135 ib = _dbus_list_get_next_link (&b, ib);
3138 return ia == NULL && ib == NULL;
3142 limits_equal (const BusLimits *a,
3146 (a->max_incoming_bytes == b->max_incoming_bytes
3147 || a->max_incoming_unix_fds == b->max_incoming_unix_fds
3148 || a->max_outgoing_bytes == b->max_outgoing_bytes
3149 || a->max_outgoing_unix_fds == b->max_outgoing_unix_fds
3150 || a->max_message_size == b->max_message_size
3151 || a->max_message_unix_fds == b->max_message_unix_fds
3152 || a->activation_timeout == b->activation_timeout
3153 || a->auth_timeout == b->auth_timeout
3154 || a->pending_fd_timeout == b->pending_fd_timeout
3155 || a->max_completed_connections == b->max_completed_connections
3156 || a->max_incomplete_connections == b->max_incomplete_connections
3157 || a->max_connections_per_user == b->max_connections_per_user
3158 || a->max_pending_activations == b->max_pending_activations
3159 || a->max_services_per_connection == b->max_services_per_connection
3160 || a->max_match_rules_per_connection == b->max_match_rules_per_connection
3161 || a->max_replies_per_connection == b->max_replies_per_connection
3162 || a->reply_timeout == b->reply_timeout);
3166 config_parsers_equal (const BusConfigParser *a,
3167 const BusConfigParser *b)
3169 if (!_dbus_string_equal (&a->basedir, &b->basedir))
3172 if (!lists_of_elements_equal (a->stack, b->stack))
3175 if (!strings_equal_or_both_null (a->user, b->user))
3178 if (!lists_of_c_strings_equal (a->listen_on, b->listen_on))
3181 if (!lists_of_c_strings_equal (a->mechanisms, b->mechanisms))
3184 if (!lists_of_c_strings_equal (a->service_dirs, b->service_dirs))
3187 /* FIXME: compare policy */
3189 /* FIXME: compare service selinux ID table */
3191 if (! limits_equal (&a->limits, &b->limits))
3194 if (!strings_equal_or_both_null (a->pidfile, b->pidfile))
3197 if (! bools_equal (a->fork, b->fork))
3200 if (! bools_equal (a->keep_umask, b->keep_umask))
3203 if (! bools_equal (a->is_toplevel, b->is_toplevel))
3210 all_are_equiv (const DBusString *target_directory)
3212 DBusString filename;
3214 BusConfigParser *first_parser;
3215 BusConfigParser *parser;
3221 first_parser = NULL;
3225 if (!_dbus_string_init (&filename))
3226 _dbus_assert_not_reached ("didn't allocate filename string");
3228 dbus_error_init (&error);
3229 dir = _dbus_directory_open (target_directory, &error);
3232 _dbus_warn ("Could not open %s: %s",
3233 _dbus_string_get_const_data (target_directory),
3235 dbus_error_free (&error);
3239 printf ("Comparing equivalent files:\n");
3242 while (_dbus_directory_get_next_file (dir, &filename, &error))
3244 DBusString full_path;
3246 if (!_dbus_string_init (&full_path))
3247 _dbus_assert_not_reached ("couldn't init string");
3249 if (!_dbus_string_copy (target_directory, 0, &full_path, 0))
3250 _dbus_assert_not_reached ("couldn't copy dir to full_path");
3252 if (!_dbus_concat_dir_and_file (&full_path, &filename))
3253 _dbus_assert_not_reached ("couldn't concat file to dir");
3255 if (!_dbus_string_ends_with_c_str (&full_path, ".conf"))
3257 _dbus_verbose ("Skipping non-.conf file %s\n",
3258 _dbus_string_get_const_data (&filename));
3259 _dbus_string_free (&full_path);
3263 printf (" %s\n", _dbus_string_get_const_data (&filename));
3265 parser = bus_config_load (&full_path, TRUE, NULL, &error);
3269 _dbus_warn ("Could not load file %s: %s",
3270 _dbus_string_get_const_data (&full_path),
3272 _dbus_string_free (&full_path);
3273 dbus_error_free (&error);
3276 else if (first_parser == NULL)
3278 _dbus_string_free (&full_path);
3279 first_parser = parser;
3283 _dbus_string_free (&full_path);
3284 equal = config_parsers_equal (first_parser, parser);
3285 bus_config_parser_unref (parser);
3294 _dbus_string_free (&filename);
3296 bus_config_parser_unref (first_parser);
3298 _dbus_directory_close (dir);
3305 process_test_equiv_subdir (const DBusString *test_base_dir,
3308 DBusString test_directory;
3309 DBusString filename;
3318 if (!_dbus_string_init (&test_directory))
3319 _dbus_assert_not_reached ("didn't allocate test_directory");
3321 _dbus_string_init_const (&filename, subdir);
3323 if (!_dbus_string_copy (test_base_dir, 0,
3324 &test_directory, 0))
3325 _dbus_assert_not_reached ("couldn't copy test_base_dir to test_directory");
3327 if (!_dbus_concat_dir_and_file (&test_directory, &filename))
3328 _dbus_assert_not_reached ("couldn't allocate full path");
3330 _dbus_string_free (&filename);
3331 if (!_dbus_string_init (&filename))
3332 _dbus_assert_not_reached ("didn't allocate filename string");
3334 dbus_error_init (&error);
3335 dir = _dbus_directory_open (&test_directory, &error);
3338 _dbus_warn ("Could not open %s: %s",
3339 _dbus_string_get_const_data (&test_directory),
3341 dbus_error_free (&error);
3345 while (_dbus_directory_get_next_file (dir, &filename, &error))
3347 DBusString full_path;
3349 /* Skip CVS's magic directories! */
3350 if (_dbus_string_equal_c_str (&filename, "CVS"))
3353 if (!_dbus_string_init (&full_path))
3354 _dbus_assert_not_reached ("couldn't init string");
3356 if (!_dbus_string_copy (&test_directory, 0, &full_path, 0))
3357 _dbus_assert_not_reached ("couldn't copy dir to full_path");
3359 if (!_dbus_concat_dir_and_file (&full_path, &filename))
3360 _dbus_assert_not_reached ("couldn't concat file to dir");
3362 equal = all_are_equiv (&full_path);
3363 _dbus_string_free (&full_path);
3372 _dbus_string_free (&test_directory);
3373 _dbus_string_free (&filename);
3375 _dbus_directory_close (dir);
3381 static const char *test_session_service_dir_matches[] =
3384 "/testhome/foo/.testlocal/testshare/dbus-1/services",
3385 "/testusr/testlocal/testshare/dbus-1/services",
3386 "/testusr/testshare/dbus-1/services",
3387 DBUS_DATADIR"/dbus-1/services",
3389 /* will be filled in test_default_session_servicedirs() */
3398 test_default_session_servicedirs (void)
3403 DBusString install_root_based;
3405 dbus_bool_t ret = FALSE;
3407 const char *common_progs;
3410 /* On Unix we don't actually use these, but it's easier to handle the
3411 * deallocation if we always allocate them, whether needed or not */
3412 if (!_dbus_string_init (&progs) ||
3413 !_dbus_string_init (&install_root_based))
3414 _dbus_assert_not_reached ("OOM allocating strings");
3417 if (!_dbus_string_append (&install_root_based, DBUS_DATADIR) ||
3418 !_dbus_string_append (&install_root_based, "/dbus-1/services") ||
3419 !_dbus_replace_install_prefix (&install_root_based))
3422 _dbus_assert (_dbus_path_is_absolute (&install_root_based));
3424 test_session_service_dir_matches[0] = _dbus_string_get_const_data (
3425 &install_root_based);
3427 common_progs = _dbus_getenv ("CommonProgramFiles");
3431 if (!_dbus_string_append (&progs, common_progs))
3434 if (!_dbus_string_append (&progs, "/dbus-1/services"))
3437 test_session_service_dir_matches[1] = _dbus_string_get_const_data(&progs);
3442 printf ("Testing retrieving the default session service directories\n");
3445 if (!dbus_setenv ("XDG_DATA_HOME", "/testhome/foo/.testlocal/testshare"))
3446 _dbus_assert_not_reached ("couldn't setenv XDG_DATA_HOME");
3448 if (!dbus_setenv ("XDG_DATA_DIRS", ":/testusr/testlocal/testshare: :/testusr/testshare:"))
3449 _dbus_assert_not_reached ("couldn't setenv XDG_DATA_DIRS");
3451 if (!_dbus_get_standard_session_servicedirs (&dirs))
3452 _dbus_assert_not_reached ("couldn't get stardard dirs");
3454 /* make sure we read and parse the env variable correctly */
3456 while ((link = _dbus_list_pop_first_link (&dirs)))
3458 printf (" test service dir: '%s'\n", (char *)link->data);
3459 printf (" current standard service dir: '%s'\n", test_session_service_dir_matches[i]);
3460 if (test_session_service_dir_matches[i] == NULL)
3462 printf ("more directories parsed than in match set\n");
3463 dbus_free (link->data);
3464 _dbus_list_free_link (link);
3468 if (strcmp (test_session_service_dir_matches[i],
3469 (char *)link->data) != 0)
3471 printf ("'%s' directory does not match '%s' in the match set\n",
3473 test_session_service_dir_matches[i]);
3474 dbus_free (link->data);
3475 _dbus_list_free_link (link);
3481 dbus_free (link->data);
3482 _dbus_list_free_link (link);
3485 if (test_session_service_dir_matches[i] != NULL)
3487 printf ("extra data %s in the match set was not matched\n",
3488 test_session_service_dir_matches[i]);
3495 _dbus_string_free (&install_root_based);
3496 _dbus_string_free (&progs);
3501 static const char *test_system_service_dir_matches[] =
3503 "/usr/local/share/dbus-1/system-services",
3504 "/usr/share/dbus-1/system-services",
3505 DBUS_DATADIR"/dbus-1/system-services",
3506 "/lib/dbus-1/system-services",
3511 test_default_system_servicedirs (void)
3519 if (!_dbus_get_standard_system_servicedirs (&dirs))
3520 _dbus_assert_not_reached ("couldn't get stardard dirs");
3522 /* make sure we read and parse the env variable correctly */
3524 while ((link = _dbus_list_pop_first_link (&dirs)))
3526 printf (" test service dir: %s\n", (char *)link->data);
3527 if (test_system_service_dir_matches[i] == NULL)
3529 printf ("more directories parsed than in match set\n");
3530 dbus_free (link->data);
3531 _dbus_list_free_link (link);
3535 if (strcmp (test_system_service_dir_matches[i],
3536 (char *)link->data) != 0)
3538 printf ("%s directory does not match %s in the match set\n",
3540 test_system_service_dir_matches[i]);
3541 dbus_free (link->data);
3542 _dbus_list_free_link (link);
3548 dbus_free (link->data);
3549 _dbus_list_free_link (link);
3552 if (test_system_service_dir_matches[i] != NULL)
3554 printf ("extra data %s in the match set was not matched\n",
3555 test_system_service_dir_matches[i]);
3565 bus_config_parser_test (const DBusString *test_data_dir)
3567 if (test_data_dir == NULL ||
3568 _dbus_string_get_length (test_data_dir) == 0)
3570 printf ("No test data\n");
3574 if (!test_default_session_servicedirs())
3578 printf("default system service dir skipped\n");
3580 if (!test_default_system_servicedirs())
3584 if (!process_test_valid_subdir (test_data_dir, "valid-config-files", VALID))
3588 if (!process_test_valid_subdir (test_data_dir, "valid-config-files-system", VALID))
3592 if (!process_test_valid_subdir (test_data_dir, "invalid-config-files", INVALID))
3595 if (!process_test_equiv_subdir (test_data_dir, "equiv-config-files"))
3601 #endif /* DBUS_ENABLE_EMBEDDED_TESTS */