@@ -3,8 +3,8 @@ |
| 3 | //! Implements a state machine for PAM-based authentication with | 3 | //! Implements a state machine for PAM-based authentication with |
| 4 | //! proper conversation handling for the greeter. | 4 | //! proper conversation handling for the greeter. |
| 5 | | 5 | |
| 6 | -use anyhow::{Context, Result}; | 6 | +use anyhow::{anyhow, Result}; |
| 7 | -use pam_client::{Context as PamContext, Flag}; | 7 | +use pam::Client; |
| 8 | | 8 | |
| 9 | /// Service name for PAM configuration | 9 | /// Service name for PAM configuration |
| 10 | const PAM_SERVICE: &str = "gardm"; | 10 | const PAM_SERVICE: &str = "gardm"; |
@@ -146,23 +146,32 @@ impl AuthSession { |
| 146 | | 146 | |
| 147 | /// Perform PAM authentication (blocking) | 147 | /// Perform PAM authentication (blocking) |
| 148 | fn pam_authenticate(username: &str, password: &str) -> Result<()> { | 148 | fn pam_authenticate(username: &str, password: &str) -> Result<()> { |
| 149 | - use pam_client::conv_mock::Conversation; | 149 | + tracing::debug!(%username, password_len = password.len(), "Starting PAM authentication"); |
| 150 | | 150 | |
| 151 | - // Create conversation handler that provides the password | 151 | + // Create client with PasswordConv (non-interactive, uses provided password) |
| 152 | - let conv = Conversation::with_credentials(username, password); | 152 | + let mut client = Client::with_password(PAM_SERVICE) |
| | 153 | + .map_err(|e| anyhow!("Failed to create PAM client: {:?}", e))?; |
| 153 | | 154 | |
| 154 | - // Create PAM context | 155 | + // Set the credentials |
| 155 | - let mut ctx = PamContext::new(PAM_SERVICE, Some(username), conv) | 156 | + client |
| 156 | - .context("Failed to create PAM context")?; | 157 | + .conversation_mut() |
| | 158 | + .set_credentials(username, password); |
| | 159 | + |
| | 160 | + tracing::debug!("PAM client created, calling authenticate"); |
| 157 | | 161 | |
| 158 | // Authenticate | 162 | // Authenticate |
| 159 | - ctx.authenticate(Flag::NONE) | 163 | + client |
| 160 | - .context("PAM authentication failed")?; | 164 | + .authenticate() |
| | 165 | + .map_err(|e| anyhow!("PAM authentication failed: {:?}", e))?; |
| | 166 | + |
| | 167 | + tracing::debug!("PAM authenticate succeeded, opening session"); |
| 161 | | 168 | |
| 162 | - // Validate account (check expiry, etc.) | 169 | + // Open session (also does account validation) |
| 163 | - ctx.acct_mgmt(Flag::NONE) | 170 | + client |
| 164 | - .context("Account validation failed")?; | 171 | + .open_session() |
| | 172 | + .map_err(|e| anyhow!("Failed to open PAM session: {:?}", e))?; |
| 165 | | 173 | |
| | 174 | + tracing::debug!("PAM session opened successfully"); |
| 166 | Ok(()) | 175 | Ok(()) |
| 167 | } | 176 | } |
| 168 | | 177 | |