chiark / gitweb /
bus: do kdbus only if this is enabled on the configure switch
[elogind.git] / src / libsystemd-bus / sd-bus.c
index 0d5deb6c6deb1f88855a9e00c014c1e4f2d9c373..1244ec2f6dd051df9d04a3e434b2e45e5f4fd7b4 100644 (file)
@@ -181,6 +181,7 @@ _public_ int sd_bus_new(sd_bus **ret) {
         r->n_ref = REFCNT_INIT;
         r->input_fd = r->output_fd = -1;
         r->message_version = 1;
+        r->creds_mask |= SD_BUS_CREDS_WELL_KNOWN_NAMES|SD_BUS_CREDS_UNIQUE_NAME;
         r->hello_flags |= KDBUS_HELLO_ACCEPT_FD;
         r->attach_flags |= KDBUS_ATTACH_NAMES;
         r->original_pid = getpid();
@@ -290,7 +291,10 @@ _public_ int sd_bus_negotiate_attach_creds(sd_bus *bus, uint64_t mask) {
         assert_return(bus->state == BUS_UNSET, -EPERM);
         assert_return(!bus_pid_changed(bus), -ECHILD);
 
-        return kdbus_translate_attach_flags(mask, &bus->creds_mask);
+        /* The well knowns we need unconditionally, so that matches can work */
+        bus->creds_mask = mask | SD_BUS_CREDS_WELL_KNOWN_NAMES|SD_BUS_CREDS_UNIQUE_NAME;
+
+        return kdbus_translate_attach_flags(bus->creds_mask, &bus->creds_mask);
 }
 
 _public_ int sd_bus_set_server(sd_bus *bus, int b, sd_id128_t server_id) {
@@ -989,7 +993,11 @@ _public_ int sd_bus_open_system(sd_bus **ret) {
         if (e)
                 r = sd_bus_set_address(b, e);
         else
+#ifdef ENABLE_KDBUS
                 r = sd_bus_set_address(b, "kernel:path=/dev/kdbus/0-system/bus;unix:path=/run/dbus/system_bus_socket");
+#else
+                r = sd_bus_set_address(b, "unix:path=/run/dbus/system_bus_socket");
+#endif
 
         if (r < 0)
                 goto fail;
@@ -1031,13 +1039,22 @@ _public_ int sd_bus_open_user(sd_bus **ret) {
 
                         ee = bus_address_escape(e);
                         if (!ee) {
-                                r = -ENOENT;
+                                r = -ENOMEM;
                                 goto fail;
                         }
 
+#ifdef ENABLE_KDBUS
                         asprintf(&b->address, "kernel:path=/dev/kdbus/%lu-user/bus;unix:path=%s/bus", (unsigned long) getuid(), ee);
-                } else
+#else
+                        b->address = strjoin("unix:path=", ee, "/bus", NULL);
+#endif
+                } else {
+#ifdef ENABLE_KDBUS
                         asprintf(&b->address, "kernel:path=/dev/kdbus/%lu-user/bus", (unsigned long) getuid());
+#else
+                        return -ECONNREFUSED;
+#endif
+                }
 
                 if (!b->address) {
                         r = -ENOMEM;
@@ -1153,9 +1170,8 @@ _public_ void sd_bus_close(sd_bus *bus) {
 
         /* We'll leave the fd open in case this is a kernel bus, since
          * there might still be memblocks around that reference this
-         * bus, and they might need to invoke the
-         * KDBUS_CMD_MSG_RELEASE ioctl on the fd when they are
-         * freed. */
+         * bus, and they might need to invoke the * KDBUS_CMD_FREE
+         * ioctl on the fd when they are freed. */
 }
 
 static void bus_enter_closing(sd_bus *bus) {
@@ -2803,7 +2819,7 @@ _public_ int sd_bus_get_peer_creds(sd_bus *bus, uint64_t mask, sd_bus_creds **re
                 c->uid = bus->ucred.uid;
                 c->gid = bus->ucred.gid;
 
-                c->mask |= ((SD_BUS_CREDS_UID | SD_BUS_CREDS_PID | SD_BUS_CREDS_GID) & mask) & bus->creds_mask;
+                c->mask |= (SD_BUS_CREDS_UID | SD_BUS_CREDS_PID | SD_BUS_CREDS_GID) & mask;
         }
 
         if (!isempty(bus->label) && (mask & SD_BUS_CREDS_SELINUX_CONTEXT)) {
@@ -2813,7 +2829,7 @@ _public_ int sd_bus_get_peer_creds(sd_bus *bus, uint64_t mask, sd_bus_creds **re
                         return -ENOMEM;
                 }
 
-                c->mask |= SD_BUS_CREDS_SELINUX_CONTEXT | bus->creds_mask;
+                c->mask |= SD_BUS_CREDS_SELINUX_CONTEXT;
         }
 
         r = bus_creds_add_more(c, mask, pid, 0);