1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* config-parser.c XML-library-agnostic configuration file parser
4 * Copyright (C) 2003 Red Hat, Inc.
6 * Licensed under the Academic Free License version 2.0
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "config-parser.h"
27 #include <dbus/dbus-list.h>
28 #include <dbus/dbus-internals.h>
52 /* we ignore policies for unknown groups/users */
66 unsigned int had_content : 1;
72 unsigned int ignore_missing : 1;
78 unsigned long gid_or_uid;
92 * Parser for bus configuration file.
94 struct BusConfigParser
96 int refcount; /**< Reference count */
98 DBusString basedir; /**< Directory we resolve paths relative to */
100 DBusList *stack; /**< stack of Element */
102 char *user; /**< user to run as */
104 char *bus_type; /**< Message bus type */
106 DBusList *listen_on; /**< List of addresses to listen to */
108 DBusList *mechanisms; /**< Auth mechanisms */
110 DBusList *service_dirs; /**< Directories to look for services in */
112 BusPolicy *policy; /**< Security policy */
114 BusLimits limits; /**< Limits */
116 char *pidfile; /**< PID file */
118 unsigned int fork : 1; /**< TRUE to fork into daemon mode */
120 unsigned int is_toplevel : 1; /**< FALSE if we are a sub-config-file inside another one */
124 element_type_to_name (ElementType type)
130 case ELEMENT_BUSCONFIG:
132 case ELEMENT_INCLUDE:
150 case ELEMENT_PIDFILE:
152 case ELEMENT_SERVICEDIR:
154 case ELEMENT_INCLUDEDIR:
160 _dbus_assert_not_reached ("bad element type");
166 push_element (BusConfigParser *parser,
171 _dbus_assert (type != ELEMENT_NONE);
173 e = dbus_new0 (Element, 1);
177 if (!_dbus_list_append (&parser->stack, e))
189 element_free (Element *e)
191 if (e->type == ELEMENT_LIMIT)
192 dbus_free (e->d.limit.name);
198 pop_element (BusConfigParser *parser)
202 e = _dbus_list_pop_last (&parser->stack);
208 peek_element (BusConfigParser *parser)
212 e = _dbus_list_get_last (&parser->stack);
218 top_element_type (BusConfigParser *parser)
222 e = _dbus_list_get_last (&parser->stack);
231 merge_included (BusConfigParser *parser,
232 BusConfigParser *included,
237 if (!bus_policy_merge (parser->policy,
244 if (included->user != NULL)
246 dbus_free (parser->user);
247 parser->user = included->user;
248 included->user = NULL;
251 if (included->bus_type != NULL)
253 dbus_free (parser->bus_type);
254 parser->bus_type = included->bus_type;
255 included->bus_type = NULL;
261 if (included->pidfile != NULL)
263 dbus_free (parser->pidfile);
264 parser->pidfile = included->pidfile;
265 included->pidfile = NULL;
268 while ((link = _dbus_list_pop_first_link (&included->listen_on)))
269 _dbus_list_append_link (&parser->listen_on, link);
271 while ((link = _dbus_list_pop_first_link (&included->mechanisms)))
272 _dbus_list_append_link (&parser->mechanisms, link);
274 while ((link = _dbus_list_pop_first_link (&included->service_dirs)))
275 _dbus_list_append_link (&parser->service_dirs, link);
281 bus_config_parser_new (const DBusString *basedir,
282 dbus_bool_t is_toplevel,
283 const BusConfigParser *parent)
285 BusConfigParser *parser;
287 parser = dbus_new0 (BusConfigParser, 1);
291 parser->is_toplevel = !!is_toplevel;
293 if (!_dbus_string_init (&parser->basedir))
299 if (((parser->policy = bus_policy_new ()) == NULL) ||
300 !_dbus_string_copy (basedir, 0, &parser->basedir, 0))
303 bus_policy_unref (parser->policy);
305 _dbus_string_free (&parser->basedir);
312 /* Initialize the parser's limits from the parent. */
313 parser->limits = parent->limits;
318 /* Make up some numbers! woot! */
319 parser->limits.max_incoming_bytes = _DBUS_ONE_MEGABYTE * 63;
320 parser->limits.max_outgoing_bytes = _DBUS_ONE_MEGABYTE * 63;
321 parser->limits.max_message_size = _DBUS_ONE_MEGABYTE * 32;
323 /* Making this long means the user has to wait longer for an error
324 * message if something screws up, but making it too short means
325 * they might see a false failure.
327 parser->limits.activation_timeout = 25000; /* 25 seconds */
329 /* Making this long risks making a DOS attack easier, but too short
330 * and legitimate auth will fail. If interactive auth (ask user for
331 * password) is allowed, then potentially it has to be quite long.
333 parser->limits.auth_timeout = 30000; /* 30 seconds */
335 parser->limits.max_incomplete_connections = 32;
336 parser->limits.max_connections_per_user = 128;
338 /* Note that max_completed_connections / max_connections_per_user
339 * is the number of users that would have to work together to
340 * DOS all the other users.
342 parser->limits.max_completed_connections = 1024;
344 parser->limits.max_pending_activations = 256;
345 parser->limits.max_services_per_connection = 256;
347 parser->limits.max_match_rules_per_connection = 128;
349 parser->limits.reply_timeout = 5 * 60 * 1000; /* 5 minutes */
350 parser->limits.max_replies_per_connection = 32;
353 parser->refcount = 1;
359 bus_config_parser_ref (BusConfigParser *parser)
361 _dbus_assert (parser->refcount > 0);
363 parser->refcount += 1;
369 bus_config_parser_unref (BusConfigParser *parser)
371 _dbus_assert (parser->refcount > 0);
373 parser->refcount -= 1;
375 if (parser->refcount == 0)
377 while (parser->stack != NULL)
378 pop_element (parser);
380 dbus_free (parser->user);
381 dbus_free (parser->bus_type);
382 dbus_free (parser->pidfile);
384 _dbus_list_foreach (&parser->listen_on,
385 (DBusForeachFunction) dbus_free,
388 _dbus_list_clear (&parser->listen_on);
390 _dbus_list_foreach (&parser->service_dirs,
391 (DBusForeachFunction) dbus_free,
394 _dbus_list_clear (&parser->service_dirs);
396 _dbus_list_foreach (&parser->mechanisms,
397 (DBusForeachFunction) dbus_free,
400 _dbus_list_clear (&parser->mechanisms);
402 _dbus_string_free (&parser->basedir);
405 bus_policy_unref (parser->policy);
412 bus_config_parser_check_doctype (BusConfigParser *parser,
416 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
418 if (strcmp (doctype, "busconfig") != 0)
420 dbus_set_error (error,
422 "Configuration file has the wrong document type %s",
437 locate_attributes (BusConfigParser *parser,
438 const char *element_name,
439 const char **attribute_names,
440 const char **attribute_values,
442 const char *first_attribute_name,
443 const char **first_attribute_retloc,
451 LocateAttr attrs[MAX_ATTRS];
455 _dbus_assert (first_attribute_name != NULL);
456 _dbus_assert (first_attribute_retloc != NULL);
461 attrs[0].name = first_attribute_name;
462 attrs[0].retloc = first_attribute_retloc;
463 *first_attribute_retloc = NULL;
465 va_start (args, first_attribute_retloc);
467 name = va_arg (args, const char*);
468 retloc = va_arg (args, const char**);
472 _dbus_assert (retloc != NULL);
473 _dbus_assert (n_attrs < MAX_ATTRS);
475 attrs[n_attrs].name = name;
476 attrs[n_attrs].retloc = retloc;
480 name = va_arg (args, const char*);
481 retloc = va_arg (args, const char**);
490 while (attribute_names[i])
499 if (strcmp (attrs[j].name, attribute_names[i]) == 0)
501 retloc = attrs[j].retloc;
505 dbus_set_error (error, DBUS_ERROR_FAILED,
506 "Attribute \"%s\" repeated twice on the same <%s> element",
507 attrs[j].name, element_name);
512 *retloc = attribute_values[i];
521 dbus_set_error (error, DBUS_ERROR_FAILED,
522 "Attribute \"%s\" is invalid on <%s> element in this context",
523 attribute_names[i], element_name);
536 check_no_attributes (BusConfigParser *parser,
537 const char *element_name,
538 const char **attribute_names,
539 const char **attribute_values,
542 if (attribute_names[0] != NULL)
544 dbus_set_error (error, DBUS_ERROR_FAILED,
545 "Attribute \"%s\" is invalid on <%s> element in this context",
546 attribute_names[0], element_name);
554 start_busconfig_child (BusConfigParser *parser,
555 const char *element_name,
556 const char **attribute_names,
557 const char **attribute_values,
560 if (strcmp (element_name, "user") == 0)
562 if (!check_no_attributes (parser, "user", attribute_names, attribute_values, error))
565 if (push_element (parser, ELEMENT_USER) == NULL)
573 else if (strcmp (element_name, "type") == 0)
575 if (!check_no_attributes (parser, "type", attribute_names, attribute_values, error))
578 if (push_element (parser, ELEMENT_TYPE) == NULL)
586 else if (strcmp (element_name, "fork") == 0)
588 if (!check_no_attributes (parser, "fork", attribute_names, attribute_values, error))
591 if (push_element (parser, ELEMENT_FORK) == NULL)
601 else if (strcmp (element_name, "pidfile") == 0)
603 if (!check_no_attributes (parser, "pidfile", attribute_names, attribute_values, error))
606 if (push_element (parser, ELEMENT_PIDFILE) == NULL)
614 else if (strcmp (element_name, "listen") == 0)
616 if (!check_no_attributes (parser, "listen", attribute_names, attribute_values, error))
619 if (push_element (parser, ELEMENT_LISTEN) == NULL)
627 else if (strcmp (element_name, "auth") == 0)
629 if (!check_no_attributes (parser, "auth", attribute_names, attribute_values, error))
632 if (push_element (parser, ELEMENT_AUTH) == NULL)
640 else if (strcmp (element_name, "includedir") == 0)
642 if (!check_no_attributes (parser, "includedir", attribute_names, attribute_values, error))
645 if (push_element (parser, ELEMENT_INCLUDEDIR) == NULL)
653 else if (strcmp (element_name, "servicedir") == 0)
655 if (!check_no_attributes (parser, "servicedir", attribute_names, attribute_values, error))
658 if (push_element (parser, ELEMENT_SERVICEDIR) == NULL)
666 else if (strcmp (element_name, "include") == 0)
669 const char *ignore_missing;
671 if ((e = push_element (parser, ELEMENT_INCLUDE)) == NULL)
677 e->d.include.ignore_missing = FALSE;
679 if (!locate_attributes (parser, "include",
683 "ignore_missing", &ignore_missing,
687 if (ignore_missing != NULL)
689 if (strcmp (ignore_missing, "yes") == 0)
690 e->d.include.ignore_missing = TRUE;
691 else if (strcmp (ignore_missing, "no") == 0)
692 e->d.include.ignore_missing = FALSE;
695 dbus_set_error (error, DBUS_ERROR_FAILED,
696 "ignore_missing attribute must have value \"yes\" or \"no\"");
703 else if (strcmp (element_name, "policy") == 0)
710 if ((e = push_element (parser, ELEMENT_POLICY)) == NULL)
716 e->d.policy.type = POLICY_IGNORED;
718 if (!locate_attributes (parser, "policy",
728 if (((context && user) ||
729 (context && group)) ||
731 !(context || user || group))
733 dbus_set_error (error, DBUS_ERROR_FAILED,
734 "<policy> element must have exactly one of (context|user|group) attributes");
740 if (strcmp (context, "default") == 0)
742 e->d.policy.type = POLICY_DEFAULT;
744 else if (strcmp (context, "mandatory") == 0)
746 e->d.policy.type = POLICY_MANDATORY;
750 dbus_set_error (error, DBUS_ERROR_FAILED,
751 "context attribute on <policy> must have the value \"default\" or \"mandatory\", not \"%s\"",
756 else if (user != NULL)
759 _dbus_string_init_const (&username, user);
761 if (_dbus_get_user_id (&username,
762 &e->d.policy.gid_or_uid))
763 e->d.policy.type = POLICY_USER;
765 _dbus_warn ("Unknown username \"%s\" in message bus configuration file\n",
768 else if (group != NULL)
770 DBusString group_name;
771 _dbus_string_init_const (&group_name, group);
773 if (_dbus_get_group_id (&group_name,
774 &e->d.policy.gid_or_uid))
775 e->d.policy.type = POLICY_GROUP;
777 _dbus_warn ("Unknown group \"%s\" in message bus configuration file\n",
782 _dbus_assert_not_reached ("all <policy> attributes null and we didn't set error");
787 else if (strcmp (element_name, "limit") == 0)
792 if ((e = push_element (parser, ELEMENT_LIMIT)) == NULL)
798 if (!locate_attributes (parser, "limit",
808 dbus_set_error (error, DBUS_ERROR_FAILED,
809 "<limit> element must have a \"name\" attribute");
813 e->d.limit.name = _dbus_strdup (name);
814 if (e->d.limit.name == NULL)
824 dbus_set_error (error, DBUS_ERROR_FAILED,
825 "Element <%s> not allowed inside <%s> in configuration file",
826 element_name, "busconfig");
832 append_rule_from_element (BusConfigParser *parser,
833 const char *element_name,
834 const char **attribute_names,
835 const char **attribute_values,
839 const char *send_interface;
840 const char *send_member;
841 const char *send_error;
842 const char *send_destination;
843 const char *send_path;
844 const char *send_type;
845 const char *receive_interface;
846 const char *receive_member;
847 const char *receive_error;
848 const char *receive_sender;
849 const char *receive_path;
850 const char *receive_type;
851 const char *eavesdrop;
852 const char *requested_reply;
858 if (!locate_attributes (parser, element_name,
862 "send_interface", &send_interface,
863 "send_member", &send_member,
864 "send_error", &send_error,
865 "send_destination", &send_destination,
866 "send_path", &send_path,
867 "send_type", &send_type,
868 "receive_interface", &receive_interface,
869 "receive_member", &receive_member,
870 "receive_error", &receive_error,
871 "receive_sender", &receive_sender,
872 "receive_path", &receive_path,
873 "receive_type", &receive_type,
874 "eavesdrop", &eavesdrop,
875 "requested_reply", &requested_reply,
882 if (!(send_interface || send_member || send_error || send_destination ||
883 send_type || send_path ||
884 receive_interface || receive_member || receive_error || receive_sender ||
885 receive_type || receive_path || eavesdrop || requested_reply ||
886 own || user || group))
888 dbus_set_error (error, DBUS_ERROR_FAILED,
889 "Element <%s> must have one or more attributes",
894 if ((send_member && (send_interface == NULL && send_path == NULL)) ||
895 (receive_member && (receive_interface == NULL && receive_path == NULL)))
897 dbus_set_error (error, DBUS_ERROR_FAILED,
898 "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.",
903 /* Allowed combinations of elements are:
905 * base, must be all send or all receive:
911 * base send_ can combine with send_destination, send_path, send_type
912 * base receive_ with receive_sender, receive_path, receive_type, eavesdrop, requested_reply
914 * user, group, own must occur alone
916 * Pretty sure the below stuff is broken, FIXME think about it more.
919 if (((send_interface && send_error) ||
920 (send_interface && receive_interface) ||
921 (send_interface && receive_member) ||
922 (send_interface && receive_error) ||
923 (send_interface && receive_sender) ||
924 (send_interface && eavesdrop) ||
925 (send_interface && requested_reply) ||
926 (send_interface && own) ||
927 (send_interface && user) ||
928 (send_interface && group)) ||
930 ((send_member && send_error) ||
931 (send_member && receive_interface) ||
932 (send_member && receive_member) ||
933 (send_member && receive_error) ||
934 (send_member && receive_sender) ||
935 (send_member && eavesdrop) ||
936 (send_member && requested_reply) ||
937 (send_member && own) ||
938 (send_member && user) ||
939 (send_member && group)) ||
941 ((send_error && receive_interface) ||
942 (send_error && receive_member) ||
943 (send_error && receive_error) ||
944 (send_error && receive_sender) ||
945 (send_error && eavesdrop) ||
946 (send_error && requested_reply) ||
947 (send_error && own) ||
948 (send_error && user) ||
949 (send_error && group)) ||
951 ((send_destination && receive_interface) ||
952 (send_destination && receive_member) ||
953 (send_destination && receive_error) ||
954 (send_destination && receive_sender) ||
955 (send_destination && eavesdrop) ||
956 (send_destination && requested_reply) ||
957 (send_destination && own) ||
958 (send_destination && user) ||
959 (send_destination && group)) ||
961 ((send_type && receive_interface) ||
962 (send_type && receive_member) ||
963 (send_type && receive_error) ||
964 (send_type && receive_sender) ||
965 (send_type && eavesdrop) ||
966 (send_type && requested_reply) ||
967 (send_type && own) ||
968 (send_type && user) ||
969 (send_type && group)) ||
971 ((send_path && receive_interface) ||
972 (send_path && receive_member) ||
973 (send_path && receive_error) ||
974 (send_path && receive_sender) ||
975 (send_path && eavesdrop) ||
976 (send_path && requested_reply) ||
977 (send_path && own) ||
978 (send_path && user) ||
979 (send_path && group)) ||
981 ((receive_interface && receive_error) ||
982 (receive_interface && own) ||
983 (receive_interface && user) ||
984 (receive_interface && group)) ||
986 ((receive_member && receive_error) ||
987 (receive_member && own) ||
988 (receive_member && user) ||
989 (receive_member && group)) ||
991 ((receive_error && own) ||
992 (receive_error && user) ||
993 (receive_error && group)) ||
995 ((eavesdrop && own) ||
996 (eavesdrop && user) ||
997 (eavesdrop && group)) ||
999 ((requested_reply && own) ||
1000 (requested_reply && user) ||
1001 (requested_reply && group)) ||
1008 dbus_set_error (error, DBUS_ERROR_FAILED,
1009 "Invalid combination of attributes on element <%s>",
1016 /* In BusPolicyRule, NULL represents wildcard.
1017 * In the config file, '*' represents it.
1019 #define IS_WILDCARD(str) ((str) && ((str)[0]) == '*' && ((str)[1]) == '\0')
1021 if (send_interface || send_member || send_error || send_destination ||
1022 send_path || send_type)
1026 if (IS_WILDCARD (send_interface))
1027 send_interface = NULL;
1028 if (IS_WILDCARD (send_member))
1030 if (IS_WILDCARD (send_error))
1032 if (IS_WILDCARD (send_destination))
1033 send_destination = NULL;
1034 if (IS_WILDCARD (send_path))
1036 if (IS_WILDCARD (send_type))
1039 message_type = DBUS_MESSAGE_TYPE_INVALID;
1040 if (send_type != NULL)
1042 message_type = dbus_message_type_from_string (send_type);
1043 if (message_type == DBUS_MESSAGE_TYPE_INVALID)
1045 dbus_set_error (error, DBUS_ERROR_FAILED,
1046 "Bad message type \"%s\"",
1052 rule = bus_policy_rule_new (BUS_POLICY_RULE_SEND, allow);
1056 rule->d.send.message_type = message_type;
1057 rule->d.send.path = _dbus_strdup (send_path);
1058 rule->d.send.interface = _dbus_strdup (send_interface);
1059 rule->d.send.member = _dbus_strdup (send_member);
1060 rule->d.send.error = _dbus_strdup (send_error);
1061 rule->d.send.destination = _dbus_strdup (send_destination);
1062 if (send_path && rule->d.send.path == NULL)
1064 if (send_interface && rule->d.send.interface == NULL)
1066 if (send_member && rule->d.send.member == NULL)
1068 if (send_error && rule->d.send.error == NULL)
1070 if (send_destination && rule->d.send.destination == NULL)
1073 else if (receive_interface || receive_member || receive_error || receive_sender ||
1074 receive_path || receive_type || eavesdrop || requested_reply)
1078 if (IS_WILDCARD (receive_interface))
1079 receive_interface = NULL;
1080 if (IS_WILDCARD (receive_member))
1081 receive_member = NULL;
1082 if (IS_WILDCARD (receive_error))
1083 receive_error = NULL;
1084 if (IS_WILDCARD (receive_sender))
1085 receive_sender = NULL;
1086 if (IS_WILDCARD (receive_path))
1087 receive_path = NULL;
1088 if (IS_WILDCARD (receive_type))
1089 receive_type = NULL;
1091 message_type = DBUS_MESSAGE_TYPE_INVALID;
1092 if (receive_type != NULL)
1094 message_type = dbus_message_type_from_string (receive_type);
1095 if (message_type == DBUS_MESSAGE_TYPE_INVALID)
1097 dbus_set_error (error, DBUS_ERROR_FAILED,
1098 "Bad message type \"%s\"",
1106 !(strcmp (eavesdrop, "true") == 0 ||
1107 strcmp (eavesdrop, "false") == 0))
1109 dbus_set_error (error, DBUS_ERROR_FAILED,
1110 "Bad value \"%s\" for %s attribute, must be true or false",
1111 "eavesdrop", eavesdrop);
1115 if (requested_reply &&
1116 !(strcmp (requested_reply, "true") == 0 ||
1117 strcmp (requested_reply, "false") == 0))
1119 dbus_set_error (error, DBUS_ERROR_FAILED,
1120 "Bad value \"%s\" for %s attribute, must be true or false",
1121 "requested_reply", requested_reply);
1125 rule = bus_policy_rule_new (BUS_POLICY_RULE_RECEIVE, allow);
1130 rule->d.receive.eavesdrop = (strcmp (eavesdrop, "true") == 0);
1132 if (requested_reply)
1133 rule->d.receive.requested_reply = (strcmp (requested_reply, "true") == 0);
1135 rule->d.receive.message_type = message_type;
1136 rule->d.receive.path = _dbus_strdup (receive_path);
1137 rule->d.receive.interface = _dbus_strdup (receive_interface);
1138 rule->d.receive.member = _dbus_strdup (receive_member);
1139 rule->d.receive.error = _dbus_strdup (receive_error);
1140 rule->d.receive.origin = _dbus_strdup (receive_sender);
1142 if (receive_path && rule->d.receive.path == NULL)
1144 if (receive_interface && rule->d.receive.interface == NULL)
1146 if (receive_member && rule->d.receive.member == NULL)
1148 if (receive_error && rule->d.receive.error == NULL)
1150 if (receive_sender && rule->d.receive.origin == NULL)
1155 rule = bus_policy_rule_new (BUS_POLICY_RULE_OWN, allow);
1159 if (IS_WILDCARD (own))
1162 rule->d.own.service_name = _dbus_strdup (own);
1163 if (own && rule->d.own.service_name == NULL)
1168 if (IS_WILDCARD (user))
1170 rule = bus_policy_rule_new (BUS_POLICY_RULE_USER, allow);
1174 rule->d.user.uid = DBUS_UID_UNSET;
1178 DBusString username;
1181 _dbus_string_init_const (&username, user);
1183 if (_dbus_get_user_id (&username, &uid))
1185 rule = bus_policy_rule_new (BUS_POLICY_RULE_USER, allow);
1189 rule->d.user.uid = uid;
1193 _dbus_warn ("Unknown username \"%s\" on element <%s>\n",
1194 user, element_name);
1200 if (IS_WILDCARD (group))
1202 rule = bus_policy_rule_new (BUS_POLICY_RULE_GROUP, allow);
1206 rule->d.group.gid = DBUS_GID_UNSET;
1210 DBusString groupname;
1213 _dbus_string_init_const (&groupname, group);
1215 if (_dbus_get_user_id (&groupname, &gid))
1217 rule = bus_policy_rule_new (BUS_POLICY_RULE_GROUP, allow);
1221 rule->d.group.gid = gid;
1225 _dbus_warn ("Unknown group \"%s\" on element <%s>\n",
1226 group, element_name);
1231 _dbus_assert_not_reached ("Did not handle some combination of attributes on <allow> or <deny>");
1237 pe = peek_element (parser);
1238 _dbus_assert (pe != NULL);
1239 _dbus_assert (pe->type == ELEMENT_POLICY);
1241 switch (pe->d.policy.type)
1243 case POLICY_IGNORED:
1244 /* drop the rule on the floor */
1247 case POLICY_DEFAULT:
1248 if (!bus_policy_append_default_rule (parser->policy, rule))
1251 case POLICY_MANDATORY:
1252 if (!bus_policy_append_mandatory_rule (parser->policy, rule))
1256 if (!BUS_POLICY_RULE_IS_PER_CLIENT (rule))
1258 dbus_set_error (error, DBUS_ERROR_FAILED,
1259 "<%s> rule cannot be per-user because it has bus-global semantics",
1264 if (!bus_policy_append_user_rule (parser->policy, pe->d.policy.gid_or_uid,
1269 if (!BUS_POLICY_RULE_IS_PER_CLIENT (rule))
1271 dbus_set_error (error, DBUS_ERROR_FAILED,
1272 "<%s> rule cannot be per-group because it has bus-global semantics",
1277 if (!bus_policy_append_group_rule (parser->policy, pe->d.policy.gid_or_uid,
1283 bus_policy_rule_unref (rule);
1290 BUS_SET_OOM (error);
1293 bus_policy_rule_unref (rule);
1298 start_policy_child (BusConfigParser *parser,
1299 const char *element_name,
1300 const char **attribute_names,
1301 const char **attribute_values,
1304 if (strcmp (element_name, "allow") == 0)
1306 if (!append_rule_from_element (parser, element_name,
1307 attribute_names, attribute_values,
1311 if (push_element (parser, ELEMENT_ALLOW) == NULL)
1313 BUS_SET_OOM (error);
1319 else if (strcmp (element_name, "deny") == 0)
1321 if (!append_rule_from_element (parser, element_name,
1322 attribute_names, attribute_values,
1326 if (push_element (parser, ELEMENT_DENY) == NULL)
1328 BUS_SET_OOM (error);
1336 dbus_set_error (error, DBUS_ERROR_FAILED,
1337 "Element <%s> not allowed inside <%s> in configuration file",
1338 element_name, "policy");
1344 bus_config_parser_start_element (BusConfigParser *parser,
1345 const char *element_name,
1346 const char **attribute_names,
1347 const char **attribute_values,
1352 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1354 /* printf ("START: %s\n", element_name); */
1356 t = top_element_type (parser);
1358 if (t == ELEMENT_NONE)
1360 if (strcmp (element_name, "busconfig") == 0)
1362 if (!check_no_attributes (parser, "busconfig", attribute_names, attribute_values, error))
1365 if (push_element (parser, ELEMENT_BUSCONFIG) == NULL)
1367 BUS_SET_OOM (error);
1375 dbus_set_error (error, DBUS_ERROR_FAILED,
1376 "Unknown element <%s> at root of configuration file",
1381 else if (t == ELEMENT_BUSCONFIG)
1383 return start_busconfig_child (parser, element_name,
1384 attribute_names, attribute_values,
1387 else if (t == ELEMENT_POLICY)
1389 return start_policy_child (parser, element_name,
1390 attribute_names, attribute_values,
1395 dbus_set_error (error, DBUS_ERROR_FAILED,
1396 "Element <%s> is not allowed in this context",
1403 set_limit (BusConfigParser *parser,
1408 dbus_bool_t must_be_positive;
1409 dbus_bool_t must_be_int;
1411 must_be_int = FALSE;
1412 must_be_positive = FALSE;
1414 if (strcmp (name, "max_incoming_bytes") == 0)
1416 must_be_positive = TRUE;
1417 parser->limits.max_incoming_bytes = value;
1419 else if (strcmp (name, "max_outgoing_bytes") == 0)
1421 must_be_positive = TRUE;
1422 parser->limits.max_outgoing_bytes = value;
1424 else if (strcmp (name, "max_message_size") == 0)
1426 must_be_positive = TRUE;
1427 parser->limits.max_message_size = value;
1429 else if (strcmp (name, "activation_timeout") == 0)
1431 must_be_positive = TRUE;
1433 parser->limits.activation_timeout = value;
1435 else if (strcmp (name, "auth_timeout") == 0)
1437 must_be_positive = TRUE;
1439 parser->limits.auth_timeout = value;
1441 else if (strcmp (name, "reply_timeout") == 0)
1443 must_be_positive = TRUE;
1445 parser->limits.reply_timeout = value;
1447 else if (strcmp (name, "max_completed_connections") == 0)
1449 must_be_positive = TRUE;
1451 parser->limits.max_completed_connections = value;
1453 else if (strcmp (name, "max_incomplete_connections") == 0)
1455 must_be_positive = TRUE;
1457 parser->limits.max_incomplete_connections = value;
1459 else if (strcmp (name, "max_connections_per_user") == 0)
1461 must_be_positive = TRUE;
1463 parser->limits.max_connections_per_user = value;
1465 else if (strcmp (name, "max_pending_activations") == 0)
1467 must_be_positive = TRUE;
1469 parser->limits.max_pending_activations = value;
1471 else if (strcmp (name, "max_services_per_connection") == 0)
1473 must_be_positive = TRUE;
1475 parser->limits.max_services_per_connection = value;
1477 else if (strcmp (name, "max_replies_per_connection") == 0)
1479 must_be_positive = TRUE;
1481 parser->limits.max_replies_per_connection = value;
1485 dbus_set_error (error, DBUS_ERROR_FAILED,
1486 "There is no limit called \"%s\"\n",
1491 if (must_be_positive && value < 0)
1493 dbus_set_error (error, DBUS_ERROR_FAILED,
1494 "<limit name=\"%s\"> must be a positive number\n",
1500 (value < _DBUS_INT_MIN || value > _DBUS_INT_MAX))
1502 dbus_set_error (error, DBUS_ERROR_FAILED,
1503 "<limit name=\"%s\"> value is too large\n",
1512 bus_config_parser_end_element (BusConfigParser *parser,
1513 const char *element_name,
1520 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1522 /* printf ("END: %s\n", element_name); */
1524 t = top_element_type (parser);
1526 if (t == ELEMENT_NONE)
1528 /* should probably be an assertion failure but
1529 * being paranoid about XML parsers
1531 dbus_set_error (error, DBUS_ERROR_FAILED,
1532 "XML parser ended element with no element on the stack");
1536 n = element_type_to_name (t);
1537 _dbus_assert (n != NULL);
1538 if (strcmp (n, element_name) != 0)
1540 /* should probably be an assertion failure but
1541 * being paranoid about XML parsers
1543 dbus_set_error (error, DBUS_ERROR_FAILED,
1544 "XML element <%s> ended but topmost element on the stack was <%s>",
1549 e = peek_element (parser);
1550 _dbus_assert (e != NULL);
1555 _dbus_assert_not_reached ("element in stack has no type");
1558 case ELEMENT_INCLUDE:
1561 case ELEMENT_LISTEN:
1562 case ELEMENT_PIDFILE:
1564 case ELEMENT_SERVICEDIR:
1565 case ELEMENT_INCLUDEDIR:
1567 if (!e->had_content)
1569 dbus_set_error (error, DBUS_ERROR_FAILED,
1570 "XML element <%s> was expected to have content inside it",
1571 element_type_to_name (e->type));
1575 if (e->type == ELEMENT_LIMIT)
1577 if (!set_limit (parser, e->d.limit.name, e->d.limit.value,
1583 case ELEMENT_BUSCONFIG:
1584 case ELEMENT_POLICY:
1591 pop_element (parser);
1597 all_whitespace (const DBusString *str)
1601 _dbus_string_skip_white (str, 0, &i);
1603 return i == _dbus_string_get_length (str);
1607 make_full_path (const DBusString *basedir,
1608 const DBusString *filename,
1609 DBusString *full_path)
1611 if (_dbus_path_is_absolute (filename))
1613 return _dbus_string_copy (filename, 0, full_path, 0);
1617 if (!_dbus_string_copy (basedir, 0, full_path, 0))
1620 if (!_dbus_concat_dir_and_file (full_path, filename))
1628 include_file (BusConfigParser *parser,
1629 const DBusString *filename,
1630 dbus_bool_t ignore_missing,
1633 /* FIXME good test case for this would load each config file in the
1634 * test suite both alone, and as an include, and check
1635 * that the result is the same
1637 BusConfigParser *included;
1638 DBusError tmp_error;
1640 dbus_error_init (&tmp_error);
1642 /* Since parser is passed in as the parent, included
1643 inherits parser's limits. */
1644 included = bus_config_load (filename, FALSE, parser, &tmp_error);
1646 if (included == NULL)
1648 _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
1650 if (dbus_error_has_name (&tmp_error, DBUS_ERROR_FILE_NOT_FOUND) &&
1653 dbus_error_free (&tmp_error);
1658 dbus_move_error (&tmp_error, error);
1664 _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
1666 if (!merge_included (parser, included, error))
1668 bus_config_parser_unref (included);
1672 /* Copy included's limits back to parser. */
1673 parser->limits = included->limits;
1675 bus_config_parser_unref (included);
1681 include_dir (BusConfigParser *parser,
1682 const DBusString *dirname,
1685 DBusString filename;
1687 DBusError tmp_error;
1690 if (!_dbus_string_init (&filename))
1692 BUS_SET_OOM (error);
1698 dir = _dbus_directory_open (dirname, error);
1703 dbus_error_init (&tmp_error);
1704 while (_dbus_directory_get_next_file (dir, &filename, &tmp_error))
1706 DBusString full_path;
1708 if (!_dbus_string_init (&full_path))
1710 BUS_SET_OOM (error);
1714 if (!_dbus_string_copy (dirname, 0, &full_path, 0))
1716 BUS_SET_OOM (error);
1717 _dbus_string_free (&full_path);
1721 if (!_dbus_concat_dir_and_file (&full_path, &filename))
1723 BUS_SET_OOM (error);
1724 _dbus_string_free (&full_path);
1728 if (_dbus_string_ends_with_c_str (&full_path, ".conf"))
1730 if (!include_file (parser, &full_path, TRUE, error))
1732 _dbus_string_free (&full_path);
1737 _dbus_string_free (&full_path);
1740 if (dbus_error_is_set (&tmp_error))
1742 dbus_move_error (&tmp_error, error);
1749 _dbus_string_free (&filename);
1752 _dbus_directory_close (dir);
1758 bus_config_parser_content (BusConfigParser *parser,
1759 const DBusString *content,
1764 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1770 _dbus_string_get_const_data (content, &c_str);
1772 printf ("CONTENT %d bytes: %s\n", _dbus_string_get_length (content), c_str);
1776 e = peek_element (parser);
1779 dbus_set_error (error, DBUS_ERROR_FAILED,
1780 "Text content outside of any XML element in configuration file");
1783 else if (e->had_content)
1785 _dbus_assert_not_reached ("Element had multiple content blocks");
1789 switch (top_element_type (parser))
1792 _dbus_assert_not_reached ("element at top of stack has no type");
1795 case ELEMENT_BUSCONFIG:
1796 case ELEMENT_POLICY:
1800 if (all_whitespace (content))
1804 dbus_set_error (error, DBUS_ERROR_FAILED,
1805 "No text content expected inside XML element %s in configuration file",
1806 element_type_to_name (top_element_type (parser)));
1810 case ELEMENT_PIDFILE:
1814 e->had_content = TRUE;
1816 if (!_dbus_string_copy_data (content, &s))
1819 dbus_free (parser->pidfile);
1820 parser->pidfile = s;
1824 case ELEMENT_INCLUDE:
1826 DBusString full_path;
1828 e->had_content = TRUE;
1830 if (!_dbus_string_init (&full_path))
1833 if (!make_full_path (&parser->basedir, content, &full_path))
1835 _dbus_string_free (&full_path);
1839 if (!include_file (parser, &full_path,
1840 e->d.include.ignore_missing, error))
1842 _dbus_string_free (&full_path);
1846 _dbus_string_free (&full_path);
1850 case ELEMENT_INCLUDEDIR:
1852 DBusString full_path;
1854 e->had_content = TRUE;
1856 if (!_dbus_string_init (&full_path))
1859 if (!make_full_path (&parser->basedir, content, &full_path))
1861 _dbus_string_free (&full_path);
1865 if (!include_dir (parser, &full_path, error))
1867 _dbus_string_free (&full_path);
1871 _dbus_string_free (&full_path);
1879 e->had_content = TRUE;
1881 if (!_dbus_string_copy_data (content, &s))
1884 dbus_free (parser->user);
1893 e->had_content = TRUE;
1895 if (!_dbus_string_copy_data (content, &s))
1898 dbus_free (parser->bus_type);
1899 parser->bus_type = s;
1903 case ELEMENT_LISTEN:
1907 e->had_content = TRUE;
1909 if (!_dbus_string_copy_data (content, &s))
1912 if (!_dbus_list_append (&parser->listen_on,
1925 e->had_content = TRUE;
1927 if (!_dbus_string_copy_data (content, &s))
1930 if (!_dbus_list_append (&parser->mechanisms,
1939 case ELEMENT_SERVICEDIR:
1942 DBusString full_path;
1944 e->had_content = TRUE;
1946 if (!_dbus_string_init (&full_path))
1949 if (!make_full_path (&parser->basedir, content, &full_path))
1951 _dbus_string_free (&full_path);
1955 if (!_dbus_string_copy_data (&full_path, &s))
1957 _dbus_string_free (&full_path);
1961 if (!_dbus_list_append (&parser->service_dirs, s))
1963 _dbus_string_free (&full_path);
1968 _dbus_string_free (&full_path);
1976 e->had_content = TRUE;
1979 if (!_dbus_string_parse_int (content, 0, &val, NULL))
1981 dbus_set_error (error, DBUS_ERROR_FAILED,
1982 "<limit name=\"%s\"> element has invalid value (could not parse as integer)",
1987 e->d.limit.value = val;
1989 _dbus_verbose ("Loaded value %ld for limit %s\n",
1996 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
2000 BUS_SET_OOM (error);
2005 bus_config_parser_finished (BusConfigParser *parser,
2008 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
2010 if (parser->stack != NULL)
2012 dbus_set_error (error, DBUS_ERROR_FAILED,
2013 "Element <%s> was not closed in configuration file",
2014 element_type_to_name (top_element_type (parser)));
2019 if (parser->is_toplevel && parser->listen_on == NULL)
2021 dbus_set_error (error, DBUS_ERROR_FAILED,
2022 "Configuration file needs one or more <listen> elements giving addresses");
2030 bus_config_parser_get_user (BusConfigParser *parser)
2032 return parser->user;
2036 bus_config_parser_get_type (BusConfigParser *parser)
2038 return parser->bus_type;
2042 bus_config_parser_get_addresses (BusConfigParser *parser)
2044 return &parser->listen_on;
2048 bus_config_parser_get_mechanisms (BusConfigParser *parser)
2050 return &parser->mechanisms;
2054 bus_config_parser_get_service_dirs (BusConfigParser *parser)
2056 return &parser->service_dirs;
2060 bus_config_parser_get_fork (BusConfigParser *parser)
2062 return parser->fork;
2066 bus_config_parser_get_pidfile (BusConfigParser *parser)
2068 return parser->pidfile;
2072 bus_config_parser_steal_policy (BusConfigParser *parser)
2076 _dbus_assert (parser->policy != NULL); /* can only steal the policy 1 time */
2078 policy = parser->policy;
2080 parser->policy = NULL;
2085 /* Overwrite any limits that were set in the configuration file */
2087 bus_config_parser_get_limits (BusConfigParser *parser,
2090 *limits = parser->limits;
2093 #ifdef DBUS_BUILD_TESTS
2104 do_load (const DBusString *full_path,
2106 dbus_bool_t oom_possible)
2108 BusConfigParser *parser;
2111 dbus_error_init (&error);
2113 parser = bus_config_load (full_path, TRUE, NULL, &error);
2116 _DBUS_ASSERT_ERROR_IS_SET (&error);
2119 dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
2121 _dbus_verbose ("Failed to load valid file due to OOM\n");
2122 dbus_error_free (&error);
2125 else if (validity == VALID)
2127 _dbus_warn ("Failed to load valid file but still had memory: %s\n",
2130 dbus_error_free (&error);
2135 dbus_error_free (&error);
2141 _DBUS_ASSERT_ERROR_IS_CLEAR (&error);
2143 bus_config_parser_unref (parser);
2145 if (validity == INVALID)
2147 _dbus_warn ("Accepted invalid file\n");
2157 const DBusString *full_path;
2162 check_loader_oom_func (void *data)
2164 LoaderOomData *d = data;
2166 return do_load (d->full_path, d->validity, TRUE);
2170 process_test_valid_subdir (const DBusString *test_base_dir,
2174 DBusString test_directory;
2175 DBusString filename;
2183 if (!_dbus_string_init (&test_directory))
2184 _dbus_assert_not_reached ("didn't allocate test_directory\n");
2186 _dbus_string_init_const (&filename, subdir);
2188 if (!_dbus_string_copy (test_base_dir, 0,
2189 &test_directory, 0))
2190 _dbus_assert_not_reached ("couldn't copy test_base_dir to test_directory");
2192 if (!_dbus_concat_dir_and_file (&test_directory, &filename))
2193 _dbus_assert_not_reached ("couldn't allocate full path");
2195 _dbus_string_free (&filename);
2196 if (!_dbus_string_init (&filename))
2197 _dbus_assert_not_reached ("didn't allocate filename string\n");
2199 dbus_error_init (&error);
2200 dir = _dbus_directory_open (&test_directory, &error);
2203 _dbus_warn ("Could not open %s: %s\n",
2204 _dbus_string_get_const_data (&test_directory),
2206 dbus_error_free (&error);
2210 printf ("Testing:\n");
2213 while (_dbus_directory_get_next_file (dir, &filename, &error))
2215 DBusString full_path;
2218 if (!_dbus_string_init (&full_path))
2219 _dbus_assert_not_reached ("couldn't init string");
2221 if (!_dbus_string_copy (&test_directory, 0, &full_path, 0))
2222 _dbus_assert_not_reached ("couldn't copy dir to full_path");
2224 if (!_dbus_concat_dir_and_file (&full_path, &filename))
2225 _dbus_assert_not_reached ("couldn't concat file to dir");
2227 if (!_dbus_string_ends_with_c_str (&full_path, ".conf"))
2229 _dbus_verbose ("Skipping non-.conf file %s\n",
2230 _dbus_string_get_const_data (&filename));
2231 _dbus_string_free (&full_path);
2235 printf (" %s\n", _dbus_string_get_const_data (&filename));
2237 _dbus_verbose (" expecting %s\n",
2238 validity == VALID ? "valid" :
2239 (validity == INVALID ? "invalid" :
2240 (validity == UNKNOWN ? "unknown" : "???")));
2242 d.full_path = &full_path;
2243 d.validity = validity;
2244 if (!_dbus_test_oom_handling ("config-loader", check_loader_oom_func, &d))
2245 _dbus_assert_not_reached ("test failed");
2247 _dbus_string_free (&full_path);
2250 if (dbus_error_is_set (&error))
2252 _dbus_warn ("Could not get next file in %s: %s\n",
2253 _dbus_string_get_const_data (&test_directory),
2255 dbus_error_free (&error);
2264 _dbus_directory_close (dir);
2265 _dbus_string_free (&test_directory);
2266 _dbus_string_free (&filename);
2272 bools_equal (dbus_bool_t a,
2279 strings_equal_or_both_null (const char *a,
2282 if (a == NULL || b == NULL)
2285 return !strcmp (a, b);
2289 elements_equal (const Element *a,
2292 if (a->type != b->type)
2295 if (!bools_equal (a->had_content, b->had_content))
2301 case ELEMENT_INCLUDE:
2302 if (!bools_equal (a->d.include.ignore_missing,
2303 b->d.include.ignore_missing))
2307 case ELEMENT_POLICY:
2308 if (a->d.policy.type != b->d.policy.type)
2310 if (a->d.policy.gid_or_uid != b->d.policy.gid_or_uid)
2315 if (strcmp (a->d.limit.name, b->d.limit.name))
2317 if (a->d.limit.value != b->d.limit.value)
2331 lists_of_elements_equal (DBusList *a,
2340 while (ia != NULL && ib != NULL)
2342 if (elements_equal (ia->data, ib->data))
2344 ia = _dbus_list_get_next_link (&a, ia);
2345 ib = _dbus_list_get_next_link (&b, ib);
2348 return ia == NULL && ib == NULL;
2352 lists_of_c_strings_equal (DBusList *a,
2361 while (ia != NULL && ib != NULL)
2363 if (strcmp (ia->data, ib->data))
2365 ia = _dbus_list_get_next_link (&a, ia);
2366 ib = _dbus_list_get_next_link (&b, ib);
2369 return ia == NULL && ib == NULL;
2373 limits_equal (const BusLimits *a,
2377 (a->max_incoming_bytes == b->max_incoming_bytes
2378 || a->max_outgoing_bytes == b->max_outgoing_bytes
2379 || a->max_message_size == b->max_message_size
2380 || a->activation_timeout == b->activation_timeout
2381 || a->auth_timeout == b->auth_timeout
2382 || a->max_completed_connections == b->max_completed_connections
2383 || a->max_incomplete_connections == b->max_incomplete_connections
2384 || a->max_connections_per_user == b->max_connections_per_user
2385 || a->max_pending_activations == b->max_pending_activations
2386 || a->max_services_per_connection == b->max_services_per_connection
2387 || a->max_match_rules_per_connection == b->max_match_rules_per_connection
2388 || a->max_replies_per_connection == b->max_replies_per_connection
2389 || a->reply_timeout == b->reply_timeout);
2393 config_parsers_equal (const BusConfigParser *a,
2394 const BusConfigParser *b)
2396 if (!_dbus_string_equal (&a->basedir, &b->basedir))
2399 if (!lists_of_elements_equal (a->stack, b->stack))
2402 if (!strings_equal_or_both_null (a->user, b->user))
2405 if (!lists_of_c_strings_equal (a->listen_on, b->listen_on))
2408 if (!lists_of_c_strings_equal (a->mechanisms, b->mechanisms))
2411 if (!lists_of_c_strings_equal (a->service_dirs, b->service_dirs))
2414 /* FIXME: compare policy */
2416 if (! limits_equal (&a->limits, &b->limits))
2419 if (!strings_equal_or_both_null (a->pidfile, b->pidfile))
2422 if (! bools_equal (a->fork, b->fork))
2425 if (! bools_equal (a->is_toplevel, b->is_toplevel))
2432 all_are_equiv (const DBusString *target_directory)
2434 DBusString filename;
2436 BusConfigParser *first_parser;
2437 BusConfigParser *parser;
2443 first_parser = NULL;
2447 if (!_dbus_string_init (&filename))
2448 _dbus_assert_not_reached ("didn't allocate filename string");
2450 dbus_error_init (&error);
2451 dir = _dbus_directory_open (target_directory, &error);
2454 _dbus_warn ("Could not open %s: %s\n",
2455 _dbus_string_get_const_data (target_directory),
2457 dbus_error_free (&error);
2461 printf ("Comparing:\n");
2464 while (_dbus_directory_get_next_file (dir, &filename, &error))
2466 DBusString full_path;
2468 if (!_dbus_string_init (&full_path))
2469 _dbus_assert_not_reached ("couldn't init string");
2471 if (!_dbus_string_copy (target_directory, 0, &full_path, 0))
2472 _dbus_assert_not_reached ("couldn't copy dir to full_path");
2474 if (!_dbus_concat_dir_and_file (&full_path, &filename))
2475 _dbus_assert_not_reached ("couldn't concat file to dir");
2477 if (!_dbus_string_ends_with_c_str (&full_path, ".conf"))
2479 _dbus_verbose ("Skipping non-.conf file %s\n",
2480 _dbus_string_get_const_data (&filename));
2481 _dbus_string_free (&full_path);
2485 printf (" %s\n", _dbus_string_get_const_data (&filename));
2487 parser = bus_config_load (&full_path, TRUE, NULL, &error);
2488 _dbus_string_free (&full_path);
2492 _dbus_warn ("Could not load file %s: %s\n",
2493 _dbus_string_get_const_data (&full_path),
2495 dbus_error_free (&error);
2498 else if (first_parser == NULL)
2500 first_parser = parser;
2504 equal = config_parsers_equal (first_parser, parser);
2505 bus_config_parser_unref (parser);
2515 _dbus_string_free (&filename);
2517 bus_config_parser_unref (first_parser);
2519 _dbus_directory_close (dir);
2526 process_test_equiv_subdir (const DBusString *test_base_dir,
2529 DBusString test_directory;
2530 DBusString filename;
2539 if (!_dbus_string_init (&test_directory))
2540 _dbus_assert_not_reached ("didn't allocate test_directory");
2542 _dbus_string_init_const (&filename, subdir);
2544 if (!_dbus_string_copy (test_base_dir, 0,
2545 &test_directory, 0))
2546 _dbus_assert_not_reached ("couldn't copy test_base_dir to test_directory");
2548 if (!_dbus_concat_dir_and_file (&test_directory, &filename))
2549 _dbus_assert_not_reached ("couldn't allocate full path");
2551 _dbus_string_free (&filename);
2552 if (!_dbus_string_init (&filename))
2553 _dbus_assert_not_reached ("didn't allocate filename string");
2555 dbus_error_init (&error);
2556 dir = _dbus_directory_open (&test_directory, &error);
2559 _dbus_warn ("Could not open %s: %s\n",
2560 _dbus_string_get_const_data (&test_directory),
2562 dbus_error_free (&error);
2566 while (_dbus_directory_get_next_file (dir, &filename, &error))
2568 DBusString full_path;
2570 /* Skip CVS's magic directories! */
2571 if (_dbus_string_equal_c_str (&filename, "CVS"))
2574 if (!_dbus_string_init (&full_path))
2575 _dbus_assert_not_reached ("couldn't init string");
2577 if (!_dbus_string_copy (&test_directory, 0, &full_path, 0))
2578 _dbus_assert_not_reached ("couldn't copy dir to full_path");
2580 if (!_dbus_concat_dir_and_file (&full_path, &filename))
2581 _dbus_assert_not_reached ("couldn't concat file to dir");
2583 equal = all_are_equiv (&full_path);
2584 _dbus_string_free (&full_path);
2593 _dbus_string_free (&test_directory);
2594 _dbus_string_free (&filename);
2596 _dbus_directory_close (dir);
2603 bus_config_parser_test (const DBusString *test_data_dir)
2605 if (test_data_dir == NULL ||
2606 _dbus_string_get_length (test_data_dir) == 0)
2608 printf ("No test data\n");
2612 if (!process_test_valid_subdir (test_data_dir, "valid-config-files", VALID))
2615 if (!process_test_equiv_subdir (test_data_dir, "equiv-config-files"))
2621 #endif /* DBUS_BUILD_TESTS */