comparison libpam-sys/src/ffi.rs @ 134:6c1e1bdb4164

Use standard #[cfg] directives rather than custom proc macros. Instead of having to do a bunch of custom parsing and other logic that tools often choke on, this change introduces an easy way to depend upon custom #[cfg]s provided by the libpam-sys crate.
author Paul Fisher <paul@pfish.zone>
date Thu, 03 Jul 2025 11:03:36 -0400
parents 32b2a545ca3e
children
comparison
equal deleted inserted replaced
133:32b2a545ca3e 134:6c1e1bdb4164
113 /// Completely unused. 113 /// Completely unused.
114 pub resp_retcode: c_int, 114 pub resp_retcode: c_int,
115 } 115 }
116 116
117 /// Definition of the PAM_XAUTHDATA item. Compatible with `xcb_auth_info_t`. 117 /// Definition of the PAM_XAUTHDATA item. Compatible with `xcb_auth_info_t`.
118 #[cfg(_hack_impl = "LinuxPam")] 118 #[cfg(pam_impl = "LinuxPam")]
119 #[repr(C)] 119 #[repr(C)]
120 pub struct pam_xauth_data { 120 pub struct pam_xauth_data {
121 namelen: c_int, 121 namelen: c_int,
122 name: *mut c_char, 122 name: *mut c_char,
123 datalen: c_int, 123 datalen: c_int,
124 data: *mut c_char, 124 data: *mut c_char,
125 } 125 }
126 126
127 #[cfg(_hack_impl = "LinuxPam")] 127 #[cfg(pam_impl = "LinuxPam")]
128 #[derive(Copy, Clone, Debug, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)] 128 #[derive(Copy, Clone, Debug, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)]
129 #[repr(i32)] 129 #[repr(i32)]
130 pub enum pam_modutil_redirect_fd { 130 pub enum pam_modutil_redirect_fd {
131 PAM_MODUTIL_IGNORE_FD, 131 PAM_MODUTIL_IGNORE_FD,
132 PAM_MODUTIL_PIPE_FD, 132 PAM_MODUTIL_PIPE_FD,
133 PAM_MODUTIL_NULL_FD, 133 PAM_MODUTIL_NULL_FD,
134 } 134 }
135 135
136 #[cfg(_hack_impl = "LinuxPam")] 136 #[cfg(pam_impl = "LinuxPam")]
137 pub use pam_modutil_redirect_fd::*; 137 pub use pam_modutil_redirect_fd::*;
138 138
139 #[cfg(_hack_impl = "LinuxPam")] 139 #[cfg(pam_impl = "LinuxPam")]
140 #[derive(Debug)] 140 #[derive(Debug)]
141 #[repr(C)] 141 #[repr(C)]
142 pub struct pam_modutil_privs { 142 pub struct pam_modutil_privs {
143 grplist: *mut libc::gid_t, 143 grplist: *mut libc::gid_t,
144 number_of_groups: c_int, 144 number_of_groups: c_int,
146 old_gid: libc::gid_t, 146 old_gid: libc::gid_t,
147 old_uid: libc::uid_t, 147 old_uid: libc::uid_t,
148 is_dropped: c_int, 148 is_dropped: c_int,
149 } 149 }
150 150
151 #[cfg(_hack_impl = "OpenPam")] 151 #[cfg(pam_impl = "OpenPam")]
152 pub type pam_func_t = unsafe extern "C" fn( 152 pub type pam_func_t = unsafe extern "C" fn(
153 handle: *mut pam_handle, 153 handle: *mut pam_handle,
154 flags: c_int, 154 flags: c_int,
155 argc: c_int, 155 argc: c_int,
156 argv: *const *const c_char, 156 argv: *const *const c_char,
157 ) -> c_int; 157 ) -> c_int;
158 158
159 #[cfg(_hack_impl = "OpenPam")] 159 #[cfg(pam_impl = "OpenPam")]
160 #[derive(Debug)] 160 #[derive(Debug)]
161 #[repr(C)] 161 #[repr(C)]
162 pub struct pam_module { 162 pub struct pam_module {
163 path: *mut c_char, 163 path: *mut c_char,
164 func: [pam_func_t; 6], 164 func: [pam_func_t; 6],
165 dlh: *mut c_void, 165 dlh: *mut c_void,
166 } 166 }
167 167
168 #[cfg(_hack_impl = "OpenPam")] 168 #[cfg(pam_impl = "OpenPam")]
169 #[derive(Debug)] 169 #[derive(Debug)]
170 #[repr(C)] 170 #[repr(C)]
171 pub struct pam_repository { 171 pub struct pam_repository {
172 typ: *mut c_char, 172 typ: *mut c_char,
173 scope: *mut c_void, 173 scope: *mut c_void,
174 scope_len: usize, 174 scope_len: usize,
175 } 175 }
176 176
177 // These are the functions specified in X/SSO. Everybody exports them. 177 // These are the functions specified in X/SSO. Everybody exports them.
178 #[link(name = "pam")]
178 extern "C" { 179 extern "C" {
179 /// Account validation. 180 /// Account validation.
180 pub fn pam_acct_mgmt(pamh: *mut pam_handle, flags: c_int) -> c_int; 181 pub fn pam_acct_mgmt(pamh: *mut pam_handle, flags: c_int) -> c_int;
181 182
182 /// Authenticate a user. 183 /// Authenticate a user.
270 /// All implementations of PAM known to this library (Linux-PAM, OpenPAM, 271 /// All implementations of PAM known to this library (Linux-PAM, OpenPAM,
271 /// and Sun) ignore `pamh` and will accept a null pointer. 272 /// and Sun) ignore `pamh` and will accept a null pointer.
272 pub fn pam_strerror(pamh: *const pam_handle, error_number: c_int) -> *mut c_char; 273 pub fn pam_strerror(pamh: *const pam_handle, error_number: c_int) -> *mut c_char;
273 } 274 }
274 275
275 // We use `_hack_impl` because ctest loses its mind 276 // We use `pam_impl` because ctest loses its mind
276 // when it comes across the `cfg_pam_impl` macro. 277 // when it comes across the `cfg_pam_impl` macro.
277 // This is a custom cfg variable set in our build.rs. Don't do this; just use 278 // This is a custom cfg variable set in our build.rs. Don't do this; just use
278 // cfg_pam_impl. 279 // cfg_pam_impl.
279 #[cfg(any(_hack_impl = "LinuxPam", _hack_impl = "OpenPam"))] 280 #[cfg(any(pam_impl = "LinuxPam", pam_impl = "OpenPam"))]
280 extern "C" { 281 extern "C" {
281 /// Gets `PAM_AUTHTOK`, or asks the user if that is unset. 282 /// Gets `PAM_AUTHTOK`, or asks the user if that is unset.
282 pub fn pam_get_authtok( 283 pub fn pam_get_authtok(
283 pamh: *mut pam_handle, 284 pamh: *mut pam_handle,
284 item: c_int, 285 item: c_int,
294 ... 295 ...
295 ) -> c_int; 296 ) -> c_int;
296 297
297 } 298 }
298 299
299 #[cfg(_hack_impl = "LinuxPam")] 300 #[cfg(pam_impl = "LinuxPam")]
300 extern "C" { 301 extern "C" {
301 pub fn pam_fail_delay(pamh: *mut pam_handle, musec_delay: c_uint) -> c_int; 302 pub fn pam_fail_delay(pamh: *mut pam_handle, musec_delay: c_uint) -> c_int;
302 303
303 /// Start a PAM transaction based on configuration in the given directory. 304 /// Start a PAM transaction based on configuration in the given directory.
304 pub fn pam_start_confdir( 305 pub fn pam_start_confdir(
399 file_name: *const c_char, 400 file_name: *const c_char,
400 key: *const c_char, 401 key: *const c_char,
401 ) -> *mut c_char; 402 ) -> *mut c_char;
402 } 403 }
403 404
404 #[cfg(_hack_impl = "OpenPam")] 405 #[cfg(pam_impl = "OpenPam")]
405 extern "C" { 406 extern "C" {
406 pub fn openpam_borrow_cred(pamh: *mut pam_handle, passwd: *const libc::passwd) -> c_int; 407 pub fn openpam_borrow_cred(pamh: *mut pam_handle, passwd: *const libc::passwd) -> c_int;
407 408
408 pub fn openpam_subst( 409 pub fn openpam_subst(
409 pamh: *const pam_handle, 410 pamh: *const pam_handle,