diff options
Diffstat (limited to 'src/libsystemd/sd-bus')
-rw-r--r-- | src/libsystemd/sd-bus/bus-internal.h | 2 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/bus-match.c | 10 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/bus-objects.c | 16 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/bus-slot.c | 20 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/bus-util.c | 59 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/bus-util.h | 6 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/sd-bus.c | 28 |
7 files changed, 109 insertions, 32 deletions
diff --git a/src/libsystemd/sd-bus/bus-internal.h b/src/libsystemd/sd-bus/bus-internal.h index 618e82c98f..f2ccdfd177 100644 --- a/src/libsystemd/sd-bus/bus-internal.h +++ b/src/libsystemd/sd-bus/bus-internal.h @@ -298,6 +298,8 @@ struct sd_bus { sd_bus_message *current_message; sd_bus_slot *current_slot; + sd_bus_message_handler_t current_handler; + void *current_userdata; sd_bus **default_bus_ptr; pid_t tid; diff --git a/src/libsystemd/sd-bus/bus-match.c b/src/libsystemd/sd-bus/bus-match.c index 9e0769caa6..88b61a75be 100644 --- a/src/libsystemd/sd-bus/bus-match.c +++ b/src/libsystemd/sd-bus/bus-match.c @@ -294,11 +294,17 @@ int bus_match_run( sd_bus_slot *slot; slot = container_of(node->leaf.callback, sd_bus_slot, match_callback); - if (bus) + if (bus) { bus->current_slot = sd_bus_slot_ref(slot); + bus->current_handler = node->leaf.callback->callback; + bus->current_userdata = slot->userdata; + } r = node->leaf.callback->callback(bus, m, slot->userdata, &error_buffer); - if (bus) + if (bus) { + bus->current_userdata = NULL; + bus->current_handler = NULL; bus->current_slot = sd_bus_slot_unref(slot); + } r = bus_maybe_reply_error(m, r, &error_buffer); if (r != 0) diff --git a/src/libsystemd/sd-bus/bus-objects.c b/src/libsystemd/sd-bus/bus-objects.c index 00e8e9655b..3a2de6520e 100644 --- a/src/libsystemd/sd-bus/bus-objects.c +++ b/src/libsystemd/sd-bus/bus-objects.c @@ -51,7 +51,9 @@ static int node_vtable_get_userdata( u = s->userdata; if (c->find) { bus->current_slot = sd_bus_slot_ref(s); + bus->current_userdata = u; r = c->find(bus, path, c->interface, u, &u, error); + bus->current_userdata = NULL; bus->current_slot = sd_bus_slot_unref(s); if (r < 0) @@ -123,7 +125,9 @@ static int add_enumerated_to_set( slot = container_of(c, sd_bus_slot, node_enumerator); bus->current_slot = sd_bus_slot_ref(slot); + bus->current_userdata = slot->userdata; r = c->callback(bus, prefix, slot->userdata, &children, error); + bus->current_userdata = NULL; bus->current_slot = sd_bus_slot_unref(slot); if (r < 0) @@ -273,7 +277,11 @@ static int node_callbacks_run( slot = container_of(c, sd_bus_slot, node_callback); bus->current_slot = sd_bus_slot_ref(slot); + bus->current_handler = c->callback; + bus->current_userdata = slot->userdata; r = c->callback(bus, m, slot->userdata, &error_buffer); + bus->current_userdata = NULL; + bus->current_handler = NULL; bus->current_slot = sd_bus_slot_unref(slot); r = bus_maybe_reply_error(m, r, &error_buffer); @@ -387,7 +395,11 @@ static int method_callbacks_run( slot = container_of(c->parent, sd_bus_slot, node_vtable); bus->current_slot = sd_bus_slot_ref(slot); + bus->current_handler = c->vtable->x.method.handler; + bus->current_userdata = u; r = c->vtable->x.method.handler(bus, m, u, &error); + bus->current_userdata = NULL; + bus->current_handler = NULL; bus->current_slot = sd_bus_slot_unref(slot); return bus_maybe_reply_error(m, r, &error); @@ -426,7 +438,9 @@ static int invoke_property_get( if (v->x.property.get) { bus->current_slot = sd_bus_slot_ref(slot); + bus->current_userdata = userdata; r = v->x.property.get(bus, path, interface, property, reply, userdata, error); + bus->current_userdata = NULL; bus->current_slot = sd_bus_slot_unref(slot); if (r < 0) @@ -488,7 +502,9 @@ static int invoke_property_set( if (v->x.property.set) { bus->current_slot = sd_bus_slot_ref(slot); + bus->current_userdata = userdata; r = v->x.property.set(bus, path, interface, property, value, userdata, error); + bus->current_userdata = NULL; bus->current_slot = sd_bus_slot_unref(slot); if (r < 0) diff --git a/src/libsystemd/sd-bus/bus-slot.c b/src/libsystemd/sd-bus/bus-slot.c index 5e927511d5..d6793c29e9 100644 --- a/src/libsystemd/sd-bus/bus-slot.c +++ b/src/libsystemd/sd-bus/bus-slot.c @@ -245,3 +245,23 @@ _public_ sd_bus_message *sd_bus_slot_get_current_message(sd_bus_slot *slot) { return slot->bus->current_message; } + +_public_ sd_bus_message_handler_t sd_bus_slot_get_current_handler(sd_bus_slot *slot) { + assert_return(slot, NULL); + assert_return(slot->type >= 0, NULL); + + if (slot->bus->current_slot != slot) + return NULL; + + return slot->bus->current_handler; +} + +_public_ void* sd_bus_slot_get_current_userdata(sd_bus_slot *slot) { + assert_return(slot, NULL); + assert_return(slot->type >= 0, NULL); + + if (slot->bus->current_slot != slot) + return NULL; + + return slot->bus->current_userdata; +} diff --git a/src/libsystemd/sd-bus/bus-util.c b/src/libsystemd/sd-bus/bus-util.c index 0ab11c3905..44facc6ef9 100644 --- a/src/libsystemd/sd-bus/bus-util.c +++ b/src/libsystemd/sd-bus/bus-util.c @@ -184,8 +184,7 @@ int bus_name_has_owner(sd_bus *c, const char *name, sd_bus_error *error) { } int bus_verify_polkit( - sd_bus *bus, - sd_bus_message *m, + sd_bus_message *call, int capability, const char *action, bool interactive, @@ -194,28 +193,26 @@ int bus_verify_polkit( int r; - assert(bus); - assert(m); + assert(call); assert(action); - r = sd_bus_query_sender_privilege(m, capability); + r = sd_bus_query_sender_privilege(call, capability); if (r < 0) return r; - if (r > 0) + else if (r > 0) return 1; - #ifdef ENABLE_POLKIT else { _cleanup_bus_message_unref_ sd_bus_message *reply = NULL; int authorized = false, challenge = false; const char *sender; - sender = sd_bus_message_get_sender(m); + sender = sd_bus_message_get_sender(call); if (!sender) return -EBADMSG; r = sd_bus_call_method( - bus, + call->bus, "org.freedesktop.PolicyKit1", "/org/freedesktop/PolicyKit1/Authority", "org.freedesktop.PolicyKit1.Authority", @@ -316,30 +313,29 @@ finish: #endif int bus_verify_polkit_async( - sd_bus *bus, - Hashmap **registry, - sd_bus_message *m, + sd_bus_message *call, int capability, const char *action, bool interactive, - sd_bus_error *error, - sd_bus_message_handler_t callback, - void *userdata) { + Hashmap **registry, + sd_bus_error *error) { #ifdef ENABLE_POLKIT _cleanup_bus_message_unref_ sd_bus_message *pk = NULL; + _cleanup_bus_slot_unref_ sd_bus_slot *slot = NULL; AsyncPolkitQuery *q; const char *sender; + sd_bus_message_handler_t callback; + void *userdata; #endif int r; - assert(bus); - assert(registry); - assert(m); + assert(call); assert(action); + assert(registry); #ifdef ENABLE_POLKIT - q = hashmap_get(*registry, m); + q = hashmap_get(*registry, call); if (q) { int authorized, challenge; @@ -376,14 +372,23 @@ int bus_verify_polkit_async( } #endif - r = sd_bus_query_sender_privilege(m, capability); + r = sd_bus_query_sender_privilege(call, capability); if (r < 0) return r; - if (r > 0) + else if (r > 0) return 1; #ifdef ENABLE_POLKIT - sender = sd_bus_message_get_sender(m); + if (sd_bus_get_current_message(call->bus) != call) + return -EINVAL; + + callback = sd_bus_get_current_handler(call->bus); + if (!callback) + return -EINVAL; + + userdata = sd_bus_get_current_userdata(call->bus); + + sender = sd_bus_message_get_sender(call); if (!sender) return -EBADMSG; @@ -392,7 +397,7 @@ int bus_verify_polkit_async( return r; r = sd_bus_message_new_method_call( - bus, + call->bus, &pk, "org.freedesktop.PolicyKit1", "/org/freedesktop/PolicyKit1/Authority", @@ -416,11 +421,11 @@ int bus_verify_polkit_async( if (!q) return -ENOMEM; - q->request = sd_bus_message_ref(m); + q->request = sd_bus_message_ref(call); q->callback = callback; q->userdata = userdata; - r = hashmap_put(*registry, m, q); + r = hashmap_put(*registry, call, q); if (r < 0) { async_polkit_query_free(q); return r; @@ -428,7 +433,7 @@ int bus_verify_polkit_async( q->registry = *registry; - r = sd_bus_call_async(bus, &q->slot, pk, async_polkit_callback, q, 0); + r = sd_bus_call_async(call->bus, &q->slot, pk, async_polkit_callback, q, 0); if (r < 0) { async_polkit_query_free(q); return r; @@ -440,7 +445,7 @@ int bus_verify_polkit_async( return -EACCES; } -void bus_verify_polkit_async_registry_free(sd_bus *bus, Hashmap *registry) { +void bus_verify_polkit_async_registry_free(Hashmap *registry) { #ifdef ENABLE_POLKIT AsyncPolkitQuery *q; diff --git a/src/libsystemd/sd-bus/bus-util.h b/src/libsystemd/sd-bus/bus-util.h index f760a1e80e..faf1775809 100644 --- a/src/libsystemd/sd-bus/bus-util.h +++ b/src/libsystemd/sd-bus/bus-util.h @@ -62,10 +62,10 @@ int bus_name_has_owner(sd_bus *c, const char *name, sd_bus_error *error); int bus_check_peercred(sd_bus *c); -int bus_verify_polkit(sd_bus *bus, sd_bus_message *m, int capability, const char *action, bool interactive, bool *_challenge, sd_bus_error *e); +int bus_verify_polkit(sd_bus_message *call, int capability, const char *action, bool interactive, bool *_challenge, sd_bus_error *e); -int bus_verify_polkit_async(sd_bus *bus, Hashmap **registry, sd_bus_message *m, int capability, const char *action, bool interactive, sd_bus_error *error, sd_bus_message_handler_t callback, void *userdata); -void bus_verify_polkit_async_registry_free(sd_bus *bus, Hashmap *registry); +int bus_verify_polkit_async(sd_bus_message *call, int capability, const char *action, bool interactive, Hashmap **registry, sd_bus_error *error); +void bus_verify_polkit_async_registry_free(Hashmap *registry); int bus_open_system_systemd(sd_bus **_bus); int bus_open_user_systemd(sd_bus **_bus); diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index 0fadd1699e..83233fd7e6 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -2102,7 +2102,11 @@ static int process_timeout(sd_bus *bus) { bus->current_message = m; bus->current_slot = sd_bus_slot_ref(slot); + bus->current_handler = c->callback; + bus->current_userdata = slot->userdata; r = c->callback(bus, m, slot->userdata, &error_buffer); + bus->current_userdata = NULL; + bus->current_handler = NULL; bus->current_slot = sd_bus_slot_unref(slot); bus->current_message = NULL; @@ -2194,7 +2198,11 @@ static int process_reply(sd_bus *bus, sd_bus_message *m) { } bus->current_slot = sd_bus_slot_ref(slot); + bus->current_handler = c->callback; + bus->current_userdata = slot->userdata; r = c->callback(bus, m, slot->userdata, &error_buffer); + bus->current_userdata = NULL; + bus->current_handler = NULL; bus->current_slot = sd_bus_slot_unref(slot); if (slot->floating) { @@ -2235,7 +2243,11 @@ static int process_filter(sd_bus *bus, sd_bus_message *m) { slot = container_of(l, sd_bus_slot, filter_callback); bus->current_slot = sd_bus_slot_ref(slot); + bus->current_handler = l->callback; + bus->current_userdata = slot->userdata; r = l->callback(bus, m, slot->userdata, &error_buffer); + bus->current_userdata = NULL; + bus->current_handler = NULL; bus->current_slot = sd_bus_slot_unref(slot); r = bus_maybe_reply_error(m, r, &error_buffer); @@ -2512,7 +2524,11 @@ static int process_closing(sd_bus *bus, sd_bus_message **ret) { bus->current_message = m; bus->current_slot = sd_bus_slot_ref(slot); + bus->current_handler = c->callback; + bus->current_userdata = slot->userdata; r = c->callback(bus, m, slot->userdata, &error_buffer); + bus->current_userdata = NULL; + bus->current_handler = NULL; bus->current_slot = sd_bus_slot_unref(slot); bus->current_message = NULL; @@ -3113,6 +3129,18 @@ _public_ sd_bus_slot* sd_bus_get_current_slot(sd_bus *bus) { return bus->current_slot; } +_public_ sd_bus_message_handler_t sd_bus_get_current_handler(sd_bus *bus) { + assert_return(bus, NULL); + + return bus->current_handler; +} + +_public_ void* sd_bus_get_current_userdata(sd_bus *bus) { + assert_return(bus, NULL); + + return bus->current_userdata; +} + static int bus_default(int (*bus_open)(sd_bus **), sd_bus **default_bus, sd_bus **ret) { sd_bus *b = NULL; int r; |