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 #ifdef DBUS_WIN_FIXME
328 _dbus_verbose ("policy.c: dbus_connection_get_unix_user check disabled under windows\n");
330 dbus_set_error (error, DBUS_ERROR_FAILED,
331 "No user ID known for connection, cannot determine security policy\n");
336 if (_dbus_hash_table_get_n_entries (policy->rules_by_uid) > 0)
340 list = _dbus_hash_table_lookup_ulong (policy->rules_by_uid,
345 if (!add_list_to_client (list, client))
350 /* Add console rules */
351 at_console = _dbus_is_console_user (uid, error);
355 if (!add_list_to_client (&policy->at_console_true_rules, client))
358 else if (dbus_error_is_set (error) == TRUE)
362 else if (!add_list_to_client (&policy->at_console_false_rules, client))
367 if (!add_list_to_client (&policy->mandatory_rules,
371 bus_client_policy_optimize (client);
378 _DBUS_ASSERT_ERROR_IS_SET (error);
380 bus_client_policy_unref (client);
385 list_allows_user (dbus_bool_t def,
388 const unsigned long *group_ids,
396 link = _dbus_list_get_first_link (list);
399 BusPolicyRule *rule = link->data;
400 link = _dbus_list_get_next_link (list, link);
402 if (rule->type == BUS_POLICY_RULE_USER)
404 _dbus_verbose ("List %p user rule uid="DBUS_UID_FORMAT"\n",
405 list, rule->d.user.uid);
407 if (rule->d.user.uid == DBUS_UID_UNSET)
409 else if (rule->d.user.uid != uid)
412 else if (rule->type == BUS_POLICY_RULE_GROUP)
414 _dbus_verbose ("List %p group rule uid="DBUS_UID_FORMAT"\n",
415 list, rule->d.user.uid);
417 if (rule->d.group.gid == DBUS_GID_UNSET)
424 while (i < n_group_ids)
426 if (rule->d.group.gid == group_ids[i])
431 if (i == n_group_ids)
438 allowed = rule->allow;
445 bus_policy_allow_user (BusPolicy *policy,
449 unsigned long *group_ids;
452 /* On OOM or error we always reject the user */
453 if (!_dbus_groups_from_uid (uid, &group_ids, &n_group_ids))
455 _dbus_verbose ("Did not get any groups for UID %lu\n",
460 /* Default to "user owning bus" or root can connect */
461 allowed = uid == _dbus_getuid ();
463 allowed = list_allows_user (allowed,
464 &policy->default_rules,
466 group_ids, n_group_ids);
468 allowed = list_allows_user (allowed,
469 &policy->mandatory_rules,
471 group_ids, n_group_ids);
473 dbus_free (group_ids);
475 _dbus_verbose ("UID %lu allowed = %d\n", uid, allowed);
481 bus_policy_append_default_rule (BusPolicy *policy,
484 if (!_dbus_list_append (&policy->default_rules, rule))
487 bus_policy_rule_ref (rule);
493 bus_policy_append_mandatory_rule (BusPolicy *policy,
496 if (!_dbus_list_append (&policy->mandatory_rules, rule))
499 bus_policy_rule_ref (rule);
507 get_list (DBusHashTable *hash,
512 list = _dbus_hash_table_lookup_ulong (hash, key);
516 list = dbus_new0 (DBusList*, 1);
520 if (!_dbus_hash_table_insert_ulong (hash, key, list))
531 bus_policy_append_user_rule (BusPolicy *policy,
537 list = get_list (policy->rules_by_uid, uid);
542 if (!_dbus_list_append (list, rule))
545 bus_policy_rule_ref (rule);
551 bus_policy_append_group_rule (BusPolicy *policy,
557 list = get_list (policy->rules_by_gid, gid);
562 if (!_dbus_list_append (list, rule))
565 bus_policy_rule_ref (rule);
571 bus_policy_append_console_rule (BusPolicy *policy,
572 dbus_bool_t at_console,
577 if (!_dbus_list_append (&policy->at_console_true_rules, rule))
582 if (!_dbus_list_append (&policy->at_console_false_rules, rule))
586 bus_policy_rule_ref (rule);
593 append_copy_of_policy_list (DBusList **list,
594 DBusList **to_append)
601 /* Preallocate all our links */
602 link = _dbus_list_get_first_link (to_append);
605 if (!_dbus_list_append (&tmp_list, link->data))
607 _dbus_list_clear (&tmp_list);
611 link = _dbus_list_get_next_link (to_append, link);
614 /* Now append them */
615 while ((link = _dbus_list_pop_first_link (&tmp_list)))
617 bus_policy_rule_ref (link->data);
618 _dbus_list_append_link (list, link);
625 merge_id_hash (DBusHashTable *dest,
626 DBusHashTable *to_absorb)
630 _dbus_hash_iter_init (to_absorb, &iter);
631 while (_dbus_hash_iter_next (&iter))
633 unsigned long id = _dbus_hash_iter_get_ulong_key (&iter);
634 DBusList **list = _dbus_hash_iter_get_value (&iter);
635 DBusList **target = get_list (dest, id);
640 if (!append_copy_of_policy_list (target, list))
648 bus_policy_merge (BusPolicy *policy,
649 BusPolicy *to_absorb)
651 /* FIXME Not properly atomic, but as used for configuration files we
652 * don't rely on it quite so much.
655 if (!append_copy_of_policy_list (&policy->default_rules,
656 &to_absorb->default_rules))
659 if (!append_copy_of_policy_list (&policy->mandatory_rules,
660 &to_absorb->mandatory_rules))
663 if (!append_copy_of_policy_list (&policy->at_console_true_rules,
664 &to_absorb->at_console_true_rules))
667 if (!append_copy_of_policy_list (&policy->at_console_false_rules,
668 &to_absorb->at_console_false_rules))
671 if (!merge_id_hash (policy->rules_by_uid,
672 to_absorb->rules_by_uid))
675 if (!merge_id_hash (policy->rules_by_gid,
676 to_absorb->rules_by_gid))
682 struct BusClientPolicy
690 bus_client_policy_new (void)
692 BusClientPolicy *policy;
694 policy = dbus_new0 (BusClientPolicy, 1);
698 policy->refcount = 1;
704 bus_client_policy_ref (BusClientPolicy *policy)
706 _dbus_assert (policy->refcount > 0);
708 policy->refcount += 1;
714 rule_unref_foreach (void *data,
717 BusPolicyRule *rule = data;
719 bus_policy_rule_unref (rule);
723 bus_client_policy_unref (BusClientPolicy *policy)
725 _dbus_assert (policy->refcount > 0);
727 policy->refcount -= 1;
729 if (policy->refcount == 0)
731 _dbus_list_foreach (&policy->rules,
735 _dbus_list_clear (&policy->rules);
742 remove_rules_by_type_up_to (BusClientPolicy *policy,
743 BusPolicyRuleType type,
748 link = _dbus_list_get_first_link (&policy->rules);
749 while (link != up_to)
751 BusPolicyRule *rule = link->data;
752 DBusList *next = _dbus_list_get_next_link (&policy->rules, link);
754 if (rule->type == type)
756 _dbus_list_remove_link (&policy->rules, link);
757 bus_policy_rule_unref (rule);
765 bus_client_policy_optimize (BusClientPolicy *policy)
769 /* The idea here is that if we have:
771 * <allow send_interface="foo.bar"/>
772 * <deny send_interface="*"/>
774 * (for example) the deny will always override the allow. So we
775 * delete the allow. Ditto for deny followed by allow, etc. This is
776 * a dumb thing to put in a config file, but the <include> feature
777 * of files allows for an "inheritance and override" pattern where
778 * it could make sense. If an included file wants to "start over"
779 * with a blanket deny, no point keeping the rules from the parent
783 _dbus_verbose ("Optimizing policy with %d rules\n",
784 _dbus_list_get_length (&policy->rules));
786 link = _dbus_list_get_first_link (&policy->rules);
791 dbus_bool_t remove_preceding;
793 next = _dbus_list_get_next_link (&policy->rules, link);
796 remove_preceding = FALSE;
798 _dbus_assert (rule != NULL);
802 case BUS_POLICY_RULE_SEND:
804 rule->d.send.message_type == DBUS_MESSAGE_TYPE_INVALID &&
805 rule->d.send.path == NULL &&
806 rule->d.send.interface == NULL &&
807 rule->d.send.member == NULL &&
808 rule->d.send.error == NULL &&
809 rule->d.send.destination == NULL;
811 case BUS_POLICY_RULE_RECEIVE:
813 rule->d.receive.message_type == DBUS_MESSAGE_TYPE_INVALID &&
814 rule->d.receive.path == NULL &&
815 rule->d.receive.interface == NULL &&
816 rule->d.receive.member == NULL &&
817 rule->d.receive.error == NULL &&
818 rule->d.receive.origin == NULL;
820 case BUS_POLICY_RULE_OWN:
822 rule->d.own.service_name == NULL;
824 case BUS_POLICY_RULE_USER:
825 case BUS_POLICY_RULE_GROUP:
826 _dbus_assert_not_reached ("invalid rule");
830 if (remove_preceding)
831 remove_rules_by_type_up_to (policy, rule->type,
837 _dbus_verbose ("After optimization, policy has %d rules\n",
838 _dbus_list_get_length (&policy->rules));
842 bus_client_policy_append_rule (BusClientPolicy *policy,
845 _dbus_verbose ("Appending rule %p with type %d to policy %p\n",
846 rule, rule->type, policy);
848 if (!_dbus_list_append (&policy->rules, rule))
851 bus_policy_rule_ref (rule);
857 bus_client_policy_check_can_send (BusClientPolicy *policy,
858 BusRegistry *registry,
859 dbus_bool_t requested_reply,
860 DBusConnection *receiver,
861 DBusMessage *message)
866 /* policy->rules is in the order the rules appeared
867 * in the config file, i.e. last rule that applies wins
870 _dbus_verbose (" (policy) checking send rules\n");
873 link = _dbus_list_get_first_link (&policy->rules);
876 BusPolicyRule *rule = link->data;
878 link = _dbus_list_get_next_link (&policy->rules, link);
880 /* Rule is skipped if it specifies a different
881 * message name from the message, or a different
882 * destination from the message
885 if (rule->type != BUS_POLICY_RULE_SEND)
887 _dbus_verbose (" (policy) skipping non-send rule\n");
891 if (rule->d.send.message_type != DBUS_MESSAGE_TYPE_INVALID)
893 if (dbus_message_get_type (message) != rule->d.send.message_type)
895 _dbus_verbose (" (policy) skipping rule for different message type\n");
900 /* If it's a reply, the requested_reply flag kicks in */
901 if (dbus_message_get_reply_serial (message) != 0)
903 /* for allow, requested_reply=true means the rule applies
904 * only when reply was requested. requested_reply=false means
907 if (!requested_reply && rule->allow && rule->d.send.requested_reply && !rule->d.send.eavesdrop)
909 _dbus_verbose (" (policy) skipping allow rule since it only applies to requested replies and does not allow eavesdropping\n");
913 /* for deny, requested_reply=false means the rule applies only
914 * when the reply was not requested. requested_reply=true means the
915 * rule always applies.
917 if (requested_reply && !rule->allow && !rule->d.send.requested_reply)
919 _dbus_verbose (" (policy) skipping deny rule since it only applies to unrequested replies\n");
924 if (rule->d.send.path != NULL)
926 if (dbus_message_get_path (message) != NULL &&
927 strcmp (dbus_message_get_path (message),
928 rule->d.send.path) != 0)
930 _dbus_verbose (" (policy) skipping rule for different path\n");
935 if (rule->d.send.interface != NULL)
937 if (dbus_message_get_interface (message) != NULL &&
938 strcmp (dbus_message_get_interface (message),
939 rule->d.send.interface) != 0)
941 _dbus_verbose (" (policy) skipping rule for different interface\n");
946 if (rule->d.send.member != NULL)
948 if (dbus_message_get_member (message) != NULL &&
949 strcmp (dbus_message_get_member (message),
950 rule->d.send.member) != 0)
952 _dbus_verbose (" (policy) skipping rule for different member\n");
957 if (rule->d.send.error != NULL)
959 if (dbus_message_get_error_name (message) != NULL &&
960 strcmp (dbus_message_get_error_name (message),
961 rule->d.send.error) != 0)
963 _dbus_verbose (" (policy) skipping rule for different error name\n");
968 if (rule->d.send.destination != NULL)
970 /* receiver can be NULL for messages that are sent to the
971 * message bus itself, we check the strings in that case as
972 * built-in services don't have a DBusConnection but messages
973 * to them have a destination service name.
975 if (receiver == NULL)
977 if (!dbus_message_has_destination (message,
978 rule->d.send.destination))
980 _dbus_verbose (" (policy) skipping rule because message dest is not %s\n",
981 rule->d.send.destination);
990 _dbus_string_init_const (&str, rule->d.send.destination);
992 service = bus_registry_lookup (registry, &str);
995 _dbus_verbose (" (policy) skipping rule because dest %s doesn't exist\n",
996 rule->d.send.destination);
1000 if (!bus_service_has_owner (service, receiver))
1002 _dbus_verbose (" (policy) skipping rule because dest %s isn't owned by receiver\n",
1003 rule->d.send.destination);
1010 allowed = rule->allow;
1012 _dbus_verbose (" (policy) used rule, allow now = %d\n",
1019 /* See docs on what the args mean on bus_context_check_security_policy()
1023 bus_client_policy_check_can_receive (BusClientPolicy *policy,
1024 BusRegistry *registry,
1025 dbus_bool_t requested_reply,
1026 DBusConnection *sender,
1027 DBusConnection *addressed_recipient,
1028 DBusConnection *proposed_recipient,
1029 DBusMessage *message)
1032 dbus_bool_t allowed;
1033 dbus_bool_t eavesdropping;
1036 addressed_recipient != proposed_recipient &&
1037 dbus_message_get_destination (message) != NULL;
1039 /* policy->rules is in the order the rules appeared
1040 * in the config file, i.e. last rule that applies wins
1043 _dbus_verbose (" (policy) checking receive rules, eavesdropping = %d\n", eavesdropping);
1046 link = _dbus_list_get_first_link (&policy->rules);
1047 while (link != NULL)
1049 BusPolicyRule *rule = link->data;
1051 link = _dbus_list_get_next_link (&policy->rules, link);
1053 if (rule->type != BUS_POLICY_RULE_RECEIVE)
1055 _dbus_verbose (" (policy) skipping non-receive rule\n");
1059 if (rule->d.receive.message_type != DBUS_MESSAGE_TYPE_INVALID)
1061 if (dbus_message_get_type (message) != rule->d.receive.message_type)
1063 _dbus_verbose (" (policy) skipping rule for different message type\n");
1068 /* for allow, eavesdrop=false means the rule doesn't apply when
1069 * eavesdropping. eavesdrop=true means always allow.
1071 if (eavesdropping && rule->allow && !rule->d.receive.eavesdrop)
1073 _dbus_verbose (" (policy) skipping allow rule since it doesn't apply to eavesdropping\n");
1077 /* for deny, eavesdrop=true means the rule applies only when
1078 * eavesdropping; eavesdrop=false means always deny.
1080 if (!eavesdropping && !rule->allow && rule->d.receive.eavesdrop)
1082 _dbus_verbose (" (policy) skipping deny rule since it only applies to eavesdropping\n");
1086 /* If it's a reply, the requested_reply flag kicks in */
1087 if (dbus_message_get_reply_serial (message) != 0)
1089 /* for allow, requested_reply=true means the rule applies
1090 * only when reply was requested. requested_reply=false means
1093 if (!requested_reply && rule->allow && rule->d.receive.requested_reply && !rule->d.receive.eavesdrop)
1095 _dbus_verbose (" (policy) skipping allow rule since it only applies to requested replies and does not allow eavesdropping\n");
1099 /* for deny, requested_reply=false means the rule applies only
1100 * when the reply was not requested. requested_reply=true means the
1101 * rule always applies.
1103 if (requested_reply && !rule->allow && !rule->d.receive.requested_reply)
1105 _dbus_verbose (" (policy) skipping deny rule since it only applies to unrequested replies\n");
1110 if (rule->d.receive.path != NULL)
1112 if (dbus_message_get_path (message) != NULL &&
1113 strcmp (dbus_message_get_path (message),
1114 rule->d.receive.path) != 0)
1116 _dbus_verbose (" (policy) skipping rule for different path\n");
1121 if (rule->d.receive.interface != NULL)
1123 if (dbus_message_get_interface (message) != NULL &&
1124 strcmp (dbus_message_get_interface (message),
1125 rule->d.receive.interface) != 0)
1127 _dbus_verbose (" (policy) skipping rule for different interface\n");
1132 if (rule->d.receive.member != NULL)
1134 if (dbus_message_get_member (message) != NULL &&
1135 strcmp (dbus_message_get_member (message),
1136 rule->d.receive.member) != 0)
1138 _dbus_verbose (" (policy) skipping rule for different member\n");
1143 if (rule->d.receive.error != NULL)
1145 if (dbus_message_get_error_name (message) != NULL &&
1146 strcmp (dbus_message_get_error_name (message),
1147 rule->d.receive.error) != 0)
1149 _dbus_verbose (" (policy) skipping rule for different error name\n");
1154 if (rule->d.receive.origin != NULL)
1156 /* sender can be NULL for messages that originate from the
1157 * message bus itself, we check the strings in that case as
1158 * built-in services don't have a DBusConnection but will
1159 * still set the sender on their messages.
1163 if (!dbus_message_has_sender (message,
1164 rule->d.receive.origin))
1166 _dbus_verbose (" (policy) skipping rule because message sender is not %s\n",
1167 rule->d.receive.origin);
1173 BusService *service;
1176 _dbus_string_init_const (&str, rule->d.receive.origin);
1178 service = bus_registry_lookup (registry, &str);
1180 if (service == NULL)
1182 _dbus_verbose (" (policy) skipping rule because origin %s doesn't exist\n",
1183 rule->d.receive.origin);
1187 if (!bus_service_has_owner (service, sender))
1189 _dbus_verbose (" (policy) skipping rule because origin %s isn't owned by sender\n",
1190 rule->d.receive.origin);
1197 allowed = rule->allow;
1199 _dbus_verbose (" (policy) used rule, allow now = %d\n",
1207 bus_client_policy_check_can_own (BusClientPolicy *policy,
1208 DBusConnection *connection,
1209 const DBusString *service_name)
1212 dbus_bool_t allowed;
1214 /* policy->rules is in the order the rules appeared
1215 * in the config file, i.e. last rule that applies wins
1219 link = _dbus_list_get_first_link (&policy->rules);
1220 while (link != NULL)
1222 BusPolicyRule *rule = link->data;
1224 link = _dbus_list_get_next_link (&policy->rules, link);
1226 /* Rule is skipped if it specifies a different service name from
1230 if (rule->type != BUS_POLICY_RULE_OWN)
1233 if (rule->d.own.service_name != NULL)
1235 if (!_dbus_string_equal_c_str (service_name,
1236 rule->d.own.service_name))
1241 allowed = rule->allow;
1247 #ifdef DBUS_BUILD_TESTS
1250 bus_policy_test (const DBusString *test_data_dir)
1252 /* This doesn't do anything for now because I decided to do it in
1253 * dispatch.c instead by having some of the clients in dispatch.c
1254 * have particular policies applied to them.
1260 #endif /* DBUS_BUILD_TESTS */