summaryrefslogtreecommitdiff
path: root/src/login/logind-user-dbus.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-01-09 16:14:19 +0100
committerLennart Poettering <lennart@poettering.net>2015-01-09 18:35:36 +0100
commit309a29dfd24f4175de334ca1593e3fe2436ab082 (patch)
treead38b8a702fcde2b5a82d07ecf130e3ffd952268 /src/login/logind-user-dbus.c
parent3909ba34ec9b2c63d9938b6ba37af54a214fcff3 (diff)
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!).
Diffstat (limited to 'src/login/logind-user-dbus.c')
-rw-r--r--src/login/logind-user-dbus.c27
1 files changed, 10 insertions, 17 deletions
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;