From cd1909f733983f841cb518eed23da5134a9be094 Mon Sep 17 00:00:00 2001 From: Chengwei Yang Date: Tue, 10 Dec 2013 17:03:32 +0800 Subject: [PATCH] Add bus_client_policy_print to print client policy rules Bug: https://bugs.freedesktop.org/show_bug.cgi?id=39463 --- bus/policy.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ bus/policy.h | 2 ++ 2 files changed, 52 insertions(+) diff --git a/bus/policy.c b/bus/policy.c index 082f385..fd5c677 100644 --- a/bus/policy.c +++ b/bus/policy.c @@ -862,6 +862,56 @@ bus_client_policy_append_rule (BusClientPolicy *policy, return TRUE; } +void +bus_client_policy_print (BusClientPolicy *policy) +{ + DBusList *link; + BusPolicyRule *rule; + + _dbus_assert (policy != NULL); + + for (link = _dbus_list_get_first_link (&policy->rules); + link != NULL; + link = _dbus_list_get_next_link (&policy->rules, link)) + { + rule = link->data; + switch (rule->type) + { + case BUS_POLICY_RULE_SEND: + _dbus_warn ("send rule (%s): dest(%s) path(%s) interface(%s) member(%s)\n", + rule->allow ? "allow" : "deny", + rule->d.send.destination, rule->d.send.path, + rule->d.send.interface, rule->d.send.member); + break; + case BUS_POLICY_RULE_RECEIVE: + _dbus_warn ("receive rule (%s): from(%s) path(%s) interface(%s) member(%s)\n", + rule->allow ? "allow" : "deny", + rule->d.receive.origin, rule->d.receive.path, + rule->d.receive.interface, rule->d.receive.member); + break; + case BUS_POLICY_RULE_OWN: + _dbus_warn ("own rule (%s): service(%s)\n", + rule->allow ? "allow" : "deny", + rule->d.own.service_name); + break; + case BUS_POLICY_RULE_GROUP: + _dbus_warn ("group rule (%s): gid(%d)\n", + rule->allow ? "allow" : "deny", + (int) rule->d.group.gid); + break; + case BUS_POLICY_RULE_USER: + _dbus_warn ("user rule (%s): uid(%d)\n", + rule->allow ? "allow" : "deny", + (int) rule->d.user.uid); + break; + default: + _dbus_warn ("invalid policy type\n"); + break; + } + } +} + + dbus_bool_t bus_client_policy_check_can_send (BusClientPolicy *policy, BusRegistry *registry, diff --git a/bus/policy.h b/bus/policy.h index d1d3e72..5b3aa00 100644 --- a/bus/policy.h +++ b/bus/policy.h @@ -161,6 +161,8 @@ dbus_bool_t bus_client_policy_append_rule (BusClientPolicy *policy, BusPolicyRule *rule); void bus_client_policy_optimize (BusClientPolicy *policy); +void bus_client_policy_print (BusClientPolicy *policy); + #ifdef DBUS_ENABLE_EMBEDDED_TESTS dbus_bool_t bus_policy_check_can_own (BusPolicy *policy, const DBusString *service_name); -- 1.7.9.5