From 3345c10cf93dd42cb37f06c7074669ae315c3280 Mon Sep 17 00:00:00 2001 From: Sebastien Bacher Date: Mon, 2 Apr 2018 10:52:47 -0400 Subject: Support polkit session agent running outside user session commit a68f5dfd7662767b7b9822090b70bc5bd145c50c made session applications that are running from a user bus work with polkitd, by falling back to using the currently active session. This commit is similar, but for the polkit agent. It allows, a polkit agent to be run from a systemd --user service that's not running directly in the users session. https://bugs.freedesktop.org/show_bug.cgi?id=96977 --- src/polkit/polkitunixsession-systemd.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/polkit/polkitunixsession-systemd.c b/src/polkit/polkitunixsession-systemd.c index 8a8bf65..c34f36a 100644 --- a/src/polkit/polkitunixsession-systemd.c +++ b/src/polkit/polkitunixsession-systemd.c @@ -451,6 +451,7 @@ polkit_unix_session_initable_init (GInitable *initable, PolkitUnixSession *session = POLKIT_UNIX_SESSION (initable); gboolean ret = FALSE; char *s; + uid_t uid; if (session->session_id != NULL) { @@ -467,6 +468,19 @@ polkit_unix_session_initable_init (GInitable *initable, goto out; } + /* Now do process -> uid -> graphical session (systemd version 213)*/ + if (sd_pid_get_owner_uid (session->pid, &uid) < 0) + goto error; + + if (sd_uid_get_display (uid, &s) >= 0) + { + session->session_id = g_strdup (s); + free (s); + ret = TRUE; + goto out; + } + +error: g_set_error (error, POLKIT_ERROR, POLKIT_ERROR_FAILED, -- cgit v1.2.1