Skip to content

Commit 48fad5f

Browse files
committed
Propagate all error kinds from pam::converse not just timeouts
This way they rather than silently discarding the error message and doing another authentication attempt, they properly report the error message and cause sudo to exit. This way for example pam_faillock won't cause a persistent error like incorrect SUDO_ASKPASS value (once implemented) to be treated as multiple successive failed password attempts.
1 parent 09635ec commit 48fad5f

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/pam/converse.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ pub(super) struct ConverserData<C> {
186186
// pam_authenticate does not return error codes returned by the conversation
187187
// function; these are set by the conversation function instead of returning
188188
// multiple error codes.
189-
pub(super) timed_out: bool,
189+
pub(super) error: Option<PamError>,
190190
pub(super) panicked: bool,
191191
}
192192

@@ -236,11 +236,10 @@ pub(super) unsafe extern "C" fn converse<C: Converser>(
236236
Ok(resp_buf) => {
237237
resp_bufs.push(resp_buf);
238238
}
239-
Err(PamError::TimedOut) => {
240-
app_data.timed_out = true;
239+
Err(err) => {
240+
app_data.error = Some(err);
241241
return PamErrorType::ConversationError;
242242
}
243-
Err(_) => return PamErrorType::ConversationError,
244243
}
245244
}
246245

@@ -417,7 +416,7 @@ mod test {
417416
converser_name: "tux".to_string(),
418417
no_interact: false,
419418
auth_prompt: Some("authenticate".to_owned()),
420-
timed_out: false,
419+
error: None,
421420
panicked: false,
422421
});
423422
let cookie = PamConvBorrow::new(hello.as_mut());

src/pam/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl PamContext {
8080
converser_name: converser_name.to_owned(),
8181
no_interact,
8282
auth_prompt: Some("authenticate".to_owned()),
83-
timed_out: false,
83+
error: None,
8484
panicked: false,
8585
}));
8686

@@ -176,8 +176,8 @@ impl PamContext {
176176
}
177177

178178
// SAFETY: self.data_ptr was created by Box::into_raw
179-
if unsafe { (*self.data_ptr).timed_out } {
180-
return Err(PamError::TimedOut);
179+
if let Some(error) = unsafe { (*self.data_ptr).error.take() } {
180+
return Err(error);
181181
}
182182

183183
#[allow(clippy::question_mark)]

0 commit comments

Comments
 (0)