chiark / gitweb /
sd-bus: allow setting a per-connection default value for the "allow-interactive-authe...
[elogind.git] / src / libsystemd / sd-bus / sd-bus.c
index 15180d042354621bff69831dcd8c41879d301e2b..6a7f9c04ac2625cabade7012a6eb09c76cef035c 100644 (file)
@@ -24,7 +24,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <netdb.h>
-#include <sys/poll.h>
+#include <poll.h>
 #include <byteswap.h>
 #include <sys/mman.h>
 #include <pthread.h>
@@ -357,6 +357,21 @@ _public_ int sd_bus_set_description(sd_bus *bus, const char *description) {
         return free_and_strdup(&bus->description, description);
 }
 
+_public_ int sd_bus_set_allow_interactive_authorization(sd_bus *bus, int b) {
+        assert_return(bus, -EINVAL);
+        assert_return(!bus_pid_changed(bus), -ECHILD);
+
+        bus->allow_interactive_authorization = !!b;
+        return 0;
+}
+
+_public_ int sd_bus_get_allow_interactive_authorization(sd_bus *bus) {
+        assert_return(bus, -EINVAL);
+        assert_return(!bus_pid_changed(bus), -ECHILD);
+
+        return bus->allow_interactive_authorization;
+}
+
 static int hello_callback(sd_bus *bus, sd_bus_message *reply, void *userdata, sd_bus_error *error) {
         const char *s;
         int r;
@@ -1286,7 +1301,7 @@ int bus_set_address_system_remote(sd_bus *b, const char *host) {
                         if (!e)
                                 return -ENOMEM;
 
-                        c = strappenda(",argv4=--machine=", m);
+                        c = strjoina(",argv4=--machine=", m);
                 }
         }
 
@@ -1704,8 +1719,8 @@ static int bus_send_internal(sd_bus *bus, sd_bus_message *_m, uint64_t *cookie,
 
         /* If this is a reply and no reply was requested, then let's
          * suppress this, if we can */
-        if (m->dont_send && !cookie)
-                return 1;
+        if (m->dont_send)
+                goto finish;
 
         if ((bus->state == BUS_RUNNING || bus->state == BUS_HELLO) && bus->wqueue_size <= 0) {
                 size_t idx = 0;
@@ -1718,7 +1733,9 @@ static int bus_send_internal(sd_bus *bus, sd_bus_message *_m, uint64_t *cookie,
                         }
 
                         return r;
-                } else if (!bus->is_kernel && idx < BUS_MESSAGE_SIZE(m))  {
+                }
+
+                if (!bus->is_kernel && idx < BUS_MESSAGE_SIZE(m))  {
                         /* Wasn't fully written. So let's remember how
                          * much was written. Note that the first entry
                          * of the wqueue array is always allocated so
@@ -1728,6 +1745,7 @@ static int bus_send_internal(sd_bus *bus, sd_bus_message *_m, uint64_t *cookie,
                         bus->wqueue_size = 1;
                         bus->windex = idx;
                 }
+
         } else {
                 /* Just append it to the queue. */
 
@@ -1740,6 +1758,7 @@ static int bus_send_internal(sd_bus *bus, sd_bus_message *_m, uint64_t *cookie,
                 bus->wqueue[bus->wqueue_size ++] = sd_bus_message_ref(m);
         }
 
+finish:
         if (cookie)
                 *cookie = BUS_MESSAGE_COOKIE(m);