Mercurial > crates > nonstick
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 108:e97534be35e3 | 109:bb465393621f |
|---|---|
| 1 //! All the constants. | 1 //! All the constants. |
| 2 | 2 |
| 3 // We have to enable these otherwise we get lit up with warnings | 3 use libpam_sys_impls::cfg_pam_impl; |
| 4 // during conditional compilation. | |
| 5 #![allow(dead_code, unused_imports)] | |
| 6 | 4 |
| 7 /// Macro to make defining a bunch of constants way easier. | 5 /// Macro to make defining a bunch of constants way easier. |
| 8 macro_rules! define { | 6 macro_rules! define { |
| 9 ($(#[$attr:meta])* $($name:ident = $value:expr);+$(;)?) => { | 7 ($(#[$attr:meta])* $($name:ident = $value:expr);+$(;)?) => { |
| 10 define!( | 8 define!( |
| 14 }; | 12 }; |
| 15 (@meta $m:tt $($i:item)+) => { define!(@expand $($m $i)+); }; | 13 (@meta $m:tt $($i:item)+) => { define!(@expand $($m $i)+); }; |
| 16 (@expand $({ $(#[$m:meta])* } $i:item)+) => {$($(#[$m])* $i)+}; | 14 (@expand $({ $(#[$m:meta])* } $i:item)+) => {$($(#[$m])* $i)+}; |
| 17 } | 15 } |
| 18 | 16 |
| 19 #[cfg(feature = "use-system-headers")] | 17 // There are a few truly universal constants. |
| 20 pub use system_headers::*; | 18 // They are defined here directly. |
| 21 | 19 pub const PAM_SUCCESS: u32 = 0; |
| 22 #[cfg(not(feature = "use-system-headers"))] | 20 |
| 23 pub use export::*; | 21 define!( |
| 24 | 22 /// An item type. |
| 25 mod export { | 23 PAM_SERVICE = 1; |
| 26 // There are a few truly universal constants. | 24 PAM_USER = 2; |
| 27 // They are defined here directly. | 25 PAM_TTY = 3; |
| 28 pub const PAM_SUCCESS: u32 = 0; | 26 PAM_RHOST = 4; |
| 29 | 27 PAM_CONV = 5; |
| 30 define!( | 28 PAM_AUTHTOK = 6; |
| 31 /// An item type. | 29 PAM_OLDAUTHTOK = 7; |
| 32 PAM_SERVICE = 1; | 30 PAM_RUSER = 8; |
| 33 PAM_USER = 2; | 31 ); |
| 34 PAM_TTY = 3; | 32 |
| 35 PAM_RHOST = 4; | 33 define!( |
| 36 PAM_CONV = 5; | 34 /// A message style. |
| 37 PAM_AUTHTOK = 6; | 35 PAM_PROMPT_ECHO_OFF = 1; |
| 38 PAM_OLDAUTHTOK = 7; | 36 PAM_PROMPT_ECHO_ON = 2; |
| 39 PAM_RUSER = 8; | 37 PAM_ERROR_MSG = 3; |
| 40 ); | 38 PAM_TEXT_INFO = 4; |
| 41 | 39 ); |
| 42 define!( | 40 |
| 43 /// A message style. | 41 define!( |
| 44 PAM_PROMPT_ECHO_OFF = 1; | 42 /// Maximum size of PAM conversation elements (suggested). |
| 45 PAM_PROMPT_ECHO_ON = 2; | 43 PAM_MAX_NUM_MSG = 32; |
| 46 PAM_ERROR_MSG = 3; | 44 PAM_MAX_MSG_SIZE = 512; |
| 47 PAM_TEXT_INFO = 4; | 45 PAM_MAX_RESP_SIZE = 512; |
| 48 ); | 46 ); |
| 49 | 47 |
| 50 define!( | 48 #[cfg_pam_impl("LinuxPam")] |
| 51 /// Maximum size of PAM conversation elements (suggested). | 49 pub use linux_pam::*; |
| 52 PAM_MAX_NUM_MSG = 32; | 50 #[cfg_pam_impl("LinuxPam")] |
| 53 PAM_MAX_MSG_SIZE = 512; | |
| 54 PAM_MAX_RESP_SIZE = 512; | |
| 55 ); | |
| 56 | |
| 57 #[cfg(pam_impl = "linux-pam")] | |
| 58 pub use super::linux_pam::*; | |
| 59 | |
| 60 #[cfg(not(pam_impl = "linux-pam"))] | |
| 61 pub use super::illumos_openpam::*; | |
| 62 | |
| 63 #[cfg(pam_impl = "illumos")] | |
| 64 pub use super::illumos::*; | |
| 65 | |
| 66 #[cfg(pam_impl = "openpam")] | |
| 67 pub use super::openpam::*; | |
| 68 } | |
| 69 | |
| 70 /// Constants extracted from PAM header files. | |
| 71 mod system_headers { | |
| 72 // include!(concat!(env!("OUT_DIR"), "/constants.rs")); | |
| 73 } | |
| 74 | |
| 75 /// Constants used by Linux-PAM. | |
| 76 mod linux_pam { | 51 mod linux_pam { |
| 77 define!( | 52 define!( |
| 78 /// An error code. | 53 /// An error code. |
| 79 PAM_OPEN_ERR = 1; | 54 PAM_OPEN_ERR = 1; |
| 80 PAM_SYMBOL_ERR = 2; | 55 PAM_SYMBOL_ERR = 2; |
| 143 PAM_RADIO_TYPE = 5; | 118 PAM_RADIO_TYPE = 5; |
| 144 PAM_BINARY_PROMPT = 7; | 119 PAM_BINARY_PROMPT = 7; |
| 145 ); | 120 ); |
| 146 } | 121 } |
| 147 | 122 |
| 148 /// Constants shared between Illumos and OpenPAM. | 123 #[cfg_pam_impl(any("Illumos", "OpenPam", "OpenPamMinimal"))] |
| 124 pub use illumos_openpam; | |
| 125 #[cfg_pam_impl(any("Illumos", "OpenPam", "OpenPamMinimal"))] | |
| 149 mod illumos_openpam { | 126 mod illumos_openpam { |
| 150 define!( | 127 define!( |
| 151 /// An error code. | 128 /// An error code. |
| 152 PAM_OPEN_ERR = 1; | 129 PAM_OPEN_ERR = 1; |
| 153 PAM_SYMBOL_ERR = 2; | 130 PAM_SYMBOL_ERR = 2; |
| 205 PAM_CHANGE_EXPIRED_AUTHTOK = 0b0100; | 182 PAM_CHANGE_EXPIRED_AUTHTOK = 0b0100; |
| 206 ); | 183 ); |
| 207 } | 184 } |
| 208 | 185 |
| 209 /// Constants exclusive to Illumos. | 186 /// Constants exclusive to Illumos. |
| 187 #[cfg_pam_impl("Illumos")] | |
| 188 pub use illumos::*; | |
| 189 #[cfg_pam_impl("Illumos")] | |
| 210 mod illumos { | 190 mod illumos { |
| 211 /// The total number of PAM error codes. | 191 /// The total number of PAM error codes. |
| 212 pub const PAM_TOTAL_ERRNUM: u32 = 28; | 192 pub const PAM_TOTAL_ERRNUM: u32 = 28; |
| 213 | 193 |
| 214 define!( | 194 define!( |
| 219 | 199 |
| 220 /// A flag for `pam_chauthtok`. | 200 /// A flag for `pam_chauthtok`. |
| 221 pub const PAM_NO_AUTHTOK_CHECK: u32 = 0b1000; | 201 pub const PAM_NO_AUTHTOK_CHECK: u32 = 0b1000; |
| 222 } | 202 } |
| 223 | 203 |
| 224 /// Constants exclusive to OpenPAM. | 204 #[cfg_pam_impl("OpenPam")] |
| 205 pub use openpam::*; | |
| 206 #[cfg_pam_impl("OpenPam")] | |
| 225 mod openpam { | 207 mod openpam { |
| 226 define!( | 208 define!( |
| 227 /// An error code. | 209 /// An error code. |
| 228 PAM_MODULE_UNKNOWN = 28; | 210 PAM_MODULE_UNKNOWN = 28; |
| 229 PAM_DOMAIN_UNKNOWN = 29; | 211 PAM_DOMAIN_UNKNOWN = 29; |
