summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-bus
diff options
context:
space:
mode:
authorMarius Vollmer <mvollmer@redhat.com>2022-09-30 11:11:04 +0300
committerLennart Poettering <lennart@poettering.net>2022-10-04 17:52:50 +0200
commit4e2baf2f0aa075db94ae6ad8a6ff25e7e104dcaa (patch)
tree0a49243fe97fffa24ac502e9d37e0beb00f7014f /src/libsystemd/sd-bus
parent043ba6a1eeec243a9a8de0cfd46a5b812707012e (diff)
downloadsystemd-4e2baf2f0aa075db94ae6ad8a6ff25e7e104dcaa.tar.gz
bus: Process authentication after write
Once everything has been written, a server bus might now process a pending "BEGIN" and start the bus.
Diffstat (limited to 'src/libsystemd/sd-bus')
-rw-r--r--src/libsystemd/sd-bus/bus-socket.c66
1 files changed, 35 insertions, 31 deletions
diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c
index cf87dac321..c94befef73 100644
--- a/src/libsystemd/sd-bus/bus-socket.c
+++ b/src/libsystemd/sd-bus/bus-socket.c
@@ -124,37 +124,6 @@ bool bus_socket_auth_needs_write(sd_bus *b) {
return false;
}
-static int bus_socket_write_auth(sd_bus *b) {
- ssize_t k;
-
- assert(b);
- assert(b->state == BUS_AUTHENTICATING);
-
- if (!bus_socket_auth_needs_write(b))
- return 0;
-
- if (b->prefer_writev)
- k = writev(b->output_fd, b->auth_iovec + b->auth_index, ELEMENTSOF(b->auth_iovec) - b->auth_index);
- else {
- struct msghdr mh = {
- .msg_iov = b->auth_iovec + b->auth_index,
- .msg_iovlen = ELEMENTSOF(b->auth_iovec) - b->auth_index,
- };
-
- k = sendmsg(b->output_fd, &mh, MSG_DONTWAIT|MSG_NOSIGNAL);
- if (k < 0 && errno == ENOTSOCK) {
- b->prefer_writev = true;
- k = writev(b->output_fd, b->auth_iovec + b->auth_index, ELEMENTSOF(b->auth_iovec) - b->auth_index);
- }
- }
-
- if (k < 0)
- return ERRNO_IS_TRANSIENT(errno) ? 0 : -errno;
-
- iovec_advance(b->auth_iovec, &b->auth_index, (size_t) k);
- return 1;
-}
-
static int bus_socket_auth_verify_client(sd_bus *b) {
char *l, *lines[4] = {};
sd_id128_t peer;
@@ -522,6 +491,41 @@ static int bus_socket_auth_verify(sd_bus *b) {
return bus_socket_auth_verify_client(b);
}
+static int bus_socket_write_auth(sd_bus *b) {
+ ssize_t k;
+
+ assert(b);
+ assert(b->state == BUS_AUTHENTICATING);
+
+ if (!bus_socket_auth_needs_write(b))
+ return 0;
+
+ if (b->prefer_writev)
+ k = writev(b->output_fd, b->auth_iovec + b->auth_index, ELEMENTSOF(b->auth_iovec) - b->auth_index);
+ else {
+ struct msghdr mh = {
+ .msg_iov = b->auth_iovec + b->auth_index,
+ .msg_iovlen = ELEMENTSOF(b->auth_iovec) - b->auth_index,
+ };
+
+ k = sendmsg(b->output_fd, &mh, MSG_DONTWAIT|MSG_NOSIGNAL);
+ if (k < 0 && errno == ENOTSOCK) {
+ b->prefer_writev = true;
+ k = writev(b->output_fd, b->auth_iovec + b->auth_index, ELEMENTSOF(b->auth_iovec) - b->auth_index);
+ }
+ }
+
+ if (k < 0)
+ return ERRNO_IS_TRANSIENT(errno) ? 0 : -errno;
+
+ iovec_advance(b->auth_iovec, &b->auth_index, (size_t) k);
+
+ /* Now crank the state machine since we might be able to make progress after writing. For example,
+ * the server only processes "BEGIN" when the write buffer is empty.
+ */
+ return bus_socket_auth_verify(b);
+}
+
static int bus_socket_read_auth(sd_bus *b) {
struct msghdr mh;
struct iovec iov = {};