Mercurial > crates > nonstick
comparison src/libpam/module.rs @ 146:1bc52025156b
Split PAM items into their own separate struct.
To trim down the number of methods on `PamShared`, this puts all the
Items into their own struct(s). This also makes the split between
authtok/authtok_item easier to understand.
| author | Paul Fisher <paul@pfish.zone> |
|---|---|
| date | Sun, 06 Jul 2025 19:10:26 -0400 |
| parents | 56b559b7ecea |
| children | 2f5913131295 |
comparison
equal
deleted
inserted
replaced
| 145:8f964b701652 | 146:1bc52025156b |
|---|---|
| 9 /// Here is full example of a PAM module that would authenticate | 9 /// Here is full example of a PAM module that would authenticate |
| 10 /// and authorize everybody: | 10 /// and authorize everybody: |
| 11 /// | 11 /// |
| 12 /// ```no_run | 12 /// ```no_run |
| 13 /// use nonstick::{ | 13 /// use nonstick::{ |
| 14 /// pam_hooks, ConversationAdapter, Flags, LibPamTransaction, PamHandleModule, PamModule, | 14 /// pam_hooks, ConversationAdapter, Flags, LibPamTransaction, ModuleClient, PamModule, |
| 15 /// Result as PamResult, | 15 /// Result as PamResult, |
| 16 /// }; | 16 /// }; |
| 17 /// use std::ffi::CStr; | 17 /// use std::ffi::CStr; |
| 18 /// # fn main() {} | 18 /// # fn main() {} |
| 19 /// | 19 /// |
| 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: ModuleClient> 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?".as_ref()))?; | 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); |
| 149 } | 149 } |
| 150 | 150 |
| 151 #[cfg(test)] | 151 #[cfg(test)] |
| 152 mod tests { | 152 mod tests { |
| 153 // Compile-time test that the `pam_hooks` macro compiles. | 153 // Compile-time test that the `pam_hooks` macro compiles. |
| 154 use crate::{PamHandleModule, PamModule}; | 154 use crate::{ModuleClient, PamModule}; |
| 155 struct Foo; | 155 struct Foo; |
| 156 impl<T: PamHandleModule> PamModule<T> for Foo {} | 156 impl<T: ModuleClient> PamModule<T> for Foo {} |
| 157 | 157 |
| 158 pam_hooks!(Foo); | 158 pam_hooks!(Foo); |
| 159 } | 159 } |
