From 00efd4988b8e4a147f96337de32e54925640f0b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 4 Jan 2019 11:19:10 +0100 Subject: [PATCH 1/2] Revert "pam_systemd: drop setting DBUS_SESSION_BUS_ADDRESS" This reverts commit 2b2b7228bffef626fe8e9f131095995f3d50ee3b. Fixes #11293. Removing the environment variable causes problems, e.g. Xfce and Chromium and ... don't communicate with the running dbus instance. If they attempt to start their own instance, things become even more confusing. Those packages could be fixed one by one, but removing the variable right now is causing too many problems. --- README | 2 +- src/login/pam_systemd.c | 42 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/README b/README index 4439be11f03..baabf69c7ca 100644 --- a/README +++ b/README @@ -170,7 +170,7 @@ REQUIREMENTS: dependencies: util-linux >= v2.27.1 required - dbus >= 1.9.14 (strictly speaking optional, but recommended) + dbus >= 1.4.0 (strictly speaking optional, but recommended) NOTE: If using dbus < 1.9.18, you should override the default policy directory (--with-dbuspolicydir=/etc/dbus-1/system.d). dracut (optional) diff --git a/src/login/pam_systemd.c b/src/login/pam_systemd.c index c7d9dcf4e20..cdec102cea1 100644 --- a/src/login/pam_systemd.c +++ b/src/login/pam_systemd.c @@ -190,6 +190,40 @@ static int get_seat_from_display(const char *display, const char **seat, uint32_ return 0; } +static int export_legacy_dbus_address( + pam_handle_t *handle, + uid_t uid, + const char *runtime) { + + _cleanup_free_ char *s = NULL; + int r = PAM_BUF_ERR; + + /* FIXME: We *really* should move the access() check into the + * daemons that spawn dbus-daemon, instead of forcing + * DBUS_SESSION_BUS_ADDRESS= here. */ + + s = strjoin(runtime, "/bus"); + if (!s) + goto error; + + if (access(s, F_OK) < 0) + return PAM_SUCCESS; + + s = mfree(s); + if (asprintf(&s, DEFAULT_USER_BUS_ADDRESS_FMT, runtime) < 0) + goto error; + + r = pam_misc_setenv(handle, "DBUS_SESSION_BUS_ADDRESS", s, 0); + if (r != PAM_SUCCESS) + goto error; + + return PAM_SUCCESS; + +error: + pam_syslog(handle, LOG_ERR, "Failed to set bus variable."); + return r; +} + static int append_session_memory_max(pam_handle_t *handle, sd_bus_message *m, const char *limit) { uint64_t val; int r; @@ -405,6 +439,10 @@ _public_ PAM_EXTERN int pam_sm_open_session( } } + r = export_legacy_dbus_address(handle, pw->pw_uid, rt); + if (r != PAM_SUCCESS) + return r; + return PAM_SUCCESS; } @@ -613,6 +651,10 @@ _public_ PAM_EXTERN int pam_sm_open_session( if (r != PAM_SUCCESS) return r; } + + r = export_legacy_dbus_address(handle, pw->pw_uid, runtime_path); + if (r != PAM_SUCCESS) + return r; } /* Most likely we got the session/type/class from environment variables, but might have gotten the data From 69bd76f2b90cd00c1596b2e2c05845a4d9596fd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 6 Jan 2019 17:37:00 +0100 Subject: [PATCH 2/2] pam_systemd: set $DBUS_SESSION_BUS_ADDRESS unconditionally There's very little lost if the variable is set for a socket that isn't connectible, but a lot lost (races, ...) if it's not set but the socket exists. Also, drop the FIXME note, since we don't plan to revert this revert any time soon. --- src/login/pam_systemd.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/login/pam_systemd.c b/src/login/pam_systemd.c index cdec102cea1..d466e509690 100644 --- a/src/login/pam_systemd.c +++ b/src/login/pam_systemd.c @@ -198,18 +198,6 @@ static int export_legacy_dbus_address( _cleanup_free_ char *s = NULL; int r = PAM_BUF_ERR; - /* FIXME: We *really* should move the access() check into the - * daemons that spawn dbus-daemon, instead of forcing - * DBUS_SESSION_BUS_ADDRESS= here. */ - - s = strjoin(runtime, "/bus"); - if (!s) - goto error; - - if (access(s, F_OK) < 0) - return PAM_SUCCESS; - - s = mfree(s); if (asprintf(&s, DEFAULT_USER_BUS_ADDRESS_FMT, runtime) < 0) goto error;