summaryrefslogtreecommitdiff
path: root/src/libsystemd-bus/sd-bus.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-03-30 15:21:06 +0100
committerLennart Poettering <lennart@poettering.net>2013-03-30 15:21:55 +0100
commit2181a7f558eb52a22f09f8add9ac0abb4f2ee016 (patch)
tree0de6c09897dd3ff80d13a9ccfab62839e2234ae5 /src/libsystemd-bus/sd-bus.c
parenta3de5ae1d7d881bbd4869c6c4a200c84bda00ced (diff)
bus: implement server mode, and anonymous authentication
Diffstat (limited to 'src/libsystemd-bus/sd-bus.c')
-rw-r--r--src/libsystemd-bus/sd-bus.c34
1 files changed, 30 insertions, 4 deletions
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index 870d617ac1..047f286f04 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -52,7 +52,7 @@ static void bus_free(sd_bus *b) {
free(b->rbuffer);
free(b->unique_name);
- free(b->auth_uid);
+ free(b->auth_buffer);
free(b->address);
free(b->exec_path);
@@ -197,6 +197,29 @@ int sd_bus_set_negotiate_fds(sd_bus *bus, int b) {
return 0;
}
+int sd_bus_set_server(sd_bus *bus, int b, sd_id128_t server) {
+ if (!bus)
+ return -EINVAL;
+ if (!b && !sd_id128_equal(server, SD_ID128_NULL))
+ return -EINVAL;
+ if (bus->state != BUS_UNSET)
+ return -EPERM;
+
+ bus->is_server = !!b;
+ bus->peer = server;
+ return 0;
+}
+
+int sd_bus_set_anonymous(sd_bus *bus, int b) {
+ if (!bus)
+ return -EINVAL;
+ if (bus->state != BUS_UNSET)
+ return -EPERM;
+
+ bus->anonymous_auth = !!b;
+ return 0;
+}
+
static int hello_callback(sd_bus *bus, int error, sd_bus_message *reply, void *userdata) {
const char *s;
int r;
@@ -716,6 +739,9 @@ int sd_bus_start(sd_bus *bus) {
bus->state = BUS_OPENING;
+ if (bus->is_server && bus->bus_client)
+ return -EINVAL;
+
if (bus->fd >= 0)
r = bus_start_fd(bus);
else if (bus->address || bus->sockaddr.sa.sa_family != AF_UNSPEC || bus->exec_path)
@@ -1350,7 +1376,7 @@ int sd_bus_get_events(sd_bus *bus) {
flags |= POLLOUT;
else if (bus->state == BUS_AUTHENTICATING) {
- if (bus->auth_index < ELEMENTSOF(bus->auth_iovec))
+ if (bus_socket_auth_needs_write(bus))
flags |= POLLOUT;
flags |= POLLIN;
@@ -1426,8 +1452,8 @@ static int process_hello(sd_bus *bus, sd_bus_message *m) {
/* Let's make sure the first message on the bus is the HELLO
* reply. But note that we don't actually parse the message
- * here (we leave that to the usual reply handling), we just
- * verify we don't let any earlier msg through. */
+ * here (we leave that to the usual handling), we just verify
+ * we don't let any earlier msg through. */
if (m->header->type != SD_BUS_MESSAGE_TYPE_METHOD_RETURN &&
m->header->type != SD_BUS_MESSAGE_TYPE_METHOD_ERROR)