return bus_list_names_dbus1(bus, acquired, activatable);
}
-static int bus_get_owner_kdbus(
- sd_bus *bus,
- const char *name,
- uint64_t mask,
- sd_bus_creds **creds) {
+static int bus_populate_creds_from_items(sd_bus *bus,
+ struct kdbus_info *info,
+ uint64_t mask,
+ sd_bus_creds *c) {
- _cleanup_bus_creds_unref_ sd_bus_creds *c = NULL;
- struct kdbus_cmd_info *cmd;
- struct kdbus_info *conn_info;
struct kdbus_item *item;
- size_t size, l;
- uint64_t m, id;
+ uint64_t m;
int r;
- r = bus_kernel_parse_unique_name(name, &id);
- if (r < 0)
- return r;
- if (r > 0) {
- size = offsetof(struct kdbus_cmd_info, items);
- cmd = alloca0_align(size, 8);
- cmd->id = id;
- } else {
- l = strlen(name) + 1;
- size = offsetof(struct kdbus_cmd_info, items) + KDBUS_ITEM_SIZE(l);
- cmd = alloca0_align(size, 8);
- cmd->items[0].size = KDBUS_ITEM_HEADER_SIZE + l;
- cmd->items[0].type = KDBUS_ITEM_NAME;
- memcpy(cmd->items[0].str, name, l);
- }
-
- cmd->size = size;
- kdbus_translate_attach_flags(mask, (uint64_t*) &cmd->flags);
-
- r = ioctl(bus->input_fd, KDBUS_CMD_CONN_INFO, cmd);
- if (r < 0)
- return -errno;
-
- conn_info = (struct kdbus_info *) ((uint8_t *) bus->kdbus_buffer + cmd->offset);
-
- /* Non-activated names are considered not available */
- if (conn_info->flags & KDBUS_HELLO_ACTIVATOR) {
- if (name[0] == ':')
- r = -ENXIO;
- else
- r = -ESRCH;
- goto fail;
- }
-
- c = bus_creds_new();
- if (!c) {
- r = -ENOMEM;
- goto fail;
- }
-
- if (mask & SD_BUS_CREDS_UNIQUE_NAME) {
- if (asprintf(&c->unique_name, ":1.%llu", (unsigned long long) conn_info->id) < 0) {
- r = -ENOMEM;
- goto fail;
- }
-
- c->mask |= SD_BUS_CREDS_UNIQUE_NAME;
- }
-
- KDBUS_ITEM_FOREACH(item, conn_info, items) {
+ KDBUS_ITEM_FOREACH(item, info, items) {
switch (item->type) {
case KDBUS_ITEM_PID_COMM:
if (mask & SD_BUS_CREDS_COMM) {
c->comm = strdup(item->str);
- if (!c->comm) {
- r = -ENOMEM;
- goto fail;
- }
+ if (!c->comm)
+ return -ENOMEM;
c->mask |= SD_BUS_CREDS_COMM;
}
case KDBUS_ITEM_TID_COMM:
if (mask & SD_BUS_CREDS_TID_COMM) {
c->tid_comm = strdup(item->str);
- if (!c->tid_comm) {
- r = -ENOMEM;
- goto fail;
- }
+ if (!c->tid_comm)
+ return -ENOMEM;
c->mask |= SD_BUS_CREDS_TID_COMM;
}
case KDBUS_ITEM_EXE:
if (mask & SD_BUS_CREDS_EXE) {
c->exe = strdup(item->str);
- if (!c->exe) {
- r = -ENOMEM;
- goto fail;
- }
+ if (!c->exe)
+ return -ENOMEM;
c->mask |= SD_BUS_CREDS_EXE;
}
if (mask & SD_BUS_CREDS_CMDLINE) {
c->cmdline_size = item->size - KDBUS_ITEM_HEADER_SIZE;
c->cmdline = memdup(item->data, c->cmdline_size);
- if (!c->cmdline) {
- r = -ENOMEM;
- goto fail;
- }
+ if (!c->cmdline)
+ return -ENOMEM;
c->mask |= SD_BUS_CREDS_CMDLINE;
}
if (m) {
c->cgroup = strdup(item->str);
- if (!c->cgroup) {
- r = -ENOMEM;
- goto fail;
- }
+ if (!c->cgroup)
+ return -ENOMEM;
r = bus_get_root_path(bus);
if (r < 0)
- goto fail;
+ return r;
c->cgroup_root = strdup(bus->cgroup_root);
- if (!c->cgroup_root) {
- r = -ENOMEM;
- goto fail;
- }
+ if (!c->cgroup_root)
+ return -ENOMEM;
c->mask |= m;
}
if (m) {
c->capability_size = item->size - KDBUS_ITEM_HEADER_SIZE;
c->capability = memdup(item->data, c->capability_size);
- if (!c->capability) {
- r = -ENOMEM;
- goto fail;
- }
+ if (!c->capability)
+ return -ENOMEM;
c->mask |= m;
}
case KDBUS_ITEM_SECLABEL:
if (mask & SD_BUS_CREDS_SELINUX_CONTEXT) {
c->label = strdup(item->str);
- if (!c->label) {
- r = -ENOMEM;
- goto fail;
- }
+ if (!c->label)
+ return -ENOMEM;
c->mask |= SD_BUS_CREDS_SELINUX_CONTEXT;
}
if ((mask & SD_BUS_CREDS_WELL_KNOWN_NAMES) && service_name_is_valid(item->name.name)) {
r = strv_extend(&c->well_known_names, item->name.name);
if (r < 0)
- goto fail;
+ return r;
c->mask |= SD_BUS_CREDS_WELL_KNOWN_NAMES;
}
case KDBUS_ITEM_CONN_NAME:
if ((mask & SD_BUS_CREDS_CONNECTION_NAME)) {
c->conn_name = strdup(item->str);
- if (!c->conn_name) {
- r = -ENOMEM;
- goto fail;
- }
+ if (!c->conn_name)
+ return -ENOMEM;
c->mask |= SD_BUS_CREDS_CONNECTION_NAME;
}
}
}
+ return 0;
+}
+
+static int bus_get_owner_kdbus(
+ sd_bus *bus,
+ const char *name,
+ uint64_t mask,
+ sd_bus_creds **creds) {
+
+ _cleanup_bus_creds_unref_ sd_bus_creds *c = NULL;
+ struct kdbus_cmd_info *cmd;
+ struct kdbus_info *conn_info;
+ size_t size, l;
+ uint64_t id;
+ int r;
+
+ r = bus_kernel_parse_unique_name(name, &id);
+ if (r < 0)
+ return r;
+ if (r > 0) {
+ size = offsetof(struct kdbus_cmd_info, items);
+ cmd = alloca0_align(size, 8);
+ cmd->id = id;
+ } else {
+ l = strlen(name) + 1;
+ size = offsetof(struct kdbus_cmd_info, items) + KDBUS_ITEM_SIZE(l);
+ cmd = alloca0_align(size, 8);
+ cmd->items[0].size = KDBUS_ITEM_HEADER_SIZE + l;
+ cmd->items[0].type = KDBUS_ITEM_NAME;
+ memcpy(cmd->items[0].str, name, l);
+ }
+
+ cmd->size = size;
+ kdbus_translate_attach_flags(mask, (uint64_t*) &cmd->flags);
+
+ r = ioctl(bus->input_fd, KDBUS_CMD_CONN_INFO, cmd);
+ if (r < 0)
+ return -errno;
+
+ conn_info = (struct kdbus_info *) ((uint8_t *) bus->kdbus_buffer + cmd->offset);
+
+ /* Non-activated names are considered not available */
+ if (conn_info->flags & KDBUS_HELLO_ACTIVATOR) {
+ if (name[0] == ':')
+ r = -ENXIO;
+ else
+ r = -ESRCH;
+ goto fail;
+ }
+
+ c = bus_creds_new();
+ if (!c) {
+ r = -ENOMEM;
+ goto fail;
+ }
+
+ if (mask & SD_BUS_CREDS_UNIQUE_NAME) {
+ if (asprintf(&c->unique_name, ":1.%llu", (unsigned long long) conn_info->id) < 0) {
+ r = -ENOMEM;
+ goto fail;
+ }
+
+ c->mask |= SD_BUS_CREDS_UNIQUE_NAME;
+ }
+
+ r = bus_populate_creds_from_items(bus, conn_info, mask, c);
+ if (r < 0)
+ goto fail;
+
if (creds) {
*creds = c;
c = NULL;