1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* policy.c Bus security policy
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <dbus/dbus-list.h>
29 #include <dbus/dbus-hash.h>
30 #include <dbus/dbus-internals.h>
33 bus_policy_rule_new (BusPolicyRuleType type,
38 rule = dbus_new0 (BusPolicyRule, 1);
48 case BUS_POLICY_RULE_USER:
49 rule->d.user.uid = DBUS_UID_UNSET;
51 case BUS_POLICY_RULE_GROUP:
52 rule->d.group.gid = DBUS_GID_UNSET;
54 case BUS_POLICY_RULE_SEND:
55 rule->d.send.message_type = DBUS_MESSAGE_TYPE_INVALID;
57 /* allow rules default to TRUE (only requested replies allowed)
58 * deny rules default to FALSE (only unrequested replies denied)
60 rule->d.send.requested_reply = rule->allow;
62 case BUS_POLICY_RULE_RECEIVE:
63 rule->d.receive.message_type = DBUS_MESSAGE_TYPE_INVALID;
64 /* allow rules default to TRUE (only requested replies allowed)
65 * deny rules default to FALSE (only unrequested replies denied)
67 rule->d.receive.requested_reply = rule->allow;
69 case BUS_POLICY_RULE_OWN:
77 bus_policy_rule_ref (BusPolicyRule *rule)
79 _dbus_assert (rule->refcount > 0);
87 bus_policy_rule_unref (BusPolicyRule *rule)
89 _dbus_assert (rule->refcount > 0);
93 if (rule->refcount == 0)
97 case BUS_POLICY_RULE_SEND:
98 dbus_free (rule->d.send.path);
99 dbus_free (rule->d.send.interface);
100 dbus_free (rule->d.send.member);
101 dbus_free (rule->d.send.error);
102 dbus_free (rule->d.send.destination);
104 case BUS_POLICY_RULE_RECEIVE:
105 dbus_free (rule->d.receive.path);
106 dbus_free (rule->d.receive.interface);
107 dbus_free (rule->d.receive.member);
108 dbus_free (rule->d.receive.error);
109 dbus_free (rule->d.receive.origin);
111 case BUS_POLICY_RULE_OWN:
112 dbus_free (rule->d.own.service_name);
114 case BUS_POLICY_RULE_USER:
116 case BUS_POLICY_RULE_GROUP:
128 DBusList *default_rules; /**< Default policy rules */
129 DBusList *mandatory_rules; /**< Mandatory policy rules */
130 DBusHashTable *rules_by_uid; /**< per-UID policy rules */
131 DBusHashTable *rules_by_gid; /**< per-GID policy rules */
132 DBusList *at_console_true_rules; /**< console user policy rules where at_console="true"*/
133 DBusList *at_console_false_rules; /**< console user policy rules where at_console="false"*/
137 free_rule_func (void *data,
140 BusPolicyRule *rule = data;
142 bus_policy_rule_unref (rule);
146 free_rule_list_func (void *data)
148 DBusList **list = data;
150 if (list == NULL) /* DBusHashTable is on crack */
153 _dbus_list_foreach (list, free_rule_func, NULL);
155 _dbus_list_clear (list);
161 bus_policy_new (void)
165 policy = dbus_new0 (BusPolicy, 1);
169 policy->refcount = 1;
171 policy->rules_by_uid = _dbus_hash_table_new (DBUS_HASH_ULONG,
173 free_rule_list_func);
174 if (policy->rules_by_uid == NULL)
177 policy->rules_by_gid = _dbus_hash_table_new (DBUS_HASH_ULONG,
179 free_rule_list_func);
180 if (policy->rules_by_gid == NULL)
186 bus_policy_unref (policy);
191 bus_policy_ref (BusPolicy *policy)
193 _dbus_assert (policy->refcount > 0);
195 policy->refcount += 1;
201 bus_policy_unref (BusPolicy *policy)
203 _dbus_assert (policy->refcount > 0);
205 policy->refcount -= 1;
207 if (policy->refcount == 0)
209 _dbus_list_foreach (&policy->default_rules, free_rule_func, NULL);
210 _dbus_list_clear (&policy->default_rules);
212 _dbus_list_foreach (&policy->mandatory_rules, free_rule_func, NULL);
213 _dbus_list_clear (&policy->mandatory_rules);
215 _dbus_list_foreach (&policy->at_console_true_rules, free_rule_func, NULL);
216 _dbus_list_clear (&policy->at_console_true_rules);
218 _dbus_list_foreach (&policy->at_console_false_rules, free_rule_func, NULL);
219 _dbus_list_clear (&policy->at_console_false_rules);
221 if (policy->rules_by_uid)
223 _dbus_hash_table_unref (policy->rules_by_uid);
224 policy->rules_by_uid = NULL;
227 if (policy->rules_by_gid)
229 _dbus_hash_table_unref (policy->rules_by_gid);
230 policy->rules_by_gid = NULL;
238 add_list_to_client (DBusList **list,
239 BusClientPolicy *client)
243 link = _dbus_list_get_first_link (list);
246 BusPolicyRule *rule = link->data;
247 link = _dbus_list_get_next_link (list, link);
251 case BUS_POLICY_RULE_USER:
252 case BUS_POLICY_RULE_GROUP:
253 /* These aren't per-connection policies */
256 case BUS_POLICY_RULE_OWN:
257 case BUS_POLICY_RULE_SEND:
258 case BUS_POLICY_RULE_RECEIVE:
259 /* These are per-connection */
260 if (!bus_client_policy_append_rule (client, rule))
270 bus_policy_create_client_policy (BusPolicy *policy,
271 DBusConnection *connection,
274 BusClientPolicy *client;
276 dbus_bool_t at_console;
278 _dbus_assert (dbus_connection_get_is_authenticated (connection));
279 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
281 client = bus_client_policy_new ();
285 if (!add_list_to_client (&policy->default_rules,
289 /* we avoid the overhead of looking up user's groups
290 * if we don't have any group rules anyway
292 if (_dbus_hash_table_get_n_entries (policy->rules_by_gid) > 0)
294 unsigned long *groups;
298 if (!bus_connection_get_groups (connection, &groups, &n_groups, error))
306 list = _dbus_hash_table_lookup_ulong (policy->rules_by_gid,
311 if (!add_list_to_client (list, client))
324 if (!dbus_connection_get_unix_user (connection, &uid))
326 dbus_set_error (error, DBUS_ERROR_FAILED,
327 "No user ID known for connection, cannot determine security policy\n");
331 if (_dbus_hash_table_get_n_entries (policy->rules_by_uid) > 0)
335 list = _dbus_hash_table_lookup_ulong (policy->rules_by_uid,
340 if (!add_list_to_client (list, client))
345 /* Add console rules */
346 at_console = _dbus_is_console_user (uid, error);
350 if (!add_list_to_client (&policy->at_console_true_rules, client))
353 else if (dbus_error_is_set (error) == TRUE)
357 else if (!add_list_to_client (&policy->at_console_false_rules, client))
362 if (!add_list_to_client (&policy->mandatory_rules,
366 bus_client_policy_optimize (client);
373 _DBUS_ASSERT_ERROR_IS_SET (error);
375 bus_client_policy_unref (client);
380 list_allows_user (dbus_bool_t def,
383 const unsigned long *group_ids,
391 link = _dbus_list_get_first_link (list);
394 BusPolicyRule *rule = link->data;
395 link = _dbus_list_get_next_link (list, link);
397 if (rule->type == BUS_POLICY_RULE_USER)
399 _dbus_verbose ("List %p user rule uid="DBUS_UID_FORMAT"\n",
400 list, rule->d.user.uid);
402 if (rule->d.user.uid == DBUS_UID_UNSET)
404 else if (rule->d.user.uid != uid)
407 else if (rule->type == BUS_POLICY_RULE_GROUP)
409 _dbus_verbose ("List %p group rule uid="DBUS_UID_FORMAT"\n",
410 list, rule->d.user.uid);
412 if (rule->d.group.gid == DBUS_GID_UNSET)
419 while (i < n_group_ids)
421 if (rule->d.group.gid == group_ids[i])
426 if (i == n_group_ids)
433 allowed = rule->allow;
440 bus_policy_allow_user (BusPolicy *policy,
441 DBusUserDatabase *user_database,
445 unsigned long *group_ids;
448 /* On OOM or error we always reject the user */
449 if (!_dbus_user_database_get_groups (user_database,
450 uid, &group_ids, &n_group_ids, NULL))
452 _dbus_verbose ("Did not get any groups for UID %lu\n",
457 /* Default to "user owning bus" or root can connect */
458 allowed = uid == _dbus_getuid ();
460 allowed = list_allows_user (allowed,
461 &policy->default_rules,
463 group_ids, n_group_ids);
465 allowed = list_allows_user (allowed,
466 &policy->mandatory_rules,
468 group_ids, n_group_ids);
470 dbus_free (group_ids);
472 _dbus_verbose ("UID %lu allowed = %d\n", uid, allowed);
478 bus_policy_append_default_rule (BusPolicy *policy,
481 if (!_dbus_list_append (&policy->default_rules, rule))
484 bus_policy_rule_ref (rule);
490 bus_policy_append_mandatory_rule (BusPolicy *policy,
493 if (!_dbus_list_append (&policy->mandatory_rules, rule))
496 bus_policy_rule_ref (rule);
504 get_list (DBusHashTable *hash,
509 list = _dbus_hash_table_lookup_ulong (hash, key);
513 list = dbus_new0 (DBusList*, 1);
517 if (!_dbus_hash_table_insert_ulong (hash, key, list))
528 bus_policy_append_user_rule (BusPolicy *policy,
534 list = get_list (policy->rules_by_uid, uid);
539 if (!_dbus_list_append (list, rule))
542 bus_policy_rule_ref (rule);
548 bus_policy_append_group_rule (BusPolicy *policy,
554 list = get_list (policy->rules_by_gid, gid);
559 if (!_dbus_list_append (list, rule))
562 bus_policy_rule_ref (rule);
568 bus_policy_append_console_rule (BusPolicy *policy,
569 dbus_bool_t at_console,
574 if (!_dbus_list_append (&policy->at_console_true_rules, rule))
579 if (!_dbus_list_append (&policy->at_console_false_rules, rule))
583 bus_policy_rule_ref (rule);
590 append_copy_of_policy_list (DBusList **list,
591 DBusList **to_append)
598 /* Preallocate all our links */
599 link = _dbus_list_get_first_link (to_append);
602 if (!_dbus_list_append (&tmp_list, link->data))
604 _dbus_list_clear (&tmp_list);
608 link = _dbus_list_get_next_link (to_append, link);
611 /* Now append them */
612 while ((link = _dbus_list_pop_first_link (&tmp_list)))
614 bus_policy_rule_ref (link->data);
615 _dbus_list_append_link (list, link);
622 merge_id_hash (DBusHashTable *dest,
623 DBusHashTable *to_absorb)
627 _dbus_hash_iter_init (to_absorb, &iter);
628 while (_dbus_hash_iter_next (&iter))
630 unsigned long id = _dbus_hash_iter_get_ulong_key (&iter);
631 DBusList **list = _dbus_hash_iter_get_value (&iter);
632 DBusList **target = get_list (dest, id);
637 if (!append_copy_of_policy_list (target, list))
645 bus_policy_merge (BusPolicy *policy,
646 BusPolicy *to_absorb)
648 /* FIXME Not properly atomic, but as used for configuration files we
649 * don't rely on it quite so much.
652 if (!append_copy_of_policy_list (&policy->default_rules,
653 &to_absorb->default_rules))
656 if (!append_copy_of_policy_list (&policy->mandatory_rules,
657 &to_absorb->mandatory_rules))
660 if (!append_copy_of_policy_list (&policy->at_console_true_rules,
661 &to_absorb->at_console_true_rules))
664 if (!append_copy_of_policy_list (&policy->at_console_false_rules,
665 &to_absorb->at_console_false_rules))
668 if (!merge_id_hash (policy->rules_by_uid,
669 to_absorb->rules_by_uid))
672 if (!merge_id_hash (policy->rules_by_gid,
673 to_absorb->rules_by_gid))
679 struct BusClientPolicy
687 bus_client_policy_new (void)
689 BusClientPolicy *policy;
691 policy = dbus_new0 (BusClientPolicy, 1);
695 policy->refcount = 1;
701 bus_client_policy_ref (BusClientPolicy *policy)
703 _dbus_assert (policy->refcount > 0);
705 policy->refcount += 1;
711 rule_unref_foreach (void *data,
714 BusPolicyRule *rule = data;
716 bus_policy_rule_unref (rule);
720 bus_client_policy_unref (BusClientPolicy *policy)
722 _dbus_assert (policy->refcount > 0);
724 policy->refcount -= 1;
726 if (policy->refcount == 0)
728 _dbus_list_foreach (&policy->rules,
732 _dbus_list_clear (&policy->rules);
739 remove_rules_by_type_up_to (BusClientPolicy *policy,
740 BusPolicyRuleType type,
745 link = _dbus_list_get_first_link (&policy->rules);
746 while (link != up_to)
748 BusPolicyRule *rule = link->data;
749 DBusList *next = _dbus_list_get_next_link (&policy->rules, link);
751 if (rule->type == type)
753 _dbus_list_remove_link (&policy->rules, link);
754 bus_policy_rule_unref (rule);
762 bus_client_policy_optimize (BusClientPolicy *policy)
766 /* The idea here is that if we have:
768 * <allow send_interface="foo.bar"/>
769 * <deny send_interface="*"/>
771 * (for example) the deny will always override the allow. So we
772 * delete the allow. Ditto for deny followed by allow, etc. This is
773 * a dumb thing to put in a config file, but the <include> feature
774 * of files allows for an "inheritance and override" pattern where
775 * it could make sense. If an included file wants to "start over"
776 * with a blanket deny, no point keeping the rules from the parent
780 _dbus_verbose ("Optimizing policy with %d rules\n",
781 _dbus_list_get_length (&policy->rules));
783 link = _dbus_list_get_first_link (&policy->rules);
788 dbus_bool_t remove_preceding;
790 next = _dbus_list_get_next_link (&policy->rules, link);
793 remove_preceding = FALSE;
795 _dbus_assert (rule != NULL);
799 case BUS_POLICY_RULE_SEND:
801 rule->d.send.message_type == DBUS_MESSAGE_TYPE_INVALID &&
802 rule->d.send.path == NULL &&
803 rule->d.send.interface == NULL &&
804 rule->d.send.member == NULL &&
805 rule->d.send.error == NULL &&
806 rule->d.send.destination == NULL;
808 case BUS_POLICY_RULE_RECEIVE:
810 rule->d.receive.message_type == DBUS_MESSAGE_TYPE_INVALID &&
811 rule->d.receive.path == NULL &&
812 rule->d.receive.interface == NULL &&
813 rule->d.receive.member == NULL &&
814 rule->d.receive.error == NULL &&
815 rule->d.receive.origin == NULL;
817 case BUS_POLICY_RULE_OWN:
819 rule->d.own.service_name == NULL;
821 case BUS_POLICY_RULE_USER:
822 case BUS_POLICY_RULE_GROUP:
823 _dbus_assert_not_reached ("invalid rule");
827 if (remove_preceding)
828 remove_rules_by_type_up_to (policy, rule->type,
834 _dbus_verbose ("After optimization, policy has %d rules\n",
835 _dbus_list_get_length (&policy->rules));
839 bus_client_policy_append_rule (BusClientPolicy *policy,
842 _dbus_verbose ("Appending rule %p with type %d to policy %p\n",
843 rule, rule->type, policy);
845 if (!_dbus_list_append (&policy->rules, rule))
848 bus_policy_rule_ref (rule);
854 bus_client_policy_check_can_send (BusClientPolicy *policy,
855 BusRegistry *registry,
856 dbus_bool_t requested_reply,
857 DBusConnection *receiver,
858 DBusMessage *message)
863 /* policy->rules is in the order the rules appeared
864 * in the config file, i.e. last rule that applies wins
867 _dbus_verbose (" (policy) checking send rules\n");
870 link = _dbus_list_get_first_link (&policy->rules);
873 BusPolicyRule *rule = link->data;
875 link = _dbus_list_get_next_link (&policy->rules, link);
877 /* Rule is skipped if it specifies a different
878 * message name from the message, or a different
879 * destination from the message
882 if (rule->type != BUS_POLICY_RULE_SEND)
884 _dbus_verbose (" (policy) skipping non-send rule\n");
888 if (rule->d.send.message_type != DBUS_MESSAGE_TYPE_INVALID)
890 if (dbus_message_get_type (message) != rule->d.send.message_type)
892 _dbus_verbose (" (policy) skipping rule for different message type\n");
897 /* If it's a reply, the requested_reply flag kicks in */
898 if (dbus_message_get_reply_serial (message) != 0)
900 /* for allow, requested_reply=true means the rule applies
901 * only when reply was requested. requested_reply=false means
904 if (!requested_reply && rule->allow && rule->d.send.requested_reply)
906 _dbus_verbose (" (policy) skipping allow rule since it only applies to requested replies\n");
910 /* for deny, requested_reply=false means the rule applies only
911 * when the reply was not requested. requested_reply=true means the
912 * rule always applies.
914 if (requested_reply && !rule->allow && !rule->d.send.requested_reply)
916 _dbus_verbose (" (policy) skipping deny rule since it only applies to unrequested replies\n");
921 if (rule->d.send.path != NULL)
923 if (dbus_message_get_path (message) != NULL &&
924 strcmp (dbus_message_get_path (message),
925 rule->d.send.path) != 0)
927 _dbus_verbose (" (policy) skipping rule for different path\n");
932 if (rule->d.send.interface != NULL)
934 if (dbus_message_get_interface (message) != NULL &&
935 strcmp (dbus_message_get_interface (message),
936 rule->d.send.interface) != 0)
938 _dbus_verbose (" (policy) skipping rule for different interface\n");
943 if (rule->d.send.member != NULL)
945 if (dbus_message_get_member (message) != NULL &&
946 strcmp (dbus_message_get_member (message),
947 rule->d.send.member) != 0)
949 _dbus_verbose (" (policy) skipping rule for different member\n");
954 if (rule->d.send.error != NULL)
956 if (dbus_message_get_error_name (message) != NULL &&
957 strcmp (dbus_message_get_error_name (message),
958 rule->d.send.error) != 0)
960 _dbus_verbose (" (policy) skipping rule for different error name\n");
965 if (rule->d.send.destination != NULL)
967 /* receiver can be NULL for messages that are sent to the
968 * message bus itself, we check the strings in that case as
969 * built-in services don't have a DBusConnection but messages
970 * to them have a destination service name.
972 if (receiver == NULL)
974 if (!dbus_message_has_destination (message,
975 rule->d.send.destination))
977 _dbus_verbose (" (policy) skipping rule because message dest is not %s\n",
978 rule->d.send.destination);
987 _dbus_string_init_const (&str, rule->d.send.destination);
989 service = bus_registry_lookup (registry, &str);
992 _dbus_verbose (" (policy) skipping rule because dest %s doesn't exist\n",
993 rule->d.send.destination);
997 if (!bus_service_has_owner (service, receiver))
999 _dbus_verbose (" (policy) skipping rule because dest %s isn't owned by receiver\n",
1000 rule->d.send.destination);
1007 allowed = rule->allow;
1009 _dbus_verbose (" (policy) used rule, allow now = %d\n",
1016 /* See docs on what the args mean on bus_context_check_security_policy()
1020 bus_client_policy_check_can_receive (BusClientPolicy *policy,
1021 BusRegistry *registry,
1022 dbus_bool_t requested_reply,
1023 DBusConnection *sender,
1024 DBusConnection *addressed_recipient,
1025 DBusConnection *proposed_recipient,
1026 DBusMessage *message)
1029 dbus_bool_t allowed;
1030 dbus_bool_t eavesdropping;
1033 addressed_recipient != proposed_recipient &&
1034 dbus_message_get_destination (message) != NULL;
1036 /* policy->rules is in the order the rules appeared
1037 * in the config file, i.e. last rule that applies wins
1040 _dbus_verbose (" (policy) checking receive rules, eavesdropping = %d\n", eavesdropping);
1043 link = _dbus_list_get_first_link (&policy->rules);
1044 while (link != NULL)
1046 BusPolicyRule *rule = link->data;
1048 link = _dbus_list_get_next_link (&policy->rules, link);
1050 if (rule->type != BUS_POLICY_RULE_RECEIVE)
1052 _dbus_verbose (" (policy) skipping non-receive rule\n");
1056 if (rule->d.receive.message_type != DBUS_MESSAGE_TYPE_INVALID)
1058 if (dbus_message_get_type (message) != rule->d.receive.message_type)
1060 _dbus_verbose (" (policy) skipping rule for different message type\n");
1065 /* for allow, eavesdrop=false means the rule doesn't apply when
1066 * eavesdropping. eavesdrop=true means always allow.
1068 if (eavesdropping && rule->allow && !rule->d.receive.eavesdrop)
1070 _dbus_verbose (" (policy) skipping allow rule since it doesn't apply to eavesdropping\n");
1074 /* for deny, eavesdrop=true means the rule applies only when
1075 * eavesdropping; eavesdrop=false means always deny.
1077 if (!eavesdropping && !rule->allow && rule->d.receive.eavesdrop)
1079 _dbus_verbose (" (policy) skipping deny rule since it only applies to eavesdropping\n");
1083 /* If it's a reply, the requested_reply flag kicks in */
1084 if (dbus_message_get_reply_serial (message) != 0)
1086 /* for allow, requested_reply=true means the rule applies
1087 * only when reply was requested. requested_reply=false means
1090 if (!requested_reply && rule->allow && rule->d.receive.requested_reply)
1092 _dbus_verbose (" (policy) skipping allow rule since it only applies to requested replies\n");
1096 /* for deny, requested_reply=false means the rule applies only
1097 * when the reply was not requested. requested_reply=true means the
1098 * rule always applies.
1100 if (requested_reply && !rule->allow && !rule->d.receive.requested_reply)
1102 _dbus_verbose (" (policy) skipping deny rule since it only applies to unrequested replies\n");
1107 if (rule->d.receive.path != NULL)
1109 if (dbus_message_get_path (message) != NULL &&
1110 strcmp (dbus_message_get_path (message),
1111 rule->d.receive.path) != 0)
1113 _dbus_verbose (" (policy) skipping rule for different path\n");
1118 if (rule->d.receive.interface != NULL)
1120 if (dbus_message_get_interface (message) != NULL &&
1121 strcmp (dbus_message_get_interface (message),
1122 rule->d.receive.interface) != 0)
1124 _dbus_verbose (" (policy) skipping rule for different interface\n");
1129 if (rule->d.receive.member != NULL)
1131 if (dbus_message_get_member (message) != NULL &&
1132 strcmp (dbus_message_get_member (message),
1133 rule->d.receive.member) != 0)
1135 _dbus_verbose (" (policy) skipping rule for different member\n");
1140 if (rule->d.receive.error != NULL)
1142 if (dbus_message_get_error_name (message) != NULL &&
1143 strcmp (dbus_message_get_error_name (message),
1144 rule->d.receive.error) != 0)
1146 _dbus_verbose (" (policy) skipping rule for different error name\n");
1151 if (rule->d.receive.origin != NULL)
1153 /* sender can be NULL for messages that originate from the
1154 * message bus itself, we check the strings in that case as
1155 * built-in services don't have a DBusConnection but will
1156 * still set the sender on their messages.
1160 if (!dbus_message_has_sender (message,
1161 rule->d.receive.origin))
1163 _dbus_verbose (" (policy) skipping rule because message sender is not %s\n",
1164 rule->d.receive.origin);
1170 BusService *service;
1173 _dbus_string_init_const (&str, rule->d.receive.origin);
1175 service = bus_registry_lookup (registry, &str);
1177 if (service == NULL)
1179 _dbus_verbose (" (policy) skipping rule because origin %s doesn't exist\n",
1180 rule->d.receive.origin);
1184 if (!bus_service_has_owner (service, sender))
1186 _dbus_verbose (" (policy) skipping rule because origin %s isn't owned by sender\n",
1187 rule->d.receive.origin);
1194 allowed = rule->allow;
1196 _dbus_verbose (" (policy) used rule, allow now = %d\n",
1204 bus_client_policy_check_can_own (BusClientPolicy *policy,
1205 DBusConnection *connection,
1206 const DBusString *service_name)
1209 dbus_bool_t allowed;
1211 /* policy->rules is in the order the rules appeared
1212 * in the config file, i.e. last rule that applies wins
1216 link = _dbus_list_get_first_link (&policy->rules);
1217 while (link != NULL)
1219 BusPolicyRule *rule = link->data;
1221 link = _dbus_list_get_next_link (&policy->rules, link);
1223 /* Rule is skipped if it specifies a different service name from
1227 if (rule->type != BUS_POLICY_RULE_OWN)
1230 if (rule->d.own.service_name != NULL)
1232 if (!_dbus_string_equal_c_str (service_name,
1233 rule->d.own.service_name))
1238 allowed = rule->allow;
1244 #ifdef DBUS_BUILD_TESTS
1247 bus_policy_test (const DBusString *test_data_dir)
1249 /* This doesn't do anything for now because I decided to do it in
1250 * dispatch.c instead by having some of the clients in dispatch.c
1251 * have particular policies applied to them.
1257 #endif /* DBUS_BUILD_TESTS */