summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-12-23 03:43:43 +0100
committerLennart Poettering <lennart@poettering.net>2013-12-23 04:20:55 +0100
commit8f04d2ebbaa5f330e5240d29917c02bce9892cff (patch)
tree8cf0bb91535b9c010dc420fc4084f0276931bc0a
parentcd789fdf45f188197bf99998e5a8be0f8c614c66 (diff)
bus: make sure to request peer cred only after connect(), not before
-rw-r--r--src/libsystemd-bus/bus-container.c4
-rw-r--r--src/libsystemd-bus/bus-socket.c34
-rw-r--r--src/libsystemd-bus/bus-socket.h3
3 files changed, 19 insertions, 22 deletions
diff --git a/src/libsystemd-bus/bus-container.c b/src/libsystemd-bus/bus-container.c
index 02886c4ded..1989afa82a 100644
--- a/src/libsystemd-bus/bus-container.c
+++ b/src/libsystemd-bus/bus-container.c
@@ -52,9 +52,7 @@ int bus_container_connect_socket(sd_bus *b) {
b->output_fd = b->input_fd;
- r = bus_socket_setup(b);
- if (r < 0)
- return r;
+ bus_socket_setup(b);
child = fork();
if (child < 0)
diff --git a/src/libsystemd-bus/bus-socket.c b/src/libsystemd-bus/bus-socket.c
index a7eaf5099d..1f5d98063a 100644
--- a/src/libsystemd-bus/bus-socket.c
+++ b/src/libsystemd-bus/bus-socket.c
@@ -602,9 +602,8 @@ static int bus_socket_read_auth(sd_bus *b) {
return 1;
}
-int bus_socket_setup(sd_bus *b) {
+void bus_socket_setup(sd_bus *b) {
int enable;
- socklen_t l;
assert(b);
@@ -620,16 +619,20 @@ int bus_socket_setup(sd_bus *b) {
fd_inc_rcvbuf(b->input_fd, SNDBUF_SIZE);
fd_inc_sndbuf(b->output_fd, SNDBUF_SIZE);
- /* Get the peer for socketpair() sockets */
- l = sizeof(b->ucred);
- if (getsockopt(b->input_fd, SOL_SOCKET, SO_PEERCRED, &b->ucred, &l) >= 0 && l >= sizeof(b->ucred))
- b->ucred_valid = b->ucred.pid > 0;
-
b->is_kernel = false;
b->message_version = 1;
b->message_endian = 0;
+}
- return 0;
+static void bus_get_peercred(sd_bus *b) {
+ socklen_t l;
+
+ assert(b);
+
+ /* Get the peer for socketpair() sockets */
+ l = sizeof(b->ucred);
+ if (getsockopt(b->input_fd, SOL_SOCKET, SO_PEERCRED, &b->ucred, &l) >= 0 && l >= sizeof(b->ucred))
+ b->ucred_valid = b->ucred.pid > 0;
}
static int bus_socket_start_auth_client(sd_bus *b) {
@@ -677,6 +680,8 @@ static int bus_socket_start_auth_client(sd_bus *b) {
int bus_socket_start_auth(sd_bus *b) {
assert(b);
+ bus_get_peercred(b);
+
b->state = BUS_AUTHENTICATING;
b->auth_timeout = now(CLOCK_MONOTONIC) + BUS_DEFAULT_TIMEOUT;
@@ -707,9 +712,7 @@ int bus_socket_connect(sd_bus *b) {
b->output_fd = b->input_fd;
- r = bus_socket_setup(b);
- if (r < 0)
- return r;
+ bus_socket_setup(b);
r = connect(b->input_fd, &b->sockaddr.sa, b->sockaddr_size);
if (r < 0) {
@@ -771,20 +774,15 @@ int bus_socket_exec(sd_bus *b) {
close_nointr_nofail(s[1]);
b->output_fd = b->input_fd = s[0];
- r = bus_socket_setup(b);
- if (r < 0)
- return r;
+ bus_socket_setup(b);
return bus_socket_start_auth(b);
}
int bus_socket_take_fd(sd_bus *b) {
- int r;
assert(b);
- r = bus_socket_setup(b);
- if (r < 0)
- return r;
+ bus_socket_setup(b);
return bus_socket_start_auth(b);
}
diff --git a/src/libsystemd-bus/bus-socket.h b/src/libsystemd-bus/bus-socket.h
index f959787e7d..5a1c7d4cf2 100644
--- a/src/libsystemd-bus/bus-socket.h
+++ b/src/libsystemd-bus/bus-socket.h
@@ -23,7 +23,8 @@
#include "sd-bus.h"
-int bus_socket_setup(sd_bus *b);
+void bus_socket_setup(sd_bus *b);
+
int bus_socket_connect(sd_bus *b);
int bus_socket_exec(sd_bus *b);
int bus_socket_take_fd(sd_bus *b);