]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pam_systemd: clean up success path 15864/head
authorLennart Poettering <lennart@poettering.net>
Thu, 7 May 2020 10:53:51 +0000 (12:53 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 19 May 2020 22:47:37 +0000 (00:47 +0200)
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

index 96ce4742f01171df40e135112d2a9946ae508934..64771153cd960d2ba471805cf4ce4a5267bd7f01 100644 (file)
@@ -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;