Mercurial > crates > nonstick
comparison libpam-sys/src/constants.rs @ 106:49d9e2b5c189
An irresponsible mix of implementing libpam-sys and other stuff.
| author | Paul Fisher <paul@pfish.zone> |
|---|---|
| date | Thu, 26 Jun 2025 22:41:28 -0400 |
| parents | |
| children | e97534be35e3 |
comparison
equal
deleted
inserted
replaced
| 105:13b4d2a19674 | 106:49d9e2b5c189 |
|---|---|
| 1 //! All the constants. | |
| 2 #![allow(dead_code)] | |
| 3 | |
| 4 /// Macro to make defining a bunch of constants way easier. | |
| 5 macro_rules! define { | |
| 6 ($(#[$attr:meta])* $($name:ident = $value:expr);+$(;)?) => { | |
| 7 define!( | |
| 8 @meta { $(#[$attr])* } | |
| 9 $(pub const $name: u32 = $value;)+ | |
| 10 ); | |
| 11 }; | |
| 12 (@meta $m:tt $($i:item)+) => { define!(@expand $($m $i)+); }; | |
| 13 (@expand $({ $(#[$m:meta])* } $i:item)+) => {$($(#[$m])* $i)+}; | |
| 14 } | |
| 15 | |
| 16 #[cfg(feature = "use-system-headers")] | |
| 17 pub use system_headers::*; | |
| 18 | |
| 19 #[cfg(not(feature = "use-system-headers"))] | |
| 20 pub use export::*; | |
| 21 | |
| 22 mod export { | |
| 23 // There are a few truly universal constants. | |
| 24 // They are defined here directly. | |
| 25 pub const PAM_SUCCESS: u32 = 0; | |
| 26 | |
| 27 define!( | |
| 28 /// An item type. | |
| 29 PAM_SERVICE = 1; | |
| 30 PAM_USER = 2; | |
| 31 PAM_TTY = 3; | |
| 32 PAM_RHOST = 4; | |
| 33 PAM_CONV = 5; | |
| 34 PAM_AUTHTOK = 6; | |
| 35 PAM_OLDAUTHTOK = 7; | |
| 36 PAM_RUSER = 8; | |
| 37 ); | |
| 38 | |
| 39 define!( | |
| 40 /// A message style. | |
| 41 PAM_PROMPT_ECHO_OFF = 1; | |
| 42 PAM_PROMPT_ECHO_ON = 2; | |
| 43 PAM_ERROR_MSG = 3; | |
| 44 PAM_TEXT_INFO = 4; | |
| 45 ); | |
| 46 | |
| 47 define!( | |
| 48 /// Maximum size of PAM conversation elements (suggested). | |
| 49 PAM_MAX_NUM_MSG = 32; | |
| 50 PAM_MAX_MSG_SIZE = 512; | |
| 51 PAM_MAX_RESP_SIZE = 512; | |
| 52 ); | |
| 53 | |
| 54 #[cfg(pam_impl = "linux-pam")] | |
| 55 pub use super::linux_pam::*; | |
| 56 | |
| 57 #[cfg(not(pam_impl = "linux-pam"))] | |
| 58 pub use super::shared::*; | |
| 59 | |
| 60 #[cfg(pam_impl = "illumos")] | |
| 61 pub use super::illumos::*; | |
| 62 | |
| 63 #[cfg(pam_impl = "openpam")] | |
| 64 pub use super::openpam::*; | |
| 65 } | |
| 66 | |
| 67 /// Constants extracted from PAM header files. | |
| 68 mod system_headers { | |
| 69 include!(concat!(env!("OUT_DIR"), "/constants.rs")); | |
| 70 } | |
| 71 | |
| 72 /// Constants used by Linux-PAM. | |
| 73 mod linux_pam { | |
| 74 define!( | |
| 75 /// An error code. | |
| 76 PAM_OPEN_ERR = 1; | |
| 77 PAM_SYMBOL_ERR = 2; | |
| 78 PAM_SERVICE_ERR = 3; | |
| 79 PAM_SYSTEM_ERR = 4; | |
| 80 PAM_BUF_ERR = 5; | |
| 81 PAM_PERM_DENIED = 6; | |
| 82 PAM_AUTH_ERR = 7; | |
| 83 PAM_CRED_INSUFFICIENT = 8; | |
| 84 PAM_AUTHINFO_UNAVAIL = 9; | |
| 85 PAM_USER_UNKNOWN = 10; | |
| 86 PAM_MAXTRIES = 11; | |
| 87 PAM_NEW_AUTHTOK_REQD = 12; | |
| 88 PAM_ACCT_EXPIRED = 13; | |
| 89 PAM_SESSION_ERR = 14; | |
| 90 PAM_CRED_UNAVAIL = 15; | |
| 91 PAM_CRED_EXPIRED = 16; | |
| 92 PAM_CRED_ERR = 17; | |
| 93 PAM_NO_MODULE_DATA = 18; | |
| 94 PAM_CONV_ERR = 19; | |
| 95 PAM_AUTHTOK_ERR = 20; | |
| 96 PAM_AUTHTOK_RECOVERY_ERR = 21; | |
| 97 PAM_AUTHTOK_LOCK_BUSY = 22; | |
| 98 PAM_AUTHTOK_DISABLE_AGING = 23; | |
| 99 PAM_TRY_AGAIN = 24; | |
| 100 PAM_IGNORE = 25; | |
| 101 PAM_ABORT = 26; | |
| 102 PAM_AUTHTOK_EXPIRED = 27; | |
| 103 PAM_MODULE_UNKNOWN = 28; | |
| 104 PAM_BAD_ITEM = 29; | |
| 105 PAM_CONV_AGAIN = 30; | |
| 106 PAM_INCOMPLETE = 31; | |
| 107 _PAM_RETURN_VALUES = 32; | |
| 108 ); | |
| 109 | |
| 110 define!( | |
| 111 /// A flag value. | |
| 112 PAM_SILENT = 0x8000; | |
| 113 PAM_DISALLOW_NULL_AUTHTOK = 0x0001; | |
| 114 PAM_ESTABLISH_CRED = 0x0002; | |
| 115 PAM_DELETE_CRED = 0x0004; | |
| 116 PAM_REINITIALIZE_CRED = 0x0008; | |
| 117 | |
| 118 PAM_CHANGE_EXPIRED_AUTHTOK = 0x0020; | |
| 119 ); | |
| 120 | |
| 121 define!( | |
| 122 PAM_USER_PROMPT = 9; | |
| 123 PAM_FAIL_DELAY = 10; | |
| 124 PAM_XDISPLAY = 11; | |
| 125 PAM_XAUTHDATA = 12; | |
| 126 PAM_AUTHTOKTYPE = 13; | |
| 127 ); | |
| 128 | |
| 129 /// To suppress messages in the item cleanup function. | |
| 130 pub const PAM_DATA_SILENT: u32 = 0x40000000; | |
| 131 | |
| 132 // Message styles | |
| 133 define!( | |
| 134 /// A message style. | |
| 135 PAM_RADIO_TYPE = 5; | |
| 136 PAM_BINARY_PROMPT = 7; | |
| 137 ); | |
| 138 } | |
| 139 | |
| 140 /// Constants shared between Illumos and OpenPAM. | |
| 141 mod shared { | |
| 142 define!( | |
| 143 /// An error code. | |
| 144 PAM_OPEN_ERR = 1; | |
| 145 PAM_SYMBOL_ERR = 2; | |
| 146 PAM_SERVICE_ERR = 3; | |
| 147 PAM_SYSTEM_ERR = 4; | |
| 148 PAM_BUF_ERR = 5; | |
| 149 PAM_CONV_ERR = 6; | |
| 150 PAM_PERM_DENIED = 7; | |
| 151 PAM_MAXTRIES = 8; | |
| 152 PAM_AUTH_ERR = 9; | |
| 153 PAM_NEW_AUTHTOK_REQD = 10; | |
| 154 PAM_CRED_INSUFFICIENT = 11; | |
| 155 PAM_AUTHINFO_UNAVAIL = 12; | |
| 156 PAM_USER_UNKNOWN = 13; | |
| 157 PAM_CRED_UNAVAIL = 14; | |
| 158 PAM_CRED_EXPIRED = 15; | |
| 159 PAM_CRED_ERR = 16; | |
| 160 PAM_ACCT_EXPIRED = 17; | |
| 161 PAM_AUTHTOK_EXPIRED = 18; | |
| 162 PAM_SESSION_ERR = 19; | |
| 163 PAM_AUTHTOK_ERR = 20; | |
| 164 PAM_AUTHTOK_RECOVERY_ERR = 21; | |
| 165 PAM_AUTHTOK_LOCK_BUSY = 22; | |
| 166 PAM_AUTHTOK_DISABLE_AGING = 23; | |
| 167 PAM_NO_MODULE_DATA = 24; | |
| 168 PAM_IGNORE = 25; | |
| 169 PAM_ABORT = 26; | |
| 170 PAM_TRY_AGAIN = 27; | |
| 171 ); | |
| 172 | |
| 173 define!( | |
| 174 /// An item type. | |
| 175 PAM_USER_PROMPT = 9; | |
| 176 PAM_REPOSITORY = 10; | |
| 177 ); | |
| 178 | |
| 179 /// A general flag for PAM operations. | |
| 180 pub const PAM_SILENT: u32 = 0x80000000; | |
| 181 | |
| 182 /// The password must be non-null. | |
| 183 pub const PAM_DISALLOW_NULL_AUTHTOK: u32 = 0b1; | |
| 184 | |
| 185 define!( | |
| 186 /// A flag for `pam_setcred`. | |
| 187 PAM_ESTABLISH_CRED = 0b0001; | |
| 188 PAM_DELETE_CRED = 0b0010; | |
| 189 PAM_REINITIALIZE_CRED = 0b0100; | |
| 190 PAM_REFRESH_CRED = 0b1000; | |
| 191 ); | |
| 192 | |
| 193 define!( | |
| 194 /// A flag for `pam_chauthtok`. | |
| 195 PAM_PRELIM_CHECK = 0b0001; | |
| 196 PAM_UPDATE_AUTHTOK = 0b0010; | |
| 197 PAM_CHANGE_EXPIRED_AUTHTOK = 0b0100; | |
| 198 ); | |
| 199 } | |
| 200 | |
| 201 /// Constants exclusive to Illumos. | |
| 202 mod illumos { | |
| 203 /// The total number of PAM error codes. | |
| 204 pub const PAM_TOTAL_ERRNUM: u32 = 28; | |
| 205 | |
| 206 define!( | |
| 207 /// An item type. | |
| 208 PAM_RESOURCE = 11; | |
| 209 PAM_AUSER = 12; | |
| 210 ); | |
| 211 | |
| 212 /// A flag for `pam_chauthtok`. | |
| 213 pub const PAM_NO_AUTHTOK_CHECK: u32 = 0b1000; | |
| 214 } | |
| 215 | |
| 216 /// Constants exclusive to OpenPAM. | |
| 217 mod openpam { | |
| 218 define!( | |
| 219 /// An error code. | |
| 220 PAM_MODULE_UNKNOWN = 28; | |
| 221 PAM_DOMAIN_UNKNOWN = 29; | |
| 222 PAM_BAD_HANDLE = 30; | |
| 223 PAM_BAD_ITEM = 31; | |
| 224 PAM_BAD_FEATURE = 32; | |
| 225 PAM_BAD_CONSTANT = 33; | |
| 226 ); | |
| 227 /// The total number of PAM error codes. | |
| 228 pub const PAM_NUM_ERRORS: i32 = 34; | |
| 229 | |
| 230 define!( | |
| 231 /// An item type. | |
| 232 PAM_AUTHTOK_PROMPT = 11; | |
| 233 PAM_OLDAUTHTOK_PROMPT = 12; | |
| 234 PAM_HOST = 13; | |
| 235 ); | |
| 236 /// The total number of PAM items. | |
| 237 pub const PAM_NUM_ITEMS: u32 = 14; | |
| 238 } | |
| 239 | |
| 240 #[cfg(test)] | |
| 241 mod test {} |
