From: Werner Fink <werner@suse.de>
Date: Wed Feb 26 14:36:27 UTC 2014
Subject: Do not clobber XDG_RUNTIME_DIR if su command preserve environment

Make sure that even if a su command without option -l or with option -m
is used, the XDG_RUNTIME_DIR will not be clobbered by the new uid.

This belongs to BNC#852015 and also to BNC#855160

---
 pam-module.c |   19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

--- systemd-209/src/login/pam-module.c
+++ systemd-209/src/login/pam-module.c	2014-02-26 14:31:30.158235525 +0000
@@ -447,6 +447,25 @@ _public_ PAM_EXTERN int pam_sm_open_sess
                 r = export_legacy_dbus_address(handle, pw->pw_uid, runtime_path);
                 if (r != PAM_SUCCESS)
                         return r;
+        } else if (getenv("XDG_RUNTIME_DIR")) {
+                _cleanup_free_ char *p = NULL;
+                
+                /* Make sure that after running YaST2 or the xdg-su scripts
+                 * the runtime directory is not clobbered. Even a normal su
+                 * command without -l or with -m may clobber. */
+
+                if ((r = asprintf(&p, "/run/user/%lu", (unsigned long)pw->pw_uid)) < 0)
+                        return PAM_BUF_ERR;
+
+                r = pam_misc_setenv(handle, "XDG_RUNTIME_DIR", p, 0);
+                if (r != PAM_SUCCESS) {
+                        pam_syslog(handle, LOG_ERR, "Failed to set runtime dir.");
+                        return r;
+                }
+
+                r = export_legacy_dbus_address(handle, pw->pw_uid, p);
+                if (r != PAM_SUCCESS)
+                        return r;
         }
 
         if (!isempty(seat)) {
