Skip to content

Commit

Permalink
bus/log: log names owned by the sender and receiver when a transmit p…
Browse files Browse the repository at this point in the history
…olicy fails

Signed-off-by: Tom Gundersen <[email protected]>
  • Loading branch information
teg authored and David Herrmann committed Feb 7, 2018
1 parent e909762 commit 1e1cefe
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 10 deletions.
48 changes: 43 additions & 5 deletions src/bus/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -107,17 +107,55 @@ 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);

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);
}
4 changes: 2 additions & 2 deletions src/bus/bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
4 changes: 3 additions & 1 deletion src/bus/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/bus/peer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down

0 comments on commit 1e1cefe

Please sign in to comment.