free(b->rbuffer);
free(b->unique_name);
- free(b->auth_uid);
+ free(b->auth_buffer);
free(b->address);
free(b->exec_path);
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;
if (r < 0)
return r;
- r = sd_bus_send_with_reply(bus, m, hello_callback, NULL, 0, NULL);
- if (r < 0)
- return r;
-
- return r;
+ return sd_bus_send_with_reply(bus, m, hello_callback, NULL, 0, &bus->hello_serial);
}
int bus_start_running(sd_bus *bus) {
errno = 0;
ul = strtoul(*p + 4, (char**) p, 10);
- if (errno != 0 || **p != '=' || ul > 256) {
+ if (errno > 0 || **p != '=' || ul > 256) {
r = -EINVAL;
goto fail;
}
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)
+ else if (bus->address || bus->sockaddr.sa.sa_family != AF_UNSPEC || bus->exec_path)
r = bus_start_address(bus);
else
return -EINVAL;
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;
return r < 0 ? r : 1;
}
+static int process_hello(sd_bus *bus, sd_bus_message *m) {
+ assert(bus);
+ assert(m);
+
+ if (bus->state != BUS_HELLO)
+ return 0;
+
+ /* 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 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)
+ return -EIO;
+
+ if (m->reply_serial != bus->hello_serial)
+ return -EIO;
+
+ return 0;
+}
+
static int process_reply(sd_bus *bus, sd_bus_message *m) {
struct reply_callback *c;
int r;
assert(bus);
assert(m);
+ r = process_hello(bus, m);
+ if (r != 0)
+ return r;
+
r = process_reply(bus, m);
if (r != 0)
return r;