Mercurial > crates > nonstick
comparison src/constants.rs @ 131:a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
| author | Paul Fisher <paul@pfish.zone> |
|---|---|
| date | Wed, 02 Jul 2025 02:24:21 -0400 |
| parents | 80c07e5ab22f |
| children | efbc235f01d3 |
comparison
equal
deleted
inserted
replaced
| 130:80c07e5ab22f | 131:a632a8874131 |
|---|---|
| 4 // between Linux-PAM and OpenPAM header files. | 4 // between Linux-PAM and OpenPAM header files. |
| 5 #![allow(clippy::unnecessary_cast)] | 5 #![allow(clippy::unnecessary_cast)] |
| 6 | 6 |
| 7 use crate::{linklist, man7, manbsd, xsso}; | 7 use crate::{linklist, man7, manbsd, xsso}; |
| 8 use bitflags::bitflags; | 8 use bitflags::bitflags; |
| 9 use std::ffi::c_int; | |
| 10 use num_enum::{IntoPrimitive, TryFromPrimitive}; | 9 use num_enum::{IntoPrimitive, TryFromPrimitive}; |
| 11 use std::error::Error; | 10 use std::error::Error; |
| 11 use std::ffi::c_int; | |
| 12 use std::fmt; | |
| 12 use std::fmt::{Display, Formatter}; | 13 use std::fmt::{Display, Formatter}; |
| 13 use std::result::Result as StdResult; | 14 use std::result::Result as StdResult; |
| 14 use std::fmt; | |
| 15 | 15 |
| 16 /// Values for constants not provided by certain PAM implementations. | 16 /// Values for constants not provided by certain PAM implementations. |
| 17 /// | 17 /// |
| 18 /// **The values of these constants are deliberately selected _not_ to match | 18 /// **The values of these constants are deliberately selected _not_ to match |
| 19 /// any PAM implementations. Applications should always use the symbolic value | 19 /// any PAM implementations. Applications should always use the symbolic value |
| 30 }; | 30 }; |
| 31 (@meta $m:tt $($i:item)+) => { define!(@expand $($m $i)+); }; | 31 (@meta $m:tt $($i:item)+) => { define!(@expand $($m $i)+); }; |
| 32 (@expand $({ $(#[$m:meta])* } $i:item)+) => {$($(#[$m])* $i)+}; | 32 (@expand $({ $(#[$m:meta])* } $i:item)+) => {$($(#[$m])* $i)+}; |
| 33 } | 33 } |
| 34 | 34 |
| 35 | |
| 36 define!( | 35 define!( |
| 37 /// A fictitious constant for testing purposes. | 36 /// A fictitious constant for testing purposes. |
| 38 #[cfg(not(feature = "link"))] | 37 #[cfg(not(feature = "link"))] |
| 39 #[cfg_pam_impl(not("OpenPam"))] | 38 #[cfg_pam_impl(not("OpenPam"))] |
| 40 PAM_BAD_CONSTANT = 513; | 39 PAM_BAD_CONSTANT = 513; |
| 54 #[cfg(not(feature = "link"))] | 53 #[cfg(not(feature = "link"))] |
| 55 #[cfg_pam_impl(not("LinuxPam"))] | 54 #[cfg_pam_impl(not("LinuxPam"))] |
| 56 PAM_CONV_AGAIN = 517; | 55 PAM_CONV_AGAIN = 517; |
| 57 PAM_INCOMPLETE = 518; | 56 PAM_INCOMPLETE = 518; |
| 58 ); | 57 ); |
| 59 | |
| 60 } | 58 } |
| 61 | 59 |
| 62 bitflags! { | 60 bitflags! { |
| 63 /// The available PAM flags. | 61 /// The available PAM flags. |
| 64 /// | 62 /// |
| 202 } | 200 } |
| 203 } | 201 } |
| 204 | 202 |
| 205 /// A basic Display implementation for if we don't link against PAM. | 203 /// A basic Display implementation for if we don't link against PAM. |
| 206 fn fmt_internal(self, f: &mut Formatter<'_>) -> fmt::Result { | 204 fn fmt_internal(self, f: &mut Formatter<'_>) -> fmt::Result { |
| 207 let n : c_int = self.into(); | 205 let n: c_int = self.into(); |
| 208 write!(f, "PAM error: {self:?} ({n})") | 206 write!(f, "PAM error: {self:?} ({n})") |
| 209 } | 207 } |
| 210 } | 208 } |
| 211 | 209 |
| 212 /// Gets a string version of an error message. | 210 /// Gets a string version of an error message. |
| 213 #[cfg(feature = "link")] | 211 #[cfg(feature = "link")] |
| 214 pub fn strerror(code: c_int) -> Option<&'static str> { | 212 pub fn strerror(code: c_int) -> Option<&'static str> { |
| 213 use std::ffi::CStr; | |
| 215 use std::ptr; | 214 use std::ptr; |
| 216 use std::ffi::CStr; | |
| 217 // SAFETY: PAM impls don't care about the PAM handle and always return | 215 // SAFETY: PAM impls don't care about the PAM handle and always return |
| 218 // static strings. | 216 // static strings. |
| 219 let strerror = unsafe { libpam_sys::pam_strerror(ptr::null(), code as c_int) }; | 217 let strerror = unsafe { libpam_sys::pam_strerror(ptr::null(), code as c_int) }; |
| 220 // SAFETY: We just got this back from PAM and we checked if it's null. | 218 // SAFETY: We just got this back from PAM and we checked if it's null. |
| 221 (!strerror.is_null()) | 219 (!strerror.is_null()) |
