chiark / gitweb /
bus: include connection name in credentials structure
authorLennart Poettering <lennart@poettering.net>
Wed, 22 Jan 2014 15:28:58 +0000 (16:28 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 22 Jan 2014 15:40:40 +0000 (16:40 +0100)
src/libsystemd/libsystemd.sym
src/libsystemd/sd-bus/bus-control.c
src/libsystemd/sd-bus/bus-creds.c
src/libsystemd/sd-bus/bus-creds.h
src/libsystemd/sd-bus/bus-dump.c
src/libsystemd/sd-bus/bus-kernel.c
src/systemd/sd-bus.h

index 0942a6e..0337e4e 100644 (file)
@@ -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;
index e7e9ba0..5548239 100644 (file)
@@ -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;
                 }
         }
 
index 52e55fc..85509e8 100644 (file)
@@ -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;
 
index d8b4aca..df33d34 100644 (file)
@@ -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);
index d2c0684..f1d00a9 100644 (file)
@@ -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) {
index 833ea55..95efbbe 100644 (file)
@@ -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;
 }
index baffd53..9992888 100644 (file)
@@ -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 */