chiark / gitweb /
logind: automatically determine client side PID if GetSessionByPID() is called with...
authorLennart Poettering <lennart@poettering.net>
Tue, 5 Nov 2013 19:44:27 +0000 (20:44 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 5 Nov 2013 19:44:27 +0000 (20:44 +0100)
src/login/logind-dbus.c
src/machine/machined-dbus.c

index dcfd25d..7e22b84 100644 (file)
@@ -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);
index b552662..505bc17 100644 (file)
@@ -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);