From a683a80c409cc4f2e57ba6a3e60d52f91b8657d0 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Sun, 21 Sep 2003 19:53:56 +0000 Subject: 2003-09-21 Havoc Pennington Get matching rules mostly working in the bus; only actually parsing the rule text remains. However, the client side of "signal connections" hasn't been started, this patch is only the bus side. * dbus/dispatch.c: fix for the matching rules changes * bus/driver.c (bus_driver_handle_remove_match) (bus_driver_handle_add_match): send an ack reply from these method calls * glib/dbus-gproxy.c (dbus_gproxy_begin_call): fix order of arguments, reported by Seth Nickell * bus/config-parser.c (append_rule_from_element): support eavesdrop=true|false attribute on policies so match rules can be prevented from snooping on the system bus. * bus/dbus-daemon-1.1.in: consistently use terminology "sender" and "destination" in attribute names; fix some docs bugs; add eavesdrop=true|false attribute * bus/driver.c (bus_driver_handle_add_match) (bus_driver_handle_remove_match): handle AddMatch, RemoveMatch messages * dbus/dbus-protocol.h (DBUS_SERVICE_ORG_FREEDESKTOP_BROADCAST): get rid of broadcast service concept, signals are just always broadcast * bus/signals.c, bus/dispatch.c, bus/connection.c, bus/bus.c: mostly implement matching rules stuff (currently only exposed as signal connections) --- bus/bus.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 13 deletions(-) (limited to 'bus/bus.c') diff --git a/bus/bus.c b/bus/bus.c index 1b461fe3..4087334e 100644 --- a/bus/bus.c +++ b/bus/bus.c @@ -28,6 +28,7 @@ #include "utils.h" #include "policy.h" #include "config-parser.h" +#include "signals.h" #include #include #include @@ -44,6 +45,7 @@ struct BusContext BusActivation *activation; BusRegistry *registry; BusPolicy *policy; + BusMatchmaker *matchmaker; DBusUserDatabase *user_database; BusLimits limits; }; @@ -505,6 +507,13 @@ bus_context_new (const DBusString *config_file, goto failed; } + context->matchmaker = bus_matchmaker_new (); + if (context->matchmaker == NULL) + { + BUS_SET_OOM (error); + goto failed; + } + context->policy = bus_config_parser_steal_policy (parser); _dbus_assert (context->policy != NULL); @@ -715,6 +724,12 @@ bus_context_unref (BusContext *context) _dbus_loop_unref (context->loop); context->loop = NULL; } + + if (context->matchmaker) + { + bus_matchmaker_unref (context->matchmaker); + context->matchmaker = NULL; + } dbus_free (context->type); dbus_free (context->address); @@ -771,6 +786,12 @@ bus_context_get_activation (BusContext *context) return context->activation; } +BusMatchmaker* +bus_context_get_matchmaker (BusContext *context) +{ + return context->matchmaker; +} + DBusLoop* bus_context_get_loop (BusContext *context) { @@ -845,18 +866,33 @@ bus_context_get_max_services_per_connection (BusContext *context) return context->limits.max_services_per_connection; } +int +bus_context_get_max_match_rules_per_connection (BusContext *context) +{ + return context->limits.max_match_rules_per_connection; +} + dbus_bool_t bus_context_check_security_policy (BusContext *context, DBusConnection *sender, - DBusConnection *recipient, + DBusConnection *addressed_recipient, + DBusConnection *proposed_recipient, DBusMessage *message, DBusError *error) { BusClientPolicy *sender_policy; BusClientPolicy *recipient_policy; - /* NULL sender/receiver means the bus driver */ + /* NULL sender, proposed_recipient means the bus driver. NULL + * addressed_recipient means the message didn't specify an explicit + * target. If proposed_recipient is NULL, then addressed_recipient + * is also NULL but is implicitly the bus driver. + */ + _dbus_assert (proposed_recipient == NULL || + (dbus_message_get_destination (message) == NULL || + addressed_recipient != NULL)); + if (sender != NULL) { if (bus_connection_is_active (sender)) @@ -869,7 +905,7 @@ bus_context_check_security_policy (BusContext *context, /* Policy for inactive connections is that they can only send * the hello message to the bus driver */ - if (recipient == NULL && + if (proposed_recipient == NULL && dbus_message_is_method_call (message, DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS, "Hello")) @@ -897,15 +933,15 @@ bus_context_check_security_policy (BusContext *context, _dbus_assert ((sender != NULL && sender_policy != NULL) || (sender == NULL && sender_policy == NULL)); - if (recipient != NULL) + if (proposed_recipient != NULL) { /* only the bus driver can send to an inactive recipient (as it * owns no services, so other apps can't address it). Inactive * recipients can receive any message. */ - if (bus_connection_is_active (recipient)) + if (bus_connection_is_active (proposed_recipient)) { - recipient_policy = bus_connection_get_policy (recipient); + recipient_policy = bus_connection_get_policy (proposed_recipient); _dbus_assert (recipient_policy != NULL); } else if (sender == NULL) @@ -922,13 +958,13 @@ bus_context_check_security_policy (BusContext *context, else recipient_policy = NULL; - _dbus_assert ((recipient != NULL && recipient_policy != NULL) || - (recipient != NULL && sender == NULL && recipient_policy == NULL) || - (recipient == NULL && recipient_policy == NULL)); + _dbus_assert ((proposed_recipient != NULL && recipient_policy != NULL) || + (proposed_recipient != NULL && sender == NULL && recipient_policy == NULL) || + (proposed_recipient == NULL && recipient_policy == NULL)); if (sender_policy && !bus_client_policy_check_can_send (sender_policy, - context->registry, recipient, + context->registry, proposed_recipient, message)) { const char *dest = dbus_message_get_destination (message); @@ -951,6 +987,7 @@ bus_context_check_security_policy (BusContext *context, if (recipient_policy && !bus_client_policy_check_can_receive (recipient_policy, context->registry, sender, + addressed_recipient, proposed_recipient, message)) { const char *dest = dbus_message_get_destination (message); @@ -971,14 +1008,16 @@ bus_context_check_security_policy (BusContext *context, } /* See if limits on size have been exceeded */ - if (recipient && - dbus_connection_get_outgoing_size (recipient) > + if (proposed_recipient && + dbus_connection_get_outgoing_size (proposed_recipient) > context->limits.max_outgoing_bytes) { const char *dest = dbus_message_get_destination (message); dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED, "The destination service \"%s\" has a full message queue", - dest ? dest : DBUS_SERVICE_ORG_FREEDESKTOP_DBUS); + dest ? dest : (proposed_recipient ? + bus_connection_get_name (proposed_recipient) : + DBUS_SERVICE_ORG_FREEDESKTOP_DBUS)); _dbus_verbose ("security policy disallowing message due to full message queue\n"); return FALSE; } -- cgit