chiark / gitweb /
bus: update kdbus.h (ABI break)
[elogind.git] / src / login / pam-module.c
index 45428a090f40e767bbd500350cc20f50efeab309..7400734fdc975f0c83eeb3dbc240c87cb66f7166 100644 (file)
@@ -120,7 +120,6 @@ static int get_seat_from_display(const char *display, const char **seat, uint32_
         _cleanup_free_ char *p = NULL, *tty = NULL;
         _cleanup_close_ int fd = -1;
         struct ucred ucred;
-        socklen_t l;
         int v, r;
 
         assert(display);
@@ -144,10 +143,9 @@ static int get_seat_from_display(const char *display, const char **seat, uint32_
         if (connect(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(sa.un.sun_path)) < 0)
                 return -errno;
 
-        l = sizeof(ucred);
-        r = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &l);
+        r = getpeercred(fd, &ucred);
         if (r < 0)
-                return -errno;
+                return r;
 
         r = get_ctty(ucred.pid, NULL, &tty);
         if (r < 0)
@@ -166,6 +164,34 @@ 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) {
+
+#ifdef ENABLE_KDBUS
+        _cleanup_free_ char *s = NULL;
+        int r;
+
+        /* skip export if kdbus is not active */
+        if (access("/dev/kdbus", F_OK) < 0)
+                return PAM_SUCCESS;
+
+        if (asprintf(&s, KERNEL_USER_BUS_FMT ";" UNIX_USER_BUS_FMT,
+                     (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,
@@ -234,6 +260,10 @@ _public_ PAM_EXTERN int pam_sm_open_session(
                                 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;
@@ -388,6 +418,10 @@ _public_ PAM_EXTERN int pam_sm_open_session(
                         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)) {