Mercurial > crates > nonstick
comparison src/libpam/pam_ffi.rs @ 89:dd3e9c4bcde3
Simplify memory management in Questions.
When we're sending Questions to the client, we don't need them to be
C-managed, we just need the pointers going to the right place.
This replaces a bunch of Question management cruft with Vecs and Boxes.
| author | Paul Fisher <paul@pfish.zone> |
|---|---|
| date | Fri, 13 Jun 2025 05:22:48 -0400 |
| parents | 05291b601f0a |
| children | f6186e41399b |
comparison
equal
deleted
inserted
replaced
| 88:c9fc7e6257d3 | 89:dd3e9c4bcde3 |
|---|---|
| 28 #[derive(Debug)] | 28 #[derive(Debug)] |
| 29 pub struct Answer { | 29 pub struct Answer { |
| 30 /// Pointer to the data returned in an answer. | 30 /// Pointer to the data returned in an answer. |
| 31 /// For most answers, this will be a [`CStr`](std::ffi::CStr), | 31 /// For most answers, this will be a [`CStr`](std::ffi::CStr), |
| 32 /// but for [`BinaryQAndA`](crate::conv::BinaryQAndA)s (a Linux-PAM extension), | 32 /// but for [`BinaryQAndA`](crate::conv::BinaryQAndA)s (a Linux-PAM extension), |
| 33 /// this will be [`CBinaryData`](crate::libpam::memory::CBinaryData) | 33 /// this will be [`CBinaryData`](crate::libpam::memory::CBinaryData). |
| 34 /// | |
| 35 /// No matter what, this can be freed with a simple [`libc::free`]. | |
| 34 pub data: *mut c_void, | 36 pub data: *mut c_void, |
| 35 /// Unused. | 37 /// Unused. Just here for the padding. |
| 36 return_code: c_int, | 38 return_code: c_int, |
| 37 _marker: Immovable, | 39 _marker: Immovable, |
| 38 } | 40 } |
| 39 | 41 |
| 40 /// A question sent by PAM or a module to an application. | 42 /// A question sent by PAM or a module to an application. |
| 41 /// | 43 /// |
| 42 /// PAM refers to this as a "message", but we call it a question | 44 /// PAM refers to this as a "message", but we call it a question |
| 43 /// to avoid confusion with [`Message`](crate::Message). | 45 /// to avoid confusion with [`Message`](crate::conv::Message). |
| 44 /// | 46 /// |
| 45 /// This question, and its internal data, is owned by its creator | 47 /// This question, and its internal data, is owned by its creator |
| 46 /// (either the module or PAM itself). | 48 /// (either the module or PAM itself). |
| 47 #[repr(C)] | 49 #[repr(C)] |
| 50 #[derive(Debug)] | |
| 48 pub struct Question { | 51 pub struct Question { |
| 49 /// The style of message to request. | 52 /// The style of message to request. |
| 50 pub style: c_uint, | 53 pub style: c_uint, |
| 51 /// A description of the data requested. | 54 /// A description of the data requested. |
| 52 /// | 55 /// |
| 53 /// For most requests, this will be an owned [`CStr`](std::ffi::CStr), but for requests | 56 /// For most requests, this will be an owned [`CStr`](std::ffi::CStr), |
| 54 /// with [`Style::BinaryPrompt`], this will be [`CBinaryData`] | 57 /// but for requests with style `PAM_BINARY_PROMPT`, |
| 55 /// (a Linux-PAM extension). | 58 /// this will be `CBinaryData` (a Linux-PAM extension). |
| 56 pub data: *mut c_void, | 59 pub data: *mut c_void, |
| 57 pub _marker: Immovable, | 60 pub _marker: Immovable, |
| 58 } | 61 } |
| 59 | 62 |
| 60 /// The callback that PAM uses to get information in a conversation. | 63 /// The callback that PAM uses to get information in a conversation. |
| 61 /// | 64 /// |
| 62 /// - `num_msg` is the number of messages in the `pam_message` array. | 65 /// - `num_msg` is the number of messages in the `questions` array. |
| 63 /// - `questions` is a pointer to the [`Question`]s being sent to the user. | 66 /// - `questions` is a pointer to the [`Question`]s being sent to the user. |
| 64 /// For information about its structure, | 67 /// For information about its structure, |
| 65 /// see [`GenericQuestions`](super::question::GenericQuestions). | 68 /// see [`QuestionsTrait`](super::question::QuestionsTrait). |
| 66 /// - `answers` is a pointer to an array of [`Answer`]s, | 69 /// - `answers` is a pointer to an array of [`Answer`]s, |
| 67 /// which PAM sets in response to a module's request. | 70 /// which PAM sets in response to a module's request. |
| 68 /// This is an array of structs, not an array of pointers to a struct. | 71 /// This is an array of structs, not an array of pointers to a struct. |
| 69 /// There should always be exactly as many `answers` as `num_msg`. | 72 /// There must always be exactly as many `answers` as `num_msg`. |
| 70 /// - `appdata` is the `appdata` field of the [`LibPamConversation`] we were passed. | 73 /// - `appdata` is the `appdata` field of the [`LibPamConversation`]. |
| 71 pub type ConversationCallback = unsafe extern "C" fn( | 74 pub type ConversationCallback = unsafe extern "C" fn( |
| 72 num_msg: c_int, | 75 num_msg: c_int, |
| 73 questions: *const *const Question, | 76 questions: *const *const Question, |
| 74 answers: *mut *mut Answer, | 77 answers: *mut *mut Answer, |
| 75 appdata: *mut AppData, | 78 appdata: *mut AppData, |
