From 1e1cefec9fa8a3e850387cfd557549f1794af046 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Mon, 5 Feb 2018 16:47:56 +0100 Subject: [PATCH] bus/log: log names owned by the sender and receiver when a transmit policy fails Signed-off-by: Tom Gundersen --- src/bus/bus.c | 48 +++++++++++++++++++++++++++++++++++++++++++----- src/bus/bus.h | 4 ++-- src/bus/driver.c | 4 +++- src/bus/peer.c | 4 ++-- 4 files changed, 50 insertions(+), 10 deletions(-) diff --git a/src/bus/bus.c b/src/bus/bus.c index 516a5af1..5382f930 100644 --- a/src/bus/bus.c +++ b/src/bus/bus.c @@ -81,7 +81,7 @@ Peer *bus_find_peer_by_name(Bus *bus, Name **namep, const char *name_str) { return peer; } -static int bus_log_commit_policy(Bus *bus, const char *action, uint64_t sender_id, uint64_t receiver_id, Message *message) { +static int bus_log_commit_policy(Bus *bus, const char *action, uint64_t sender_id, uint64_t receiver_id, NameSet *sender_names, NameSet *receiver_names, Message *message) { Log *log = bus->log; int r; @@ -107,6 +107,44 @@ static int bus_log_commit_policy(Bus *bus, const char *action, uint64_t sender_i receiver_id); } + if (sender_names) { + if (sender_names->type == NAME_SET_TYPE_OWNER) { + NameOwnership *ownership; + size_t i = 0; + + c_rbtree_for_each_entry(ownership, + &sender_names->owner->ownership_tree, + owner_node) + log_appendf(log, + "DBUS_BROKER_SENDER_WELL_KNOWN_NAME_%zu=%s\n", + i++, ownership->name->name); + } else if (sender_names->type == NAME_SET_TYPE_SNAPSHOT) { + for (size_t i = 0; i < sender_names->snapshot->n_names; ++i) + log_appendf(log, + "DBUS_BROKER_SENDER_WELL_KNOWN_NAME_%zu=%s\n", + i, sender_names->snapshot->names[i]->name); + } + } + + if (receiver_names) { + if (receiver_names->type == NAME_SET_TYPE_OWNER) { + NameOwnership *ownership; + size_t i = 0; + + c_rbtree_for_each_entry(ownership, + &receiver_names->owner->ownership_tree, + owner_node) + log_appendf(log, + "DBUS_BROKER_RECEIVER_WELL_KNOWN_NAME_%zu=%s\n", + i++, ownership->name->name); + } else if (receiver_names->type == NAME_SET_TYPE_SNAPSHOT) { + for (size_t i = 0; i < receiver_names->snapshot->n_names; ++i) + log_appendf(log, + "DBUS_BROKER_RECEIVER_WELL_KNOWN_NAME_%zu=%s\n", + i, receiver_names->snapshot->names[i]->name); + } + } + r = log_commitf(log, ":1.%llu failed to %s message, due to policy.", sender_id, action); if (r) return error_fold(r); @@ -114,10 +152,10 @@ static int bus_log_commit_policy(Bus *bus, const char *action, uint64_t sender_i return 0; } -int bus_log_commit_policy_send(Bus *bus, uint64_t sender_id, uint64_t receiver_id, Message *message) { - return bus_log_commit_policy(bus, "send", sender_id, receiver_id, message); +int bus_log_commit_policy_send(Bus *bus, uint64_t sender_id, uint64_t receiver_id, NameSet *sender_names, NameSet *receiver_names, Message *message) { + return bus_log_commit_policy(bus, "send", sender_id, receiver_id, sender_names, receiver_names, message); } -int bus_log_commit_policy_receive(Bus *bus, uint64_t receiver_id, uint64_t sender_id, Message *message) { - return bus_log_commit_policy(bus, "receive", sender_id, receiver_id, message); +int bus_log_commit_policy_receive(Bus *bus, uint64_t receiver_id, uint64_t sender_id, NameSet *sender_names, NameSet *receiver_names, Message *message) { + return bus_log_commit_policy(bus, "receive", sender_id, receiver_id, sender_names, receiver_names, message); } diff --git a/src/bus/bus.h b/src/bus/bus.h index 93319d19..3f590f2f 100644 --- a/src/bus/bus.h +++ b/src/bus/bus.h @@ -65,5 +65,5 @@ void bus_deinit(Bus *bus); Peer *bus_find_peer_by_name(Bus *bus, Name **namep, const char *name); -int bus_log_commit_policy_send(Bus *bus, uint64_t sender_id, uint64_t receiver_id, Message *message); -int bus_log_commit_policy_receive(Bus *bus, uint64_t sender_id, uint64_t receiver_id, Message *message); +int bus_log_commit_policy_send(Bus *bus, uint64_t sender_id, uint64_t receiver_id, NameSet *sender_names, NameSet *receiver_names, Message *message); +int bus_log_commit_policy_receive(Bus *bus, uint64_t sender_id, uint64_t receiver_id, NameSet *sender_names, NameSet *receievr_names, Message *message); diff --git a/src/bus/driver.c b/src/bus/driver.c index 326c86d3..0cd84768 100644 --- a/src/bus/driver.c +++ b/src/bus/driver.c @@ -1730,8 +1730,10 @@ static int driver_dispatch_interface(Peer *peer, uint32_t serial, const char *in r = policy_snapshot_check_send(peer->policy, NULL, NULL, interface, member, path, message->header->type); if (r) { if (r == POLICY_E_ACCESS_DENIED) { + NameSet names = NAME_SET_INIT_FROM_OWNER(&peer->owned_names); + log_append_here(peer->bus->log, LOG_WARNING, 0); - r = bus_log_commit_policy_send(peer->bus, peer->id, ADDRESS_ID_INVALID, message); + r = bus_log_commit_policy_send(peer->bus, peer->id, ADDRESS_ID_INVALID, &names, NULL, message); if (r) return error_fold(r); diff --git a/src/bus/peer.c b/src/bus/peer.c index eb2e15b1..6ded104c 100644 --- a/src/bus/peer.c +++ b/src/bus/peer.c @@ -633,7 +633,7 @@ int peer_queue_call(PolicySnapshot *sender_policy, NameSet *sender_names, MatchR if (r) { if (r == POLICY_E_ACCESS_DENIED) { log_append_here(receiver->bus->log, LOG_WARNING, 0); - r = bus_log_commit_policy_receive(receiver->bus, receiver->id, sender_id, message); + r = bus_log_commit_policy_receive(receiver->bus, receiver->id, sender_id, sender_names, &receiver_names, message); if (r) return error_fold(r); @@ -653,7 +653,7 @@ int peer_queue_call(PolicySnapshot *sender_policy, NameSet *sender_names, MatchR if (r) { if (r == POLICY_E_ACCESS_DENIED) { log_append_here(receiver->bus->log, LOG_WARNING, 0); - r = bus_log_commit_policy_send(receiver->bus, sender_id, receiver->id, message); + r = bus_log_commit_policy_send(receiver->bus, sender_id, receiver->id, sender_names, &receiver_names, message); if (r) return error_fold(r);