diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-11-05 20:52:39 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-11-05 20:52:39 +0100 |
commit | 927b1649448b812a7620ad013f4752d597b12407 (patch) | |
tree | 94d08ee1e874788c666e943c145558ce42fde164 /src/login/logind-user-dbus.c | |
parent | d16bd0556127962e0dc19f2b049edb09f354bedb (diff) |
logind: add virtual object paths that always can be used to refer to the callers session, user, seat or machine object
This way clients can skip invoking GetSessionByPID() for their own PID
or a similar call to access these objects.
Diffstat (limited to 'src/login/logind-user-dbus.c')
-rw-r--r-- | src/login/logind-user-dbus.c | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/src/login/logind-user-dbus.c b/src/login/logind-user-dbus.c index dbd617f7ac..563c7ef6be 100644 --- a/src/login/logind-user-dbus.c +++ b/src/login/logind-user-dbus.c @@ -236,11 +236,7 @@ const sd_bus_vtable user_vtable[] = { }; int user_object_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) { - - _cleanup_free_ char *e = NULL; Manager *m = userdata; - unsigned long lu; - const char *p; User *user; int r; @@ -250,17 +246,37 @@ int user_object_find(sd_bus *bus, const char *path, const char *interface, void assert(found); assert(m); - p = startswith(path, "/org/freedesktop/login1/user/_"); - if (!p) - return 0; + if (streq(path, "/org/freedesktop/login1/user/self")) { + sd_bus_message *message; + pid_t pid; - r = safe_atolu(p, &lu); - if (r < 0) - return 0; + message = sd_bus_get_current(bus); + if (!message) + return 0; - user = hashmap_get(m->users, ULONG_TO_PTR(lu)); - if (!user) - return 0; + r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid); + if (r < 0) + return 0; + + r = manager_get_user_by_pid(m, pid, &user); + if (r <= 0) + return 0; + } else { + unsigned long lu; + const char *p; + + p = startswith(path, "/org/freedesktop/login1/user/_"); + if (!p) + return 0; + + r = safe_atolu(p, &lu); + if (r < 0) + return 0; + + user = hashmap_get(m->users, ULONG_TO_PTR(lu)); + if (!user) + return 0; + } *found = user; return 1; |