bus-control.c revision 3c42e8b281b092b4d10f24c80e21d69b0f232b96
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
d710d36375bacbf9cfb8903107bedf2c0aada84eMichal Schmidt This file is part of systemd.
fff87a35d9e26c0d4ea41273a963c0eb20e18da4Zbigniew Jędrzejewski-Szmek Copyright 2013 Lennart Poettering
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt systemd is free software; you can redistribute it and/or modify it
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt under the terms of the GNU Lesser General Public License as published by
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt the Free Software Foundation; either version 2.1 of the License, or
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier (at your option) any later version.
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt systemd is distributed in the hope that it will be useful, but
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt WITHOUT ANY WARRANTY; without even the implied warranty of
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41a5ef639b248aa3d10609d9af5d0043b909d93cHarald Hoyer Lesser General Public License for more details.
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt You should have received a copy of the GNU Lesser General Public License
41a5ef639b248aa3d10609d9af5d0043b909d93cHarald Hoyer along with systemd; If not, see <http://www.gnu.org/licenses/>.
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt_public_ int sd_bus_get_unique_name(sd_bus *bus, const char **unique) {
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt assert_return(!bus_pid_changed(bus), -ECHILD);
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidtstatic int bus_request_name_kernel(sd_bus *bus, const char *name, uint64_t flags) {
d710d36375bacbf9cfb8903107bedf2c0aada84eMichal Schmidt size = offsetof(struct kdbus_cmd, items) + KDBUS_ITEM_SIZE(l);
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt n->flags = request_name_flags_to_kdbus(flags);
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt n->items[0].size = KDBUS_ITEM_HEADER_SIZE + l;
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt r = ioctl(bus->input_fd, KDBUS_CMD_NAME_ACQUIRE, n);
r = sd_bus_call_method(
bus,
"/org/freedesktop/DBus",
NULL,
&reply,
name,
param);
return -EALREADY;
return -EEXIST;
return -EIO;
assert_return(!(flags & ~(SD_BUS_NAME_ALLOW_REPLACEMENT|SD_BUS_NAME_REPLACE_EXISTING|SD_BUS_NAME_QUEUE)), -EINVAL);
return -EINVAL;
return -EINVAL;
return -ENOTCONN;
struct kdbus_cmd *n;
#ifdef HAVE_VALGRIND_MEMCHECK_H
return -errno;
r = sd_bus_call_method(
bus,
"/org/freedesktop/DBus",
NULL,
&reply,
name);
return -ESRCH;
return -EADDRINUSE;
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -ENOTCONN;
return -errno;
r = -ENOMEM;
goto fail;
r = strv_consume(x, n);
goto fail;
r = -ENOMEM;
goto fail;
fail:
if (acquired) {
if (activatable) {
*activatable = y;
y = NULL;
if (acquired) {
*acquired = x;
x = NULL;
if (acquired) {
r = sd_bus_call_method(
bus,
"/org/freedesktop/DBus",
NULL,
&reply,
NULL);
if (activatable) {
r = sd_bus_call_method(
bus,
"/org/freedesktop/DBus",
NULL,
&reply,
NULL);
*activatable = y;
y = NULL;
if (acquired) {
*acquired = x;
x = NULL;
return -EINVAL;
return -ENOTCONN;
static int bus_populate_creds_from_items(
sd_bus_creds *c) {
uint64_t m;
assert(c);
case KDBUS_ITEM_PIDS:
c->ppid = 0;
case KDBUS_ITEM_CREDS:
case KDBUS_ITEM_PID_COMM:
case KDBUS_ITEM_TID_COMM:
case KDBUS_ITEM_EXE:
case KDBUS_ITEM_CMDLINE:
if (!c->cmdline)
return -ENOMEM;
case KDBUS_ITEM_CGROUP:
c->mask |= m;
case KDBUS_ITEM_CAPS:
item->size - offsetof(struct kdbus_item, caps.caps) < DIV_ROUND_UP(item->caps.last_cap, 32U) * 4 * 4)
return -EBADMSG;
if (!c->capability)
return -ENOMEM;
c->mask |= m;
case KDBUS_ITEM_SECLABEL:
case KDBUS_ITEM_AUDIT:
case KDBUS_ITEM_OWNED_NAME:
case KDBUS_ITEM_AUXGROUPS:
size_t i, n;
uid_t *g;
return -ENOMEM;
c->supplementary_gids = g;
c->n_supplementary_gids = n;
const char *name,
bool allow_activator,
return -EOPNOTSUPP;
SD_BUS_CREDS_CGROUP|SD_BUS_CREDS_UNIT|SD_BUS_CREDS_USER_UNIT|SD_BUS_CREDS_SLICE|SD_BUS_CREDS_SESSION|SD_BUS_CREDS_OWNER_UID|
SD_BUS_CREDS_EFFECTIVE_CAPS|SD_BUS_CREDS_PERMITTED_CAPS|SD_BUS_CREDS_INHERITABLE_CAPS|SD_BUS_CREDS_BOUNDING_CAPS|
return -errno;
r = -ENXIO;
r = -ESRCH;
goto fail;
c = bus_creds_new();
r = -ENOMEM;
goto fail;
r = -ENOMEM;
goto fail;
goto fail;
goto fail;
if (creds) {
*creds = c;
c = NULL;
fail:
static int bus_get_name_creds_dbus1(
const char *name,
r = sd_bus_call_method(
bus,
"/org/freedesktop/DBus",
NULL,
name);
if (mask != 0) {
c = bus_creds_new();
return -ENOMEM;
if (!c->unique_name)
return -ENOMEM;
SD_BUS_CREDS_CGROUP|SD_BUS_CREDS_UNIT|SD_BUS_CREDS_USER_UNIT|SD_BUS_CREDS_SLICE|SD_BUS_CREDS_SESSION|SD_BUS_CREDS_OWNER_UID|
SD_BUS_CREDS_EFFECTIVE_CAPS|SD_BUS_CREDS_PERMITTED_CAPS|SD_BUS_CREDS_INHERITABLE_CAPS|SD_BUS_CREDS_BOUNDING_CAPS|
uint32_t u;
r = sd_bus_call_method(
bus,
"/org/freedesktop/DBus",
NULL,
&reply,
pid = u;
c->pid = u;
uint32_t u;
r = sd_bus_call_method(
bus,
"/org/freedesktop/DBus",
NULL,
&reply,
c->euid = u;
const void *p = NULL;
r = sd_bus_call_method(
bus,
"/org/freedesktop/DBus",
&error,
&reply,
if (!c->label)
return -ENOMEM;
if (creds) {
*creds = c;
c = NULL;
const char *name,
return -EINVAL;
return -EINVAL;
return -ENOTCONN;
c = bus_creds_new();
return -ENOMEM;
SD_BUS_CREDS_CGROUP|SD_BUS_CREDS_UNIT|SD_BUS_CREDS_USER_UNIT|SD_BUS_CREDS_SLICE|SD_BUS_CREDS_SESSION|SD_BUS_CREDS_OWNER_UID|
SD_BUS_CREDS_EFFECTIVE_CAPS|SD_BUS_CREDS_PERMITTED_CAPS|SD_BUS_CREDS_INHERITABLE_CAPS|SD_BUS_CREDS_BOUNDING_CAPS|
return -errno;
*ret = c;
c = NULL;
return -ENODATA;
c = bus_creds_new();
return -ENOMEM;
if (!c->label)
return -ENOMEM;
*ret = c;
c = NULL;
return -ENOTCONN;
const char *name,
const char *old_owner,
const char *new_owner) {
if (name) {
if (is_name_id < 0)
if (is_name_id <= 0) {
struct kdbus_cmd_match *m;
if (name)
return -errno;
return -errno;
return -errno;
if (is_name_id != 0) {
struct kdbus_cmd_match *m;
sizeof(struct kdbus_notify_id_change));
sizeof(struct kdbus_notify_id_change);
return -errno;
return -errno;
unsigned n_components,
struct kdbus_cmd_match *m;
bool using_bloom = false;
bool matches_name_change = true;
for (i = 0; i < n_components; i++) {
switch (c->type) {
case BUS_MATCH_SENDER:
matches_name_change = false;
case BUS_MATCH_MESSAGE_TYPE:
matches_name_change = false;
bloom_add_pair(bloom, bus->bloom_size, bus->bloom_n_hash, "message-type", bus_message_type_to_string(c->value_u8));
using_bloom = true;
case BUS_MATCH_INTERFACE:
matches_name_change = false;
using_bloom = true;
case BUS_MATCH_MEMBER:
matches_name_change = false;
using_bloom = true;
case BUS_MATCH_PATH:
matches_name_change = false;
using_bloom = true;
case BUS_MATCH_PATH_NAMESPACE:
using_bloom = true;
using_bloom = true;
using_bloom = true;
using_bloom = true;
case BUS_MATCH_DESTINATION:
case BUS_MATCH_ROOT:
case BUS_MATCH_VALUE:
case BUS_MATCH_LEAF:
case _BUS_MATCH_NODE_TYPE_MAX:
if (using_bloom)
if (using_bloom) {
if (sender) {
return -errno;
if (matches_name_change) {
static int bus_add_match_internal_dbus1(
const char *match) {
return sd_bus_call_method(
bus,
"/org/freedesktop/DBus",
NULL,
NULL,
const char *match,
unsigned n_components,
return -EINVAL;
struct kdbus_cmd_match m = {
return -errno;
static int bus_remove_match_internal_dbus1(
const char *match) {
return sd_bus_call_method(
bus,
"/org/freedesktop/DBus",
NULL,
NULL,
const char *match,
return -EINVAL;
const char *mid;
return -EINVAL;
return -ENOTCONN;
bus,
name,
r = sd_bus_message_set_auto_start(m, false);