+ KDBUS_PART_FOREACH(item, name_info, items) {
+
+ switch (item->type) {
+
+ case KDBUS_ITEM_CREDS:
+ m = (SD_BUS_CREDS_UID | SD_BUS_CREDS_GID | SD_BUS_CREDS_PID |
+ SD_BUS_CREDS_TID | SD_BUS_CREDS_PID_STARTTIME) & mask;
+
+ if (m) {
+ c->uid = item->creds.uid;
+ c->pid = item->creds.pid;
+ c->gid = item->creds.gid;
+ c->tid = item->creds.tid;
+ c->pid_starttime = item->creds.starttime;
+ c->mask |= m;
+ }
+ break;
+
+ case KDBUS_ITEM_PID_COMM:
+ if (mask & SD_BUS_CREDS_COMM) {
+ c->comm = strdup(item->str);
+ if (!c->comm) {
+ r = -ENOMEM;
+ goto fail;
+ }
+
+ c->mask |= SD_BUS_CREDS_COMM;
+ }
+ break;
+
+ 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;
+ }
+
+ c->mask |= SD_BUS_CREDS_TID_COMM;
+ }
+ break;
+
+ case KDBUS_ITEM_EXE:
+ if (mask & SD_BUS_CREDS_EXE) {
+ c->exe = strdup(item->str);
+ if (!c->exe) {
+ r = -ENOMEM;
+ goto fail;
+ }
+
+ c->mask |= SD_BUS_CREDS_EXE;
+ }
+ break;
+
+ case KDBUS_ITEM_CMDLINE:
+ if (mask & SD_BUS_CREDS_CMDLINE) {
+ c->cmdline_size = item->size - KDBUS_PART_HEADER_SIZE;
+ c->cmdline = memdup(item->data, c->cmdline_size);
+ if (!c->cmdline) {
+ r = -ENOMEM;
+ goto fail;
+ }
+
+ c->mask |= SD_BUS_CREDS_CMDLINE;
+ }
+ break;
+
+ case KDBUS_ITEM_CGROUP:
+ m = (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) & mask;
+
+ if (m) {
+ c->cgroup = strdup(item->str);
+ if (!c->cgroup) {
+ r = -ENOMEM;
+ goto fail;
+ }
+
+ c->mask |= m;
+ }
+ break;
+
+ case KDBUS_ITEM_CAPS:
+ m = (SD_BUS_CREDS_EFFECTIVE_CAPS | SD_BUS_CREDS_PERMITTED_CAPS |
+ SD_BUS_CREDS_INHERITABLE_CAPS | SD_BUS_CREDS_BOUNDING_CAPS) & mask;
+
+ if (m) {
+ c->capability_size = item->size - KDBUS_PART_HEADER_SIZE;
+ c->capability = memdup(item->data, c->capability_size);
+ if (!c->capability) {
+ r = -ENOMEM;
+ goto fail;
+ }
+
+ c->mask |= m;
+ }
+ break;
+
+ case KDBUS_ITEM_SECLABEL:
+ if (mask & SD_BUS_CREDS_SELINUX_CONTEXT) {
+ c->label = strdup(item->str);
+ if (!c->label) {
+ r = -ENOMEM;
+ goto fail;
+ }
+
+ c->mask |= SD_BUS_CREDS_SELINUX_CONTEXT;
+ }
+ break;
+
+ case KDBUS_ITEM_AUDIT:
+ m = (SD_BUS_CREDS_AUDIT_SESSION_ID | SD_BUS_CREDS_AUDIT_LOGIN_UID) & mask;
+
+ if (m) {
+ c->audit_session_id = item->audit.sessionid;
+ c->audit_login_uid = item->audit.loginuid;
+ c->mask |= m;
+ }
+ break;
+
+ case KDBUS_ITEM_NAMES:
+ if (mask & SD_BUS_CREDS_WELL_KNOWN_NAMES) {
+ c->well_known_names_size = item->size - KDBUS_PART_HEADER_SIZE;
+ c->well_known_names = memdup(item->data, c->well_known_names_size);
+ if (!c->well_known_names) {
+ r = -ENOMEM;
+ goto fail;
+ }
+
+ c->mask |= SD_BUS_CREDS_WELL_KNOWN_NAMES;
+ }
+ break;
+ }
+ }
+
+ if (creds) {
+ *creds = c;
+ c = NULL;
+ }
+
+ r = 0;
+
+fail:
+ ioctl(bus->input_fd, KDBUS_CMD_FREE, &cmd->offset);
+ return r;
+}
+
+_public_ int sd_bus_get_owner(
+ sd_bus *bus,
+ const char *name,
+ uint64_t mask,
+ sd_bus_creds **creds) {
+
+ assert_return(bus, -EINVAL);
+ assert_return(name, -EINVAL);
+ assert_return(mask <= _SD_BUS_CREDS_MAX, -ENOTSUP);
+ assert_return(mask == 0 || creds, -EINVAL);
+ assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
+ assert_return(!bus_pid_changed(bus), -ECHILD);
+
+ if (bus->is_kernel)
+ return bus_get_owner_kdbus(bus, name, mask, creds);
+ else
+ return bus_get_owner_dbus(bus, name, mask, creds);