Mercurial > crates > nonstick
view 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 |
line wrap: on
line source
//! FFI to the PAM library. use libc::c_char; use std::ffi::c_int; use std::marker::{PhantomData, PhantomPinned}; /// An opaque pointer given to us by PAM. #[repr(C)] pub struct Handle { _data: (), _marker: PhantomData<(*mut u8, PhantomPinned)>, } #[link(name = "pam")] extern "C" { pub fn pam_get_data( pamh: *const Handle, module_data_name: *const c_char, data: &mut *const libc::c_void, ) -> c_int; pub fn pam_set_data( pamh: *mut Handle, module_data_name: *const c_char, data: *const libc::c_void, cleanup: extern "C" fn( pamh: *const libc::c_void, data: *mut libc::c_void, error_status: c_int, ), ) -> c_int; pub fn pam_get_item( pamh: *const Handle, item_type: c_int, item: &mut *const libc::c_void, ) -> c_int; pub fn pam_set_item(pamh: *mut Handle, item_type: c_int, item: *const libc::c_void) -> c_int; pub fn pam_get_user( pamh: *const Handle, user: &mut *const c_char, prompt: *const c_char, ) -> c_int; pub fn pam_get_authtok( pamh: *const Handle, item_type: c_int, data: &mut *const c_char, prompt: *const c_char, ) -> c_int; pub fn pam_end(pamh: *mut Handle, status: c_int) -> c_int; }