From 3dfb6d3cf596d293c68dbe25e308b5ee5b9c3858 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Mon, 19 May 2014 10:19:49 +0900 Subject: [PATCH] sessionmonitor-systemd: prepare for D-Bus "user bus" model In the D-Bus "user bus" model, all sessions of a user share the same D-Bus instance, a polkit requesting process might live outside the login session which registered the user's polkit agent. In case a polkit requesting process is not part of the user's login session, we ask systemd-logind for the the user's "display" session instead. --- .../polkitbackendsessionmonitor-systemd.c | 24 +++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/polkitbackend/polkitbackendsessionmonitor-systemd.c b/src/polkitbackend/polkitbackendsessionmonitor-systemd.c index 756b728..4047ea1 100644 --- a/src/polkitbackend/polkitbackendsessionmonitor-systemd.c +++ b/src/polkitbackend/polkitbackendsessionmonitor-systemd.c @@ -318,6 +318,7 @@ polkit_backend_session_monitor_get_session_for_subject (PolkitBackendSessionMoni PolkitSubject *session = NULL; char *session_id = NULL; pid_t pid; + uid_t uid; if (POLKIT_IS_UNIX_PROCESS (subject)) process = POLKIT_UNIX_PROCESS (subject); /* We already have a process */ @@ -338,15 +339,28 @@ polkit_backend_session_monitor_get_session_for_subject (PolkitBackendSessionMoni g_type_name (G_TYPE_FROM_INSTANCE (subject))); } - /* Now do process -> pid -> session */ + /* Now do process -> pid -> same session */ g_assert (process != NULL); pid = polkit_unix_process_get_pid (process); - if (sd_pid_get_session (pid, &session_id) < 0) + if (sd_pid_get_session (pid, &session_id) >= 0) + { + session = polkit_unix_session_new (session_id); + free (session_id); + goto out; + } + + /* Now do process -> uid -> graphical session */ + if (sd_pid_get_owner_uid(pid, &uid) < 0) goto out; - - session = polkit_unix_session_new (session_id); - free (session_id); + + if (sd_uid_get_display(uid, &session_id) >= 0) + { + session = polkit_unix_session_new (session_id); + free (session_id); + goto out; + } + out: if (tmp_process) g_object_unref (tmp_process); return session; -- 1.9.0