ryantimwilson / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone
Blob Blame History Raw
From 05188f9029780396097d5355198b8ec818852353 Mon Sep 17 00:00:00 2001
From: Ryan Wilson <ryantimwilson@meta.com>
Date: Tue, 12 Nov 2024 22:17:53 -0800
Subject: [PATCH] pam_systemd: Make pam_systemd 256 backwards compatible to
 logind 255

---
 src/login/pam_systemd.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/src/login/pam_systemd.c b/src/login/pam_systemd.c
index a711c89b12..7222d5a0df 100644
--- a/src/login/pam_systemd.c
+++ b/src/login/pam_systemd.c
@@ -1124,6 +1124,25 @@ _public_ PAM_EXTERN int pam_sm_open_session(
 
                 r = sd_bus_call(bus, m, LOGIN_SLOW_BUS_CALL_TIMEOUT_USEC, &error, &reply);
         }
+        if (r < 0 && sd_bus_error_has_name(&error, SD_BUS_ERROR_INVALID_ARGS)) {
+                SessionContext context2 = context;
+                context2.class = "";
+
+                sd_bus_error_free(&error);
+                pam_debug_syslog(handle, debug,
+                                 "New session classes are not available, retrying after unsetting class.");
+
+                m = sd_bus_message_unref(m);
+                r = create_session_message(bus,
+                                           handle,
+                                           &context2,
+                                           /* avoid_pidfd = */ true,
+                                           &m);
+                if (r < 0)
+                        return pam_bus_log_create_error(handle, r);
+
+                r = sd_bus_call(bus, m, LOGIN_SLOW_BUS_CALL_TIMEOUT_USEC, &error, &reply);
+        }
         if (r < 0) {
                 if (sd_bus_error_has_name(&error, BUS_ERROR_SESSION_BUSY)) {
                         /* We are already in a session, don't do anything */
-- 
2.43.5