chiark / gitweb /
bus: fake client side creds in the proxy to the caller's creds
[elogind.git] / src / libsystemd-bus / bus-control.c
index a38ce0cb600b40f8f64360b0c083deb7e594c68a..1eed7b9e320952036e3f78899cd65d635381717d 100644 (file)
@@ -230,10 +230,10 @@ static int kernel_get_list(sd_bus *bus, uint64_t flags, char ***x) {
 
         KDBUS_ITEM_FOREACH(name, name_list, names) {
 
-                if ((flags & KDBUS_NAME_LIST_UNIQUE) && name->id != previous_id) {
+                if ((flags & KDBUS_NAME_LIST_UNIQUE) && name->owner_id != previous_id) {
                         char *n;
 
-                        if (asprintf(&n, ":1.%llu", (unsigned long long) name->id) < 0)
+                        if (asprintf(&n, ":1.%llu", (unsigned long long) name->owner_id) < 0)
                                 return -ENOMEM;
 
                         r = strv_push(x, n);
@@ -242,7 +242,7 @@ static int kernel_get_list(sd_bus *bus, uint64_t flags, char ***x) {
                                 return -ENOMEM;
                         }
 
-                        previous_id = name->id;
+                        previous_id = name->owner_id;
                 }
 
                 if (name->size > sizeof(*name) && service_name_is_valid(name->name)) {
@@ -907,8 +907,7 @@ int bus_add_match_internal_kernel(
 
         zero(bloom);
 
-        sz = ALIGN8(offsetof(struct kdbus_cmd_match, items) +
-                    offsetof(struct kdbus_item, id) + sizeof(uint64_t));
+        sz = ALIGN8(offsetof(struct kdbus_cmd_match, items));
 
         for (i = 0; i < n_components; i++) {
                 struct bus_match_component *c = &components[i];
@@ -922,8 +921,9 @@ int bus_add_match_internal_kernel(
                         r = bus_kernel_parse_unique_name(c->value_str, &src_id);
                         if (r < 0)
                                 return r;
-
-                        if (r > 0) {
+                        else if (r > 0)
+                                sz += ALIGN8(offsetof(struct kdbus_item, id) + sizeof(uint64_t));
+                        else  {
                                 sender = c->value_str;
                                 sender_length = strlen(sender);
                                 sz += ALIGN8(offsetof(struct kdbus_item, str) + sender_length + 1);
@@ -1023,22 +1023,25 @@ int bus_add_match_internal_kernel(
         m = alloca0(sz);
         m->size = sz;
         m->cookie = cookie;
-        m->id = id;
+        m->owner_id = id;
 
         item = m->items;
-        item->size = offsetof(struct kdbus_item, id) + sizeof(uint64_t);
-        item->type = KDBUS_ITEM_ID;
-        item->id = src_id;
 
-        if (using_bloom) {
+        if (src_id != KDBUS_MATCH_ID_ANY) {
+                item->size = offsetof(struct kdbus_item, id) + sizeof(uint64_t);
+                item->type = KDBUS_ITEM_ID;
+                item->id = src_id;
                 item = KDBUS_ITEM_NEXT(item);
+        }
+
+        if (using_bloom) {
                 item->size = offsetof(struct kdbus_item, data64) + BLOOM_SIZE;
                 item->type = KDBUS_ITEM_BLOOM;
                 memcpy(item->data64, bloom, BLOOM_SIZE);
+                item = KDBUS_ITEM_NEXT(item);
         }
 
         if (sender) {
-                item = KDBUS_ITEM_NEXT(item);
                 item->size = offsetof(struct kdbus_item, str) + sender_length + 1;
                 item->type = KDBUS_ITEM_NAME;
                 memcpy(item->str, sender, sender_length + 1);
@@ -1111,7 +1114,7 @@ int bus_remove_match_internal_kernel(
         zero(m);
         m.size = offsetof(struct kdbus_cmd_match, items);
         m.cookie = cookie;
-        m.id = id;
+        m.owner_id = id;
 
         r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_REMOVE, &m);
         if (r < 0)