]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bus: prefix custom endpoints with "$UID-"
authorDavid Herrmann <dh.herrmann@gmail.com>
Thu, 27 Nov 2014 12:49:41 +0000 (13:49 +0100)
committerDavid Herrmann <dh.herrmann@gmail.com>
Thu, 27 Nov 2014 12:49:41 +0000 (13:49 +0100)
The kdbus module will later get a policy that endpoint-names are
restricted to "<uid>-<name>" just like bus-names. Make sure that systemd
is already compatible to that.

src/libsystemd/sd-bus/bus-kernel.c

index 2beaa892bca66de40c370af3cf9044a590c4a092..651ca4726e07f13b03f33f4a722326df1c467efc 100644 (file)
@@ -1534,25 +1534,25 @@ int bus_kernel_create_endpoint(const char *bus_name, const char *ep_name, char *
         _cleanup_free_ char *path = NULL;
         struct kdbus_cmd_make *make;
         struct kdbus_item *n;
-        size_t size;
+        const char *name;
         int fd;
 
         fd = bus_kernel_open_bus_fd(bus_name, &path);
         if (fd < 0)
                 return fd;
 
-        size = ALIGN8(offsetof(struct kdbus_cmd_make, items));
-        size += ALIGN8(offsetof(struct kdbus_item, str) + strlen(ep_name) + 1);
-
-        make = alloca0_align(size, 8);
-        make->size = size;
+        make = alloca0_align(ALIGN8(offsetof(struct kdbus_cmd_make, items)) +
+                             ALIGN8(offsetof(struct kdbus_item, str) + DECIMAL_STR_MAX(uid_t) + 1 + strlen(ep_name) + 1),
+                             8);
+        make->size = ALIGN8(offsetof(struct kdbus_cmd_make, items));
         make->flags = KDBUS_MAKE_ACCESS_WORLD;
 
         n = make->items;
-
+        sprintf(n->str, UID_FMT "-%s", getuid(), ep_name);
+        n->size = offsetof(struct kdbus_item, str) + strlen(n->str) + 1;
         n->type = KDBUS_ITEM_MAKE_NAME;
-        n->size = offsetof(struct kdbus_item, str) + strlen(ep_name) + 1;
-        strcpy(n->str, ep_name);
+        make->size += ALIGN8(n->size);
+        name = n->str;
 
         if (ioctl(fd, KDBUS_CMD_ENDPOINT_MAKE, make) < 0) {
                 safe_close(fd);
@@ -1562,7 +1562,7 @@ int bus_kernel_create_endpoint(const char *bus_name, const char *ep_name, char *
         if (ep_path) {
                 char *p;
 
-                p = strjoin(dirname(path), "/", ep_name, NULL);
+                p = strjoin(dirname(path), "/", name, NULL);
                 if (!p) {
                         safe_close(fd);
                         return -ENOMEM;