1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
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_unix_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 if (_dbus_hash_table_get_n_entries (policy->rules_by_uid) > 0)
330 list = _dbus_hash_table_lookup_ulong (policy->rules_by_uid,
335 if (!add_list_to_client (list, client))
340 /* Add console rules */
341 at_console = _dbus_unix_user_is_at_console (uid, error);
345 if (!add_list_to_client (&policy->at_console_true_rules, client))
348 else if (dbus_error_is_set (error) == TRUE)
352 else if (!add_list_to_client (&policy->at_console_false_rules, client))
358 if (!add_list_to_client (&policy->mandatory_rules,
362 bus_client_policy_optimize (client);
369 _DBUS_ASSERT_ERROR_IS_SET (error);
371 bus_client_policy_unref (client);
376 list_allows_user (dbus_bool_t def,
379 const unsigned long *group_ids,
387 link = _dbus_list_get_first_link (list);
390 BusPolicyRule *rule = link->data;
391 link = _dbus_list_get_next_link (list, link);
393 if (rule->type == BUS_POLICY_RULE_USER)
395 _dbus_verbose ("List %p user rule uid="DBUS_UID_FORMAT"\n",
396 list, rule->d.user.uid);
398 if (rule->d.user.uid == DBUS_UID_UNSET)
400 else if (rule->d.user.uid != uid)
403 else if (rule->type == BUS_POLICY_RULE_GROUP)
405 _dbus_verbose ("List %p group rule uid="DBUS_UID_FORMAT"\n",
406 list, rule->d.user.uid);
408 if (rule->d.group.gid == DBUS_GID_UNSET)
415 while (i < n_group_ids)
417 if (rule->d.group.gid == group_ids[i])
422 if (i == n_group_ids)
429 allowed = rule->allow;
436 bus_policy_allow_unix_user (BusPolicy *policy,
440 unsigned long *group_ids;
443 /* On OOM or error we always reject the user */
444 if (!_dbus_unix_groups_from_uid (uid, &group_ids, &n_group_ids))
446 _dbus_verbose ("Did not get any groups for UID %lu\n",
451 /* Default to "user owning bus" can connect */
452 allowed = _dbus_unix_user_is_process_owner (uid);
454 allowed = list_allows_user (allowed,
455 &policy->default_rules,
457 group_ids, n_group_ids);
459 allowed = list_allows_user (allowed,
460 &policy->mandatory_rules,
462 group_ids, n_group_ids);
464 dbus_free (group_ids);
466 _dbus_verbose ("UID %lu allowed = %d\n", uid, allowed);
471 /* For now this is never actually called because the default
472 * DBusConnection behavior of 'same user that owns the bus can
473 * connect' is all it would do. Set the windows user function in
474 * connection.c if the config file ever supports doing something
478 bus_policy_allow_windows_user (BusPolicy *policy,
479 const char *windows_sid)
481 /* Windows has no policies here since only the session bus
482 * is really used for now, so just checking that the
483 * connecting person is the same as the bus owner is fine.
485 return _dbus_windows_user_is_process_owner (windows_sid);
489 bus_policy_append_default_rule (BusPolicy *policy,
492 if (!_dbus_list_append (&policy->default_rules, rule))
495 bus_policy_rule_ref (rule);
501 bus_policy_append_mandatory_rule (BusPolicy *policy,
504 if (!_dbus_list_append (&policy->mandatory_rules, rule))
507 bus_policy_rule_ref (rule);
515 get_list (DBusHashTable *hash,
520 list = _dbus_hash_table_lookup_ulong (hash, key);
524 list = dbus_new0 (DBusList*, 1);
528 if (!_dbus_hash_table_insert_ulong (hash, key, list))
539 bus_policy_append_user_rule (BusPolicy *policy,
545 list = get_list (policy->rules_by_uid, uid);
550 if (!_dbus_list_append (list, rule))
553 bus_policy_rule_ref (rule);
559 bus_policy_append_group_rule (BusPolicy *policy,
565 list = get_list (policy->rules_by_gid, gid);
570 if (!_dbus_list_append (list, rule))
573 bus_policy_rule_ref (rule);
579 bus_policy_append_console_rule (BusPolicy *policy,
580 dbus_bool_t at_console,
585 if (!_dbus_list_append (&policy->at_console_true_rules, rule))
590 if (!_dbus_list_append (&policy->at_console_false_rules, rule))
594 bus_policy_rule_ref (rule);
601 append_copy_of_policy_list (DBusList **list,
602 DBusList **to_append)
609 /* Preallocate all our links */
610 link = _dbus_list_get_first_link (to_append);
613 if (!_dbus_list_append (&tmp_list, link->data))
615 _dbus_list_clear (&tmp_list);
619 link = _dbus_list_get_next_link (to_append, link);
622 /* Now append them */
623 while ((link = _dbus_list_pop_first_link (&tmp_list)))
625 bus_policy_rule_ref (link->data);
626 _dbus_list_append_link (list, link);
633 merge_id_hash (DBusHashTable *dest,
634 DBusHashTable *to_absorb)
638 _dbus_hash_iter_init (to_absorb, &iter);
639 while (_dbus_hash_iter_next (&iter))
641 unsigned long id = _dbus_hash_iter_get_ulong_key (&iter);
642 DBusList **list = _dbus_hash_iter_get_value (&iter);
643 DBusList **target = get_list (dest, id);
648 if (!append_copy_of_policy_list (target, list))
656 bus_policy_merge (BusPolicy *policy,
657 BusPolicy *to_absorb)
659 /* FIXME Not properly atomic, but as used for configuration files we
660 * don't rely on it quite so much.
663 if (!append_copy_of_policy_list (&policy->default_rules,
664 &to_absorb->default_rules))
667 if (!append_copy_of_policy_list (&policy->mandatory_rules,
668 &to_absorb->mandatory_rules))
671 if (!append_copy_of_policy_list (&policy->at_console_true_rules,
672 &to_absorb->at_console_true_rules))
675 if (!append_copy_of_policy_list (&policy->at_console_false_rules,
676 &to_absorb->at_console_false_rules))
679 if (!merge_id_hash (policy->rules_by_uid,
680 to_absorb->rules_by_uid))
683 if (!merge_id_hash (policy->rules_by_gid,
684 to_absorb->rules_by_gid))
690 struct BusClientPolicy
698 bus_client_policy_new (void)
700 BusClientPolicy *policy;
702 policy = dbus_new0 (BusClientPolicy, 1);
706 policy->refcount = 1;
712 bus_client_policy_ref (BusClientPolicy *policy)
714 _dbus_assert (policy->refcount > 0);
716 policy->refcount += 1;
722 rule_unref_foreach (void *data,
725 BusPolicyRule *rule = data;
727 bus_policy_rule_unref (rule);
731 bus_client_policy_unref (BusClientPolicy *policy)
733 _dbus_assert (policy->refcount > 0);
735 policy->refcount -= 1;
737 if (policy->refcount == 0)
739 _dbus_list_foreach (&policy->rules,
743 _dbus_list_clear (&policy->rules);
750 remove_rules_by_type_up_to (BusClientPolicy *policy,
751 BusPolicyRuleType type,
756 link = _dbus_list_get_first_link (&policy->rules);
757 while (link != up_to)
759 BusPolicyRule *rule = link->data;
760 DBusList *next = _dbus_list_get_next_link (&policy->rules, link);
762 if (rule->type == type)
764 _dbus_list_remove_link (&policy->rules, link);
765 bus_policy_rule_unref (rule);
773 bus_client_policy_optimize (BusClientPolicy *policy)
777 /* The idea here is that if we have:
779 * <allow send_interface="foo.bar"/>
780 * <deny send_interface="*"/>
782 * (for example) the deny will always override the allow. So we
783 * delete the allow. Ditto for deny followed by allow, etc. This is
784 * a dumb thing to put in a config file, but the <include> feature
785 * of files allows for an "inheritance and override" pattern where
786 * it could make sense. If an included file wants to "start over"
787 * with a blanket deny, no point keeping the rules from the parent
791 _dbus_verbose ("Optimizing policy with %d rules\n",
792 _dbus_list_get_length (&policy->rules));
794 link = _dbus_list_get_first_link (&policy->rules);
799 dbus_bool_t remove_preceding;
801 next = _dbus_list_get_next_link (&policy->rules, link);
804 remove_preceding = FALSE;
806 _dbus_assert (rule != NULL);
810 case BUS_POLICY_RULE_SEND:
812 rule->d.send.message_type == DBUS_MESSAGE_TYPE_INVALID &&
813 rule->d.send.path == NULL &&
814 rule->d.send.interface == NULL &&
815 rule->d.send.member == NULL &&
816 rule->d.send.error == NULL &&
817 rule->d.send.destination == NULL;
819 case BUS_POLICY_RULE_RECEIVE:
821 rule->d.receive.message_type == DBUS_MESSAGE_TYPE_INVALID &&
822 rule->d.receive.path == NULL &&
823 rule->d.receive.interface == NULL &&
824 rule->d.receive.member == NULL &&
825 rule->d.receive.error == NULL &&
826 rule->d.receive.origin == NULL;
828 case BUS_POLICY_RULE_OWN:
830 rule->d.own.service_name == NULL;
832 case BUS_POLICY_RULE_USER:
833 case BUS_POLICY_RULE_GROUP:
834 _dbus_assert_not_reached ("invalid rule");
838 if (remove_preceding)
839 remove_rules_by_type_up_to (policy, rule->type,
845 _dbus_verbose ("After optimization, policy has %d rules\n",
846 _dbus_list_get_length (&policy->rules));
850 bus_client_policy_append_rule (BusClientPolicy *policy,
853 _dbus_verbose ("Appending rule %p with type %d to policy %p\n",
854 rule, rule->type, policy);
856 if (!_dbus_list_append (&policy->rules, rule))
859 bus_policy_rule_ref (rule);
865 bus_client_policy_check_can_send (BusClientPolicy *policy,
866 BusRegistry *registry,
867 dbus_bool_t requested_reply,
868 DBusConnection *receiver,
869 DBusMessage *message)
874 /* policy->rules is in the order the rules appeared
875 * in the config file, i.e. last rule that applies wins
878 _dbus_verbose (" (policy) checking send rules\n");
881 link = _dbus_list_get_first_link (&policy->rules);
884 BusPolicyRule *rule = link->data;
886 link = _dbus_list_get_next_link (&policy->rules, link);
888 /* Rule is skipped if it specifies a different
889 * message name from the message, or a different
890 * destination from the message
893 if (rule->type != BUS_POLICY_RULE_SEND)
895 _dbus_verbose (" (policy) skipping non-send rule\n");
899 if (rule->d.send.message_type != DBUS_MESSAGE_TYPE_INVALID)
901 if (dbus_message_get_type (message) != rule->d.send.message_type)
903 _dbus_verbose (" (policy) skipping rule for different message type\n");
908 /* If it's a reply, the requested_reply flag kicks in */
909 if (dbus_message_get_reply_serial (message) != 0)
911 /* for allow, requested_reply=true means the rule applies
912 * only when reply was requested. requested_reply=false means
915 if (!requested_reply && rule->allow && rule->d.send.requested_reply && !rule->d.send.eavesdrop)
917 _dbus_verbose (" (policy) skipping allow rule since it only applies to requested replies and does not allow eavesdropping\n");
921 /* for deny, requested_reply=false means the rule applies only
922 * when the reply was not requested. requested_reply=true means the
923 * rule always applies.
925 if (requested_reply && !rule->allow && !rule->d.send.requested_reply)
927 _dbus_verbose (" (policy) skipping deny rule since it only applies to unrequested replies\n");
932 if (rule->d.send.path != NULL)
934 if (dbus_message_get_path (message) != NULL &&
935 strcmp (dbus_message_get_path (message),
936 rule->d.send.path) != 0)
938 _dbus_verbose (" (policy) skipping rule for different path\n");
943 if (rule->d.send.interface != NULL)
945 if (dbus_message_get_interface (message) != NULL &&
946 strcmp (dbus_message_get_interface (message),
947 rule->d.send.interface) != 0)
949 _dbus_verbose (" (policy) skipping rule for different interface\n");
954 if (rule->d.send.member != NULL)
956 if (dbus_message_get_member (message) != NULL &&
957 strcmp (dbus_message_get_member (message),
958 rule->d.send.member) != 0)
960 _dbus_verbose (" (policy) skipping rule for different member\n");
965 if (rule->d.send.error != NULL)
967 if (dbus_message_get_error_name (message) != NULL &&
968 strcmp (dbus_message_get_error_name (message),
969 rule->d.send.error) != 0)
971 _dbus_verbose (" (policy) skipping rule for different error name\n");
976 if (rule->d.send.destination != NULL)
978 /* receiver can be NULL for messages that are sent to the
979 * message bus itself, we check the strings in that case as
980 * built-in services don't have a DBusConnection but messages
981 * to them have a destination service name.
983 if (receiver == NULL)
985 if (!dbus_message_has_destination (message,
986 rule->d.send.destination))
988 _dbus_verbose (" (policy) skipping rule because message dest is not %s\n",
989 rule->d.send.destination);
998 _dbus_string_init_const (&str, rule->d.send.destination);
1000 service = bus_registry_lookup (registry, &str);
1001 if (service == NULL)
1003 _dbus_verbose (" (policy) skipping rule because dest %s doesn't exist\n",
1004 rule->d.send.destination);
1008 if (!bus_service_has_owner (service, receiver))
1010 _dbus_verbose (" (policy) skipping rule because dest %s isn't owned by receiver\n",
1011 rule->d.send.destination);
1018 allowed = rule->allow;
1020 _dbus_verbose (" (policy) used rule, allow now = %d\n",
1027 /* See docs on what the args mean on bus_context_check_security_policy()
1031 bus_client_policy_check_can_receive (BusClientPolicy *policy,
1032 BusRegistry *registry,
1033 dbus_bool_t requested_reply,
1034 DBusConnection *sender,
1035 DBusConnection *addressed_recipient,
1036 DBusConnection *proposed_recipient,
1037 DBusMessage *message)
1040 dbus_bool_t allowed;
1041 dbus_bool_t eavesdropping;
1044 addressed_recipient != proposed_recipient &&
1045 dbus_message_get_destination (message) != NULL;
1047 /* policy->rules is in the order the rules appeared
1048 * in the config file, i.e. last rule that applies wins
1051 _dbus_verbose (" (policy) checking receive rules, eavesdropping = %d\n", eavesdropping);
1054 link = _dbus_list_get_first_link (&policy->rules);
1055 while (link != NULL)
1057 BusPolicyRule *rule = link->data;
1059 link = _dbus_list_get_next_link (&policy->rules, link);
1061 if (rule->type != BUS_POLICY_RULE_RECEIVE)
1063 _dbus_verbose (" (policy) skipping non-receive rule\n");
1067 if (rule->d.receive.message_type != DBUS_MESSAGE_TYPE_INVALID)
1069 if (dbus_message_get_type (message) != rule->d.receive.message_type)
1071 _dbus_verbose (" (policy) skipping rule for different message type\n");
1076 /* for allow, eavesdrop=false means the rule doesn't apply when
1077 * eavesdropping. eavesdrop=true means always allow.
1079 if (eavesdropping && rule->allow && !rule->d.receive.eavesdrop)
1081 _dbus_verbose (" (policy) skipping allow rule since it doesn't apply to eavesdropping\n");
1085 /* for deny, eavesdrop=true means the rule applies only when
1086 * eavesdropping; eavesdrop=false means always deny.
1088 if (!eavesdropping && !rule->allow && rule->d.receive.eavesdrop)
1090 _dbus_verbose (" (policy) skipping deny rule since it only applies to eavesdropping\n");
1094 /* If it's a reply, the requested_reply flag kicks in */
1095 if (dbus_message_get_reply_serial (message) != 0)
1097 /* for allow, requested_reply=true means the rule applies
1098 * only when reply was requested. requested_reply=false means
1101 if (!requested_reply && rule->allow && rule->d.receive.requested_reply && !rule->d.receive.eavesdrop)
1103 _dbus_verbose (" (policy) skipping allow rule since it only applies to requested replies and does not allow eavesdropping\n");
1107 /* for deny, requested_reply=false means the rule applies only
1108 * when the reply was not requested. requested_reply=true means the
1109 * rule always applies.
1111 if (requested_reply && !rule->allow && !rule->d.receive.requested_reply)
1113 _dbus_verbose (" (policy) skipping deny rule since it only applies to unrequested replies\n");
1118 if (rule->d.receive.path != NULL)
1120 if (dbus_message_get_path (message) != NULL &&
1121 strcmp (dbus_message_get_path (message),
1122 rule->d.receive.path) != 0)
1124 _dbus_verbose (" (policy) skipping rule for different path\n");
1129 if (rule->d.receive.interface != NULL)
1131 if (dbus_message_get_interface (message) != NULL &&
1132 strcmp (dbus_message_get_interface (message),
1133 rule->d.receive.interface) != 0)
1135 _dbus_verbose (" (policy) skipping rule for different interface\n");
1140 if (rule->d.receive.member != NULL)
1142 if (dbus_message_get_member (message) != NULL &&
1143 strcmp (dbus_message_get_member (message),
1144 rule->d.receive.member) != 0)
1146 _dbus_verbose (" (policy) skipping rule for different member\n");
1151 if (rule->d.receive.error != NULL)
1153 if (dbus_message_get_error_name (message) != NULL &&
1154 strcmp (dbus_message_get_error_name (message),
1155 rule->d.receive.error) != 0)
1157 _dbus_verbose (" (policy) skipping rule for different error name\n");
1162 if (rule->d.receive.origin != NULL)
1164 /* sender can be NULL for messages that originate from the
1165 * message bus itself, we check the strings in that case as
1166 * built-in services don't have a DBusConnection but will
1167 * still set the sender on their messages.
1171 if (!dbus_message_has_sender (message,
1172 rule->d.receive.origin))
1174 _dbus_verbose (" (policy) skipping rule because message sender is not %s\n",
1175 rule->d.receive.origin);
1181 BusService *service;
1184 _dbus_string_init_const (&str, rule->d.receive.origin);
1186 service = bus_registry_lookup (registry, &str);
1188 if (service == NULL)
1190 _dbus_verbose (" (policy) skipping rule because origin %s doesn't exist\n",
1191 rule->d.receive.origin);
1195 if (!bus_service_has_owner (service, sender))
1197 _dbus_verbose (" (policy) skipping rule because origin %s isn't owned by sender\n",
1198 rule->d.receive.origin);
1205 allowed = rule->allow;
1207 _dbus_verbose (" (policy) used rule, allow now = %d\n",
1215 bus_client_policy_check_can_own (BusClientPolicy *policy,
1216 DBusConnection *connection,
1217 const DBusString *service_name)
1220 dbus_bool_t allowed;
1222 /* policy->rules is in the order the rules appeared
1223 * in the config file, i.e. last rule that applies wins
1227 link = _dbus_list_get_first_link (&policy->rules);
1228 while (link != NULL)
1230 BusPolicyRule *rule = link->data;
1232 link = _dbus_list_get_next_link (&policy->rules, link);
1234 /* Rule is skipped if it specifies a different service name from
1238 if (rule->type != BUS_POLICY_RULE_OWN)
1241 if (rule->d.own.service_name != NULL)
1243 if (!_dbus_string_equal_c_str (service_name,
1244 rule->d.own.service_name))
1249 allowed = rule->allow;
1255 #ifdef DBUS_BUILD_TESTS
1258 bus_policy_test (const DBusString *test_data_dir)
1260 /* This doesn't do anything for now because I decided to do it in
1261 * dispatch.c instead by having some of the clients in dispatch.c
1262 * have particular policies applied to them.
1268 #endif /* DBUS_BUILD_TESTS */