comparison src/libpam/module.rs @ 143:ebb71a412b58

Turn everything into OsString and Just Walk Out! for strings with nul. To reduce the hazard surface of the API, this replaces most uses of &str with &OsStr (and likewise with String/OsString). Also, I've decided that instead of dealing with callers putting `\0` in their parameters, I'm going to follow the example of std::env and Just Walk Out! (i.e., panic!()). This makes things a lot less annoying for both me and (hopefully) users.
author Paul Fisher <paul@pfish.zone>
date Sat, 05 Jul 2025 22:12:46 -0400
parents a508a69c068a
children 56b559b7ecea
comparison
equal deleted inserted replaced
142:5c1e315c18ff 143:ebb71a412b58
20 /// struct MyPamModule; 20 /// struct MyPamModule;
21 /// pam_hooks!(MyPamModule); 21 /// pam_hooks!(MyPamModule);
22 /// 22 ///
23 /// impl<T: PamHandleModule> PamModule<T> for MyPamModule { 23 /// impl<T: PamHandleModule> PamModule<T> for MyPamModule {
24 /// fn authenticate(handle: &mut T, args: Vec<&CStr>, flags: Flags) -> PamResult<()> { 24 /// fn authenticate(handle: &mut T, args: Vec<&CStr>, flags: Flags) -> PamResult<()> {
25 /// let password = handle.authtok(Some("what's your password?"))?; 25 /// let password = handle.authtok(Some("what's your password?".as_ref()))?;
26 /// let response = 26 /// let response =
27 /// format!("If you say your password is {password:?}, who am I to disagree?"); 27 /// format!("If you say your password is {password:?}, who am I to disagree?");
28 /// handle.info_msg(&response); 28 /// handle.info_msg(&response);
29 /// Ok(()) 29 /// Ok(())
30 /// } 30 /// }
31 /// 31 ///
32 /// fn account_management(handle: &mut T, args: Vec<&CStr>, flags: Flags) -> PamResult<()> { 32 /// fn account_management(handle: &mut T, args: Vec<&CStr>, flags: Flags) -> PamResult<()> {
33 /// let username = handle.username(None)?; 33 /// let username = handle.username(None)?;
34 /// let response = format!("Hello {username}! I trust you unconditionally."); 34 /// let response = format!("Hello {username:?}! I trust you unconditionally.");
35 /// handle.info_msg(&response); 35 /// handle.info_msg(&response);
36 /// Ok(()) 36 /// Ok(())
37 /// } 37 /// }
38 /// } 38 /// }
39 /// ``` 39 /// ```