chiark / gitweb /
sd-bus: fake valid well-known-names metadata for faked bus messages
authorLennart Poettering <lennart@poettering.net>
Thu, 27 Nov 2014 01:37:05 +0000 (02:37 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 27 Nov 2014 21:02:12 +0000 (22:02 +0100)
src/libsystemd/sd-bus/bus-creds.c
src/libsystemd/sd-bus/bus-creds.h
src/libsystemd/sd-bus/bus-kernel.c

index ad0e2e1..e3bdda8 100644 (file)
@@ -551,6 +551,18 @@ _public_ int sd_bus_creds_get_well_known_names(sd_bus_creds *c, char ***well_kno
         if (!(c->mask & SD_BUS_CREDS_WELL_KNOWN_NAMES))
                 return -ENODATA;
 
+        /* As a special hack we return the bus driver as well-known
+         * names list when this is requested. */
+        if (c->well_known_names_driver) {
+                static const char* const wkn[] = {
+                        "org.freedesktop.DBus",
+                        NULL
+                };
+
+                *well_known_names = (char**) wkn;
+                return 0;
+        }
+
         *well_known_names = c->well_known_names;
         return 0;
 }
index 882110b..9d6a5bf 100644 (file)
@@ -72,6 +72,7 @@ struct sd_bus_creds {
         char *unique_name;
 
         char **well_known_names;
+        bool well_known_names_driver;
 
         char *cgroup_root;
 
index 1276cd8..9349c1d 100644 (file)
@@ -737,9 +737,11 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
         }
 
         /* Override information from the user header with data from the kernel */
-        if (k->src_id == KDBUS_SRC_ID_KERNEL)
+        if (k->src_id == KDBUS_SRC_ID_KERNEL) {
                 m->sender = m->creds.unique_name = (char*) "org.freedesktop.DBus";
-        else {
+                m->creds.well_known_names_driver = true;
+                m->creds.mask |= SD_BUS_CREDS_WELL_KNOWN_NAMES & bus->creds_mask;
+        } else {
                 snprintf(m->sender_buffer, sizeof(m->sender_buffer), ":1.%llu", (unsigned long long) k->src_id);
                 m->sender = m->creds.unique_name = m->sender_buffer;
         }
@@ -1074,6 +1076,8 @@ static int push_name_owner_changed(sd_bus *bus, const char *name, const char *ol
                 return r;
 
         m->sender = "org.freedesktop.DBus";
+        m->creds.well_known_names_driver = true;
+        m->creds.mask |= SD_BUS_CREDS_WELL_KNOWN_NAMES & bus->creds_mask;
 
         r = bus_seal_synthetic_message(bus, m);
         if (r < 0)
@@ -1143,6 +1147,8 @@ static int translate_reply(sd_bus *bus, struct kdbus_msg *k, struct kdbus_item *
                 return r;
 
         m->sender = "org.freedesktop.DBus";
+        m->creds.well_known_names_driver = true;
+        m->creds.mask |= SD_BUS_CREDS_WELL_KNOWN_NAMES & bus->creds_mask;
 
         r = bus_seal_synthetic_message(bus, m);
         if (r < 0)