From 927b1649448b812a7620ad013f4752d597b12407 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 5 Nov 2013 20:52:39 +0100 Subject: 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. --- src/login/logind-session-dbus.c | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) (limited to 'src/login/logind-session-dbus.c') diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c index cda6a0a482..a559e6045b 100644 --- a/src/login/logind-session-dbus.c +++ b/src/login/logind-session-dbus.c @@ -465,10 +465,9 @@ const sd_bus_vtable session_vtable[] = { }; int session_object_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) { - _cleanup_free_ char *e = NULL; Manager *m = userdata; Session *session; - const char *p; + int r; assert(bus); assert(path); @@ -476,17 +475,37 @@ int session_object_find(sd_bus *bus, const char *path, const char *interface, vo assert(found); assert(m); - p = startswith(path, "/org/freedesktop/login1/session/"); - if (!p) - return 0; + if (streq(path, "/org/freedesktop/login1/session/self")) { + sd_bus_message *message; + pid_t pid; - e = bus_path_unescape(p); - if (!e) - return -ENOMEM; + message = sd_bus_get_current(bus); + if (!message) + return 0; - session = hashmap_get(m->sessions, e); - if (!session) - return 0; + r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid); + if (r < 0) + return 0; + + r = manager_get_session_by_pid(m, pid, &session); + if (r <= 0) + return 0; + } else { + _cleanup_free_ char *e = NULL; + const char *p; + + p = startswith(path, "/org/freedesktop/login1/session/"); + if (!p) + return 0; + + e = bus_path_unescape(p); + if (!e) + return -ENOMEM; + + session = hashmap_get(m->sessions, e); + if (!session) + return 0; + } *found = session; return 1; -- cgit v1.2.3-54-g00ecf