dbus.c revision b2c23da8cea1987a1a329f5a964d3299b7ca7890
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering/***
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering This file is part of systemd.
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering Copyright 2010 Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering systemd is free software; you can redistribute it and/or modify it
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering under the terms of the GNU Lesser General Public License as published by
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering (at your option) any later version.
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering systemd is distributed in the hope that it will be useful, but
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering Lesser General Public License for more details.
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering You should have received a copy of the GNU Lesser General Public License
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering***/
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering#include <sys/epoll.h>
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering#include <errno.h>
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering#include <unistd.h>
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering#include "sd-bus.h"
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering#include "log.h"
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering#include "strv.h"
9eb977db5b89b44f254ab40c1876a76b7d7ea2d0Kay Sievers#include "mkdir.h"
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering#include "missing.h"
a5c32cff1f56afe6f0c6c70d91a88a7a8238b2d7Harald Hoyer#include "dbus-unit.h"
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering#include "dbus-job.h"
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering#include "dbus-manager.h"
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering#include "dbus-execute.h"
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering#include "dbus-kill.h"
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering#include "dbus-cgroup.h"
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering#include "special.h"
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering#include "dbus.h"
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering#include "bus-util.h"
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering#include "bus-error.h"
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering#include "bus-common-errors.h"
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering#include "strxcpyx.h"
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering#include "bus-internal.h"
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering#include "selinux-access.h"
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering#define CONNECTIONS_MAX 4096
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
2b6bf07dd23bb467099d213c97b3875c5e453491Zbigniew Jędrzejewski-Szmekstatic void destroy_bus(Manager *m, sd_bus **bus);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringint bus_send_queued_message(Manager *m) {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering int r;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering assert(m);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (!m->queued_message)
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering return 0;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering /* If we cannot get rid of this message we won't dispatch any
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering * D-Bus messages, so that we won't end up wanting to queue
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering * another message. */
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering r = sd_bus_send(NULL, m->queued_message, NULL);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (r < 0)
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering log_warning_errno(r, "Failed to send queued message: %m");
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering m->queued_message = sd_bus_message_unref(m->queued_message);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering return 0;
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering}
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering
cc3773810855956bad92337cee8fa193584ab62eLennart Poetteringstatic int signal_agent_released(sd_bus_message *message, void *userdata, sd_bus_error *error) {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering Manager *m = userdata;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering const char *cgroup;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering int r;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering assert(message);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering assert(m);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering r = sd_bus_message_read(message, "s", &cgroup);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (r < 0) {
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering bus_log_parse_error(r);
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering return 0;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering }
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering manager_notify_cgroup_empty(m, cgroup);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
d2e54fae5ca7a0f71b5ac8b356a589ff0a09ea0aKay Sievers /* only forward to system bus if running as system instance */
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (m->running_as != MANAGER_SYSTEM || !m->system_bus)
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering return 0;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering r = sd_bus_message_rewind(message, 1);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (r < 0)
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering goto exit;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering r = sd_bus_send(m->system_bus, message, NULL);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringexit:
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (r < 0)
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering log_warning_errno(r, "Failed to forward Released message: %m");
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering return 0;
90b2de37b80603168f4e9c9c81cff7eea4efa21aZbigniew Jędrzejewski-Szmek}
90b2de37b80603168f4e9c9c81cff7eea4efa21aZbigniew Jędrzejewski-Szmek
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic int signal_disconnected(sd_bus_message *message, void *userdata, sd_bus_error *error) {
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering Manager *m = userdata;
90b2de37b80603168f4e9c9c81cff7eea4efa21aZbigniew Jędrzejewski-Szmek sd_bus *bus;
90b2de37b80603168f4e9c9c81cff7eea4efa21aZbigniew Jędrzejewski-Szmek
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering assert(message);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering assert(m);
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering assert_se(bus = sd_bus_message_get_bus(message));
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (bus == m->api_bus)
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering destroy_bus(m, &m->api_bus);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (bus == m->system_bus)
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering destroy_bus(m, &m->system_bus);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (set_remove(m->private_buses, bus)) {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering log_debug("Got disconnect on private connection.");
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering destroy_bus(m, &bus);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering }
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering return 0;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering}
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic int signal_name_owner_changed(sd_bus_message *message, void *userdata, sd_bus_error *error) {
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering const char *name, *old_owner, *new_owner;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering Manager *m = userdata;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering int r;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering assert(message);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering assert(m);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering r = sd_bus_message_read(message, "sss", &name, &old_owner, &new_owner);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (r < 0) {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering bus_log_parse_error(r);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering return 0;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering }
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering manager_dispatch_bus_name_owner_changed(
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering m, name,
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering isempty(old_owner) ? NULL : old_owner,
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering isempty(new_owner) ? NULL : new_owner);
90b2de37b80603168f4e9c9c81cff7eea4efa21aZbigniew Jędrzejewski-Szmek
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering return 0;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering}
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic int signal_activation_request(sd_bus_message *message, void *userdata, sd_bus_error *ret_error) {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering Manager *m = userdata;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering const char *name;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering Unit *u;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering int r;
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering assert(message);
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering assert(m);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering r = sd_bus_message_read(message, "s", &name);
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering if (r < 0) {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering bus_log_parse_error(r);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering return 0;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering }
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (manager_unit_inactive_or_pending(m, SPECIAL_DBUS_SERVICE) ||
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering manager_unit_inactive_or_pending(m, SPECIAL_DBUS_SOCKET)) {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering r = sd_bus_error_setf(&error, BUS_ERROR_SHUTTING_DOWN, "Refusing activation, D-Bus is shutting down.");
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering goto failed;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering }
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering r = manager_load_unit(m, name, NULL, &error, &u);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (r < 0)
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering goto failed;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering if (u->refuse_manual_start) {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering r = sd_bus_error_setf(&error, BUS_ERROR_ONLY_BY_DEPENDENCY, "Operation refused, %s may be requested by dependency only.", u->id);
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering goto failed;
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering }
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering r = manager_add_job(m, JOB_START, u, JOB_REPLACE, true, &error, NULL);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (r < 0)
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering goto failed;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering /* Successfully queued, that's it for us */
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering return 0;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringfailed:
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (!sd_bus_error_is_set(&error))
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering sd_bus_error_set_errno(&error, r);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering log_debug("D-Bus activation failed for %s: %s", name, bus_error_message(&error, r));
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering r = sd_bus_message_new_signal(sd_bus_message_get_bus(message), &reply, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Activator", "ActivationFailure");
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (r < 0) {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering bus_log_create_error(r);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering return 0;
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering }
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering r = sd_bus_message_append(reply, "sss", name, error.name, error.message);
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering if (r < 0) {
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering bus_log_create_error(r);
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering return 0;
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering }
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering r = sd_bus_send_to(NULL, reply, "org.freedesktop.DBus", NULL);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (r < 0)
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering return log_error_errno(r, "Failed to respond with to bus activation request: %m");
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering return 0;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering}
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering#ifdef HAVE_SELINUX
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic int mac_selinux_filter(sd_bus_message *message, void *userdata, sd_bus_error *error) {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering Manager *m = userdata;
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering const char *verb, *path;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering Unit *u = NULL;
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering Job *j;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering int r;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering assert(message);
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering /* Our own method calls are all protected individually with
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering * selinux checks, but the built-in interfaces need to be
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering * protected too. */
a34faf579d2be139b0b9e8cd0c73ad4d918ef736Lukas Nykryn
a34faf579d2be139b0b9e8cd0c73ad4d918ef736Lukas Nykryn if (sd_bus_message_is_method_call(message, "org.freedesktop.DBus.Properties", "Set"))
a34faf579d2be139b0b9e8cd0c73ad4d918ef736Lukas Nykryn verb = "reload";
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering else if (sd_bus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", NULL) ||
a34faf579d2be139b0b9e8cd0c73ad4d918ef736Lukas Nykryn sd_bus_message_is_method_call(message, "org.freedesktop.DBus.Properties", NULL) ||
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering sd_bus_message_is_method_call(message, "org.freedesktop.DBus.ObjectManager", NULL) ||
a34faf579d2be139b0b9e8cd0c73ad4d918ef736Lukas Nykryn sd_bus_message_is_method_call(message, "org.freedesktop.DBus.Peer", NULL))
a34faf579d2be139b0b9e8cd0c73ad4d918ef736Lukas Nykryn verb = "status";
a34faf579d2be139b0b9e8cd0c73ad4d918ef736Lukas Nykryn else
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering return 0;
a34faf579d2be139b0b9e8cd0c73ad4d918ef736Lukas Nykryn
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering path = sd_bus_message_get_path(message);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (object_path_startswith("/org/freedesktop/systemd1", path)) {
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering r = mac_selinux_access_check(message, verb, error);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (r < 0)
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering return r;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering return 0;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering }
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (streq_ptr(path, "/org/freedesktop/systemd1/unit/self")) {
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering pid_t pid;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (r < 0)
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering return 0;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering r = sd_bus_creds_get_pid(creds, &pid);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (r < 0)
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering return 0;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering u = manager_get_unit_by_pid(m, pid);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering } else {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering r = manager_get_job_from_dbus_path(m, path, &j);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (r >= 0)
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering u = j->unit;
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering else
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering manager_load_unit_from_dbus_path(m, path, NULL, &u);
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering }
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering if (!u)
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering return 0;
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering r = mac_selinux_unit_access_check(u, message, verb, error);
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering if (r < 0)
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering return r;
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering return 0;
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering}
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering#endif
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic int bus_job_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering Manager *m = userdata;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering Job *j;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering int r;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering assert(bus);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering assert(path);
d2e54fae5ca7a0f71b5ac8b356a589ff0a09ea0aKay Sievers assert(interface);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering assert(found);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering assert(m);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering r = manager_get_job_from_dbus_path(m, path, &j);
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering if (r < 0)
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering return 0;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering *found = j;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering return 1;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering}
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic int find_unit(Manager *m, sd_bus *bus, const char *path, Unit **unit, sd_bus_error *error) {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering Unit *u;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering int r;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering assert(m);
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering assert(bus);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering assert(path);
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering if (streq_ptr(path, "/org/freedesktop/systemd1/unit/self")) {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering sd_bus_message *message;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering pid_t pid;
718db96199eb307751264e4163555662c9a389faLennart Poettering
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering message = sd_bus_get_current_message(bus);
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering if (!message)
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering return 0;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (r < 0)
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering return r;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering r = sd_bus_creds_get_pid(creds, &pid);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (r < 0)
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering return r;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering u = manager_get_unit_by_pid(m, pid);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering } else {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering r = manager_load_unit_from_dbus_path(m, path, error, &u);
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering if (r < 0)
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering return 0;
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering }
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (!u)
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering return 0;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering *unit = u;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering return 1;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering}
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic int bus_unit_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering Manager *m = userdata;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering assert(bus);
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering assert(path);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering assert(interface);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering assert(found);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering assert(m);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering return find_unit(m, bus, path, (Unit**) found, error);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering}
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poetteringstatic int bus_unit_interface_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering Manager *m = userdata;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering Unit *u;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering int r;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering assert(bus);
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering assert(path);
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering assert(interface);
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering assert(found);
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering assert(m);
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering
2c4f86c1298f402220965682ab0e7729e150a562Lennart Poettering r = find_unit(m, bus, path, &u, error);
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering if (r <= 0)
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering return r;
2c4f86c1298f402220965682ab0e7729e150a562Lennart Poettering
2c4f86c1298f402220965682ab0e7729e150a562Lennart Poettering if (!streq_ptr(interface, UNIT_VTABLE(u)->bus_interface))
2c4f86c1298f402220965682ab0e7729e150a562Lennart Poettering return 0;
2c4f86c1298f402220965682ab0e7729e150a562Lennart Poettering
2c4f86c1298f402220965682ab0e7729e150a562Lennart Poettering *found = u;
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering return 1;
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering}
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poetteringstatic int bus_unit_cgroup_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering Manager *m = userdata;
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering Unit *u;
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering int r;
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering
409133be63387fc04d927e8aecd2f6ba03d2f143Lennart Poettering assert(bus);
409133be63387fc04d927e8aecd2f6ba03d2f143Lennart Poettering assert(path);
85a428c69465b047731b6abb5005f01824f1444eLennart Poettering assert(interface);
85a428c69465b047731b6abb5005f01824f1444eLennart Poettering assert(found);
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering assert(m);
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering r = find_unit(m, bus, path, &u, error);
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering if (r <= 0)
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering return r;
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering if (!streq_ptr(interface, UNIT_VTABLE(u)->bus_interface))
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering return 0;
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering if (!unit_get_cgroup_context(u))
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering return 0;
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering *found = u;
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering return 1;
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering}
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering
409133be63387fc04d927e8aecd2f6ba03d2f143Lennart Poetteringstatic int bus_cgroup_context_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
409133be63387fc04d927e8aecd2f6ba03d2f143Lennart Poettering Manager *m = userdata;
409133be63387fc04d927e8aecd2f6ba03d2f143Lennart Poettering CGroupContext *c;
409133be63387fc04d927e8aecd2f6ba03d2f143Lennart Poettering Unit *u;
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering int r;
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering assert(bus);
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering assert(path);
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering assert(interface);
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering assert(found);
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering assert(m);
85a428c69465b047731b6abb5005f01824f1444eLennart Poettering
85a428c69465b047731b6abb5005f01824f1444eLennart Poettering r = find_unit(m, bus, path, &u, error);
85a428c69465b047731b6abb5005f01824f1444eLennart Poettering if (r <= 0)
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering return r;
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering if (!streq_ptr(interface, UNIT_VTABLE(u)->bus_interface))
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering return 0;
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering c = unit_get_cgroup_context(u);
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering if (!c)
c7b5eb98e8eeafe63a079ee3c51e9670872437aeLennart Poettering return 0;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
ec202eae8e84a4c99f054f771cb832046cb8769fShawn Landden *found = c;
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering return 1;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering}
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic int bus_exec_context_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering Manager *m = userdata;
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering ExecContext *c;
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering Unit *u;
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering int r;
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering assert(bus);
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering assert(path);
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering assert(interface);
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering assert(found);
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering assert(m);
8e7fd6ade44ce5dde0867ba748c7978ed1206865Lennart Poettering
8e7fd6ade44ce5dde0867ba748c7978ed1206865Lennart Poettering r = find_unit(m, bus, path, &u, error);
8e7fd6ade44ce5dde0867ba748c7978ed1206865Lennart Poettering if (r <= 0)
8e7fd6ade44ce5dde0867ba748c7978ed1206865Lennart Poettering return r;
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering if (!streq_ptr(interface, UNIT_VTABLE(u)->bus_interface))
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering return 0;
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering c = unit_get_exec_context(u);
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering if (!c)
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering return 0;
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering *found = c;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering return 1;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering}
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poetteringstatic int bus_kill_context_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering Manager *m = userdata;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering KillContext *c;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering Unit *u;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering int r;
641906e9366891e0ad3e6e38b7396a427678c4cfThomas Hindoe Paaboel Andersen
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering assert(bus);
641906e9366891e0ad3e6e38b7396a427678c4cfThomas Hindoe Paaboel Andersen assert(path);
4943c1c94ba751c98763f4232b4350481b22c90aLennart Poettering assert(interface);
641906e9366891e0ad3e6e38b7396a427678c4cfThomas Hindoe Paaboel Andersen assert(found);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering assert(m);
641906e9366891e0ad3e6e38b7396a427678c4cfThomas Hindoe Paaboel Andersen
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering r = find_unit(m, bus, path, &u, error);
641906e9366891e0ad3e6e38b7396a427678c4cfThomas Hindoe Paaboel Andersen if (r <= 0)
8e7fd6ade44ce5dde0867ba748c7978ed1206865Lennart Poettering return r;
641906e9366891e0ad3e6e38b7396a427678c4cfThomas Hindoe Paaboel Andersen
8e7fd6ade44ce5dde0867ba748c7978ed1206865Lennart Poettering if (!streq_ptr(interface, UNIT_VTABLE(u)->bus_interface))
641906e9366891e0ad3e6e38b7396a427678c4cfThomas Hindoe Paaboel Andersen return 0;
beaafb2ea6be591882aef21fe19b88e3b2461087Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering c = unit_get_kill_context(u);
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering if (!c)
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering return 0;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering *found = c;
f8e2fb7b14e53f5a4bcfd66d26910af1dee185c6Lennart Poettering return 1;
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering}
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poetteringstatic int bus_job_enumerate(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering _cleanup_free_ char **l = NULL;
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering Manager *m = userdata;
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering unsigned k = 0;
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering Iterator i;
Job *j;
l = new0(char*, hashmap_size(m->jobs)+1);
if (!l)
return -ENOMEM;
HASHMAP_FOREACH(j, m->jobs, i) {
l[k] = job_dbus_path(j);
if (!l[k])
return -ENOMEM;
k++;
}
assert(hashmap_size(m->jobs) == k);
*nodes = l;
l = NULL;
return k;
}
static int bus_unit_enumerate(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
_cleanup_free_ char **l = NULL;
Manager *m = userdata;
unsigned k = 0;
Iterator i;
Unit *u;
l = new0(char*, hashmap_size(m->units)+1);
if (!l)
return -ENOMEM;
HASHMAP_FOREACH(u, m->units, i) {
l[k] = unit_dbus_path(u);
if (!l[k])
return -ENOMEM;
k++;
}
*nodes = l;
l = NULL;
return k;
}
static int bus_setup_api_vtables(Manager *m, sd_bus *bus) {
UnitType t;
int r;
assert(m);
assert(bus);
#ifdef HAVE_SELINUX
r = sd_bus_add_filter(bus, NULL, mac_selinux_filter, m);
if (r < 0)
return log_error_errno(r, "Failed to add SELinux access filter: %m");
#endif
r = sd_bus_add_object_vtable(bus, NULL, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", bus_manager_vtable, m);
if (r < 0)
return log_error_errno(r, "Failed to register Manager vtable: %m");
r = sd_bus_add_fallback_vtable(bus, NULL, "/org/freedesktop/systemd1/job", "org.freedesktop.systemd1.Job", bus_job_vtable, bus_job_find, m);
if (r < 0)
return log_error_errno(r, "Failed to register Job vtable: %m");
r = sd_bus_add_node_enumerator(bus, NULL, "/org/freedesktop/systemd1/job", bus_job_enumerate, m);
if (r < 0)
return log_error_errno(r, "Failed to add job enumerator: %m");
r = sd_bus_add_fallback_vtable(bus, NULL, "/org/freedesktop/systemd1/unit", "org.freedesktop.systemd1.Unit", bus_unit_vtable, bus_unit_find, m);
if (r < 0)
return log_error_errno(r, "Failed to register Unit vtable: %m");
r = sd_bus_add_node_enumerator(bus, NULL, "/org/freedesktop/systemd1/unit", bus_unit_enumerate, m);
if (r < 0)
return log_error_errno(r, "Failed to add job enumerator: %m");
for (t = 0; t < _UNIT_TYPE_MAX; t++) {
r = sd_bus_add_fallback_vtable(bus, NULL, "/org/freedesktop/systemd1/unit", unit_vtable[t]->bus_interface, unit_vtable[t]->bus_vtable, bus_unit_interface_find, m);
if (r < 0)
return log_error_errno(r, "Failed to register type specific vtable for %s: %m", unit_vtable[t]->bus_interface);
if (unit_vtable[t]->cgroup_context_offset > 0) {
r = sd_bus_add_fallback_vtable(bus, NULL, "/org/freedesktop/systemd1/unit", unit_vtable[t]->bus_interface, bus_unit_cgroup_vtable, bus_unit_cgroup_find, m);
if (r < 0)
return log_error_errno(r, "Failed to register control group unit vtable for %s: %m", unit_vtable[t]->bus_interface);
r = sd_bus_add_fallback_vtable(bus, NULL, "/org/freedesktop/systemd1/unit", unit_vtable[t]->bus_interface, bus_cgroup_vtable, bus_cgroup_context_find, m);
if (r < 0)
return log_error_errno(r, "Failed to register control group vtable for %s: %m", unit_vtable[t]->bus_interface);
}
if (unit_vtable[t]->exec_context_offset > 0) {
r = sd_bus_add_fallback_vtable(bus, NULL, "/org/freedesktop/systemd1/unit", unit_vtable[t]->bus_interface, bus_exec_vtable, bus_exec_context_find, m);
if (r < 0)
return log_error_errno(r, "Failed to register execute vtable for %s: %m", unit_vtable[t]->bus_interface);
}
if (unit_vtable[t]->kill_context_offset > 0) {
r = sd_bus_add_fallback_vtable(bus, NULL, "/org/freedesktop/systemd1/unit", unit_vtable[t]->bus_interface, bus_kill_vtable, bus_kill_context_find, m);
if (r < 0)
return log_error_errno(r, "Failed to register kill vtable for %s: %m", unit_vtable[t]->bus_interface);
}
}
return 0;
}
static int bus_setup_disconnected_match(Manager *m, sd_bus *bus) {
int r;
assert(m);
assert(bus);
r = sd_bus_add_match(
bus,
NULL,
"sender='org.freedesktop.DBus.Local',"
"type='signal',"
"path='/org/freedesktop/DBus/Local',"
"interface='org.freedesktop.DBus.Local',"
"member='Disconnected'",
signal_disconnected, m);
if (r < 0)
return log_error_errno(r, "Failed to register match for Disconnected message: %m");
return 0;
}
static int bus_on_connection(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
_cleanup_bus_unref_ sd_bus *bus = NULL;
_cleanup_close_ int nfd = -1;
Manager *m = userdata;
sd_id128_t id;
int r;
assert(s);
assert(m);
nfd = accept4(fd, NULL, NULL, SOCK_NONBLOCK|SOCK_CLOEXEC);
if (nfd < 0) {
log_warning_errno(errno, "Failed to accept private connection, ignoring: %m");
return 0;
}
if (set_size(m->private_buses) >= CONNECTIONS_MAX) {
log_warning("Too many concurrent connections, refusing");
return 0;
}
r = set_ensure_allocated(&m->private_buses, NULL);
if (r < 0) {
log_oom();
return 0;
}
r = sd_bus_new(&bus);
if (r < 0) {
log_warning_errno(r, "Failed to allocate new private connection bus: %m");
return 0;
}
r = sd_bus_set_fd(bus, nfd, nfd);
if (r < 0) {
log_warning_errno(r, "Failed to set fd on new connection bus: %m");
return 0;
}
nfd = -1;
r = bus_check_peercred(bus);
if (r < 0) {
log_warning_errno(r, "Incoming private connection from unprivileged client, refusing: %m");
return 0;
}
assert_se(sd_id128_randomize(&id) >= 0);
r = sd_bus_set_server(bus, 1, id);
if (r < 0) {
log_warning_errno(r, "Failed to enable server support for new connection bus: %m");
return 0;
}
r = sd_bus_negotiate_creds(bus, 1,
SD_BUS_CREDS_PID|SD_BUS_CREDS_UID|
SD_BUS_CREDS_EUID|SD_BUS_CREDS_EFFECTIVE_CAPS|
SD_BUS_CREDS_SELINUX_CONTEXT);
if (r < 0) {
log_warning_errno(r, "Failed to enable credentials for new connection: %m");
return 0;
}
r = sd_bus_start(bus);
if (r < 0) {
log_warning_errno(r, "Failed to start new connection bus: %m");
return 0;
}
r = sd_bus_attach_event(bus, m->event, SD_EVENT_PRIORITY_NORMAL);
if (r < 0) {
log_warning_errno(r, "Failed to attach new connection bus to event loop: %m");
return 0;
}
if (m->running_as == MANAGER_SYSTEM) {
/* When we run as system instance we get the Released
* signal via a direct connection */
r = sd_bus_add_match(
bus,
NULL,
"type='signal',"
"interface='org.freedesktop.systemd1.Agent',"
"member='Released',"
"path='/org/freedesktop/systemd1/agent'",
signal_agent_released, m);
if (r < 0) {
log_warning_errno(r, "Failed to register Released match on new connection bus: %m");
return 0;
}
}
r = bus_setup_disconnected_match(m, bus);
if (r < 0)
return 0;
r = bus_setup_api_vtables(m, bus);
if (r < 0) {
log_warning_errno(r, "Failed to set up API vtables on new connection bus: %m");
return 0;
}
r = set_put(m->private_buses, bus);
if (r < 0) {
log_warning_errno(r, "Failed to add new connection bus to set: %m");
return 0;
}
bus = NULL;
log_debug("Accepted new private connection.");
return 0;
}
static int bus_list_names(Manager *m, sd_bus *bus) {
_cleanup_strv_free_ char **names = NULL;
char **i;
int r;
assert(m);
assert(bus);
r = sd_bus_list_names(bus, &names, NULL);
if (r < 0)
return log_error_errno(r, "Failed to get initial list of names: %m");
/* This is a bit hacky, we say the owner of the name is the
* name itself, because we don't want the extra traffic to
* figure out the real owner. */
STRV_FOREACH(i, names)
manager_dispatch_bus_name_owner_changed(m, *i, NULL, *i);
return 0;
}
static int bus_setup_api(Manager *m, sd_bus *bus) {
int r;
assert(m);
assert(bus);
/* Let's make sure we have enough credential bits so that we can make security and selinux decisions */
r = sd_bus_negotiate_creds(bus, 1,
SD_BUS_CREDS_PID|SD_BUS_CREDS_UID|
SD_BUS_CREDS_EUID|SD_BUS_CREDS_EFFECTIVE_CAPS|
SD_BUS_CREDS_SELINUX_CONTEXT);
if (r < 0)
log_warning_errno(r, "Failed to enable credential passing, ignoring: %m");
r = bus_setup_api_vtables(m, bus);
if (r < 0)
return r;
r = sd_bus_add_match(
bus,
NULL,
"type='signal',"
"sender='org.freedesktop.DBus',"
"path='/org/freedesktop/DBus',"
"interface='org.freedesktop.DBus',"
"member='NameOwnerChanged'",
signal_name_owner_changed, m);
if (r < 0)
log_warning_errno(r, "Failed to subscribe to NameOwnerChanged signal: %m");
r = sd_bus_add_match(
bus,
NULL,
"type='signal',"
"sender='org.freedesktop.DBus',"
"path='/org/freedesktop/DBus',"
"interface='org.freedesktop.systemd1.Activator',"
"member='ActivationRequest'",
signal_activation_request, m);
if (r < 0)
log_warning_errno(r, "Failed to subscribe to activation signal: %m");
/* Allow replacing of our name, to ease implementation of
* reexecution, where we keep the old connection open until
* after the new connection is set up and the name installed
* to allow clients to synchronously wait for reexecution to
* finish */
r = sd_bus_request_name(bus,"org.freedesktop.systemd1", SD_BUS_NAME_REPLACE_EXISTING|SD_BUS_NAME_ALLOW_REPLACEMENT);
if (r < 0)
return log_error_errno(r, "Failed to register name: %m");
bus_list_names(m, bus);
log_debug("Successfully connected to API bus.");
return 0;
}
static int bus_init_api(Manager *m) {
_cleanup_bus_unref_ sd_bus *bus = NULL;
int r;
if (m->api_bus)
return 0;
/* The API and system bus is the same if we are running in system mode */
if (m->running_as == MANAGER_SYSTEM && m->system_bus)
bus = sd_bus_ref(m->system_bus);
else {
if (m->running_as == MANAGER_SYSTEM)
r = sd_bus_open_system(&bus);
else
r = sd_bus_open_user(&bus);
if (r < 0) {
log_debug("Failed to connect to API bus, retrying later...");
return 0;
}
r = sd_bus_attach_event(bus, m->event, SD_EVENT_PRIORITY_NORMAL);
if (r < 0) {
log_error_errno(r, "Failed to attach API bus to event loop: %m");
return 0;
}
r = bus_setup_disconnected_match(m, bus);
if (r < 0)
return 0;
}
r = bus_setup_api(m, bus);
if (r < 0) {
log_error_errno(r, "Failed to set up API bus: %m");
return 0;
}
m->api_bus = bus;
bus = NULL;
return 0;
}
static int bus_setup_system(Manager *m, sd_bus *bus) {
int r;
assert(m);
assert(bus);
/* On kdbus or if we are a user instance we get the Released message via the system bus */
if (m->running_as == MANAGER_USER || m->kdbus_fd >= 0) {
r = sd_bus_add_match(
bus,
NULL,
"type='signal',"
"interface='org.freedesktop.systemd1.Agent',"
"member='Released',"
"path='/org/freedesktop/systemd1/agent'",
signal_agent_released, m);
if (r < 0)
log_warning_errno(r, "Failed to register Released match on system bus: %m");
}
log_debug("Successfully connected to system bus.");
return 0;
}
static int bus_init_system(Manager *m) {
_cleanup_bus_unref_ sd_bus *bus = NULL;
int r;
if (m->system_bus)
return 0;
/* The API and system bus is the same if we are running in system mode */
if (m->running_as == MANAGER_SYSTEM && m->api_bus) {
m->system_bus = sd_bus_ref(m->api_bus);
return 0;
}
r = sd_bus_open_system(&bus);
if (r < 0) {
log_debug("Failed to connect to system bus, retrying later...");
return 0;
}
r = bus_setup_disconnected_match(m, bus);
if (r < 0)
return 0;
r = sd_bus_attach_event(bus, m->event, SD_EVENT_PRIORITY_NORMAL);
if (r < 0) {
log_error_errno(r, "Failed to attach system bus to event loop: %m");
return 0;
}
r = bus_setup_system(m, bus);
if (r < 0) {
log_error_errno(r, "Failed to set up system bus: %m");
return 0;
}
m->system_bus = bus;
bus = NULL;
return 0;
}
static int bus_init_private(Manager *m) {
_cleanup_close_ int fd = -1;
union sockaddr_union sa = {
.un.sun_family = AF_UNIX
};
sd_event_source *s;
socklen_t salen;
int r;
assert(m);
if (m->private_listen_fd >= 0)
return 0;
/* We don't need the private socket if we have kdbus */
if (m->kdbus_fd >= 0)
return 0;
if (m->running_as == MANAGER_SYSTEM) {
/* We want the private bus only when running as init */
if (getpid() != 1)
return 0;
strcpy(sa.un.sun_path, "/run/systemd/private");
salen = offsetof(union sockaddr_union, un.sun_path) + strlen("/run/systemd/private");
} else {
size_t left = sizeof(sa.un.sun_path);
char *p = sa.un.sun_path;
const char *e;
e = secure_getenv("XDG_RUNTIME_DIR");
if (!e) {
log_error("Failed to determine XDG_RUNTIME_DIR");
return -EHOSTDOWN;
}
left = strpcpy(&p, left, e);
left = strpcpy(&p, left, "/systemd/private");
salen = sizeof(sa.un) - left;
}
(void) mkdir_parents_label(sa.un.sun_path, 0755);
(void) unlink(sa.un.sun_path);
fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
if (fd < 0)
return log_error_errno(errno, "Failed to allocate private socket: %m");
r = bind(fd, &sa.sa, salen);
if (r < 0)
return log_error_errno(errno, "Failed to bind private socket: %m");
r = listen(fd, SOMAXCONN);
if (r < 0)
return log_error_errno(errno, "Failed to make private socket listening: %m");
r = sd_event_add_io(m->event, &s, fd, EPOLLIN, bus_on_connection, m);
if (r < 0)
return log_error_errno(r, "Failed to allocate event source: %m");
(void) sd_event_source_set_description(s, "bus-connection");
m->private_listen_fd = fd;
m->private_listen_event_source = s;
fd = -1;
log_debug("Successfully created private D-Bus server.");
return 0;
}
int bus_init(Manager *m, bool try_bus_connect) {
int r;
if (try_bus_connect) {
r = bus_init_system(m);
if (r < 0)
return r;
r = bus_init_api(m);
if (r < 0)
return r;
}
r = bus_init_private(m);
if (r < 0)
return r;
return 0;
}
static void destroy_bus(Manager *m, sd_bus **bus) {
Iterator i;
Job *j;
assert(m);
assert(bus);
if (!*bus)
return;
/* Get rid of tracked clients on this bus */
if (m->subscribed && sd_bus_track_get_bus(m->subscribed) == *bus)
m->subscribed = sd_bus_track_unref(m->subscribed);
HASHMAP_FOREACH(j, m->jobs, i)
if (j->clients && sd_bus_track_get_bus(j->clients) == *bus)
j->clients = sd_bus_track_unref(j->clients);
/* Get rid of queued message on this bus */
if (m->queued_message && sd_bus_message_get_bus(m->queued_message) == *bus)
m->queued_message = sd_bus_message_unref(m->queued_message);
/* Possibly flush unwritten data, but only if we are
* unprivileged, since we don't want to sync here */
if (m->running_as != MANAGER_SYSTEM)
sd_bus_flush(*bus);
/* And destroy the object */
sd_bus_close(*bus);
*bus = sd_bus_unref(*bus);
}
void bus_done(Manager *m) {
sd_bus *b;
assert(m);
if (m->api_bus)
destroy_bus(m, &m->api_bus);
if (m->system_bus)
destroy_bus(m, &m->system_bus);
while ((b = set_steal_first(m->private_buses)))
destroy_bus(m, &b);
set_free(m->private_buses);
m->private_buses = NULL;
m->subscribed = sd_bus_track_unref(m->subscribed);
strv_free(m->deserialized_subscribed);
m->deserialized_subscribed = NULL;
if (m->private_listen_event_source)
m->private_listen_event_source = sd_event_source_unref(m->private_listen_event_source);
m->private_listen_fd = safe_close(m->private_listen_fd);
bus_verify_polkit_async_registry_free(m->polkit_registry);
}
int bus_fdset_add_all(Manager *m, FDSet *fds) {
Iterator i;
sd_bus *b;
int fd;
assert(m);
assert(fds);
/* When we are about to reexecute we add all D-Bus fds to the
* set to pass over to the newly executed systemd. They won't
* be used there however, except thatt they are closed at the
* very end of deserialization, those making it possible for
* clients to synchronously wait for systemd to reexec by
* simply waiting for disconnection */
if (m->api_bus) {
fd = sd_bus_get_fd(m->api_bus);
if (fd >= 0) {
fd = fdset_put_dup(fds, fd);
if (fd < 0)
return fd;
}
}
SET_FOREACH(b, m->private_buses, i) {
fd = sd_bus_get_fd(b);
if (fd >= 0) {
fd = fdset_put_dup(fds, fd);
if (fd < 0)
return fd;
}
}
/* We don't offer any APIs on the system bus (well, unless it
* is the same as the API bus) hence we don't bother with it
* here */
return 0;
}
int bus_foreach_bus(
Manager *m,
sd_bus_track *subscribed2,
int (*send_message)(sd_bus *bus, void *userdata),
void *userdata) {
Iterator i;
sd_bus *b;
int r, ret = 0;
/* Send to all direct buses, unconditionally */
SET_FOREACH(b, m->private_buses, i) {
r = send_message(b, userdata);
if (r < 0)
ret = r;
}
/* Send to API bus, but only if somebody is subscribed */
if (sd_bus_track_count(m->subscribed) > 0 ||
sd_bus_track_count(subscribed2) > 0) {
r = send_message(m->api_bus, userdata);
if (r < 0)
ret = r;
}
return ret;
}
void bus_track_serialize(sd_bus_track *t, FILE *f) {
const char *n;
assert(f);
for (n = sd_bus_track_first(t); n; n = sd_bus_track_next(t))
fprintf(f, "subscribed=%s\n", n);
}
int bus_track_deserialize_item(char ***l, const char *line) {
const char *e;
int r;
assert(l);
assert(line);
e = startswith(line, "subscribed=");
if (!e)
return 0;
r = strv_extend(l, e);
if (r < 0)
return r;
return 1;
}
int bus_track_coldplug(Manager *m, sd_bus_track **t, char ***l) {
int r = 0;
assert(m);
assert(t);
assert(l);
if (!strv_isempty(*l) && m->api_bus) {
char **i;
if (!*t) {
r = sd_bus_track_new(m->api_bus, t, NULL, NULL);
if (r < 0)
return r;
}
r = 0;
STRV_FOREACH(i, *l) {
int k;
k = sd_bus_track_add_name(*t, *i);
if (k < 0)
r = k;
}
}
strv_free(*l);
*l = NULL;
return r;
}
int bus_verify_manage_units_async(Manager *m, sd_bus_message *call, sd_bus_error *error) {
return bus_verify_polkit_async(call, CAP_SYS_ADMIN, "org.freedesktop.systemd1.manage-units", false, UID_INVALID, &m->polkit_registry, error);
}
/* Same as bus_verify_manage_unit_async(), but checks for CAP_KILL instead of CAP_SYS_ADMIN */
int bus_verify_manage_units_async_for_kill(Manager *m, sd_bus_message *call, sd_bus_error *error) {
return bus_verify_polkit_async(call, CAP_KILL, "org.freedesktop.systemd1.manage-units", false, UID_INVALID, &m->polkit_registry, error);
}
int bus_verify_manage_unit_files_async(Manager *m, sd_bus_message *call, sd_bus_error *error) {
return bus_verify_polkit_async(call, CAP_SYS_ADMIN, "org.freedesktop.systemd1.manage-unit-files", false, UID_INVALID, &m->polkit_registry, error);
}
int bus_verify_reload_daemon_async(Manager *m, sd_bus_message *call, sd_bus_error *error) {
return bus_verify_polkit_async(call, CAP_SYS_ADMIN, "org.freedesktop.systemd1.reload-daemon", false, UID_INVALID, &m->polkit_registry, error);
}
int bus_verify_set_environment_async(Manager *m, sd_bus_message *call, sd_bus_error *error) {
return bus_verify_polkit_async(call, CAP_SYS_ADMIN, "org.freedesktop.systemd1.set-environment", false, UID_INVALID, &m->polkit_registry, error);
}