Mercurial > crates > nonstick
comparison src/libpam/pam_ffi.rs @ 98:b87100c5eed4
Start on environment variables, and make pointers nicer.
This starts work on the PAM environment handling, and in so doing,
introduces the CHeapBox and CHeapString structs. These are analogous
to Box and CString, but they're located on the C heap rather than
being Rust-managed memory.
This is because environment variables deal with even more pointers
and it turns out we can lose a lot of manual freeing using homemade
smart pointers.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Tue, 24 Jun 2025 04:25:25 -0400 |
parents | efe2f5f8b5b2 |
children | 94b51fa4f797 |
comparison
equal
deleted
inserted
replaced
97:efe2f5f8b5b2 | 98:b87100c5eed4 |
---|---|
1 //! The types that are directly represented in PAM function signatures. | 1 //! The types that are directly represented in PAM function signatures. |
2 | 2 |
3 #![allow(non_camel_case_types, non_upper_case_globals)] | 3 #![allow(non_camel_case_types, non_upper_case_globals)] |
4 | 4 |
5 use crate::libpam::memory::Immovable; | 5 use crate::libpam::memory::{CHeapBox, Immovable}; |
6 use std::ffi::{c_int, c_uint, c_void, CStr}; | 6 use std::ffi::{c_int, c_uint, c_void, CStr}; |
7 use std::marker::PhantomData; | 7 use std::marker::PhantomData; |
8 use std::ptr; | 8 use std::ptr; |
9 | 9 |
10 /// An opaque structure that a PAM handle points to. | 10 /// An opaque structure that a PAM handle points to. |
24 /// Generic version of answer data. | 24 /// Generic version of answer data. |
25 /// | 25 /// |
26 /// This has the same structure as [`BinaryAnswer`](crate::libpam::answer::BinaryAnswer) | 26 /// This has the same structure as [`BinaryAnswer`](crate::libpam::answer::BinaryAnswer) |
27 /// and [`TextAnswer`](crate::libpam::answer::TextAnswer). | 27 /// and [`TextAnswer`](crate::libpam::answer::TextAnswer). |
28 #[repr(C)] | 28 #[repr(C)] |
29 #[derive(Debug)] | 29 #[derive(Debug, Default)] |
30 pub struct Answer { | 30 pub struct Answer { |
31 /// Pointer to the data returned in an answer. | 31 /// Owned pointer to the data returned in an answer. |
32 /// For most answers, this will be a [`CStr`], | 32 /// For most answers, this will be a [`CHeapString`], |
33 /// but for [`BinaryQAndA`](crate::conv::BinaryQAndA)s (a Linux-PAM extension), | 33 /// but for [`BinaryQAndA`](crate::conv::BinaryQAndA)s (a Linux-PAM extension), |
34 /// this will be [`CBinaryData`](crate::libpam::memory::CBinaryData). | 34 /// this will be a [`CHeapBox`] of |
35 /// | 35 /// [`CBinaryData`](crate::libpam::memory::CBinaryData). |
36 /// No matter what, this can be freed with a simple [`libc::free`]. | 36 pub data: Option<CHeapBox<c_void>>, |
37 pub data: *mut c_void, | |
38 /// Unused. Just here for the padding. | 37 /// Unused. Just here for the padding. |
39 return_code: c_int, | 38 return_code: c_int, |
40 _marker: Immovable, | 39 _marker: Immovable, |
41 } | 40 } |
42 | 41 |
55 /// A description of the data requested. | 54 /// A description of the data requested. |
56 /// | 55 /// |
57 /// For most requests, this will be an owned [`CStr`], | 56 /// For most requests, this will be an owned [`CStr`], |
58 /// but for requests with style `PAM_BINARY_PROMPT`, | 57 /// but for requests with style `PAM_BINARY_PROMPT`, |
59 /// this will be `CBinaryData` (a Linux-PAM extension). | 58 /// this will be `CBinaryData` (a Linux-PAM extension). |
60 pub data: *mut c_void, | 59 pub data: Option<CHeapBox<c_void>>, |
61 pub _marker: Immovable, | 60 pub _marker: Immovable, |
62 } | 61 } |
63 | 62 |
64 /// The callback that PAM uses to get information in a conversation. | 63 /// The callback that PAM uses to get information in a conversation. |
65 /// | 64 /// |