gardesk/gardm / adee740

Browse files

main: Pass password to session spawner

Connect the authentication module to the session spawner by:
- Adding password field to SessionStartInfo (with redacted Debug impl)
- Passing password to UserSession::start() for both X11 and Wayland
- Improved error handling for Wayland session failures with X restart
- Add debug logging for session startup flow
Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
adee740243dadbe9c027f872db21f20e64990f3e
Parents
c1683bc
Tree
36eb0b4

1 changed file

StatusFile+-
M gardmd/src/main.rs 64 8
gardmd/src/main.rsmodified
@@ -182,14 +182,30 @@ async fn run_display_manager(args: Args, config: Config) -> Result<()> {
182182
             tracing::warn!(error = %e, "Failed to kill greeter");
183183
         }
184184
 
185
+        eprintln!("[MAIN] Greeter session ended, processing result");
186
+        tracing::debug!(?session_result, "Greeter session ended, processing result");
187
+
185188
         match session_result {
186189
             Ok(Some(session_info)) => {
190
+                eprintln!("[MAIN] Got session_info: {} {:?} ({})",
191
+                    session_info.username, session_info.cmd, session_info.session_type);
192
+                tracing::info!(
193
+                    "Processing session start: {} {:?} ({})",
194
+                    session_info.username,
195
+                    session_info.cmd,
196
+                    session_info.session_type
197
+                );
187198
                 let vt = x_server.as_ref().map(|x| x.vt()).unwrap_or(1);
188199
                 let is_wayland = session_info.session_type == "wayland";
189200
 
190201
                 if is_wayland {
191202
                     // WAYLAND SESSION: Stop X server first, then start compositor
192
-                    tracing::info!("Wayland session selected, stopping X server");
203
+                    tracing::info!(
204
+                        username = %session_info.username,
205
+                        cmd = ?session_info.cmd,
206
+                        vt,
207
+                        "Wayland session selected, stopping X server"
208
+                    );
193209
 
194210
                     // Stop X server - compositor needs direct VT access
195211
                     if let Some(x) = x_server.take() {
@@ -198,13 +214,29 @@ async fn run_display_manager(args: Args, config: Config) -> Result<()> {
198214
                     }
199215
 
200216
                     // Start Wayland compositor directly on VT
201
-                    let mut session = UserSession::start(
217
+                    tracing::info!("Starting Wayland compositor");
218
+                    let mut session = match UserSession::start(
202219
                         &session_info.username,
220
+                        &session_info.password,
203221
                         &session_info.cmd,
204222
                         "wayland",
205223
                         None, // No DISPLAY for Wayland
206224
                         vt,
207
-                    )?;
225
+                    ) {
226
+                        Ok(s) => {
227
+                            tracing::info!(pid = s.pid(), "Wayland session started successfully");
228
+                            s
229
+                        }
230
+                        Err(e) => {
231
+                            tracing::error!(error = %e, "Failed to start Wayland session");
232
+                            // Restart X server and try again with greeter
233
+                            tracing::info!("Restarting X server after Wayland session failure");
234
+                            let new_x = XServer::start(&x_display, vt)?;
235
+                            vt::switch_to_vt(vt)?;
236
+                            x_server = Some(new_x);
237
+                            continue;
238
+                        }
239
+                    };
208240
 
209241
                     // Wait for session to end
210242
                     let session_ended = tokio::select! {
@@ -235,6 +267,7 @@ async fn run_display_manager(args: Args, config: Config) -> Result<()> {
235267
                     // X11 SESSION: Keep X server running (existing behavior)
236268
                     let mut session = UserSession::start(
237269
                         &session_info.username,
270
+                        &session_info.password,
238271
                         &session_info.cmd,
239272
                         "x11",
240273
                         Some(&x_display),
@@ -278,10 +311,22 @@ async fn run_display_manager(args: Args, config: Config) -> Result<()> {
278311
 /// Information needed to start a user session
279312
 struct SessionStartInfo {
280313
     username: String,
314
+    password: String, // Needed for PAM open_session in child process
281315
     cmd: Vec<String>,
282316
     session_type: String,
283317
 }
284318
 
319
+impl std::fmt::Debug for SessionStartInfo {
320
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
321
+        f.debug_struct("SessionStartInfo")
322
+            .field("username", &self.username)
323
+            .field("password", &"[REDACTED]")
324
+            .field("cmd", &self.cmd)
325
+            .field("session_type", &self.session_type)
326
+            .finish()
327
+    }
328
+}
329
+
285330
 /// Handle greeter IPC until we get a successful auth and StartSession
286331
 async fn handle_greeter_session(
287332
     server: &ipc::Server,
@@ -298,9 +343,20 @@ async fn handle_greeter_session(
298343
 
299344
         let (response, session_info) = handle_greeter_request(request, &mut auth).await;
300345
 
346
+        eprintln!("[IPC] About to send response, has_session_info={}", session_info.is_some());
347
+        tracing::debug!(?response, has_session_info = session_info.is_some(), "Sending response to greeter");
301348
         conn.send(&response).await?;
349
+        eprintln!("[IPC] Response sent successfully");
350
+        tracing::debug!("Response sent successfully");
302351
 
303352
         if let Some(info) = session_info {
353
+            eprintln!("[IPC] Returning session info: {} {:?}", info.username, info.cmd);
354
+            tracing::info!(
355
+                username = %info.username,
356
+                cmd = ?info.cmd,
357
+                session_type = %info.session_type,
358
+                "Returning session info to main loop"
359
+            );
304360
             return Ok(Some(info));
305361
         }
306362
     }
@@ -336,12 +392,12 @@ async fn handle_greeter_request(
336392
         }
337393
 
338394
         Request::StartSession { cmd, session_type, env: _ } => {
339
-            if let Some(username) = auth.take_authenticated() {
395
+            tracing::debug!("Processing StartSession request");
396
+            if let Some((username, password)) = auth.take_authenticated() {
340397
                 tracing::info!(%username, ?cmd, %session_type, "Session start requested");
341
-                (
342
-                    Response::Success,
343
-                    Some(SessionStartInfo { username, cmd, session_type }),
344
-                )
398
+                let info = SessionStartInfo { username, password, cmd, session_type };
399
+                tracing::debug!(?info, "Created SessionStartInfo");
400
+                (Response::Success, Some(info))
345401
             } else {
346402
                 (
347403
                     Response::Error {