diff options
Diffstat (limited to 'src/bus-proxyd/driver.c')
-rw-r--r-- | src/bus-proxyd/driver.c | 113 |
1 files changed, 84 insertions, 29 deletions
diff --git a/src/bus-proxyd/driver.c b/src/bus-proxyd/driver.c index 1cb5ea5008..fa4aee691a 100644 --- a/src/bus-proxyd/driver.c +++ b/src/bus-proxyd/driver.c @@ -35,6 +35,7 @@ #include "driver.h" #include "proxy.h" #include "synthesize.h" +#include "env-util.h" static int get_creds_by_name(sd_bus *bus, const char *name, uint64_t mask, sd_bus_creds **_creds, sd_bus_error *error) { _cleanup_bus_creds_unref_ sd_bus_creds *c = NULL; @@ -71,6 +72,27 @@ static int get_creds_by_message(sd_bus *bus, sd_bus_message *m, uint64_t mask, s return get_creds_by_name(bus, name, mask, _creds, error); } +static int driver_activation(sd_bus_message *reply, void *userdata, sd_bus_error *error) { + _cleanup_bus_message_unref_ sd_bus_message *m = NULL; + ProxyActivation *activation = userdata; + + /* + * The org.freedesktop.DBus.Peer.Ping() call returned. We don't care + * whether this succeeded, failed, was not implemented or timed out. We + * cannot assume that the target reacts to this properly. Hence, just + * send the reply to the activation request and be done. + */ + + m = activation->request; /* claim reference */ + + --activation->proxy->n_activations; + LIST_REMOVE(activations_by_proxy, activation->proxy->activations, activation); + sd_bus_slot_unref(activation->slot); + free(activation); + + return synthetic_reply_method_return(m, "u", BUS_START_REPLY_SUCCESS); +} + int bus_proxy_process_driver(Proxy *p, sd_bus *a, sd_bus *b, sd_bus_message *m, SharedPolicy *sp, const struct ucred *ucred, Set *owned_names) { int r; @@ -441,27 +463,29 @@ int bus_proxy_process_driver(Proxy *p, sd_bus *a, sd_bus *b, sd_bus_message *m, name_list = (struct kdbus_info *) ((uint8_t *) a->kdbus_buffer + cmd.offset); KDBUS_FOREACH(name, name_list, cmd.list_size) { - const char *entry_name = NULL; struct kdbus_item *item; char *n; - KDBUS_ITEM_FOREACH(item, name, items) - if (item->type == KDBUS_ITEM_OWNED_NAME) - entry_name = item->name.name; - - if (!streq_ptr(entry_name, arg0)) - continue; - - if (asprintf(&n, ":1.%llu", (unsigned long long) name->id) < 0) { - err = -ENOMEM; - break; + KDBUS_ITEM_FOREACH(item, name, items) { + if (item->type == KDBUS_ITEM_OWNED_NAME) { + if (!streq_ptr(item->name.name, arg0)) + continue; + + if (asprintf(&n, ":1.%llu", (unsigned long long) name->id) < 0) { + err = -ENOMEM; + break; + } + + r = strv_consume(&owners, n); + if (r < 0) { + err = r; + break; + } + } } - r = strv_consume(&owners, n); - if (r < 0) { - err = r; + if (err < 0) break; - } } r = bus_kernel_cmd_free(a, cmd.offset); @@ -585,7 +609,9 @@ int bus_proxy_process_driver(Proxy *p, sd_bus *a, sd_bus *b, sd_bus_message *m, } else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", "StartServiceByName")) { _cleanup_bus_message_unref_ sd_bus_message *msg = NULL; + ProxyActivation *activation; const char *name; + uint64_t cookie; uint32_t flags; if (!sd_bus_message_has_signature(m, "su")) @@ -604,21 +630,46 @@ int bus_proxy_process_driver(Proxy *p, sd_bus *a, sd_bus *b, sd_bus_message *m, if (r != -ESRCH) return synthetic_reply_method_errno(m, r, NULL); - r = sd_bus_message_new_method_call( - a, - &msg, - name, - "/", - "org.freedesktop.DBus.Peer", - "Ping"); + if (p->n_activations >= PROXY_ACTIVATIONS_MAX) + return synthetic_reply_method_errno(m, -EMFILE, NULL); + + r = sd_bus_message_get_cookie(m, &cookie); + if (r < 0) + return synthetic_reply_method_errno(m, r, NULL); + + r = sd_bus_message_new_method_call(a, + &msg, + name, + "/", + "org.freedesktop.DBus.Peer", + "Ping"); if (r < 0) return synthetic_reply_method_errno(m, r, NULL); - r = sd_bus_send(a, msg, NULL); + r = bus_message_seal(msg, cookie, BUS_DEFAULT_TIMEOUT); if (r < 0) return synthetic_reply_method_errno(m, r, NULL); - return synthetic_reply_method_return(m, "u", BUS_START_REPLY_SUCCESS); + activation = new0(ProxyActivation, 1); + if (!activation) + return synthetic_reply_method_errno(m, -ENOMEM, NULL); + + r = sd_bus_call_async(a, + &activation->slot, + msg, + driver_activation, + activation, + 0); + if (r < 0) { + free(activation); + return synthetic_reply_method_errno(m, r, NULL); + } + + activation->proxy = p; + activation->request = sd_bus_message_ref(m); + LIST_PREPEND(activations_by_proxy, p->activations, activation); + ++p->n_activations; + return 1; } else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", "UpdateActivationEnvironment")) { _cleanup_bus_message_unref_ sd_bus_message *msg = NULL; @@ -644,9 +695,13 @@ int bus_proxy_process_driver(Proxy *p, sd_bus *a, sd_bus *b, sd_bus_message *m, if (!s) return synthetic_reply_method_errno(m, -ENOMEM, NULL); - r = strv_extend(&args, s); - if (r < 0) - return synthetic_reply_method_errno(m, r, NULL); + if (!env_assignment_is_valid(s)) { + log_warning("UpdateActivationEnvironment() called with invalid assignment, discarding: %s", s); + } else { + r = strv_extend(&args, s); + if (r < 0) + return synthetic_reply_method_errno(m, r, NULL); + } r = sd_bus_message_exit_container(m); if (r < 0) @@ -657,8 +712,8 @@ int bus_proxy_process_driver(Proxy *p, sd_bus *a, sd_bus *b, sd_bus_message *m, if (r < 0) return synthetic_reply_method_errno(m, r, NULL); - if (!args) - return synthetic_reply_method_errno(m, -EINVAL, NULL); + if (strv_isempty(args)) /* nothing to do? */ + return synthetic_reply_method_return(m, NULL); r = sd_bus_message_new_method_call( a, |