chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
bus: connect directly via kdbus in sd_bus_open_system_container()
[elogind.git]
/
src
/
libsystemd-bus
/
sd-bus.c
diff --git
a/src/libsystemd-bus/sd-bus.c
b/src/libsystemd-bus/sd-bus.c
index e224be7056c9a8281b0c24307deeaa07235c01cc..edd917e30375786811727fd44590625e99ce3df1 100644
(file)
--- a/
src/libsystemd-bus/sd-bus.c
+++ b/
src/libsystemd-bus/sd-bus.c
@@
-47,6
+47,7
@@
#include "bus-objects.h"
#include "bus-util.h"
#include "bus-container.h"
#include "bus-objects.h"
#include "bus-util.h"
#include "bus-container.h"
+#include "bus-protocol.h"
static int bus_poll(sd_bus *bus, bool need_more, uint64_t timeout_usec);
static int bus_poll(sd_bus *bus, bool need_more, uint64_t timeout_usec);
@@
-287,7
+288,7
@@
_public_ int sd_bus_negotiate_attach_timestamp(sd_bus *bus, int b) {
_public_ int sd_bus_negotiate_attach_creds(sd_bus *bus, uint64_t mask) {
assert_return(bus, -EINVAL);
_public_ int sd_bus_negotiate_attach_creds(sd_bus *bus, uint64_t mask) {
assert_return(bus, -EINVAL);
- assert_return(mask <= _SD_BUS_CREDS_
MAX
, -EINVAL);
+ assert_return(mask <= _SD_BUS_CREDS_
ALL
, -EINVAL);
assert_return(bus->state == BUS_UNSET, -EPERM);
assert_return(!bus_pid_changed(bus), -ECHILD);
assert_return(bus->state == BUS_UNSET, -EPERM);
assert_return(!bus_pid_changed(bus), -ECHILD);
@@
-317,6
+318,15
@@
_public_ int sd_bus_set_anonymous(sd_bus *bus, int b) {
return 0;
}
return 0;
}
+_public_ int sd_bus_set_trusted(sd_bus *bus, int b) {
+ assert_return(bus, -EINVAL);
+ assert_return(bus->state == BUS_UNSET, -EPERM);
+ assert_return(!bus_pid_changed(bus), -ECHILD);
+
+ bus->trusted = !!b;
+ return 0;
+}
+
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;
@@
-754,6
+764,9
@@
static int parse_container_address(sd_bus *b, const char **p, char **guid) {
if (!machine)
return -EINVAL;
if (!machine)
return -EINVAL;
+ if (!filename_is_safe(machine))
+ return -EINVAL;
+
free(b->machine);
b->machine = machine;
machine = NULL;
free(b->machine);
b->machine = machine;
machine = NULL;
@@
-993,13
+1006,22
@@
_public_ int sd_bus_open_system(sd_bus **ret) {
if (e)
r = sd_bus_set_address(b, e);
else
if (e)
r = sd_bus_set_address(b, e);
else
+#ifdef ENABLE_KDBUS
r = sd_bus_set_address(b, "kernel:path=/dev/kdbus/0-system/bus;unix:path=/run/dbus/system_bus_socket");
r = sd_bus_set_address(b, "kernel:path=/dev/kdbus/0-system/bus;unix:path=/run/dbus/system_bus_socket");
+#else
+ r = sd_bus_set_address(b, "unix:path=/run/dbus/system_bus_socket");
+#endif
if (r < 0)
goto fail;
b->bus_client = true;
if (r < 0)
goto fail;
b->bus_client = true;
+ /* Let's do per-method access control on the system bus. We
+ * need the caller's UID and capability set for that. */
+ b->trusted = false;
+ b->attach_flags |= KDBUS_ATTACH_CAPS | KDBUS_ATTACH_CREDS;
+
r = sd_bus_start(b);
if (r < 0)
goto fail;
r = sd_bus_start(b);
if (r < 0)
goto fail;
@@
-1035,13
+1057,22
@@
_public_ int sd_bus_open_user(sd_bus **ret) {
ee = bus_address_escape(e);
if (!ee) {
ee = bus_address_escape(e);
if (!ee) {
- r = -ENO
ENT
;
+ r = -ENO
MEM
;
goto fail;
}
goto fail;
}
+#ifdef ENABLE_KDBUS
asprintf(&b->address, "kernel:path=/dev/kdbus/%lu-user/bus;unix:path=%s/bus", (unsigned long) getuid(), ee);
asprintf(&b->address, "kernel:path=/dev/kdbus/%lu-user/bus;unix:path=%s/bus", (unsigned long) getuid(), ee);
- } else
+#else
+ b->address = strjoin("unix:path=", ee, "/bus", NULL);
+#endif
+ } else {
+#ifdef ENABLE_KDBUS
asprintf(&b->address, "kernel:path=/dev/kdbus/%lu-user/bus", (unsigned long) getuid());
asprintf(&b->address, "kernel:path=/dev/kdbus/%lu-user/bus", (unsigned long) getuid());
+#else
+ return -ECONNREFUSED;
+#endif
+ }
if (!b->address) {
r = -ENOMEM;
if (!b->address) {
r = -ENOMEM;
@@
-1051,6
+1082,10
@@
_public_ int sd_bus_open_user(sd_bus **ret) {
b->bus_client = true;
b->bus_client = true;
+ /* We don't do any per-method access control on the user
+ * bus. */
+ b->trusted = true;
+
r = sd_bus_start(b);
if (r < 0)
goto fail;
r = sd_bus_start(b);
if (r < 0)
goto fail;
@@
-1107,12
+1142,17
@@
_public_ int sd_bus_open_system_container(const char *machine, sd_bus **ret) {
assert_return(machine, -EINVAL);
assert_return(ret, -EINVAL);
assert_return(machine, -EINVAL);
assert_return(ret, -EINVAL);
+ assert_return(filename_is_safe(machine), -EINVAL);
e = bus_address_escape(machine);
if (!e)
return -ENOMEM;
e = bus_address_escape(machine);
if (!e)
return -ENOMEM;
+#ifdef ENABLE_KDBUS
+ p = strjoin("kernel:path=/dev/kdbus/ns/machine-", e, "/0-system/bus;x-container:machine=", e, NULL);
+#else
p = strjoin("x-container:machine=", e, NULL);
p = strjoin("x-container:machine=", e, NULL);
+#endif
if (!p)
return -ENOMEM;
if (!p)
return -ENOMEM;
@@
-1182,7
+1222,9
@@
_public_ sd_bus *sd_bus_ref(sd_bus *bus) {
}
_public_ sd_bus *sd_bus_unref(sd_bus *bus) {
}
_public_ sd_bus *sd_bus_unref(sd_bus *bus) {
- assert_return(bus, NULL);
+
+ if (!bus)
+ return NULL;
if (REFCNT_DEC(bus->n_ref) <= 0)
bus_free(bus);
if (REFCNT_DEC(bus->n_ref) <= 0)
bus_free(bus);
@@
-1271,8
+1313,6
@@
int bus_seal_synthetic_message(sd_bus *b, sd_bus_message *m) {
}
static int bus_write_message(sd_bus *bus, sd_bus_message *message, size_t *idx) {
}
static int bus_write_message(sd_bus *bus, sd_bus_message *message, size_t *idx) {
- int r;
-
assert(bus);
assert(message);
assert(bus);
assert(message);
@@
-1280,8
+1320,6
@@
static int bus_write_message(sd_bus *bus, sd_bus_message *message, size_t *idx)
return bus_kernel_write_message(bus, message);
else
return bus_socket_write_message(bus, message, idx);
return bus_kernel_write_message(bus, message);
else
return bus_socket_write_message(bus, message, idx);
-
- return r;
}
static int dispatch_wqueue(sd_bus *bus) {
}
static int dispatch_wqueue(sd_bus *bus) {
@@
-1399,7
+1437,7
@@
_public_ int sd_bus_send(sd_bus *bus, sd_bus_message *m, uint64_t *serial) {
/* If the serial number isn't kept, then we know that no reply
* is expected */
if (!serial && !m->sealed)
/* If the serial number isn't kept, then we know that no reply
* is expected */
if (!serial && !m->sealed)
- m->header->flags |=
SD_
BUS_MESSAGE_NO_REPLY_EXPECTED;
+ m->header->flags |= BUS_MESSAGE_NO_REPLY_EXPECTED;
r = bus_seal_message(bus, m);
if (r < 0)
r = bus_seal_message(bus, m);
if (r < 0)
@@
-1515,7
+1553,7
@@
_public_ int sd_bus_call_async(
assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
assert_return(m, -EINVAL);
assert_return(m->header->type == SD_BUS_MESSAGE_METHOD_CALL, -EINVAL);
assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
assert_return(m, -EINVAL);
assert_return(m->header->type == SD_BUS_MESSAGE_METHOD_CALL, -EINVAL);
- assert_return(!(m->header->flags &
SD_
BUS_MESSAGE_NO_REPLY_EXPECTED), -EINVAL);
+ assert_return(!(m->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED), -EINVAL);
assert_return(callback, -EINVAL);
assert_return(!bus_pid_changed(bus), -ECHILD);
assert_return(callback, -EINVAL);
assert_return(!bus_pid_changed(bus), -ECHILD);
@@
-1625,7
+1663,7
@@
_public_ int sd_bus_call(
assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
assert_return(m, -EINVAL);
assert_return(m->header->type == SD_BUS_MESSAGE_METHOD_CALL, -EINVAL);
assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
assert_return(m, -EINVAL);
assert_return(m->header->type == SD_BUS_MESSAGE_METHOD_CALL, -EINVAL);
- assert_return(!(m->header->flags &
SD_
BUS_MESSAGE_NO_REPLY_EXPECTED), -EINVAL);
+ assert_return(!(m->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED), -EINVAL);
assert_return(!bus_error_is_dirty(error), -EINVAL);
assert_return(!bus_pid_changed(bus), -ECHILD);
assert_return(!bus_error_is_dirty(error), -EINVAL);
assert_return(!bus_pid_changed(bus), -ECHILD);
@@
-1967,7
+2005,7
@@
static int process_builtin(sd_bus *bus, sd_bus_message *m) {
if (!streq_ptr(m->interface, "org.freedesktop.DBus.Peer"))
return 0;
if (!streq_ptr(m->interface, "org.freedesktop.DBus.Peer"))
return 0;
- if (m->header->flags &
SD_
BUS_MESSAGE_NO_REPLY_EXPECTED)
+ if (m->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED)
return 1;
if (streq_ptr(m->member, "Ping"))
return 1;
if (streq_ptr(m->member, "Ping"))
@@
-2615,7
+2653,9
@@
fail:
_public_ int sd_bus_detach_event(sd_bus *bus) {
assert_return(bus, -EINVAL);
_public_ int sd_bus_detach_event(sd_bus *bus) {
assert_return(bus, -EINVAL);
- assert_return(bus->event, -ENXIO);
+
+ if (!bus->event)
+ return 0;
if (bus->input_io_event_source) {
sd_event_source_set_enabled(bus->input_io_event_source, SD_EVENT_OFF);
if (bus->input_io_event_source) {
sd_event_source_set_enabled(bus->input_io_event_source, SD_EVENT_OFF);
@@
-2640,7
+2680,7
@@
_public_ int sd_bus_detach_event(sd_bus *bus) {
if (bus->event)
bus->event = sd_event_unref(bus->event);
if (bus->event)
bus->event = sd_event_unref(bus->event);
- return
0
;
+ return
1
;
}
_public_ sd_event* sd_bus_get_event(sd_bus *bus) {
}
_public_ sd_event* sd_bus_get_event(sd_bus *bus) {
@@
-2788,7
+2828,7
@@
_public_ int sd_bus_get_peer_creds(sd_bus *bus, uint64_t mask, sd_bus_creds **re
int r;
assert_return(bus, -EINVAL);
int r;
assert_return(bus, -EINVAL);
- assert_return(mask <= _SD_BUS_CREDS_
MAX
, -ENOTSUP);
+ assert_return(mask <= _SD_BUS_CREDS_
ALL
, -ENOTSUP);
assert_return(ret, -EINVAL);
assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
assert_return(!bus_pid_changed(bus), -ECHILD);
assert_return(ret, -EINVAL);
assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
assert_return(!bus_pid_changed(bus), -ECHILD);