chiark / gitweb /
sd-bus: allow setting a per-connection default value for the "allow-interactive-authe...
authorLennart Poettering <lennart@poettering.net>
Tue, 17 Feb 2015 19:30:33 +0000 (20:30 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 18 Feb 2015 10:43:18 +0000 (11:43 +0100)
Most of our client tools want to set this bit for all their method
calls, even though it defaults to off in sd-bus, and rightfully so.
Hence, to simplify thing, introduce a per sd_bus-object flag that sets
the default value for all messages created on the connection.

src/libsystemd/libsystemd.sym.m4
src/libsystemd/sd-bus/bus-internal.h
src/libsystemd/sd-bus/bus-message.c
src/libsystemd/sd-bus/sd-bus.c
src/systemd/sd-bus.h

index 76a8c92..81f1122 100644 (file)
@@ -185,6 +185,8 @@ global:
         sd_bus_set_trusted;
         sd_bus_set_monitor;
         sd_bus_set_description;
         sd_bus_set_trusted;
         sd_bus_set_monitor;
         sd_bus_set_description;
+        sd_bus_set_allow_interactive_authorization;
+        sd_bus_get_allow_interactive_authorization;
         sd_bus_negotiate_fds;
         sd_bus_negotiate_timestamp;
         sd_bus_negotiate_creds;
         sd_bus_negotiate_fds;
         sd_bus_negotiate_timestamp;
         sd_bus_negotiate_creds;
index e9f1a81..bebb2c2 100644 (file)
@@ -211,6 +211,7 @@ struct sd_bus {
         bool manual_peer_interface:1;
         bool is_system:1;
         bool is_user:1;
         bool manual_peer_interface:1;
         bool is_system:1;
         bool is_user:1;
+        bool allow_interactive_authorization:1;
 
         int use_memfd;
 
 
         int use_memfd;
 
index 2959303..076b85f 100644 (file)
@@ -634,6 +634,9 @@ static sd_bus_message *message_new(sd_bus *bus, uint8_t type) {
         m->root_container.need_offsets = BUS_MESSAGE_IS_GVARIANT(m);
         m->bus = sd_bus_ref(bus);
 
         m->root_container.need_offsets = BUS_MESSAGE_IS_GVARIANT(m);
         m->bus = sd_bus_ref(bus);
 
+        if (bus->allow_interactive_authorization)
+                m->header->flags |= BUS_MESSAGE_ALLOW_INTERACTIVE_AUTHORIZATION;
+
         return m;
 }
 
         return m;
 }
 
index cac9b65..6a7f9c0 100644 (file)
@@ -357,6 +357,21 @@ _public_ int sd_bus_set_description(sd_bus *bus, const char *description) {
         return free_and_strdup(&bus->description, 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;
 static int hello_callback(sd_bus *bus, sd_bus_message *reply, void *userdata, sd_bus_error *error) {
         const char *s;
         int r;
index ca2d83e..f6262a3 100644 (file)
@@ -143,6 +143,8 @@ int sd_bus_can_send(sd_bus *bus, char type);
 int sd_bus_negotiate_timestamp(sd_bus *bus, int b);
 int sd_bus_negotiate_creds(sd_bus *bus, int b, uint64_t creds_mask);
 int sd_bus_get_creds_mask(sd_bus *bus, uint64_t *creds_mask);
 int sd_bus_negotiate_timestamp(sd_bus *bus, int b);
 int sd_bus_negotiate_creds(sd_bus *bus, int b, uint64_t creds_mask);
 int sd_bus_get_creds_mask(sd_bus *bus, uint64_t *creds_mask);
+int sd_bus_set_allow_interactive_authorization(sd_bus *bus, int b);
+int sd_bus_get_allow_interactive_authorization(sd_bus *bus);
 
 int sd_bus_start(sd_bus *ret);
 
 
 int sd_bus_start(sd_bus *ret);