Mercurial > crates > nonstick
annotate libpam-sys/src/structs.rs @ 125:2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Mon, 30 Jun 2025 17:47:32 -0400 |
parents | 476a22db8639 |
children |
rev | line source |
---|---|
125
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
1 //! Structs and wrappers that PAM is made of. |
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
2 #![allow(non_camel_case_types)] |
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
3 |
118
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
4 use std::ffi::{c_int, c_void}; |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
5 use std::fmt; |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
6 use std::marker::{PhantomData, PhantomPinned}; |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
7 |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
8 /// A marker struct to make whatever it's in `!Sync`, `!Send`, and `!Unpin`. |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
9 #[derive(Default, PartialOrd, PartialEq, Ord, Eq)] |
125
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
10 #[repr(C)] |
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
11 struct ExtremelyUnsafe { |
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
12 _value: (), |
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
13 _marker: PhantomData<(PhantomPinned, *mut c_void)>, |
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
14 } |
118
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
15 |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
16 impl fmt::Debug for ExtremelyUnsafe { |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
17 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
18 f.write_str("ExtremelyUnsafe") |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
19 } |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
20 } |
106
49d9e2b5c189
An irresponsible mix of implementing libpam-sys and other stuff.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
21 |
118
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
22 /// An opaque structure that PAM uses to communicate. |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
23 /// |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
24 /// This is only ever returned in pointer form and cannot be constructed. |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
25 #[repr(C)] |
125
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
26 pub struct pam_handle_t(ExtremelyUnsafe); |
118
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
27 |
125
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
28 impl fmt::Debug for pam_handle_t { |
118
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
29 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
30 write!(f, "PamHandle({self:p}") |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
31 } |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
32 } |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
33 |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
34 /// An opaque structure that is passed through PAM in a conversation. |
125
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
35 #[repr(C)] |
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
36 pub struct AppData(ExtremelyUnsafe); |
106
49d9e2b5c189
An irresponsible mix of implementing libpam-sys and other stuff.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
37 |
118
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
38 impl fmt::Debug for AppData { |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
39 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
40 write!(f, "AppData({self:p}") |
106
49d9e2b5c189
An irresponsible mix of implementing libpam-sys and other stuff.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
41 } |
49d9e2b5c189
An irresponsible mix of implementing libpam-sys and other stuff.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
42 } |
118
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
43 |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
44 /// The callback that PAM uses to get information in a conversation. |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
45 /// |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
46 /// For important details about the format of `messages`, |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
47 /// see the [`helpers`](crate::helpers) module. |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
48 pub type ConversationCallback = unsafe extern "C" fn( |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
49 num_msg: c_int, |
119
476a22db8639
Add PtrPtrVec to make it easy to pass pointer-to-pointers to PAM.
Paul Fisher <paul@pfish.zone>
parents:
118
diff
changeset
|
50 // This is a *const *const because accessing memory from a reference |
476a22db8639
Add PtrPtrVec to make it easy to pass pointer-to-pointers to PAM.
Paul Fisher <paul@pfish.zone>
parents:
118
diff
changeset
|
51 // outside its bounds is undefined behavior, and *messages is an array |
476a22db8639
Add PtrPtrVec to make it easy to pass pointer-to-pointers to PAM.
Paul Fisher <paul@pfish.zone>
parents:
118
diff
changeset
|
52 // in X/SSO PAM impls. |
125
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
53 msg: *const *const pam_message, |
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
54 // This is a &mut *mut because the caller sets the pointer in `resp` |
119
476a22db8639
Add PtrPtrVec to make it easy to pass pointer-to-pointers to PAM.
Paul Fisher <paul@pfish.zone>
parents:
118
diff
changeset
|
55 // but does not mess around outside its memory space. |
125
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
56 resp: &mut *mut pam_response, |
118
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
57 appdata: *const AppData, |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
58 ) -> c_int; |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
59 |
125
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
60 /// Called to clean up data set using [`pam_set_data`](crate::pam_set_data). |
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
61 pub type CleanupCallback = unsafe extern "C" fn( |
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
62 pamh: *mut pam_handle_t, |
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
63 data: *mut c_void, |
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
64 pam_end_status: c_int, |
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
65 ) -> c_int; |
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
66 |
118
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
67 /// Used by PAM to communicate between the module and the application. |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
68 #[repr(C)] |
125
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
69 pub struct pam_conv { |
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
70 pub conv: ConversationCallback, |
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
71 pub appdata_ptr: *const AppData, |
118
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
72 } |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
73 |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
74 /// A message sent into a PAM conversation. |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
75 #[repr(C)] |
125
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
76 pub struct pam_message { |
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
77 pub msg_style: c_int, |
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
78 pub msg: *const c_void, |
118
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
79 } |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
80 |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
81 /// A response returned from a PAM conversation. |
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
82 #[repr(C)] |
125
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
83 pub struct pam_response { |
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
84 pub resp: *mut c_void, |
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
85 /// Completely unused. |
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
119
diff
changeset
|
86 pub resp_retcode: c_int, |
118
39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents:
117
diff
changeset
|
87 } |