From e945dd9eedb4feb8fbc94f3e8579586f98fe10f2 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 7 May 2020 12:53:51 +0200 Subject: [PATCH] pam_systemd: clean up success path Let's make sure we always apply the process properties from the user record, in all our three successful paths: 1. when we register a regular session 2. when we run for the systemd --user session 3. when we have no logind (but might still have complex user records from elsewhere) and thus exit early --- src/login/pam_systemd.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/login/pam_systemd.c b/src/login/pam_systemd.c index 96ce4742f01..64771153cd9 100644 --- a/src/login/pam_systemd.c +++ b/src/login/pam_systemd.c @@ -647,10 +647,6 @@ _public_ PAM_EXTERN int pam_sm_open_session( assert(handle); - /* Make this a NOP on non-logind systems */ - if (!logind_running()) - return PAM_SUCCESS; - if (parse_argv(handle, argc, argv, &class_pam, @@ -666,6 +662,10 @@ _public_ PAM_EXTERN int pam_sm_open_session( if (r != PAM_SUCCESS) return r; + /* Make most of this a NOP on non-logind systems */ + if (!logind_running()) + goto success; + /* Make sure we don't enter a loop by talking to * systemd-logind when it is actually waiting for the * background to finish start-up. If the service is @@ -689,11 +689,7 @@ _public_ PAM_EXTERN int pam_sm_open_session( if (r != PAM_SUCCESS) return r; - r = apply_user_record_settings(handle, ur, debug); - if (r != PAM_SUCCESS) - return r; - - return PAM_SUCCESS; + goto success; } /* Otherwise, we ask logind to create a session for us */ @@ -847,7 +843,9 @@ _public_ PAM_EXTERN int pam_sm_open_session( if (sd_bus_error_has_name(&error, BUS_ERROR_SESSION_BUSY)) { if (debug) pam_syslog(handle, LOG_DEBUG, "Not creating session: %s", bus_error_message(&error, r)); - return PAM_SUCCESS; + + /* We are already in a session, don't do anything */ + goto success; } else { pam_syslog(handle, LOG_ERR, "Failed to create session: %s", bus_error_message(&error, r)); return PAM_SESSION_ERR; @@ -944,6 +942,7 @@ _public_ PAM_EXTERN int pam_sm_open_session( } } +success: r = apply_user_record_settings(handle, ur, debug); if (r != PAM_SUCCESS) return r; -- 2.47.3