Mercurial > crates > nonstick
comparison src/libpam/module.rs @ 77:351bdc13005e
Update the libpam module to work with the new structure.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Sun, 08 Jun 2025 01:03:46 -0400 |
parents | c30811b4afae |
children | 002adfb98c5c |
comparison
equal
deleted
inserted
replaced
76:e58d24849e82 | 77:351bdc13005e |
---|---|
1 use std::ffi::CStr; | |
2 | |
3 /// Generates the dynamic library entry points for a [PamModule] implementation. | 1 /// Generates the dynamic library entry points for a [PamModule] implementation. |
4 /// | 2 /// |
5 /// Calling `pam_hooks!(SomeType)` on a type that implements [PamModule] will | 3 /// Calling `pam_hooks!(SomeType)` on a type that implements [PamModule] will |
6 /// generate the exported `extern "C"` functions that PAM uses to call into | 4 /// generate the exported `extern "C"` functions that PAM uses to call into |
7 /// your module. | 5 /// your module. |
8 /// | 6 /// |
9 /// ## Examples: | 7 /// ## Examples: |
10 /// | 8 /// |
11 /// Here is full example of a PAM module that would authenticate and authorize everybody: | 9 /// Here is full example of a PAM module that would authenticate and authorize everybody: |
12 /// | 10 /// |
13 /// ``` | 11 /// ```no_run |
14 /// use nonstick::{Flags, OwnedLibPamHandle, PamModule, PamHandleModule, Result as PamResult, pam_hooks}; | 12 /// use nonstick::{Flags, SimpleConversation, OwnedLibPamHandle, PamModule, PamHandleModule, Result as PamResult, pam_hooks}; |
15 /// use std::ffi::CStr; | 13 /// use std::ffi::CStr; |
16 /// # fn main() {} | 14 /// # fn main() {} |
17 /// | 15 /// |
18 /// struct MyPamModule; | 16 /// struct MyPamModule; |
19 /// pam_hooks!(MyPamModule); | 17 /// pam_hooks!(MyPamModule); |
20 /// | 18 /// |
21 /// impl<T: PamHandleModule> PamModule<T> for MyPamModule { | 19 /// impl<T: PamHandleModule> PamModule<T> for MyPamModule { |
22 /// fn authenticate(handle: &mut T, args: Vec<&CStr>, flags: Flags) -> PamResult<()> { | 20 /// fn authenticate(handle: &mut T, args: Vec<&CStr>, flags: Flags) -> PamResult<()> { |
23 /// let password = handle.get_authtok(Some("what's your password?"))?; | 21 /// let password = handle.get_authtok(Some("what's your password?"))?; |
24 /// handle.info_msg(fmt!("If you say your password is {password:?}, who am I to disagree?")); | 22 /// let response = format!("If you say your password is {password:?}, who am I to disagree?"); |
23 /// handle.info_msg(&response); | |
24 /// Ok(()) | |
25 /// } | 25 /// } |
26 /// | 26 /// |
27 /// fn account_management(handle: &mut T, args: Vec<&CStr>, flags: Flags) -> PamResult<()> { | 27 /// fn account_management(handle: &mut T, args: Vec<&CStr>, flags: Flags) -> PamResult<()> { |
28 /// let username = handle.get_user(None)?; | 28 /// let username = handle.get_user(None)?; |
29 /// handle.info_msg(fmt!("Hello {username}! I trust you unconditionally.")) | 29 /// let response = format!("Hello {username}! I trust you unconditionally."); |
30 /// handle.info_msg(&response); | |
30 /// Ok(()) | 31 /// Ok(()) |
31 /// } | 32 /// } |
32 /// } | 33 /// } |
33 /// ``` | 34 /// ``` |
34 #[macro_export] | 35 #[macro_export] |