Mercurial > crates > nonstick
diff libpam-sys/src/constants.rs @ 109:bb465393621f
Minor cleanup and reorg.
- Use those nice new macros we just implemented.
- Straighten out the macro file.
- Move the `BinaryPayload` into `structs.rs`, leaving helpers behind.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Sat, 28 Jun 2025 02:49:35 -0400 |
parents | e97534be35e3 |
children | 2346fd501b7a |
line wrap: on
line diff
--- a/libpam-sys/src/constants.rs Sat Jun 28 00:34:45 2025 -0400 +++ b/libpam-sys/src/constants.rs Sat Jun 28 02:49:35 2025 -0400 @@ -1,8 +1,6 @@ //! All the constants. -// We have to enable these otherwise we get lit up with warnings -// during conditional compilation. -#![allow(dead_code, unused_imports)] +use libpam_sys_impls::cfg_pam_impl; /// Macro to make defining a bunch of constants way easier. macro_rules! define { @@ -16,63 +14,40 @@ (@expand $({ $(#[$m:meta])* } $i:item)+) => {$($(#[$m])* $i)+}; } -#[cfg(feature = "use-system-headers")] -pub use system_headers::*; - -#[cfg(not(feature = "use-system-headers"))] -pub use export::*; - -mod export { - // There are a few truly universal constants. - // They are defined here directly. - pub const PAM_SUCCESS: u32 = 0; +// There are a few truly universal constants. +// They are defined here directly. +pub const PAM_SUCCESS: u32 = 0; - define!( - /// An item type. - PAM_SERVICE = 1; - PAM_USER = 2; - PAM_TTY = 3; - PAM_RHOST = 4; - PAM_CONV = 5; - PAM_AUTHTOK = 6; - PAM_OLDAUTHTOK = 7; - PAM_RUSER = 8; - ); +define!( + /// An item type. + PAM_SERVICE = 1; + PAM_USER = 2; + PAM_TTY = 3; + PAM_RHOST = 4; + PAM_CONV = 5; + PAM_AUTHTOK = 6; + PAM_OLDAUTHTOK = 7; + PAM_RUSER = 8; +); - define!( - /// A message style. - PAM_PROMPT_ECHO_OFF = 1; - PAM_PROMPT_ECHO_ON = 2; - PAM_ERROR_MSG = 3; - PAM_TEXT_INFO = 4; - ); - - define!( - /// Maximum size of PAM conversation elements (suggested). - PAM_MAX_NUM_MSG = 32; - PAM_MAX_MSG_SIZE = 512; - PAM_MAX_RESP_SIZE = 512; - ); +define!( + /// A message style. + PAM_PROMPT_ECHO_OFF = 1; + PAM_PROMPT_ECHO_ON = 2; + PAM_ERROR_MSG = 3; + PAM_TEXT_INFO = 4; +); - #[cfg(pam_impl = "linux-pam")] - pub use super::linux_pam::*; - - #[cfg(not(pam_impl = "linux-pam"))] - pub use super::illumos_openpam::*; - - #[cfg(pam_impl = "illumos")] - pub use super::illumos::*; +define!( + /// Maximum size of PAM conversation elements (suggested). + PAM_MAX_NUM_MSG = 32; + PAM_MAX_MSG_SIZE = 512; + PAM_MAX_RESP_SIZE = 512; +); - #[cfg(pam_impl = "openpam")] - pub use super::openpam::*; -} - -/// Constants extracted from PAM header files. -mod system_headers { - // include!(concat!(env!("OUT_DIR"), "/constants.rs")); -} - -/// Constants used by Linux-PAM. +#[cfg_pam_impl("LinuxPam")] +pub use linux_pam::*; +#[cfg_pam_impl("LinuxPam")] mod linux_pam { define!( /// An error code. @@ -145,7 +120,9 @@ ); } -/// Constants shared between Illumos and OpenPAM. +#[cfg_pam_impl(any("Illumos", "OpenPam", "OpenPamMinimal"))] +pub use illumos_openpam; +#[cfg_pam_impl(any("Illumos", "OpenPam", "OpenPamMinimal"))] mod illumos_openpam { define!( /// An error code. @@ -207,6 +184,9 @@ } /// Constants exclusive to Illumos. +#[cfg_pam_impl("Illumos")] +pub use illumos::*; +#[cfg_pam_impl("Illumos")] mod illumos { /// The total number of PAM error codes. pub const PAM_TOTAL_ERRNUM: u32 = 28; @@ -221,7 +201,9 @@ pub const PAM_NO_AUTHTOK_CHECK: u32 = 0b1000; } -/// Constants exclusive to OpenPAM. +#[cfg_pam_impl("OpenPam")] +pub use openpam::*; +#[cfg_pam_impl("OpenPam")] mod openpam { define!( /// An error code.