chiark / gitweb /
sd-bus: by default allow all creds to be passed along
[elogind.git] / src / libsystemd / sd-bus / bus-kernel.c
index 136c90fc6304a6597ed17407a87511d328a0c9d5..153abee56f3bbfebd1235e3a334181d033a1a674 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "util.h"
 #include "strv.h"
+#include "memfd-util.h"
 
 #include "bus-internal.h"
 #include "bus-message.h"
@@ -275,12 +276,7 @@ static int bus_message_setup_kmsg(sd_bus *b, sd_bus_message *m) {
         } else {
                 struct timespec now;
 
-                r = clock_gettime(CLOCK_MONOTONIC_COARSE, &now);
-                if (r < 0) {
-                        r = -errno;
-                        goto fail;
-                }
-
+                assert_se(clock_gettime(CLOCK_MONOTONIC_COARSE, &now) == 0);
                 m->kdbus->timeout_ns = now.tv_sec * NSEC_PER_SEC + now.tv_nsec +
                                        m->timeout * NSEC_PER_USEC;
         }
@@ -580,8 +576,8 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
                         break;
 
                 case KDBUS_ITEM_CAPS:
-                        m->creds.capability = d->data;
-                        m->creds.capability_size = l;
+                        m->creds.capability = (uint8_t *) d->caps.caps;
+                        m->creds.capability_size = d->size - offsetof(struct kdbus_item, caps.caps);
                         m->creds.mask |= (SD_BUS_CREDS_EFFECTIVE_CAPS|SD_BUS_CREDS_PERMITTED_CAPS|SD_BUS_CREDS_INHERITABLE_CAPS|SD_BUS_CREDS_BOUNDING_CAPS) & bus->creds_mask;
                         break;
 
@@ -592,7 +588,7 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
                         destination = d->str;
                         break;
 
-                case KDBUS_ITEM_NAME:
+                case KDBUS_ITEM_OWNED_NAME:
                         if (!service_name_is_valid(d->name.name))
                                 return -EBADMSG;
 
@@ -601,9 +597,9 @@ 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;
+                case KDBUS_ITEM_CONN_DESCRIPTION:
+                        m->creds.description = d->str;
+                        m->creds.mask |= SD_BUS_CREDS_DESCRIPTION & bus->creds_mask;
                         break;
 
                 case KDBUS_ITEM_FDS:
@@ -670,8 +666,8 @@ int bus_kernel_take_fd(sd_bus *b) {
 
         b->use_memfd = 1;
 
-        if (b->connection_name) {
-                g = bus_label_escape(b->connection_name);
+        if (b->description) {
+                g = bus_label_escape(b->description);
                 if (!g)
                         return -ENOMEM;
 
@@ -704,8 +700,8 @@ int bus_kernel_take_fd(sd_bus *b) {
                         name = g;
                 }
 
-                b->connection_name = bus_label_unescape(name);
-                if (!b->connection_name)
+                b->description = bus_label_unescape(name);
+                if (!b->description)
                         return -ENOMEM;
         }
 
@@ -725,13 +721,14 @@ int bus_kernel_take_fd(sd_bus *b) {
         hello = alloca0_align(sz, 8);
         hello->size = sz;
         hello->flags = b->hello_flags;
-        hello->attach_flags = b->attach_flags;
+        hello->attach_flags_send = _KDBUS_ATTACH_ANY;
+        hello->attach_flags_recv = b->attach_flags;
         hello->pool_size = KDBUS_POOL_SIZE;
 
         item = hello->items;
 
         item->size = offsetof(struct kdbus_item, str) + m + 1;
-        item->type = KDBUS_ITEM_CONN_NAME;
+        item->type = KDBUS_ITEM_CONN_DESCRIPTION;
         memcpy(item->str, name, m + 1);
         item = KDBUS_ITEM_NEXT(item);
 
@@ -1123,20 +1120,13 @@ int bus_kernel_pop_memfd(sd_bus *bus, void **address, size_t *mapped, size_t *al
         assert_se(pthread_mutex_lock(&bus->memfd_cache_mutex) >= 0);
 
         if (bus->n_memfd_cache <= 0) {
-                _cleanup_free_ char *g = NULL;
                 int r;
 
                 assert_se(pthread_mutex_unlock(&bus->memfd_cache_mutex) >= 0);
 
-                assert(bus->connection_name);
-
-                g = bus_label_escape(bus->connection_name);
-                if (!g)
-                        return -ENOMEM;
-
-                r = memfd_create(g, MFD_ALLOW_SEALING);
+                r = memfd_new(bus->description);
                 if (r < 0)
-                        return -errno;
+                        return r;
 
                 *address = NULL;
                 *mapped = 0;
@@ -1193,7 +1183,7 @@ void bus_kernel_push_memfd(sd_bus *bus, int fd, void *address, size_t mapped, si
 
         /* If overly long, let's return a bit to the OS */
         if (mapped > max_mapped) {
-                assert_se(ftruncate(fd, max_mapped) >= 0);
+                assert_se(memfd_set_size(fd, max_mapped) >= 0);
                 assert_se(munmap((uint8_t*) address + max_mapped, PAGE_ALIGN(mapped - max_mapped)) >= 0);
                 c->mapped = c->allocated = max_mapped;
         } else {
@@ -1266,8 +1256,8 @@ 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;
+        if (mask & SD_BUS_CREDS_DESCRIPTION)
+                m |= KDBUS_ATTACH_CONN_DESCRIPTION;
 
         *kdbus_mask = m;
         return 0;
@@ -1567,7 +1557,8 @@ int bus_kernel_make_starter(
                 (activating ? KDBUS_HELLO_ACTIVATOR : KDBUS_HELLO_POLICY_HOLDER) |
                 (accept_fd ? KDBUS_HELLO_ACCEPT_FD : 0);
         hello->pool_size = KDBUS_POOL_SIZE;
-        hello->attach_flags = _KDBUS_ATTACH_ALL;
+        hello->attach_flags_send = _KDBUS_ATTACH_ANY;
+        hello->attach_flags_recv = _KDBUS_ATTACH_ALL;
 
         if (ioctl(fd, KDBUS_CMD_HELLO, hello) < 0)
                 return -errno;