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>
31 #include <dbus/dbus-userdb.h>
34 bus_policy_rule_new (BusPolicyRuleType type,
39 rule = dbus_new0 (BusPolicyRule, 1);
49 case BUS_POLICY_RULE_USER:
50 rule->d.user.uid = DBUS_UID_UNSET;
52 case BUS_POLICY_RULE_GROUP:
53 rule->d.group.gid = DBUS_GID_UNSET;
55 case BUS_POLICY_RULE_SEND:
56 rule->d.send.message_type = DBUS_MESSAGE_TYPE_INVALID;
58 /* allow rules default to TRUE (only requested replies allowed)
59 * deny rules default to FALSE (only unrequested replies denied)
61 rule->d.send.requested_reply = rule->allow;
63 case BUS_POLICY_RULE_RECEIVE:
64 rule->d.receive.message_type = DBUS_MESSAGE_TYPE_INVALID;
65 /* allow rules default to TRUE (only requested replies allowed)
66 * deny rules default to FALSE (only unrequested replies denied)
68 rule->d.receive.requested_reply = rule->allow;
70 case BUS_POLICY_RULE_OWN:
78 bus_policy_rule_ref (BusPolicyRule *rule)
80 _dbus_assert (rule->refcount > 0);
88 bus_policy_rule_unref (BusPolicyRule *rule)
90 _dbus_assert (rule->refcount > 0);
94 if (rule->refcount == 0)
98 case BUS_POLICY_RULE_SEND:
99 dbus_free (rule->d.send.path);
100 dbus_free (rule->d.send.interface);
101 dbus_free (rule->d.send.member);
102 dbus_free (rule->d.send.error);
103 dbus_free (rule->d.send.destination);
105 case BUS_POLICY_RULE_RECEIVE:
106 dbus_free (rule->d.receive.path);
107 dbus_free (rule->d.receive.interface);
108 dbus_free (rule->d.receive.member);
109 dbus_free (rule->d.receive.error);
110 dbus_free (rule->d.receive.origin);
112 case BUS_POLICY_RULE_OWN:
113 dbus_free (rule->d.own.service_name);
115 case BUS_POLICY_RULE_USER:
117 case BUS_POLICY_RULE_GROUP:
129 DBusList *default_rules; /**< Default policy rules */
130 DBusList *mandatory_rules; /**< Mandatory policy rules */
131 DBusHashTable *rules_by_uid; /**< per-UID policy rules */
132 DBusHashTable *rules_by_gid; /**< per-GID policy rules */
133 DBusList *at_console_true_rules; /**< console user policy rules where at_console="true"*/
134 DBusList *at_console_false_rules; /**< console user policy rules where at_console="false"*/
138 free_rule_func (void *data,
141 BusPolicyRule *rule = data;
143 bus_policy_rule_unref (rule);
147 free_rule_list_func (void *data)
149 DBusList **list = data;
151 if (list == NULL) /* DBusHashTable is on crack */
154 _dbus_list_foreach (list, free_rule_func, NULL);
156 _dbus_list_clear (list);
162 bus_policy_new (void)
166 policy = dbus_new0 (BusPolicy, 1);
170 policy->refcount = 1;
172 policy->rules_by_uid = _dbus_hash_table_new (DBUS_HASH_ULONG,
174 free_rule_list_func);
175 if (policy->rules_by_uid == NULL)
178 policy->rules_by_gid = _dbus_hash_table_new (DBUS_HASH_ULONG,
180 free_rule_list_func);
181 if (policy->rules_by_gid == NULL)
187 bus_policy_unref (policy);
192 bus_policy_ref (BusPolicy *policy)
194 _dbus_assert (policy->refcount > 0);
196 policy->refcount += 1;
202 bus_policy_unref (BusPolicy *policy)
204 _dbus_assert (policy->refcount > 0);
206 policy->refcount -= 1;
208 if (policy->refcount == 0)
210 _dbus_list_foreach (&policy->default_rules, free_rule_func, NULL);
211 _dbus_list_clear (&policy->default_rules);
213 _dbus_list_foreach (&policy->mandatory_rules, free_rule_func, NULL);
214 _dbus_list_clear (&policy->mandatory_rules);
216 _dbus_list_foreach (&policy->at_console_true_rules, free_rule_func, NULL);
217 _dbus_list_clear (&policy->at_console_true_rules);
219 _dbus_list_foreach (&policy->at_console_false_rules, free_rule_func, NULL);
220 _dbus_list_clear (&policy->at_console_false_rules);
222 if (policy->rules_by_uid)
224 _dbus_hash_table_unref (policy->rules_by_uid);
225 policy->rules_by_uid = NULL;
228 if (policy->rules_by_gid)
230 _dbus_hash_table_unref (policy->rules_by_gid);
231 policy->rules_by_gid = NULL;
239 add_list_to_client (DBusList **list,
240 BusClientPolicy *client)
244 link = _dbus_list_get_first_link (list);
247 BusPolicyRule *rule = link->data;
248 link = _dbus_list_get_next_link (list, link);
252 case BUS_POLICY_RULE_USER:
253 case BUS_POLICY_RULE_GROUP:
254 /* These aren't per-connection policies */
257 case BUS_POLICY_RULE_OWN:
258 case BUS_POLICY_RULE_SEND:
259 case BUS_POLICY_RULE_RECEIVE:
260 /* These are per-connection */
261 if (!bus_client_policy_append_rule (client, rule))
271 bus_policy_create_client_policy (BusPolicy *policy,
272 DBusConnection *connection,
275 BusClientPolicy *client;
277 dbus_bool_t at_console;
279 _dbus_assert (dbus_connection_get_is_authenticated (connection));
280 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
282 client = bus_client_policy_new ();
286 if (!add_list_to_client (&policy->default_rules,
290 /* we avoid the overhead of looking up user's groups
291 * if we don't have any group rules anyway
293 if (_dbus_hash_table_get_n_entries (policy->rules_by_gid) > 0)
295 unsigned long *groups;
299 if (!bus_connection_get_groups (connection, &groups, &n_groups, error))
307 list = _dbus_hash_table_lookup_ulong (policy->rules_by_gid,
312 if (!add_list_to_client (list, client))
325 if (!dbus_connection_get_unix_user (connection, &uid))
327 dbus_set_error (error, DBUS_ERROR_FAILED,
328 "No user ID known for connection, cannot determine security policy\n");
332 if (_dbus_hash_table_get_n_entries (policy->rules_by_uid) > 0)
336 list = _dbus_hash_table_lookup_ulong (policy->rules_by_uid,
341 if (!add_list_to_client (list, client))
346 /* Add console rules */
347 at_console = _dbus_is_console_user (uid, error);
351 if (!add_list_to_client (&policy->at_console_true_rules, client))
354 else if (dbus_error_is_set (error) == TRUE)
358 else if (!add_list_to_client (&policy->at_console_false_rules, client))
363 if (!add_list_to_client (&policy->mandatory_rules,
367 bus_client_policy_optimize (client);
374 _DBUS_ASSERT_ERROR_IS_SET (error);
376 bus_client_policy_unref (client);
381 list_allows_user (dbus_bool_t def,
384 const unsigned long *group_ids,
392 link = _dbus_list_get_first_link (list);
395 BusPolicyRule *rule = link->data;
396 link = _dbus_list_get_next_link (list, link);
398 if (rule->type == BUS_POLICY_RULE_USER)
400 _dbus_verbose ("List %p user rule uid="DBUS_UID_FORMAT"\n",
401 list, rule->d.user.uid);
403 if (rule->d.user.uid == DBUS_UID_UNSET)
405 else if (rule->d.user.uid != uid)
408 else if (rule->type == BUS_POLICY_RULE_GROUP)
410 _dbus_verbose ("List %p group rule uid="DBUS_UID_FORMAT"\n",
411 list, rule->d.user.uid);
413 if (rule->d.group.gid == DBUS_GID_UNSET)
420 while (i < n_group_ids)
422 if (rule->d.group.gid == group_ids[i])
427 if (i == n_group_ids)
434 allowed = rule->allow;
441 bus_policy_allow_user (BusPolicy *policy,
445 unsigned long *group_ids;
448 /* On OOM or error we always reject the user */
449 if (!_dbus_groups_from_uid (uid, &group_ids, &n_group_ids))
451 _dbus_verbose ("Did not get any groups for UID %lu\n",
456 /* Default to "user owning bus" or root can connect */
457 allowed = uid == _dbus_getuid ();
459 allowed = list_allows_user (allowed,
460 &policy->default_rules,
462 group_ids, n_group_ids);
464 allowed = list_allows_user (allowed,
465 &policy->mandatory_rules,
467 group_ids, n_group_ids);
469 dbus_free (group_ids);
471 _dbus_verbose ("UID %lu allowed = %d\n", uid, allowed);
477 bus_policy_append_default_rule (BusPolicy *policy,
480 if (!_dbus_list_append (&policy->default_rules, rule))
483 bus_policy_rule_ref (rule);
489 bus_policy_append_mandatory_rule (BusPolicy *policy,
492 if (!_dbus_list_append (&policy->mandatory_rules, rule))
495 bus_policy_rule_ref (rule);
503 get_list (DBusHashTable *hash,
508 list = _dbus_hash_table_lookup_ulong (hash, key);
512 list = dbus_new0 (DBusList*, 1);
516 if (!_dbus_hash_table_insert_ulong (hash, key, list))
527 bus_policy_append_user_rule (BusPolicy *policy,
533 list = get_list (policy->rules_by_uid, uid);
538 if (!_dbus_list_append (list, rule))
541 bus_policy_rule_ref (rule);
547 bus_policy_append_group_rule (BusPolicy *policy,
553 list = get_list (policy->rules_by_gid, gid);
558 if (!_dbus_list_append (list, rule))
561 bus_policy_rule_ref (rule);
567 bus_policy_append_console_rule (BusPolicy *policy,
568 dbus_bool_t at_console,
573 if (!_dbus_list_append (&policy->at_console_true_rules, rule))
578 if (!_dbus_list_append (&policy->at_console_false_rules, rule))
582 bus_policy_rule_ref (rule);
589 append_copy_of_policy_list (DBusList **list,
590 DBusList **to_append)
597 /* Preallocate all our links */
598 link = _dbus_list_get_first_link (to_append);
601 if (!_dbus_list_append (&tmp_list, link->data))
603 _dbus_list_clear (&tmp_list);
607 link = _dbus_list_get_next_link (to_append, link);
610 /* Now append them */
611 while ((link = _dbus_list_pop_first_link (&tmp_list)))
613 bus_policy_rule_ref (link->data);
614 _dbus_list_append_link (list, link);
621 merge_id_hash (DBusHashTable *dest,
622 DBusHashTable *to_absorb)
626 _dbus_hash_iter_init (to_absorb, &iter);
627 while (_dbus_hash_iter_next (&iter))
629 unsigned long id = _dbus_hash_iter_get_ulong_key (&iter);
630 DBusList **list = _dbus_hash_iter_get_value (&iter);
631 DBusList **target = get_list (dest, id);
636 if (!append_copy_of_policy_list (target, list))
644 bus_policy_merge (BusPolicy *policy,
645 BusPolicy *to_absorb)
647 /* FIXME Not properly atomic, but as used for configuration files we
648 * don't rely on it quite so much.
651 if (!append_copy_of_policy_list (&policy->default_rules,
652 &to_absorb->default_rules))
655 if (!append_copy_of_policy_list (&policy->mandatory_rules,
656 &to_absorb->mandatory_rules))
659 if (!append_copy_of_policy_list (&policy->at_console_true_rules,
660 &to_absorb->at_console_true_rules))
663 if (!append_copy_of_policy_list (&policy->at_console_false_rules,
664 &to_absorb->at_console_false_rules))
667 if (!merge_id_hash (policy->rules_by_uid,
668 to_absorb->rules_by_uid))
671 if (!merge_id_hash (policy->rules_by_gid,
672 to_absorb->rules_by_gid))
678 struct BusClientPolicy
686 bus_client_policy_new (void)
688 BusClientPolicy *policy;
690 policy = dbus_new0 (BusClientPolicy, 1);
694 policy->refcount = 1;
700 bus_client_policy_ref (BusClientPolicy *policy)
702 _dbus_assert (policy->refcount > 0);
704 policy->refcount += 1;
710 rule_unref_foreach (void *data,
713 BusPolicyRule *rule = data;
715 bus_policy_rule_unref (rule);
719 bus_client_policy_unref (BusClientPolicy *policy)
721 _dbus_assert (policy->refcount > 0);
723 policy->refcount -= 1;
725 if (policy->refcount == 0)
727 _dbus_list_foreach (&policy->rules,
731 _dbus_list_clear (&policy->rules);
738 remove_rules_by_type_up_to (BusClientPolicy *policy,
739 BusPolicyRuleType type,
744 link = _dbus_list_get_first_link (&policy->rules);
745 while (link != up_to)
747 BusPolicyRule *rule = link->data;
748 DBusList *next = _dbus_list_get_next_link (&policy->rules, link);
750 if (rule->type == type)
752 _dbus_list_remove_link (&policy->rules, link);
753 bus_policy_rule_unref (rule);
761 bus_client_policy_optimize (BusClientPolicy *policy)
765 /* The idea here is that if we have:
767 * <allow send_interface="foo.bar"/>
768 * <deny send_interface="*"/>
770 * (for example) the deny will always override the allow. So we
771 * delete the allow. Ditto for deny followed by allow, etc. This is
772 * a dumb thing to put in a config file, but the <include> feature
773 * of files allows for an "inheritance and override" pattern where
774 * it could make sense. If an included file wants to "start over"
775 * with a blanket deny, no point keeping the rules from the parent
779 _dbus_verbose ("Optimizing policy with %d rules\n",
780 _dbus_list_get_length (&policy->rules));
782 link = _dbus_list_get_first_link (&policy->rules);
787 dbus_bool_t remove_preceding;
789 next = _dbus_list_get_next_link (&policy->rules, link);
792 remove_preceding = FALSE;
794 _dbus_assert (rule != NULL);
798 case BUS_POLICY_RULE_SEND:
800 rule->d.send.message_type == DBUS_MESSAGE_TYPE_INVALID &&
801 rule->d.send.path == NULL &&
802 rule->d.send.interface == NULL &&
803 rule->d.send.member == NULL &&
804 rule->d.send.error == NULL &&
805 rule->d.send.destination == NULL;
807 case BUS_POLICY_RULE_RECEIVE:
809 rule->d.receive.message_type == DBUS_MESSAGE_TYPE_INVALID &&
810 rule->d.receive.path == NULL &&
811 rule->d.receive.interface == NULL &&
812 rule->d.receive.member == NULL &&
813 rule->d.receive.error == NULL &&
814 rule->d.receive.origin == NULL;
816 case BUS_POLICY_RULE_OWN:
818 rule->d.own.service_name == NULL;
820 case BUS_POLICY_RULE_USER:
821 case BUS_POLICY_RULE_GROUP:
822 _dbus_assert_not_reached ("invalid rule");
826 if (remove_preceding)
827 remove_rules_by_type_up_to (policy, rule->type,
833 _dbus_verbose ("After optimization, policy has %d rules\n",
834 _dbus_list_get_length (&policy->rules));
838 bus_client_policy_append_rule (BusClientPolicy *policy,
841 _dbus_verbose ("Appending rule %p with type %d to policy %p\n",
842 rule, rule->type, policy);
844 if (!_dbus_list_append (&policy->rules, rule))
847 bus_policy_rule_ref (rule);
853 bus_client_policy_check_can_send (BusClientPolicy *policy,
854 BusRegistry *registry,
855 dbus_bool_t requested_reply,
856 DBusConnection *receiver,
857 DBusMessage *message)
862 /* policy->rules is in the order the rules appeared
863 * in the config file, i.e. last rule that applies wins
866 _dbus_verbose (" (policy) checking send rules\n");
869 link = _dbus_list_get_first_link (&policy->rules);
872 BusPolicyRule *rule = link->data;
874 link = _dbus_list_get_next_link (&policy->rules, link);
876 /* Rule is skipped if it specifies a different
877 * message name from the message, or a different
878 * destination from the message
881 if (rule->type != BUS_POLICY_RULE_SEND)
883 _dbus_verbose (" (policy) skipping non-send rule\n");
887 if (rule->d.send.message_type != DBUS_MESSAGE_TYPE_INVALID)
889 if (dbus_message_get_type (message) != rule->d.send.message_type)
891 _dbus_verbose (" (policy) skipping rule for different message type\n");
896 /* If it's a reply, the requested_reply flag kicks in */
897 if (dbus_message_get_reply_serial (message) != 0)
899 /* for allow, requested_reply=true means the rule applies
900 * only when reply was requested. requested_reply=false means
903 if (!requested_reply && rule->allow && rule->d.send.requested_reply && !rule->d.send.eavesdrop)
905 _dbus_verbose (" (policy) skipping allow rule since it only applies to requested replies and does not allow eavesdropping\n");
909 /* for deny, requested_reply=false means the rule applies only
910 * when the reply was not requested. requested_reply=true means the
911 * rule always applies.
913 if (requested_reply && !rule->allow && !rule->d.send.requested_reply)
915 _dbus_verbose (" (policy) skipping deny rule since it only applies to unrequested replies\n");
920 if (rule->d.send.path != NULL)
922 if (dbus_message_get_path (message) != NULL &&
923 strcmp (dbus_message_get_path (message),
924 rule->d.send.path) != 0)
926 _dbus_verbose (" (policy) skipping rule for different path\n");
931 if (rule->d.send.interface != NULL)
933 if (dbus_message_get_interface (message) != NULL &&
934 strcmp (dbus_message_get_interface (message),
935 rule->d.send.interface) != 0)
937 _dbus_verbose (" (policy) skipping rule for different interface\n");
942 if (rule->d.send.member != NULL)
944 if (dbus_message_get_member (message) != NULL &&
945 strcmp (dbus_message_get_member (message),
946 rule->d.send.member) != 0)
948 _dbus_verbose (" (policy) skipping rule for different member\n");
953 if (rule->d.send.error != NULL)
955 if (dbus_message_get_error_name (message) != NULL &&
956 strcmp (dbus_message_get_error_name (message),
957 rule->d.send.error) != 0)
959 _dbus_verbose (" (policy) skipping rule for different error name\n");
964 if (rule->d.send.destination != NULL)
966 /* receiver can be NULL for messages that are sent to the
967 * message bus itself, we check the strings in that case as
968 * built-in services don't have a DBusConnection but messages
969 * to them have a destination service name.
971 if (receiver == NULL)
973 if (!dbus_message_has_destination (message,
974 rule->d.send.destination))
976 _dbus_verbose (" (policy) skipping rule because message dest is not %s\n",
977 rule->d.send.destination);
986 _dbus_string_init_const (&str, rule->d.send.destination);
988 service = bus_registry_lookup (registry, &str);
991 _dbus_verbose (" (policy) skipping rule because dest %s doesn't exist\n",
992 rule->d.send.destination);
996 if (!bus_service_has_owner (service, receiver))
998 _dbus_verbose (" (policy) skipping rule because dest %s isn't owned by receiver\n",
999 rule->d.send.destination);
1006 allowed = rule->allow;
1008 _dbus_verbose (" (policy) used rule, allow now = %d\n",
1015 /* See docs on what the args mean on bus_context_check_security_policy()
1019 bus_client_policy_check_can_receive (BusClientPolicy *policy,
1020 BusRegistry *registry,
1021 dbus_bool_t requested_reply,
1022 DBusConnection *sender,
1023 DBusConnection *addressed_recipient,
1024 DBusConnection *proposed_recipient,
1025 DBusMessage *message)
1028 dbus_bool_t allowed;
1029 dbus_bool_t eavesdropping;
1032 addressed_recipient != proposed_recipient &&
1033 dbus_message_get_destination (message) != NULL;
1035 /* policy->rules is in the order the rules appeared
1036 * in the config file, i.e. last rule that applies wins
1039 _dbus_verbose (" (policy) checking receive rules, eavesdropping = %d\n", eavesdropping);
1042 link = _dbus_list_get_first_link (&policy->rules);
1043 while (link != NULL)
1045 BusPolicyRule *rule = link->data;
1047 link = _dbus_list_get_next_link (&policy->rules, link);
1049 if (rule->type != BUS_POLICY_RULE_RECEIVE)
1051 _dbus_verbose (" (policy) skipping non-receive rule\n");
1055 if (rule->d.receive.message_type != DBUS_MESSAGE_TYPE_INVALID)
1057 if (dbus_message_get_type (message) != rule->d.receive.message_type)
1059 _dbus_verbose (" (policy) skipping rule for different message type\n");
1064 /* for allow, eavesdrop=false means the rule doesn't apply when
1065 * eavesdropping. eavesdrop=true means always allow.
1067 if (eavesdropping && rule->allow && !rule->d.receive.eavesdrop)
1069 _dbus_verbose (" (policy) skipping allow rule since it doesn't apply to eavesdropping\n");
1073 /* for deny, eavesdrop=true means the rule applies only when
1074 * eavesdropping; eavesdrop=false means always deny.
1076 if (!eavesdropping && !rule->allow && rule->d.receive.eavesdrop)
1078 _dbus_verbose (" (policy) skipping deny rule since it only applies to eavesdropping\n");
1082 /* If it's a reply, the requested_reply flag kicks in */
1083 if (dbus_message_get_reply_serial (message) != 0)
1085 /* for allow, requested_reply=true means the rule applies
1086 * only when reply was requested. requested_reply=false means
1089 if (!requested_reply && rule->allow && rule->d.receive.requested_reply && !rule->d.receive.eavesdrop)
1091 _dbus_verbose (" (policy) skipping allow rule since it only applies to requested replies and does not allow eavesdropping\n");
1095 /* for deny, requested_reply=false means the rule applies only
1096 * when the reply was not requested. requested_reply=true means the
1097 * rule always applies.
1099 if (requested_reply && !rule->allow && !rule->d.receive.requested_reply)
1101 _dbus_verbose (" (policy) skipping deny rule since it only applies to unrequested replies\n");
1106 if (rule->d.receive.path != NULL)
1108 if (dbus_message_get_path (message) != NULL &&
1109 strcmp (dbus_message_get_path (message),
1110 rule->d.receive.path) != 0)
1112 _dbus_verbose (" (policy) skipping rule for different path\n");
1117 if (rule->d.receive.interface != NULL)
1119 if (dbus_message_get_interface (message) != NULL &&
1120 strcmp (dbus_message_get_interface (message),
1121 rule->d.receive.interface) != 0)
1123 _dbus_verbose (" (policy) skipping rule for different interface\n");
1128 if (rule->d.receive.member != NULL)
1130 if (dbus_message_get_member (message) != NULL &&
1131 strcmp (dbus_message_get_member (message),
1132 rule->d.receive.member) != 0)
1134 _dbus_verbose (" (policy) skipping rule for different member\n");
1139 if (rule->d.receive.error != NULL)
1141 if (dbus_message_get_error_name (message) != NULL &&
1142 strcmp (dbus_message_get_error_name (message),
1143 rule->d.receive.error) != 0)
1145 _dbus_verbose (" (policy) skipping rule for different error name\n");
1150 if (rule->d.receive.origin != NULL)
1152 /* sender can be NULL for messages that originate from the
1153 * message bus itself, we check the strings in that case as
1154 * built-in services don't have a DBusConnection but will
1155 * still set the sender on their messages.
1159 if (!dbus_message_has_sender (message,
1160 rule->d.receive.origin))
1162 _dbus_verbose (" (policy) skipping rule because message sender is not %s\n",
1163 rule->d.receive.origin);
1169 BusService *service;
1172 _dbus_string_init_const (&str, rule->d.receive.origin);
1174 service = bus_registry_lookup (registry, &str);
1176 if (service == NULL)
1178 _dbus_verbose (" (policy) skipping rule because origin %s doesn't exist\n",
1179 rule->d.receive.origin);
1183 if (!bus_service_has_owner (service, sender))
1185 _dbus_verbose (" (policy) skipping rule because origin %s isn't owned by sender\n",
1186 rule->d.receive.origin);
1193 allowed = rule->allow;
1195 _dbus_verbose (" (policy) used rule, allow now = %d\n",
1203 bus_client_policy_check_can_own (BusClientPolicy *policy,
1204 DBusConnection *connection,
1205 const DBusString *service_name)
1208 dbus_bool_t allowed;
1210 /* policy->rules is in the order the rules appeared
1211 * in the config file, i.e. last rule that applies wins
1215 link = _dbus_list_get_first_link (&policy->rules);
1216 while (link != NULL)
1218 BusPolicyRule *rule = link->data;
1220 link = _dbus_list_get_next_link (&policy->rules, link);
1222 /* Rule is skipped if it specifies a different service name from
1226 if (rule->type != BUS_POLICY_RULE_OWN)
1229 if (rule->d.own.service_name != NULL)
1231 if (!_dbus_string_equal_c_str (service_name,
1232 rule->d.own.service_name))
1237 allowed = rule->allow;
1243 #ifdef DBUS_BUILD_TESTS
1246 bus_policy_test (const DBusString *test_data_dir)
1248 /* This doesn't do anything for now because I decided to do it in
1249 * dispatch.c instead by having some of the clients in dispatch.c
1250 * have particular policies applied to them.
1256 #endif /* DBUS_BUILD_TESTS */