Mercurial > crates > nonstick
comparison src/pam_ffi.rs @ 66:a674799a5cd3
Make `PamHandle` and `PamModuleHandle` traits.
This creates traits for PAM functionality and pulls the definitions
of that functionality out of the original `PamHandle` (renamed to
`LibPamHandle`) and into those traits. This supports testing PAM
module implementations using mock PAM library implementations.
Also uses a better representation of opaque pointers.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Tue, 27 May 2025 14:37:28 -0400 |
parents | bbe84835d6db |
children |
comparison
equal
deleted
inserted
replaced
65:8e507c7af9cf | 66:a674799a5cd3 |
---|---|
1 //! FFI to the PAM library. | 1 //! FFI to the PAM library. |
2 | 2 |
3 use libc::c_char; | 3 use libc::c_char; |
4 use std::ffi::c_int; | 4 use std::ffi::c_int; |
5 use std::marker::{PhantomData, PhantomPinned}; | |
6 | |
7 /// An opaque pointer given to us by PAM. | |
8 #[repr(C)] | |
9 pub struct Handle { | |
10 _data: (), | |
11 _marker: PhantomData<(*mut u8, PhantomPinned)>, | |
12 } | |
5 | 13 |
6 #[link(name = "pam")] | 14 #[link(name = "pam")] |
7 extern "C" { | 15 extern "C" { |
8 pub fn pam_get_data( | 16 pub fn pam_get_data( |
9 pamh: *const libc::c_void, | 17 pamh: *const Handle, |
10 module_data_name: *const c_char, | 18 module_data_name: *const c_char, |
11 data: &mut *const libc::c_void, | 19 data: &mut *const libc::c_void, |
12 ) -> c_int; | 20 ) -> c_int; |
13 | 21 |
14 pub fn pam_set_data( | 22 pub fn pam_set_data( |
15 pamh: *mut libc::c_void, | 23 pamh: *mut Handle, |
16 module_data_name: *const c_char, | 24 module_data_name: *const c_char, |
17 data: *const libc::c_void, | 25 data: *const libc::c_void, |
18 cleanup: extern "C" fn( | 26 cleanup: extern "C" fn( |
19 pamh: *const libc::c_void, | 27 pamh: *const libc::c_void, |
20 data: *mut libc::c_void, | 28 data: *mut libc::c_void, |
21 error_status: c_int, | 29 error_status: c_int, |
22 ), | 30 ), |
23 ) -> c_int; | 31 ) -> c_int; |
24 | 32 |
25 pub fn pam_get_item( | 33 pub fn pam_get_item( |
26 pamh: *const libc::c_void, | 34 pamh: *const Handle, |
27 item_type: c_int, | 35 item_type: c_int, |
28 item: &mut *const libc::c_void, | 36 item: &mut *const libc::c_void, |
29 ) -> c_int; | 37 ) -> c_int; |
30 | 38 |
31 pub fn pam_set_item( | 39 pub fn pam_set_item(pamh: *mut Handle, item_type: c_int, item: *const libc::c_void) -> c_int; |
32 pamh: *mut libc::c_void, | |
33 item_type: c_int, | |
34 item: *const libc::c_void, | |
35 ) -> c_int; | |
36 | 40 |
37 pub fn pam_get_user( | 41 pub fn pam_get_user( |
38 pamh: *const libc::c_void, | 42 pamh: *const Handle, |
39 user: &mut *const c_char, | 43 user: &mut *const c_char, |
40 prompt: *const c_char, | 44 prompt: *const c_char, |
41 ) -> c_int; | 45 ) -> c_int; |
42 | 46 |
43 pub fn pam_get_authtok( | 47 pub fn pam_get_authtok( |
44 pamh: *const libc::c_void, | 48 pamh: *const Handle, |
45 item_type: c_int, | 49 item_type: c_int, |
46 data: &mut *const c_char, | 50 data: &mut *const c_char, |
47 prompt: *const c_char, | 51 prompt: *const c_char, |
48 ) -> c_int; | 52 ) -> c_int; |
53 | |
54 pub fn pam_end(pamh: *mut Handle, status: c_int) -> c_int; | |
49 } | 55 } |