chiark / gitweb /
sd-bus: the attach_mask kernel module parameter is 64bit now, hence initialize it...
[elogind.git] / src / libsystemd / sd-bus / bus-control.c
index 0ebaf85d57b83c8660543ab8e104a61859494e07..e6e905c0e0c694d8e1cebddbf9fb022a2d1d8242 100644 (file)
@@ -62,7 +62,7 @@ static int bus_request_name_kernel(sd_bus *bus, const char *name, uint64_t flags
         size = offsetof(struct kdbus_cmd_name, items) + KDBUS_ITEM_SIZE(l);
         n = alloca0_align(size, 8);
         n->size = size;
-        kdbus_translate_request_name_flags(flags, (uint64_t *) &n->flags);
+        n->flags = request_name_flags_to_kdbus(flags);
 
         n->items[0].size = KDBUS_ITEM_HEADER_SIZE + l;
         n->items[0].type = KDBUS_ITEM_NAME;
@@ -402,6 +402,10 @@ static int bus_populate_creds_from_items(
         uint64_t m;
         int r;
 
+        assert(bus);
+        assert(info);
+        assert(c);
+
         KDBUS_ITEM_FOREACH(item, info, items) {
 
                 switch (item->type) {
@@ -590,18 +594,18 @@ static int bus_populate_creds_from_items(
 
                 case KDBUS_ITEM_AUXGROUPS:
                         if (mask & SD_BUS_CREDS_SUPPLEMENTARY_GIDS) {
-                                size_t i, n;
-                                uid_t *u;
+                                size_t n;
+                                uid_t *g;
 
-                                n = (item->size - offsetof(struct kdbus_item, data64)) / sizeof(uint64_t);
-                                u = new(uid_t, n);
-                                if (!u)
-                                        return -ENOMEM;
+                                assert_cc(sizeof(gid_t) == sizeof(uint32_t));
 
-                                for (i = 0; i < n; i++)
-                                        u[i] = (uid_t) item->data64[i];
+                                n = (item->size - offsetof(struct kdbus_item, data32)) / sizeof(uint32_t);
+                                g = newdup(gid_t, item->data32, n);
+                                if (!g)
+                                        return -ENOMEM;
 
-                                c->supplementary_gids = u;
+                                free(c->supplementary_gids);
+                                c->supplementary_gids = g;
                                 c->n_supplementary_gids = n;
 
                                 c->mask |= SD_BUS_CREDS_SUPPLEMENTARY_GIDS;
@@ -643,7 +647,7 @@ static int bus_get_name_creds_kdbus(
         }
 
         cmd->size = size;
-        kdbus_translate_attach_flags(mask, (uint64_t*) &cmd->flags);
+        cmd->flags = attach_flags_to_kdbus(mask);
 
         /* If augmentation is on, and the bus doesn't didn't allow us
          * to get the bits we want, then ask for the PID/TID so that we
@@ -688,6 +692,13 @@ static int bus_get_name_creds_kdbus(
                 c->mask |= SD_BUS_CREDS_UNIQUE_NAME;
         }
 
+        /* If KDBUS_ITEM_OWNED_NAME is requested then we'll get 0 of
+           them in case the service has no names. This does not mean
+           however that the list of owned names could not be
+           acquired. Hence, let's explicitly clarify that the data is
+           complete. */
+        c->mask |= mask & SD_BUS_CREDS_WELL_KNOWN_NAMES;
+
         r = bus_populate_creds_from_items(bus, conn_info, mask, c);
         if (r < 0)
                 goto fail;
@@ -927,7 +938,7 @@ _public_ int sd_bus_get_owner_creds(sd_bus *bus, uint64_t mask, sd_bus_creds **r
                 struct kdbus_info *creator_info;
 
                 cmd.size = sizeof(cmd);
-                kdbus_translate_attach_flags(mask, (uint64_t*) &cmd.flags);
+                cmd.flags = attach_flags_to_kdbus(mask);
 
                 /* If augmentation is on, and the bus doesn't didn't allow us
                  * to get the bits we want, then ask for the PID/TID so that we