From 309a29dfd24f4175de334ca1593e3fe2436ab082 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 9 Jan 2015 16:14:19 +0100 Subject: logind: when a bus call is done on a session, user or seat, optionally determine them from the caller credentials More specifically, if an operation is requested on a session with an empty name, the caller's session is used. If an operation is requested on a seat with an empty name, the seat of the caller's session is used. Finally, if an operation on the user with UID -1 is requested, the user of the client's session is used (and not the UID of the client!). --- src/login/logind-user-dbus.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) (limited to 'src/login/logind-user-dbus.c') diff --git a/src/login/logind-user-dbus.c b/src/login/logind-user-dbus.c index e811b37369..717740ad04 100644 --- a/src/login/logind-user-dbus.c +++ b/src/login/logind-user-dbus.c @@ -235,6 +235,7 @@ const sd_bus_vtable user_vtable[] = { int user_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) { Manager *m = userdata; + uid_t uid; User *user; int r; @@ -247,39 +248,31 @@ int user_object_find(sd_bus *bus, const char *path, const char *interface, void if (streq(path, "/org/freedesktop/login1/user/self")) { _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL; sd_bus_message *message; - pid_t pid; message = sd_bus_get_current_message(bus); if (!message) return 0; - r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds); + r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_OWNER_UID|SD_BUS_CREDS_AUGMENT, &creds); if (r < 0) return r; - r = sd_bus_creds_get_pid(creds, &pid); - if (r < 0) - return r; - - r = manager_get_user_by_pid(m, pid, &user); - if (r <= 0) - return 0; + r = sd_bus_creds_get_owner_uid(creds, &uid); } 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; + r = parse_uid(p, &uid); } + if (r < 0) + return 0; + + user = hashmap_get(m->users, ULONG_TO_PTR((unsigned long) uid)); + if (!user) + return 0; *found = user; return 1; -- cgit v1.2.3-54-g00ecf