summaryrefslogtreecommitdiff
path: root/src/dbus.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2011-07-01 22:34:37 +0200
committerLennart Poettering <lennart@poettering.net>2011-07-01 22:34:37 +0200
commitbe81bfc4a700e2b8544857279dc09a17b1efcf2d (patch)
tree2959b3ace56a0aeb50e25fb7f05821d21630e54f /src/dbus.c
parent8fef76590052b235eec789f1acd24a0d1acbdaef (diff)
dbus: listen on private sockets in user mode too
Diffstat (limited to 'src/dbus.c')
-rw-r--r--src/dbus.c39
1 files changed, 31 insertions, 8 deletions
diff --git a/src/dbus.c b/src/dbus.c
index 8c7f0ab383..daa2c84a05 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -731,8 +731,8 @@ static int bus_setup_loop(Manager *m, DBusConnection *bus) {
return 0;
}
-static dbus_bool_t allow_only_root(DBusConnection *connection, unsigned long uid, void *data) {
- return uid == 0;
+static dbus_bool_t allow_only_same_user(DBusConnection *connection, unsigned long uid, void *data) {
+ return uid == 0 || uid == geteuid();
}
static void bus_new_connection(
@@ -749,7 +749,7 @@ static void bus_new_connection(
return;
}
- dbus_connection_set_unix_user_function(new_connection, allow_only_root, NULL, NULL);
+ dbus_connection_set_unix_user_function(new_connection, allow_only_same_user, NULL, NULL);
if (bus_setup_loop(m, new_connection) < 0)
return;
@@ -930,12 +930,35 @@ static int bus_init_private(Manager *m) {
if (m->private_bus)
return 0;
- /* We want the private bus only when running as init */
- if (getpid() != 1)
- return 0;
+ if (m->running_as == MANAGER_SYSTEM) {
+
+ /* We want the private bus only when running as init */
+ if (getpid() != 1)
+ return 0;
+
+ unlink("/run/systemd/private");
+ m->private_bus = dbus_server_listen("unix:path=/run/systemd/private", &error);
+ } else {
+ const char *e;
+ char *p;
+
+ e = getenv("XDG_RUNTIME_DIR");
+ if (!e)
+ return 0;
+
+ if (asprintf(&p, "unix:path=%s/systemd/private", e) < 0) {
+ log_error("Not enough memory");
+ r = -ENOMEM;
+ goto fail;
+ }
+
+ mkdir_parents(p+10, 0755);
+ unlink(p+10);
+ m->private_bus = dbus_server_listen(p, &error);
+ free(p);
+ }
- unlink("/run/systemd/private");
- if (!(m->private_bus = dbus_server_listen("unix:path=/run/systemd/private", &error))) {
+ if (!m->private_bus) {
log_error("Failed to create private D-Bus server: %s", bus_error_message(&error));
r = -EIO;
goto fail;