From b658ae66dc20156d9cdea80af29c79854fc171d5 Mon Sep 17 00:00:00 2001 From: Alban Crequy Date: Wed Oct 6 16:46:16 2010 +0300 Subject: [PATCH 2/2] Add GetConnectionMatchRules in the bus driver Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=24307 diff --git a/bus/driver.c b/bus/driver.c index cc8d1f2..7787208 100644 --- a/bus/driver.c +++ b/bus/driver.c @@ -1405,6 +1405,84 @@ bus_driver_handle_get_connection_unix_process_id (DBusConnection *connection, } static dbus_bool_t +bus_driver_handle_get_connection_match_rules (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + const char *service; + DBusString str; + BusRegistry *registry; + BusService *serv; + DBusConnection *conn; + DBusMessage *reply; + unsigned long pid; + dbus_uint32_t pid32; + BusContext *context; + BusMatchmaker *matchmaker; + DBusString rule_text; + char *reply_str; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + registry = bus_connection_get_registry (connection); + + service = NULL; + reply = NULL; + + if (! dbus_message_get_args (message, error, + DBUS_TYPE_STRING, &service, + DBUS_TYPE_INVALID)) + goto failed; + + _dbus_string_init_const (&str, service); + serv = bus_registry_lookup (registry, &str); + if (serv == NULL) + { + dbus_set_error (error, + DBUS_ERROR_NAME_HAS_NO_OWNER, + "Could not get PID of name '%s': no such name", service); + goto failed; + } + + conn = bus_service_get_primary_owners_connection (serv); + + reply = dbus_message_new_method_return (message); + if (reply == NULL) + goto oom; + + + context = bus_transaction_get_context (transaction); + matchmaker = bus_context_get_matchmaker (context); + + bus_match_rule_dump (matchmaker, &rule_text, conn); + + reply_str = _dbus_string_get_data (&rule_text); + + if (! dbus_message_append_args (reply, + DBUS_TYPE_STRING, + &reply_str, + DBUS_TYPE_INVALID)) + goto oom; + + if (! bus_transaction_send_from_driver (transaction, connection, reply)) + goto oom; + + dbus_message_unref (reply); + + return TRUE; + + oom: + BUS_SET_OOM (error); + + failed: + _DBUS_ASSERT_ERROR_IS_SET (error); + if (reply) + dbus_message_unref (reply); + return FALSE; +} + +static dbus_bool_t bus_driver_handle_get_adt_audit_session_data (DBusConnection *connection, BusTransaction *transaction, DBusMessage *message, @@ -1714,6 +1792,10 @@ static struct DBUS_TYPE_STRING_AS_STRING, DBUS_TYPE_UINT32_AS_STRING, bus_driver_handle_get_connection_unix_process_id }, + { "GetConnectionMatchRules", + DBUS_TYPE_STRING_AS_STRING, + DBUS_TYPE_STRING_AS_STRING, + bus_driver_handle_get_connection_match_rules }, { "GetAdtAuditSessionData", DBUS_TYPE_STRING_AS_STRING, DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING, diff --git a/bus/signals.c b/bus/signals.c index 3ff7b8c..0a4bf47 100644 --- a/bus/signals.c +++ b/bus/signals.c @@ -115,7 +115,6 @@ bus_match_rule_unref (BusMatchRule *rule) } } -#ifdef DBUS_ENABLE_VERBOSE_MODE /* Note this function does not do escaping, so it's only * good for debug spew at the moment */ @@ -274,7 +273,6 @@ match_rule_to_string (BusMatchRule *rule) return s; } } -#endif /* DBUS_ENABLE_VERBOSE_MODE */ dbus_bool_t bus_match_rule_set_message_type (BusMatchRule *rule, @@ -1068,6 +1066,60 @@ struct BusMatchmaker RulePool rules_by_type[DBUS_NUM_MESSAGE_TYPES]; }; +void +bus_match_rule_dump (BusMatchmaker *matchmaker, DBusString *rule_text_out, + DBusConnection *conn_filter) +{ + int i; + _dbus_string_init (rule_text_out); + + for (i = 0 ; i < DBUS_NUM_MESSAGE_TYPES ; i++) + { + DBusHashIter iter; + DBusList *list; + DBusList *link; + + _dbus_hash_iter_init (matchmaker->rules_by_type[i].rules_by_iface, &iter); + while (_dbus_hash_iter_next (&iter)) + { + list = *((DBusList **)_dbus_hash_iter_get_value (&iter)); + link = _dbus_list_get_first_link (&list); + while (link != NULL) + { + DBusList *next = _dbus_list_get_next_link (&list, link); + BusMatchRule *rule = link->data; + + if (conn_filter == NULL || rule->matches_go_to == conn_filter) + { + char *s = match_rule_to_string (rule); + _dbus_string_append (rule_text_out, s); + _dbus_string_append (rule_text_out, "\n"); + dbus_free (s); + } + + link = next; + } + } + list = matchmaker->rules_by_type[i].rules_without_iface; + link = _dbus_list_get_first_link (&list); + while (link != NULL) + { + DBusList *next = _dbus_list_get_next_link (&list, link); + BusMatchRule *rule = link->data; + + if (conn_filter == NULL || rule->matches_go_to == conn_filter) + { + char *s = match_rule_to_string (rule); + _dbus_string_append (rule_text_out, s); + _dbus_string_append (rule_text_out, "\n"); + dbus_free (s); + } + + link = next; + } + } +} + static void rule_list_free (DBusList **rules) { diff --git a/bus/signals.h b/bus/signals.h index eeb1d2d..7fbc036 100644 --- a/bus/signals.h +++ b/bus/signals.h @@ -65,6 +65,10 @@ BusMatchRule* bus_match_rule_parse (DBusConnection *matches_go_to, const DBusString *rule_text, DBusError *error); +void bus_match_rule_dump (BusMatchmaker *matchmaker, + DBusString *rule_text_out, + DBusConnection *conn_filter); + BusMatchmaker* bus_matchmaker_new (void); BusMatchmaker* bus_matchmaker_ref (BusMatchmaker *matchmaker); void bus_matchmaker_unref (BusMatchmaker *matchmaker);