chiark / gitweb /
pam_systemd: export DBUS_SESSION_BUS_ADDRESS
[elogind.git] / src / login / pam-module.c
index 89623aa765747e5bc93c0e2a3191dba3eb8f2b7d..c67e677384b11e0ce4b37c5ec099786924838dfb 100644 (file)
@@ -164,6 +164,30 @@ static int get_seat_from_display(const char *display, const char **seat, uint32_
         return 0;
 }
 
         return 0;
 }
 
+static int export_legacy_dbus_address(
+                pam_handle_t *handle,
+                uid_t uid,
+                const char *runtime) {
+
+#ifdef ENABLE_KDBUS
+        _cleanup_free_ char *s = NULL;
+        int r;
+
+        if (asprintf(&s, "kernel:path=/dev/kdbus/%lu-user/bus;unix:path=%s/bus",
+                     (unsigned long) uid, runtime) < 0) {
+                pam_syslog(handle, LOG_ERR, "Failed to set bus variable.");
+                return PAM_BUF_ERR;
+        }
+
+        r = pam_misc_setenv(handle, "DBUS_SESSION_BUS_ADDRESS", s, 0);
+        if (r != PAM_SUCCESS) {
+                pam_syslog(handle, LOG_ERR, "Failed to set bus variable.");
+                return r;
+        }
+#endif
+        return PAM_SUCCESS;
+}
+
 _public_ PAM_EXTERN int pam_sm_open_session(
                 pam_handle_t *handle,
                 int flags,
 _public_ PAM_EXTERN int pam_sm_open_session(
                 pam_handle_t *handle,
                 int flags,
@@ -232,6 +256,10 @@ _public_ PAM_EXTERN int pam_sm_open_session(
                                 pam_syslog(handle, LOG_ERR, "Failed to set runtime dir.");
                                 return r;
                         }
                                 pam_syslog(handle, LOG_ERR, "Failed to set runtime dir.");
                                 return r;
                         }
+
+                        r = export_legacy_dbus_address(handle, pw->pw_uid, rt);
+                        if (r != PAM_SUCCESS)
+                                return r;
                 }
 
                 return PAM_SUCCESS;
                 }
 
                 return PAM_SUCCESS;
@@ -386,6 +414,10 @@ _public_ PAM_EXTERN int pam_sm_open_session(
                         pam_syslog(handle, LOG_ERR, "Failed to set runtime dir.");
                         return r;
                 }
                         pam_syslog(handle, LOG_ERR, "Failed to set runtime dir.");
                         return r;
                 }
+
+                r = export_legacy_dbus_address(handle, pw->pw_uid, runtime_path);
+                if (r != PAM_SUCCESS)
+                        return r;
         }
 
         if (!isempty(seat)) {
         }
 
         if (!isempty(seat)) {