comparison testharness/src/bin/testharness.rs @ 171:e27c5c667a5a

Create full new types for return code and flags, separate end to end. This plumbs the ReturnCode and RawFlags types through the places where we call into or are called from PAM. Also adds Sun documentation to the project.
author Paul Fisher <paul@pfish.zone>
date Fri, 25 Jul 2025 20:52:14 -0400
parents 0cabe7b94a4f
children 6727cbe56f4a
comparison
equal deleted inserted replaced
170:f052e2417195 171:e27c5c667a5a
20 struct TestHarness { 20 struct TestHarness {
21 username_requested: Cell<bool>, 21 username_requested: Cell<bool>,
22 wrong_username: bool, 22 wrong_username: bool,
23 wrong_password: bool, 23 wrong_password: bool,
24 changing_password: Cell<bool>, 24 changing_password: Cell<bool>,
25 change_prompt_count: Cell<u8>, 25 change_prompt_count: Cell<usize>,
26 } 26 }
27 27
28 impl Conversation for &TestHarness { 28 impl Conversation for &TestHarness {
29 fn communicate(&self, messages: &[Exchange]) { 29 fn communicate(&self, messages: &[Exchange]) {
30 if let [only_msg] = messages { 30 if let [only_msg] = messages {
40 } 40 }
41 self.username_requested.set(true) 41 self.username_requested.set(true)
42 } 42 }
43 Exchange::MaskedPrompt(p) => { 43 Exchange::MaskedPrompt(p) => {
44 let answer = if self.changing_password.get() { 44 let answer = if self.changing_password.get() {
45 let prompts = self.change_prompt_count.get(); 45 let prompt_count = self.change_prompt_count.get();
46 eprintln!("CHANGING PASSWORD PROMPT {prompts}"); 46 eprintln!("CHANGING PASSWORD PROMPT {prompt_count}");
47 eprintln!("-> {p:?}"); 47 eprintln!("-> {p:?}");
48 self.change_prompt_count.set(prompts + 1); 48 self.change_prompt_count.set(prompt_count + 1);
49 match prompts { 49 // When changing passwords after logging in, Sun PAM
50 0 => "old token!", 50 // uses the existing authtok that was just entered as
51 1 => "mistake", 51 // the old_authtok. Other PAMs prompt the user to enter
52 2 => "mismatch", 52 // their existing password again.
53 3 => "old token!", 53 let responses: &[&str] = if cfg!(pam_impl = "Sun") {
54 4 => "acceptable", 54 &["mistake", "mismatch", "acceptable", "acceptable"]
55 5 => "acceptable", 55 } else {
56 _ => panic!("unexpected number of prompts!"), 56 &[
57 } 57 "old token!",
58 "mistake",
59 "mismatch",
60 "old token!",
61 "acceptable",
62 "acceptable",
63 ]
64 };
65 responses[prompt_count]
58 } else if self.wrong_password { 66 } else if self.wrong_password {
59 "bogus" 67 "bogus"
60 } else { 68 } else {
61 "valid" 69 "valid"
62 }; 70 };