Mercurial > crates > nonstick
diff src/pam_ffi/mod.rs @ 73:ac6881304c78
Do conversations, along with way too much stuff.
This implements conversations, along with all the memory management
brouhaha that goes along with it. The conversation now lives directly
on the handle rather than being a thing you have to get from it
and then call manually. It Turns Out this makes things a lot easier!
I guess we reorganized things again. For the last time. For real.
I promise.
This all passes ASAN, so it seems Pretty Good!
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Thu, 05 Jun 2025 03:41:38 -0400 |
parents | 47eb242a4f88 |
children | c7c596e6388f |
line wrap: on
line diff
--- a/src/pam_ffi/mod.rs Wed Jun 04 03:53:36 2025 -0400 +++ b/src/pam_ffi/mod.rs Thu Jun 05 03:41:38 2025 -0400 @@ -9,95 +9,56 @@ #![allow(dead_code)] -pub mod memory; +mod conversation; +mod handle; +mod memory; mod message; mod response; -use crate::pam_ffi::memory::Immovable; -use crate::pam_ffi::message::OwnedMessages; -#[doc(inline)] -pub use message::Message; -#[doc(inline)] -pub use response::RawResponse; +pub use handle::{LibPamHandle, OwnedLibPamHandle}; use std::ffi::{c_char, c_int, c_void}; -/// An opaque structure that a PAM handle points to. -#[repr(C)] -pub struct LibPamHandle { - _data: (), - _marker: Immovable, -} - -/// An opaque structure that is passed through PAM in a conversation. -#[repr(C)] -pub struct AppData { - _data: (), - _marker: Immovable, -} - -/// The callback that PAM uses to get information in a conversation. -/// -/// - `num_msg` is the number of messages in the `pam_message` array. -/// - `messages` is a pointer to the messages being sent to the user. -/// For details about its structure, see the documentation of -/// [`OwnedMessages`](super::OwnedMessages). -/// - `responses` is a pointer to an array of [`RawResponse`]s, -/// which PAM sets in response to a module's request. -/// This is an array of structs, not an array of pointers to a struct. -/// There should always be exactly as many `responses` as `num_msg`. -/// - `appdata` is the `appdata` field of the [`LibPamConversation`] we were passed. -pub type ConversationCallback = extern "C" fn( - num_msg: c_int, - messages: &OwnedMessages, - responses: &mut *mut RawResponse, - appdata: *const AppData, -) -> c_int; - -/// The type used by libpam to call back into a conversation. -#[repr(C)] -pub struct LibPamConversation { - /// The function that is called to get information from the user. - callback: ConversationCallback, - /// The pointer that will be passed as the last parameter - /// to the conversation callback. - appdata: *const AppData, -} - #[link(name = "pam")] extern "C" { - pub fn pam_get_data( - pamh: *const LibPamHandle, + fn pam_get_data( + pamh: *mut LibPamHandle, module_data_name: *const c_char, data: &mut *const c_void, ) -> c_int; - pub fn pam_set_data( + fn pam_set_data( pamh: *mut LibPamHandle, module_data_name: *const c_char, data: *const c_void, cleanup: extern "C" fn(pamh: *const c_void, data: *mut c_void, error_status: c_int), ) -> c_int; - pub fn pam_get_item( - pamh: *mut LibPamHandle, - item_type: c_int, - item: &mut *const c_void, - ) -> c_int; + fn pam_get_item(pamh: *mut LibPamHandle, item_type: c_int, item: &mut *const c_void) -> c_int; - pub fn pam_set_item(pamh: *mut LibPamHandle, item_type: c_int, item: *const c_void) -> c_int; + fn pam_set_item(pamh: *mut LibPamHandle, item_type: c_int, item: *const c_void) -> c_int; - pub fn pam_get_user( + fn pam_get_user( pamh: *mut LibPamHandle, user: &mut *const c_char, prompt: *const c_char, ) -> c_int; - pub fn pam_get_authtok( + fn pam_get_authtok( pamh: *mut LibPamHandle, item_type: c_int, data: &mut *const c_char, prompt: *const c_char, ) -> c_int; - pub fn pam_end(pamh: *mut LibPamHandle, status: c_int) -> c_int; + fn pam_end(pamh: *mut LibPamHandle, status: c_int) -> c_int; + + // TODO: pam_authenticate - app + // pam_setcred - app + // pam_acct_mgmt - app + // pam_chauthtok - app + // pam_open_session - app + // pam_close_session - app + // pam_putenv - shared + // pam_getenv - shared + // pam_getenvlist - shared }