diff options
-rw-r--r-- | src/login/logind-dbus.c | 20 | ||||
-rw-r--r-- | src/machine/machined-dbus.c | 10 |
2 files changed, 27 insertions, 3 deletions
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index dcfd25d69b..7e22b842a4 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -157,17 +157,25 @@ static int method_get_session_by_pid(sd_bus *bus, sd_bus_message *message, void _cleanup_free_ char *p = NULL; Session *session = NULL; Manager *m = userdata; - uint32_t pid; + pid_t pid; int r; assert(bus); assert(message); assert(m); + assert_cc(sizeof(pid_t) == sizeof(uint32_t)); + r = sd_bus_message_read(message, "u", &pid); if (r < 0) return sd_bus_reply_method_errno(bus, message, r, NULL); + if (pid == 0) { + r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid); + if (r < 0) + return sd_bus_reply_method_errno(bus, message, r, NULL); + } + r = manager_get_session_by_pid(m, pid, &session); if (r < 0) return sd_bus_reply_method_errno(bus, message, r, NULL); @@ -211,17 +219,25 @@ static int method_get_user_by_pid(sd_bus *bus, sd_bus_message *message, void *us _cleanup_free_ char *p = NULL; Manager *m = userdata; User *user = NULL; - uint32_t pid; + pid_t pid; int r; assert(bus); assert(message); assert(m); + assert_cc(sizeof(pid_t) == sizeof(uint32_t)); + r = sd_bus_message_read(message, "u", &pid); if (r < 0) return sd_bus_reply_method_errno(bus, message, r, NULL); + if (pid == 0) { + r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid); + if (r < 0) + return sd_bus_reply_method_errno(bus, message, r, NULL); + } + r = manager_get_user_by_pid(m, pid, &user); if (r < 0) return sd_bus_reply_method_errno(bus, message, r, NULL); diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c index b55266249b..505bc17e6a 100644 --- a/src/machine/machined-dbus.c +++ b/src/machine/machined-dbus.c @@ -86,17 +86,25 @@ static int method_get_machine_by_pid(sd_bus *bus, sd_bus_message *message, void _cleanup_free_ char *p = NULL; Manager *m = userdata; Machine *machine = NULL; - uint32_t pid; + pid_t pid; int r; assert(bus); assert(message); assert(m); + assert_cc(sizeof(pid_t) == sizeof(uint32_t)); + r = sd_bus_message_read(message, "u", &pid); if (r < 0) return sd_bus_reply_method_errno(bus, message, r, NULL); + if (pid == 0) { + r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid); + if (r < 0) + return sd_bus_reply_method_errno(bus, message, r, NULL); + } + r = manager_get_machine_by_pid(m, pid, &machine); if (r < 0) return sd_bus_reply_method_errno(bus, message, r, NULL); |