return TRUE;
}
+struct MatchSendRuleParams {
+ BusRegistry *registry;
+ dbus_bool_t requested_reply;
+ DBusConnection *receiver;
+ DBusMessage *message;
+};
+
static dbus_bool_t
check_send_rule (const BusPolicyRule *rule,
- BusRegistry *registry,
- dbus_bool_t requested_reply,
- DBusConnection *receiver,
- DBusMessage *message,
- BusResult *result,
- const char **privilege)
+ const struct MatchSendRuleParams *match_params,
+ BusResult *result,
+ const char **privilege)
{
/* Rule is skipped if it specifies a different
* message name from the message, or a different
if (rule->d.send.message_type != DBUS_MESSAGE_TYPE_INVALID)
{
- if (dbus_message_get_type (message) != rule->d.send.message_type)
+ if (dbus_message_get_type (match_params->message) != rule->d.send.message_type)
{
_dbus_verbose (" (policy) skipping rule for different message type\n");
return FALSE;
}
/* If it's a reply, the requested_reply flag kicks in */
- if (dbus_message_get_reply_serial (message) != 0)
+ if (dbus_message_get_reply_serial (match_params->message) != 0)
{
/* for allow or check requested_reply=true means the rule applies
* only when reply was requested. requested_reply=false means the
* rule always applies
*/
- if (!requested_reply && rule->access != BUS_POLICY_RULE_ACCESS_DENY && rule->d.send.requested_reply && !rule->d.send.eavesdrop)
+ if (!match_params->requested_reply && rule->access != BUS_POLICY_RULE_ACCESS_DENY && rule->d.send.requested_reply && !rule->d.send.eavesdrop)
{
_dbus_verbose (" (policy) skipping %s rule since it only applies to requested replies and does not allow eavesdropping\n",
rule->access == BUS_POLICY_RULE_ACCESS_ALLOW ? "allow" : "check");
* when the reply was not requested. requested_reply=true means the
* rule always applies.
*/
- if (requested_reply && rule->access == BUS_POLICY_RULE_ACCESS_DENY && !rule->d.send.requested_reply)
+ if (match_params->requested_reply && rule->access == BUS_POLICY_RULE_ACCESS_DENY && !rule->d.send.requested_reply)
{
_dbus_verbose (" (policy) skipping deny rule since it only applies to unrequested replies\n");
return FALSE;
if (rule->d.send.path != NULL)
{
- if (dbus_message_get_path (message) != NULL &&
- strcmp (dbus_message_get_path (message),
+ if (dbus_message_get_path (match_params->message) != NULL &&
+ strcmp (dbus_message_get_path (match_params->message),
rule->d.send.path) != 0)
{
_dbus_verbose (" (policy) skipping rule for different path\n");
*/
dbus_bool_t no_interface;
- no_interface = dbus_message_get_interface (message) == NULL;
+ no_interface = dbus_message_get_interface (match_params->message) == NULL;
if ((no_interface && rule->access != BUS_POLICY_RULE_ACCESS_DENY) ||
(!no_interface &&
- strcmp (dbus_message_get_interface (message),
+ strcmp (dbus_message_get_interface (match_params->message),
rule->d.send.interface) != 0))
{
_dbus_verbose (" (policy) skipping rule for different interface\n");
if (rule->d.send.member != NULL)
{
- if (dbus_message_get_member (message) != NULL &&
- strcmp (dbus_message_get_member (message),
+ if (dbus_message_get_member (match_params->message) != NULL &&
+ strcmp (dbus_message_get_member (match_params->message),
rule->d.send.member) != 0)
{
_dbus_verbose (" (policy) skipping rule for different member\n");
if (rule->d.send.error != NULL)
{
- if (dbus_message_get_error_name (message) != NULL &&
- strcmp (dbus_message_get_error_name (message),
+ if (dbus_message_get_error_name (match_params->message) != NULL &&
+ strcmp (dbus_message_get_error_name (match_params->message),
rule->d.send.error) != 0)
{
_dbus_verbose (" (policy) skipping rule for different error name\n");
* on the assumption that the activated service will have the
* requested name and no others.
*/
- if (receiver == NULL)
+ if (match_params->receiver == NULL)
{
- if (!dbus_message_has_destination (message,
+ if (!dbus_message_has_destination (match_params->message,
rule->d.send.destination))
{
_dbus_verbose (" (policy) skipping rule because message dest is not %s\n",
_dbus_string_init_const (&str, rule->d.send.destination);
- service = bus_registry_lookup (registry, &str);
+ service = bus_registry_lookup (match_params->registry, &str);
if (service == NULL)
{
_dbus_verbose (" (policy) skipping rule because dest %s doesn't exist\n",
return FALSE;
}
- if (!bus_service_has_owner (service, receiver))
+ if (!bus_service_has_owner (service, match_params->receiver))
{
_dbus_verbose (" (policy) skipping rule because dest %s isn't owned by receiver\n",
rule->d.send.destination);
else if (rule->d.send.destination_prefix)
{
/* receiver can be NULL - the same as in !send.destination_prefix */
- if (receiver == NULL)
+ if (match_params->receiver == NULL)
{
- const char *destination = dbus_message_get_destination (message);
+ const char *destination = dbus_message_get_destination (match_params->message);
DBusString dest_name;
if (destination == NULL)
}
else
{
- if (!bus_connection_is_service_owner_by_prefix (receiver,
+ if (!bus_connection_is_service_owner_by_prefix (match_params->receiver,
rule->d.send.destination))
{
_dbus_verbose (" (policy) skipping rule because no dest with prefix %s is owned by receiver\n",
BusResult result;
const char *privilege;
BusPolicyRule *matched_rule = NULL;
+ struct MatchSendRuleParams params;
+
+ params.registry = registry;
+ params.requested_reply = requested_reply;
+ params.receiver = receiver;
+ params.message = message;
/* policy->rules is in the order the rules appeared
* in the config file, i.e. last rule that applies wins
link = _dbus_list_get_next_link (&policy->rules, link);
- if (check_send_rule (rule, registry, requested_reply, receiver, message,
- &result, &privilege))
+ if (check_send_rule (rule, ¶ms, &result, &privilege))
{
*log = rule->d.send.log;
(*toggles)++;
return result;
}
+struct MatchReceiveRuleParams {
+ BusRegistry *registry;
+ dbus_bool_t requested_reply;
+ DBusConnection *sender;
+ DBusMessage *message;
+ dbus_bool_t eavesdropping;
+};
+
static dbus_bool_t
check_receive_rule (const BusPolicyRule *rule,
- BusRegistry *registry,
- dbus_bool_t requested_reply,
- DBusConnection *sender,
- DBusMessage *message,
- dbus_bool_t eavesdropping,
- BusResult *result,
- const char **privilege)
+ const struct MatchReceiveRuleParams *match_params,
+ BusResult *result,
+ const char **privilege)
{
if (rule->type != BUS_POLICY_RULE_RECEIVE)
{
if (rule->d.receive.message_type != DBUS_MESSAGE_TYPE_INVALID)
{
- if (dbus_message_get_type (message) != rule->d.receive.message_type)
+ if (dbus_message_get_type (match_params->message) != rule->d.receive.message_type)
{
_dbus_verbose (" (policy) skipping rule for different message type\n");
return FALSE;
/* for allow or check, eavesdrop=false means the rule doesn't apply when
* eavesdropping. eavesdrop=true means the rule always applies
*/
- if (eavesdropping && rule->access != BUS_POLICY_RULE_ACCESS_DENY && !rule->d.receive.eavesdrop)
+ if (match_params->eavesdropping && rule->access != BUS_POLICY_RULE_ACCESS_DENY && !rule->d.receive.eavesdrop)
{
_dbus_verbose (" (policy) skipping %s rule since it doesn't apply to eavesdropping\n",
rule->access == BUS_POLICY_RULE_ACCESS_ALLOW ? "allow" : "check");
/* for deny, eavesdrop=true means the rule applies only when
* eavesdropping; eavesdrop=false means always deny.
*/
- if (!eavesdropping && rule->access == BUS_POLICY_RULE_ACCESS_DENY && rule->d.receive.eavesdrop)
+ if (!match_params->eavesdropping && rule->access == BUS_POLICY_RULE_ACCESS_DENY && rule->d.receive.eavesdrop)
{
_dbus_verbose (" (policy) skipping deny rule since it only applies to eavesdropping\n");
return FALSE;
}
/* If it's a reply, the requested_reply flag kicks in */
- if (dbus_message_get_reply_serial (message) != 0)
+ if (dbus_message_get_reply_serial (match_params->message) != 0)
{
/* for allow or check requested_reply=true means the rule applies
* only when reply was requested. requested_reply=false means the
* rule always applies
*/
- if (!requested_reply && rule->access != BUS_POLICY_RULE_ACCESS_DENY && rule->d.send.requested_reply && !rule->d.send.eavesdrop)
+ if (!match_params->requested_reply && rule->access != BUS_POLICY_RULE_ACCESS_DENY && rule->d.send.requested_reply && !rule->d.send.eavesdrop)
{
_dbus_verbose (" (policy) skipping %s rule since it only applies to requested replies and does not allow eavesdropping\n",
rule->access == BUS_POLICY_RULE_ACCESS_DENY ? "allow" : "deny");
* when the reply was not requested. requested_reply=true means the
* rule always applies.
*/
- if (requested_reply && rule->access == BUS_POLICY_RULE_ACCESS_DENY && !rule->d.receive.requested_reply)
+ if (match_params->requested_reply && rule->access == BUS_POLICY_RULE_ACCESS_DENY && !rule->d.receive.requested_reply)
{
_dbus_verbose (" (policy) skipping deny rule since it only applies to unrequested replies\n");
return FALSE;
if (rule->d.receive.path != NULL)
{
- if (dbus_message_get_path (message) != NULL &&
- strcmp (dbus_message_get_path (message),
+ if (dbus_message_get_path (match_params->message) != NULL &&
+ strcmp (dbus_message_get_path (match_params->message),
rule->d.receive.path) != 0)
{
_dbus_verbose (" (policy) skipping rule for different path\n");
*/
dbus_bool_t no_interface;
- no_interface = dbus_message_get_interface (message) == NULL;
+ no_interface = dbus_message_get_interface (match_params->message) == NULL;
if ((no_interface && rule->access != BUS_POLICY_RULE_ACCESS_DENY) ||
(!no_interface &&
- strcmp (dbus_message_get_interface (message),
+ strcmp (dbus_message_get_interface (match_params->message),
rule->d.receive.interface) != 0))
{
_dbus_verbose (" (policy) skipping rule for different interface\n");
if (rule->d.receive.member != NULL)
{
- if (dbus_message_get_member (message) != NULL &&
- strcmp (dbus_message_get_member (message),
+ if (dbus_message_get_member (match_params->message) != NULL &&
+ strcmp (dbus_message_get_member (match_params->message),
rule->d.receive.member) != 0)
{
_dbus_verbose (" (policy) skipping rule for different member\n");
if (rule->d.receive.error != NULL)
{
- if (dbus_message_get_error_name (message) != NULL &&
- strcmp (dbus_message_get_error_name (message),
+ if (dbus_message_get_error_name (match_params->message) != NULL &&
+ strcmp (dbus_message_get_error_name (match_params->message),
rule->d.receive.error) != 0)
{
_dbus_verbose (" (policy) skipping rule for different error name\n");
* built-in services don't have a DBusConnection but will
* still set the sender on their messages.
*/
- if (sender == NULL)
+ if (match_params->sender == NULL)
{
- if (!dbus_message_has_sender (message,
+ if (!dbus_message_has_sender (match_params->message,
rule->d.receive.origin))
{
_dbus_verbose (" (policy) skipping rule because message sender is not %s\n",
_dbus_string_init_const (&str, rule->d.receive.origin);
- service = bus_registry_lookup (registry, &str);
+ service = bus_registry_lookup (match_params->registry, &str);
if (service == NULL)
{
return FALSE;
}
- if (!bus_service_has_owner (service, sender))
+ if (!bus_service_has_owner (service, match_params->sender))
{
_dbus_verbose (" (policy) skipping rule because origin %s isn't owned by sender\n",
rule->d.receive.origin);
char **out_rule)
{
DBusList *link;
- dbus_bool_t eavesdropping;
BusResult result;
const char *privilege;
BusPolicyRule *matched_rule = NULL;
+ struct MatchReceiveRuleParams params;
- eavesdropping =
+ params.eavesdropping =
addressed_recipient != proposed_recipient &&
dbus_message_get_destination (message) != NULL;
+ params.registry = registry;
+ params.requested_reply = requested_reply;
+ params.sender = sender;
+ params.message = message;
/* policy->rules is in the order the rules appeared
* in the config file, i.e. last rule that applies wins
link = _dbus_list_get_next_link (&policy->rules, link);
- if (check_receive_rule (rule, registry, requested_reply, sender,
- message, eavesdropping, &result, &privilege))
+ if (check_receive_rule (rule, ¶ms, &result, &privilege))
{
(*toggles)++;
matched_rule = (BusPolicyRule *)rule;