diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-01-22 16:28:58 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-01-22 16:40:40 +0100 |
commit | cccb0b2cdbd25e90ae92d2d5b107125cb1ca3433 (patch) | |
tree | f004ea3e54e6022bfd625b0cbdb4eb97a2a495c0 | |
parent | 8d1db1d154c1134c9bf92b202ef198cc79979ea8 (diff) |
bus: include connection name in credentials structure
-rw-r--r-- | src/libsystemd/libsystemd.sym | 1 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/bus-control.c | 15 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/bus-creds.c | 13 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/bus-creds.h | 2 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/bus-dump.c | 4 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/bus-kernel.c | 8 | ||||
-rw-r--r-- | src/systemd/sd-bus.h | 4 |
7 files changed, 44 insertions, 3 deletions
diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym index 0942a6e93e..0337e4eb0c 100644 --- a/src/libsystemd/libsystemd.sym +++ b/src/libsystemd/libsystemd.sym @@ -187,6 +187,7 @@ global: sd_bus_creds_get_audit_login_uid; sd_bus_creds_get_unique_name; sd_bus_creds_get_well_known_names; + sd_bus_creds_get_connection_name; /* Error structures */ sd_bus_error_free; diff --git a/src/libsystemd/sd-bus/bus-control.c b/src/libsystemd/sd-bus/bus-control.c index e7e9ba07b0..5548239426 100644 --- a/src/libsystemd/sd-bus/bus-control.c +++ b/src/libsystemd/sd-bus/bus-control.c @@ -379,9 +379,10 @@ static int bus_get_owner_kdbus( cmd = alloca0(size); strcpy(cmd->name, name); } - cmd->flags = KDBUS_ATTACH_NAMES; 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; @@ -553,6 +554,18 @@ static int bus_get_owner_kdbus( c->mask |= SD_BUS_CREDS_WELL_KNOWN_NAMES; } break; + + 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; + } + + c->mask |= SD_BUS_CREDS_CONNECTION_NAME; + } + break; } } diff --git a/src/libsystemd/sd-bus/bus-creds.c b/src/libsystemd/sd-bus/bus-creds.c index 52e55fc5e1..85509e8819 100644 --- a/src/libsystemd/sd-bus/bus-creds.c +++ b/src/libsystemd/sd-bus/bus-creds.c @@ -92,6 +92,7 @@ _public_ sd_bus_creds *sd_bus_creds_unref(sd_bus_creds *c) { free(c->label); free(c->unique_name); free(c->cgroup_root); + free(c->conn_name); free(c); } } else { @@ -462,6 +463,18 @@ _public_ int sd_bus_creds_get_well_known_names(sd_bus_creds *c, char ***well_kno return 0; } +_public_ int sd_bus_creds_get_connection_name(sd_bus_creds *c, const char **ret) { + assert_return(c, -EINVAL); + assert_return(ret, -EINVAL); + + if (!(c->mask & SD_BUS_CREDS_CONNECTION_NAME)) + return -ENODATA; + + assert(c->conn_name); + *ret = c->conn_name; + return 0; +} + static int has_cap(sd_bus_creds *c, unsigned offset, int capability) { size_t sz; diff --git a/src/libsystemd/sd-bus/bus-creds.h b/src/libsystemd/sd-bus/bus-creds.h index d8b4aca2a0..df33d34b65 100644 --- a/src/libsystemd/sd-bus/bus-creds.h +++ b/src/libsystemd/sd-bus/bus-creds.h @@ -64,6 +64,8 @@ struct sd_bus_creds { char **well_known_names; char *cgroup_root; + + char *conn_name; }; sd_bus_creds* bus_creds_new(void); diff --git a/src/libsystemd/sd-bus/bus-dump.c b/src/libsystemd/sd-bus/bus-dump.c index d2c0684448..f1d00a952b 100644 --- a/src/libsystemd/sd-bus/bus-dump.c +++ b/src/libsystemd/sd-bus/bus-dump.c @@ -342,8 +342,10 @@ int bus_creds_dump(sd_bus_creds *c, FILE *f) { fprintf(f, " TIDComm=%s", c->tid_comm); if (c->mask & SD_BUS_CREDS_SELINUX_CONTEXT) fprintf(f, " Label=%s", c->label); + if (c->mask & SD_BUS_CREDS_CONNECTION_NAME) + fprintf(f, " ConnectionName=%s", c->conn_name); - if (c->mask & (SD_BUS_CREDS_EXE|SD_BUS_CREDS_COMM|SD_BUS_CREDS_TID_COMM|SD_BUS_CREDS_SELINUX_CONTEXT)) + if (c->mask & (SD_BUS_CREDS_EXE|SD_BUS_CREDS_COMM|SD_BUS_CREDS_TID_COMM|SD_BUS_CREDS_SELINUX_CONTEXT|SD_BUS_CREDS_CONNECTION_NAME)) fputs("\n", f); if (sd_bus_creds_get_cmdline(c, &cmdline) >= 0) { diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c index 833ea5574d..95efbbeeb8 100644 --- a/src/libsystemd/sd-bus/bus-kernel.c +++ b/src/libsystemd/sd-bus/bus-kernel.c @@ -568,6 +568,11 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) { goto fail; break; + case KDBUS_ITEM_CONN_NAME: + m->creds.conn_name = d->str; + m->creds.mask |= SD_BUS_CREDS_CONNECTION_NAME & bus->creds_mask; + break; + case KDBUS_ITEM_FDS: case KDBUS_ITEM_SECLABEL: break; @@ -1240,6 +1245,9 @@ int kdbus_translate_attach_flags(uint64_t mask, uint64_t *kdbus_mask) { if (mask & SD_BUS_CREDS_WELL_KNOWN_NAMES) m |= KDBUS_ATTACH_NAMES; + if (mask & SD_BUS_CREDS_CONNECTION_NAME) + m |= KDBUS_ATTACH_CONN_NAME; + *kdbus_mask = m; return 0; } diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h index baffd5330e..99928882f2 100644 --- a/src/systemd/sd-bus.h +++ b/src/systemd/sd-bus.h @@ -72,7 +72,8 @@ enum { SD_BUS_CREDS_AUDIT_LOGIN_UID = 1ULL << 21, SD_BUS_CREDS_UNIQUE_NAME = 1ULL << 22, SD_BUS_CREDS_WELL_KNOWN_NAMES = 1ULL << 23, - _SD_BUS_CREDS_ALL = (1ULL << 24) -1, + SD_BUS_CREDS_CONNECTION_NAME = 1ULL << 24, + _SD_BUS_CREDS_ALL = (1ULL << 25) -1, }; enum { @@ -309,6 +310,7 @@ int sd_bus_creds_get_audit_session_id(sd_bus_creds *c, uint32_t *sessionid); int sd_bus_creds_get_audit_login_uid(sd_bus_creds *c, uid_t *loginuid); int sd_bus_creds_get_unique_name(sd_bus_creds *c, const char **name); int sd_bus_creds_get_well_known_names(sd_bus_creds *c, char ***names); +int sd_bus_creds_get_connection_name(sd_bus_creds *c, const char **name); /* Error structures */ |