From: Kay Sievers Date: Mon, 19 May 2014 10:19:49 +0900 Subject: [PATCH] 0.113: 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 user's "display" session instead. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=78905 Bug-Debian: https://bugs.debian.org/779988 Applied-upstream: 0.113, commit:a68f5dfd7662767b7b9822090b70bc5bd145c50c [smcv: backport configure.ac changes; fail with #error if the required API is not found] Imported from policykit-1_0.105-25.debian.tar.xz Signed-off-by: Michael Olbrich --- configure.ac | 4 +++ .../polkitbackendsessionmonitor-systemd.c | 29 +++++++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index f4a0c4177fbf..aa2760f90606 100644 --- a/configure.ac +++ b/configure.ac @@ -165,6 +165,10 @@ if test "$enable_systemd" != "no"; then have_systemd=no) if test "$have_systemd" = "yes"; then SESSION_TRACKING=systemd + save_LIBS=$LIBS + LIBS=$SYSTEMD_LIBS + AC_CHECK_FUNCS(sd_uid_get_display) + LIBS=$save_LIBS else if test "$enable_systemd" = "yes"; then AC_MSG_ERROR([systemd support requested but libsystemd-login1 library not found]) diff --git a/src/polkitbackend/polkitbackendsessionmonitor-systemd.c b/src/polkitbackend/polkitbackendsessionmonitor-systemd.c index 756b728ab952..ebd05cea45dc 100644 --- a/src/polkitbackend/polkitbackendsessionmonitor-systemd.c +++ b/src/polkitbackend/polkitbackendsessionmonitor-systemd.c @@ -318,6 +318,9 @@ polkit_backend_session_monitor_get_session_for_subject (PolkitBackendSessionMoni PolkitSubject *session = NULL; char *session_id = NULL; pid_t pid; +#if HAVE_SD_UID_GET_DISPLAY + uid_t uid; +#endif if (POLKIT_IS_UNIX_PROCESS (subject)) process = POLKIT_UNIX_PROCESS (subject); /* We already have a process */ @@ -338,16 +341,32 @@ 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); + goto out; + } + +#if HAVE_SD_UID_GET_DISPLAY + /* Now do process -> uid -> graphical session (systemd version 213)*/ + 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); + goto out; + } +#else +#error Debian should have sd_uid_get_display() +#endif + out: + free (session_id); if (tmp_process) g_object_unref (tmp_process); return session; }