diff 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
line wrap: on
line diff
--- a/src/libpam/pam_ffi.rs	Tue Jun 10 05:36:58 2025 -0400
+++ b/src/libpam/pam_ffi.rs	Fri Jun 13 05:22:48 2025 -0400
@@ -30,9 +30,11 @@
     /// Pointer to the data returned in an answer.
     /// For most answers, this will be a [`CStr`](std::ffi::CStr),
     /// but for [`BinaryQAndA`](crate::conv::BinaryQAndA)s (a Linux-PAM extension),
-    /// this will be [`CBinaryData`](crate::libpam::memory::CBinaryData)
+    /// this will be [`CBinaryData`](crate::libpam::memory::CBinaryData).
+    ///
+    /// No matter what, this can be freed with a simple [`libc::free`].
     pub data: *mut c_void,
-    /// Unused.
+    /// Unused. Just here for the padding.
     return_code: c_int,
     _marker: Immovable,
 }
@@ -40,34 +42,35 @@
 /// A question sent by PAM or a module to an application.
 ///
 /// PAM refers to this as a "message", but we call it a question
-/// to avoid confusion with [`Message`](crate::Message).
+/// to avoid confusion with [`Message`](crate::conv::Message).
 ///
 /// This question, and its internal data, is owned by its creator
 /// (either the module or PAM itself).
 #[repr(C)]
+#[derive(Debug)]
 pub struct Question {
     /// The style of message to request.
     pub style: c_uint,
     /// A description of the data requested.
     ///
-    /// For most requests, this will be an owned [`CStr`](std::ffi::CStr), but for requests
-    /// with [`Style::BinaryPrompt`], this will be [`CBinaryData`]
-    /// (a Linux-PAM extension).
+    /// For most requests, this will be an owned [`CStr`](std::ffi::CStr),
+    /// but for requests with style `PAM_BINARY_PROMPT`,
+    /// this will be `CBinaryData` (a Linux-PAM extension).
     pub data: *mut c_void,
     pub _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.
+/// - `num_msg` is the number of messages in the `questions` array.
 /// - `questions` is a pointer to the [`Question`]s being sent to the user.
 ///   For information about its structure,
-///   see [`GenericQuestions`](super::question::GenericQuestions).
+///   see [`QuestionsTrait`](super::question::QuestionsTrait).
 /// - `answers` is a pointer to an array of [`Answer`]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 `answers` as `num_msg`.
-/// - `appdata` is the `appdata` field of the [`LibPamConversation`] we were passed.
+///   There must always be exactly as many `answers` as `num_msg`.
+/// - `appdata` is the `appdata` field of the [`LibPamConversation`].
 pub type ConversationCallback = unsafe extern "C" fn(
     num_msg: c_int,
     questions: *const *const Question,