From f759db240fd2f2b3d6dcdeff2f53bb4f0d8cab08 Mon Sep 17 00:00:00 2001 From: Alban Crequy Date: Tue, 1 Jul 2014 15:07:09 +0100 Subject: [PATCH 4/4] bus driver: check whether the interface is enabled https://bugs.freedesktop.org/show_bug.cgi?id=80759 --- bus/bus.c | 18 ++++++++++++++++++ bus/bus.h | 2 ++ bus/driver.c | 17 +++++++++++------ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/bus/bus.c b/bus/bus.c index 89d87de..96a8c81 100644 --- a/bus/bus.c +++ b/bus/bus.c @@ -1667,3 +1667,21 @@ bus_context_check_security_policy (BusContext *context, _dbus_verbose ("security policy allowing message\n"); return TRUE; } + +/* + * Check if the interface is enabled in the configuration + */ +dbus_bool_t +bus_context_is_interface_enabled (BusContext *context, const char *interface) +{ + DBusList *node; + + for (node = _dbus_list_get_first_link (&context->interfaces); node; + node = _dbus_list_get_next_link (&context->interfaces, node)) + { + if (!strcmp (node->data, interface)) + return TRUE; + } + + return FALSE; +} diff --git a/bus/bus.h b/bus/bus.h index 3597884..591d89a 100644 --- a/bus/bus.h +++ b/bus/bus.h @@ -125,5 +125,7 @@ dbus_bool_t bus_context_check_security_policy (BusContext DBusConnection *proposed_recipient, DBusMessage *message, DBusError *error); +dbus_bool_t bus_context_is_interface_enabled (BusContext *context, + const char *interface); #endif /* BUS_BUS_H */ diff --git a/bus/driver.c b/bus/driver.c index fd52883..60bf237 100644 --- a/bus/driver.c +++ b/bus/driver.c @@ -1798,6 +1798,7 @@ typedef struct { const char *name; const MessageHandler *message_handlers; const char *extra_introspection; + const dbus_bool_t default_enabled; } InterfaceHandler; /* These should ideally be sorted by frequency of use, although it @@ -1814,10 +1815,10 @@ static InterfaceHandler interface_handlers[] = { " \n" " \n" " \n" - " \n" }, - { DBUS_INTERFACE_INTROSPECTABLE, introspectable_message_handlers, NULL }, + " \n", TRUE }, + { DBUS_INTERFACE_INTROSPECTABLE, introspectable_message_handlers, NULL, TRUE }, #ifdef DBUS_ENABLE_STATS - { BUS_INTERFACE_STATS, stats_message_handlers, NULL }, + { BUS_INTERFACE_STATS, stats_message_handlers, NULL, FALSE }, #endif { NULL, NULL, NULL } }; @@ -1976,14 +1977,14 @@ bus_driver_handle_message (DBusConnection *connection, const InterfaceHandler *ih; const MessageHandler *mh; dbus_bool_t found_interface = FALSE; + BusContext *context; + + context = bus_connection_get_context (connection); _DBUS_ASSERT_ERROR_IS_CLEAR (error); if (dbus_message_is_signal (message, "org.freedesktop.systemd1.Activator", "ActivationFailure")) { - BusContext *context; - - context = bus_connection_get_context (connection); return dbus_activation_systemd_failure(bus_context_get_activation(context), message); } @@ -2011,6 +2012,10 @@ bus_driver_handle_message (DBusConnection *connection, if (interface != NULL && strcmp (interface, ih->name) != 0) continue; + if (!ih->default_enabled && + !bus_context_is_interface_enabled (context, interface)) + continue; + found_interface = TRUE; for (mh = ih->message_handlers; mh->name != NULL; mh++) -- 1.8.5.3