comparison libpam-sys/src/ffi.rs @ 130:80c07e5ab22f

Transfer over (almost) completely to using libpam-sys. This reimplements everything in nonstick on top of the new -sys crate. We don't yet use libpam-sys's helpers for binary message payloads. Soon.
author Paul Fisher <paul@pfish.zone>
date Tue, 01 Jul 2025 06:11:43 -0400
parents 5b2de52dd8b2
children a632a8874131
comparison
equal deleted inserted replaced
129:5b2de52dd8b2 130:80c07e5ab22f
76 /// let name = CString::new("name").unwrap(); 76 /// let name = CString::new("name").unwrap();
77 /// unsafe { 77 /// unsafe {
78 /// pam_set_data(handle, name.as_ptr().cast_mut(), data_ptr.cast(), cleanup()); 78 /// pam_set_data(handle, name.as_ptr().cast_mut(), data_ptr.cast(), cleanup());
79 /// } 79 /// }
80 /// ``` 80 /// ```
81 pub type CleanupCallback = unsafe extern "C" fn( 81 pub type CleanupCallback =
82 pamh: *mut pam_handle, 82 unsafe extern "C" fn(pamh: *mut pam_handle, data: *mut c_void, pam_end_status: c_int);
83 data: *mut c_void,
84 pam_end_status: c_int,
85 );
86 83
87 /// Used by PAM to communicate between the module and the application. 84 /// Used by PAM to communicate between the module and the application.
88 #[repr(C)] 85 #[repr(C)]
89 pub struct pam_conv { 86 pub struct pam_conv {
90 pub conv: unsafe extern "C" fn( 87 pub conv: unsafe extern "C" fn(
109 pub resp: *mut c_char, 106 pub resp: *mut c_char,
110 /// Completely unused. 107 /// Completely unused.
111 pub resp_retcode: c_int, 108 pub resp_retcode: c_int,
112 } 109 }
113 110
114
115 // These are the functions specified in X/SSO. Everybody exports them. 111 // These are the functions specified in X/SSO. Everybody exports them.
116 extern "C" { 112 extern "C" {
117 /// Account validation. 113 /// Account validation.
118 pub fn pam_acct_mgmt(pamh: *mut pam_handle, flags: c_int) -> c_int; 114 pub fn pam_acct_mgmt(pamh: *mut pam_handle, flags: c_int) -> c_int;
119 115
137 module_data_name: *const c_char, 133 module_data_name: *const c_char,
138 data: *mut *const c_void, 134 data: *mut *const c_void,
139 ) -> c_int; 135 ) -> c_int;
140 136
141 /// Gets an environment variable. You own the return value. 137 /// Gets an environment variable. You own the return value.
142 pub fn pam_getenv(pamh: *mut pam_handle, name: *const c_char) -> *mut c_char; 138 pub fn pam_getenv(pamh: *const pam_handle, name: *const c_char) -> *mut c_char;
143 139
144 /// Gets all the environment variables. You own everything it points to. 140 /// Gets all the environment variables. You own everything it points to.
145 pub fn pam_getenvlist(pamh: *mut pam_handle) -> *mut *mut c_char; 141 pub fn pam_getenvlist(pamh: *const pam_handle) -> *mut *mut c_char;
146 142
147 /// Get information about the transaction. 143 /// Get information about the transaction.
148 /// 144 ///
149 /// The item is owned by PAM. 145 /// The item is owned by PAM.
150 pub fn pam_get_item( 146 pub fn pam_get_item(
151 pamh: *mut pam_handle, 147 pamh: *const pam_handle,
152 item_type: c_int, 148 item_type: c_int,
153 item: *mut *const c_void, 149 item: *mut *const c_void,
154 ) -> c_int; 150 ) -> c_int;
155 151
156 // Nobody implements pam_get_mapped_authtok. 152 // Nobody implements pam_get_mapped_authtok.
212 208
213 // We use `_private_pam_impl_hack` because ctest loses its mind 209 // We use `_private_pam_impl_hack` because ctest loses its mind
214 // when it comes across the `cfg_pam_impl` macro. 210 // when it comes across the `cfg_pam_impl` macro.
215 // This is a custom cfg variable set in our build.rs. Don't do this; just use 211 // This is a custom cfg variable set in our build.rs. Don't do this; just use
216 // cfg_pam_impl. 212 // cfg_pam_impl.
217 #[cfg(_private_pam_impl_hack = "LinuxPam")] 213 #[cfg(any(_private_pam_impl_hack = "LinuxPam", _private_pam_impl_hack = "OpenPam"))]
218 extern "C" { 214 extern "C" {
219 pub fn pam_get_authtok(pamh: *mut pam_handle, x: c_int, token: *mut *const c_char, prompt: *const c_char) -> c_int; 215 pub fn pam_get_authtok(
220 } 216 pamh: *mut pam_handle,
217 x: c_int,
218 token: *mut *const c_char,
219 prompt: *const c_char,
220 ) -> c_int;
221 }