]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pam-systemd: modernize export_legacy_dbus_address() a bit
authorLennart Poettering <lennart@poettering.net>
Wed, 26 Feb 2025 17:13:10 +0000 (18:13 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 26 Feb 2025 17:29:19 +0000 (18:29 +0100)
Let's log about unexpected access() failures among other things

src/login/pam_systemd.c

index eca3283da8e65dfbf0806e4884bccb32b3e60c21..280e0a506d83fe9d16eb0ea83d9b73028ae42771 100644 (file)
@@ -370,14 +370,14 @@ static int export_legacy_dbus_address(
                 pam_handle_t *handle,
                 const char *runtime) {
 
-        const char *s;
-        _cleanup_free_ char *t = NULL;
-        int r = PAM_BUF_ERR;
+        int r;
+
+        assert(handle);
 
         /* We need to export $DBUS_SESSION_BUS_ADDRESS because various applications will not connect
-         * correctly to the bus without it. This setting matches what dbus.socket does for the user
-         * session using 'systemctl --user set-environment'. We want to have the same configuration
-         * in processes started from the PAM session.
+         * correctly to the bus without it. This setting matches what dbus.socket does for the user session
+         * using 'systemctl --user set-environment'. We want to have the same configuration in processes
+         * started from the PAM session.
          *
          * The setting of the address is guarded by the access() check because it is also possible to compile
          * dbus without --enable-user-session, in which case this socket is not used, and
@@ -386,14 +386,22 @@ static int export_legacy_dbus_address(
          * expect the socket to be present by the time we do this check, so we can just as well check once
          * here. */
 
-        s = strjoina(runtime, "/bus");
-        if (access(s, F_OK) < 0)
+        if (!runtime)
                 return PAM_SUCCESS;
 
+        const char *s = strjoina(runtime, "/bus");
+        if (access(s, F_OK) < 0)  {
+                if (errno != ENOENT)
+                        pam_syslog_errno(handle, LOG_WARNING, errno, "Failed to check if %s/bus exists, ignoring: %m", runtime);
+
+                return PAM_SUCCESS;
+        }
+
+        _cleanup_free_ char *t = NULL;
         if (asprintf(&t, DEFAULT_USER_BUS_ADDRESS_FMT, runtime) < 0)
                 return pam_log_oom(handle);
 
-        r = pam_misc_setenv(handle, "DBUS_SESSION_BUS_ADDRESS", t, 0);
+        r = pam_misc_setenv(handle, "DBUS_SESSION_BUS_ADDRESS", t, /* readonly= */ false);
         if (r != PAM_SUCCESS)
                 return pam_syslog_pam_error(handle, LOG_ERR, r, "Failed to set bus variable: @PAMERR@");