Mercurial > crates > nonstick
comparison src/libpam/handle.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 | a632a8874131 |
children |
comparison
equal
deleted
inserted
replaced
133:32b2a545ca3e | 134:6c1e1bdb4164 |
---|---|
12 }; | 12 }; |
13 use num_enum::{IntoPrimitive, TryFromPrimitive}; | 13 use num_enum::{IntoPrimitive, TryFromPrimitive}; |
14 use std::cell::Cell; | 14 use std::cell::Cell; |
15 use std::ffi::{c_char, c_int, CString}; | 15 use std::ffi::{c_char, c_int, CString}; |
16 | 16 |
17 use libpam_sys::cfg_pam_impl; | |
18 use std::ptr; | 17 use std::ptr; |
19 use std::ptr::NonNull; | 18 use std::ptr::NonNull; |
20 | 19 |
21 /// Owner for a PAM handle. | 20 /// Owner for a PAM handle. |
22 pub struct LibPamHandle(pub NonNull<libpam_sys::pam_handle>); | 21 pub struct LibPamHandle(pub NonNull<libpam_sys::pam_handle>); |
277 } | 276 } |
278 } | 277 } |
279 } | 278 } |
280 | 279 |
281 impl PamHandleModule for LibPamHandle { | 280 impl PamHandleModule for LibPamHandle { |
282 #[cfg_pam_impl(any("LinuxPam", "OpenPam"))] | 281 #[cfg(any(pam_impl = "LinuxPam", pam_impl = "OpenPam"))] |
283 fn authtok(&mut self, prompt: Option<&str>) -> Result<String> { | 282 fn authtok(&mut self, prompt: Option<&str>) -> Result<String> { |
284 let prompt = memory::option_cstr(prompt)?; | 283 let prompt = memory::option_cstr(prompt)?; |
285 let mut output: *const c_char = ptr::null_mut(); | 284 let mut output: *const c_char = ptr::null_mut(); |
286 // SAFETY: We're calling this with known-good values. | 285 // SAFETY: We're calling this with known-good values. |
287 let res = unsafe { | 286 let res = unsafe { |
297 unsafe { memory::copy_pam_string(output) } | 296 unsafe { memory::copy_pam_string(output) } |
298 .transpose() | 297 .transpose() |
299 .unwrap_or(Err(ErrorCode::ConversationError)) | 298 .unwrap_or(Err(ErrorCode::ConversationError)) |
300 } | 299 } |
301 | 300 |
302 #[cfg_pam_impl(not(any("LinuxPam", "OpenPam")))] | 301 #[cfg(not(any(pam_impl = "LinuxPam", pam_impl = "OpenPam")))] |
303 fn authtok(&mut self, prompt: Option<&str>) -> Result<String> { | 302 fn authtok(&mut self, prompt: Option<&str>) -> Result<String> { |
304 Err(ErrorCode::ConversationError) | 303 Err(ErrorCode::ConversationError) |
305 } | 304 } |
306 | 305 |
307 cstr_item!(get = authtok_item, item = ItemType::AuthTok); | 306 cstr_item!(get = authtok_item, item = ItemType::AuthTok); |