Mercurial > crates > nonstick
comparison libpam-sys/src/constants.rs @ 176:0730f5f2ee2a
Turn `libpam-sys-consts` back into `libpam-sys-impls`.
This moves the constants into `libpam-sys` and makes `libpam-sys-impls`
responsible solely for detecting the current PAM implementation.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Wed, 30 Jul 2025 17:53:31 -0400 |
parents | libpam-sys/libpam-sys-consts/src/constants.rs@f052e2417195 |
children |
comparison
equal
deleted
inserted
replaced
175:e30775c80b49 | 176:0730f5f2ee2a |
---|---|
1 //! All of `libpam`'s constants. | |
2 //! | |
3 //! These constants are tested on a per-platform basis by `libpam-sys-test`'s | |
4 //! `test_constants.rs`. | |
5 | |
6 #![allow(non_camel_case_types)] | |
7 | |
8 /// Macro to make defining a bunch of constants way easier. | |
9 macro_rules! define { | |
10 ($(#[$attr:meta])* $($name:ident = $value:expr);+$(;)?) => { | |
11 define!( | |
12 @meta { $(#[$attr])* } | |
13 $(pub const $name: i32 = $value;)+ | |
14 ); | |
15 }; | |
16 (@meta $m:tt $($i:item)+) => { define!(@expand $($m $i)+); }; | |
17 (@expand $({ $(#[$m:meta])* } $i:item)+) => {$($(#[$m])* $i)+}; | |
18 } | |
19 | |
20 /// Macro to make defining C-style enums way easier. | |
21 macro_rules! c_enum { | |
22 ($(#[$attr:meta])* $($name:ident $(= $value:expr)?,)*) => { | |
23 c_enum!( | |
24 (0) | |
25 $(#[$attr])* | |
26 $($name $(= $value)?,)* | |
27 ); | |
28 }; | |
29 (($n:expr) $(#[$attr:meta])* $name:ident, $($rest:ident $(= $rv:expr)?,)*) => { | |
30 $(#[$attr])* pub const $name: i32 = $n; | |
31 c_enum!(($n + 1) $(#[$attr])* $($rest $(= $rv)?,)*); | |
32 }; | |
33 (($n:expr) $(#[$attr:meta])* $name:ident = $value:expr, $($rest:ident $(= $rv:expr)?,)*) => { | |
34 $(#[$attr])* pub const $name: i32 = $value; | |
35 c_enum!(($value + 1) $(#[$attr])* $($rest $(= $rv)?,)*); | |
36 }; | |
37 (($n:expr) $(#[$attr:meta])*) => {}; | |
38 } | |
39 | |
40 // There are a few truly universal constants. | |
41 // They are defined here directly. | |
42 /// The successful return code. | |
43 pub const PAM_SUCCESS: i32 = 0; | |
44 | |
45 c_enum!( | |
46 /// An item type. | |
47 PAM_SERVICE = 1, | |
48 PAM_USER, | |
49 PAM_TTY, | |
50 PAM_RHOST, | |
51 PAM_CONV, | |
52 PAM_AUTHTOK, | |
53 PAM_OLDAUTHTOK, | |
54 PAM_RUSER, | |
55 PAM_USER_PROMPT, | |
56 ); | |
57 | |
58 c_enum!( | |
59 /// A message style. | |
60 PAM_PROMPT_ECHO_OFF = 1, | |
61 PAM_PROMPT_ECHO_ON, | |
62 PAM_ERROR_MSG, | |
63 PAM_TEXT_INFO, | |
64 ); | |
65 | |
66 define!( | |
67 /// Maximum size of PAM conversation elements (suggested). | |
68 PAM_MAX_NUM_MSG = 32; | |
69 PAM_MAX_MSG_SIZE = 512; | |
70 PAM_MAX_RESP_SIZE = 512; | |
71 ); | |
72 | |
73 /// A flag for `pam_authenticate`. | |
74 pub const PAM_DISALLOW_NULL_AUTHTOK: i32 = 0x1; | |
75 | |
76 #[cfg(pam_impl = "LinuxPam")] | |
77 pub use linux_pam::*; | |
78 #[cfg(pam_impl = "LinuxPam")] | |
79 mod linux_pam { | |
80 c_enum!( | |
81 /// An error return code. | |
82 PAM_OPEN_ERR = 1, | |
83 PAM_SYMBOL_ERR, | |
84 PAM_SERVICE_ERR, | |
85 PAM_SYSTEM_ERR, | |
86 PAM_BUF_ERR, | |
87 PAM_PERM_DENIED, | |
88 PAM_AUTH_ERR, | |
89 PAM_CRED_INSUFFICIENT, | |
90 PAM_AUTHINFO_UNAVAIL, | |
91 PAM_USER_UNKNOWN, | |
92 PAM_MAXTRIES, | |
93 PAM_NEW_AUTHTOK_REQD, | |
94 PAM_ACCT_EXPIRED, | |
95 PAM_SESSION_ERR, | |
96 PAM_CRED_UNAVAIL, | |
97 PAM_CRED_EXPIRED, | |
98 PAM_CRED_ERR, | |
99 PAM_NO_MODULE_DATA, | |
100 PAM_CONV_ERR, | |
101 PAM_AUTHTOK_ERR, | |
102 PAM_AUTHTOK_RECOVERY_ERR, | |
103 PAM_AUTHTOK_LOCK_BUSY, | |
104 PAM_AUTHTOK_DISABLE_AGING, | |
105 PAM_TRY_AGAIN, | |
106 PAM_IGNORE, | |
107 PAM_ABORT, | |
108 PAM_AUTHTOK_EXPIRED, | |
109 PAM_MODULE_UNKNOWN, | |
110 PAM_BAD_ITEM, | |
111 PAM_CONV_AGAIN, | |
112 PAM_INCOMPLETE, | |
113 _PAM_RETURN_VALUES, | |
114 ); | |
115 | |
116 define!( | |
117 /// A flag value. | |
118 PAM_SILENT = 0x8000; | |
119 PAM_ESTABLISH_CRED = 0x0002; | |
120 PAM_DELETE_CRED = 0x0004; | |
121 PAM_REINITIALIZE_CRED = 0x0008; | |
122 PAM_REFRESH_CRED = 0x0010; | |
123 | |
124 PAM_CHANGE_EXPIRED_AUTHTOK = 0x0020; | |
125 | |
126 PAM_PRELIM_CHECK = 0x4000; | |
127 PAM_UPDATE_AUTHTOK = 0x2000; | |
128 PAM_DATA_REPLACE = 0x20000000; | |
129 ); | |
130 | |
131 c_enum!( | |
132 /// An item type (Linux-only). | |
133 PAM_FAIL_DELAY = 10, | |
134 PAM_XDISPLAY, | |
135 PAM_XAUTHDATA, | |
136 PAM_AUTHTOK_TYPE, | |
137 ); | |
138 | |
139 /// To suppress messages in the item cleanup function. | |
140 pub const PAM_DATA_SILENT: i32 = 0x40000000; | |
141 | |
142 // Message styles | |
143 define!( | |
144 /// A message style. | |
145 PAM_RADIO_TYPE = 5; | |
146 PAM_BINARY_PROMPT = 7; | |
147 ); | |
148 | |
149 pub const PAM_MODUTIL_NGROUPS: i32 = 64; | |
150 | |
151 #[derive(Copy, Clone, Debug, PartialEq, Eq)] | |
152 #[repr(i32)] | |
153 pub enum pam_modutil_redirect_fd { | |
154 PAM_MODUTIL_IGNORE_FD, | |
155 PAM_MODUTIL_PIPE_FD, | |
156 PAM_MODUTIL_NULL_FD, | |
157 } | |
158 | |
159 impl From<pam_modutil_redirect_fd> for i32 { | |
160 fn from(value: pam_modutil_redirect_fd) -> Self { | |
161 value as Self | |
162 } | |
163 } | |
164 | |
165 impl TryFrom<i32> for pam_modutil_redirect_fd { | |
166 type Error = i32; | |
167 fn try_from(value: i32) -> Result<Self, Self::Error> { | |
168 match value { | |
169 0..=2 => Ok(unsafe { *(&value as *const i32).cast() }), | |
170 other => Err(other), | |
171 } | |
172 } | |
173 } | |
174 | |
175 pub use pam_modutil_redirect_fd::*; | |
176 } | |
177 | |
178 #[cfg(any(pam_impl = "OpenPam", pam_impl = "Sun", pam_impl = "XSso"))] | |
179 pub use xsso_shared::*; | |
180 #[cfg(any(pam_impl = "OpenPam", pam_impl = "Sun", pam_impl = "XSso"))] | |
181 mod xsso_shared { | |
182 c_enum!( | |
183 /// An error return code. | |
184 PAM_OPEN_ERR = 1, | |
185 PAM_SYMBOL_ERR, | |
186 PAM_SERVICE_ERR, | |
187 PAM_SYSTEM_ERR, | |
188 PAM_BUF_ERR, | |
189 PAM_CONV_ERR, | |
190 PAM_PERM_DENIED, | |
191 PAM_MAXTRIES, | |
192 PAM_AUTH_ERR, | |
193 PAM_NEW_AUTHTOK_REQD, | |
194 PAM_CRED_INSUFFICIENT, | |
195 PAM_AUTHINFO_UNAVAIL, | |
196 PAM_USER_UNKNOWN, | |
197 PAM_CRED_UNAVAIL, | |
198 PAM_CRED_EXPIRED, | |
199 PAM_CRED_ERR, | |
200 PAM_ACCT_EXPIRED, | |
201 PAM_AUTHTOK_EXPIRED, | |
202 PAM_SESSION_ERR, | |
203 PAM_AUTHTOK_ERR, | |
204 PAM_AUTHTOK_RECOVERY_ERR, | |
205 PAM_AUTHTOK_LOCK_BUSY, | |
206 PAM_AUTHTOK_DISABLE_AGING, | |
207 PAM_NO_MODULE_DATA, | |
208 PAM_IGNORE, | |
209 PAM_ABORT, | |
210 PAM_TRY_AGAIN, | |
211 ); | |
212 // While `PAM_MODULE_UNKNOWN` and `PAM_DOMAIN_UNKNOWN` are in X/SSO, | |
213 // Sun doesn't use them so we're omitting them here. | |
214 | |
215 /// A general flag for PAM operations. | |
216 pub const PAM_SILENT: i32 = 0x80000000u32 as i32; | |
217 | |
218 define!( | |
219 /// A flag for `pam_setcred`. | |
220 PAM_ESTABLISH_CRED = 0b0001; | |
221 PAM_DELETE_CRED = 0b0010; | |
222 PAM_REINITIALIZE_CRED = 0b0100; | |
223 PAM_REFRESH_CRED = 0b1000; | |
224 ); | |
225 | |
226 define!( | |
227 /// A flag for `pam_sm_chauthtok`. | |
228 PAM_PRELIM_CHECK = 0b0001; | |
229 PAM_UPDATE_AUTHTOK = 0b0010; | |
230 PAM_CHANGE_EXPIRED_AUTHTOK = 0b0100; | |
231 ); | |
232 } | |
233 | |
234 #[cfg(pam_impl = "OpenPam")] | |
235 pub use openpam::*; | |
236 #[cfg(pam_impl = "OpenPam")] | |
237 mod openpam { | |
238 c_enum!( | |
239 /// An error return code. | |
240 PAM_MODULE_UNKNOWN = 28, | |
241 PAM_DOMAIN_UNKNOWN, | |
242 PAM_BAD_HANDLE, | |
243 PAM_BAD_ITEM, | |
244 PAM_BAD_FEATURE, | |
245 PAM_BAD_CONSTANT, | |
246 ); | |
247 /// The total number of PAM error codes (including success). | |
248 pub const PAM_NUM_ERRORS: i32 = 34; | |
249 | |
250 c_enum!( | |
251 /// An item type. | |
252 PAM_REPOSITORY = 10, | |
253 PAM_AUTHTOK_PROMPT, | |
254 PAM_OLDAUTHTOK_PROMPT, | |
255 PAM_HOST, | |
256 ); | |
257 /// The total number of PAM items. | |
258 pub const PAM_NUM_ITEMS: i32 = 14; | |
259 | |
260 c_enum!( | |
261 /// An optional OpenPAM feature. | |
262 OPENPAM_RESTRICT_SERVICE_NAME, | |
263 OPENPAM_VERIFY_POLICY_FILE, | |
264 OPENPAM_RESTRICT_MODULE_NAME, | |
265 OPENPAM_VERIFY_MODULE_FILE, | |
266 OPENPAM_FALLBACK_TO_OTHER, | |
267 ); | |
268 /// The number of optional OpenPAM features. | |
269 pub const OPENPAM_NUM_FEATURES: i32 = 5; | |
270 | |
271 c_enum!( | |
272 /// Log level. | |
273 PAM_LOG_LIBDEBUG = -1, | |
274 PAM_LOG_DEBUG, | |
275 PAM_LOG_VERBOSE, | |
276 PAM_LOG_NOTICE, | |
277 PAM_LOG_ERROR, | |
278 ); | |
279 | |
280 c_enum!( | |
281 /// PAM primitives. | |
282 PAM_SM_AUTHENTICATE, | |
283 PAM_SM_SETCRED, | |
284 PAM_SM_ACCT_MGMT, | |
285 PAM_SM_OPEN_SESSION, | |
286 PAM_SM_CLOSE_SESSION, | |
287 PAM_SM_CHAUTHTOK, | |
288 ); | |
289 /// The number of PAM primitives. | |
290 pub const PAM_NUM_PRIMITIVES: i32 = 6; | |
291 } | |
292 | |
293 /// Constants exclusive to Illumos. | |
294 #[cfg(pam_impl = "Sun")] | |
295 pub use sun::*; | |
296 #[cfg(pam_impl = "Sun")] | |
297 mod sun { | |
298 /// The total number of PAM error codes. | |
299 pub const PAM_TOTAL_ERRNUM: i32 = 28; | |
300 | |
301 c_enum!( | |
302 /// An item type. | |
303 PAM_REPOSITORY = 10, | |
304 PAM_RESOURCE, | |
305 PAM_AUSER, | |
306 ); | |
307 | |
308 /// A flag for `pam_chauthtok`. | |
309 pub const PAM_NO_AUTHTOK_CHECK: i32 = 0b1000; | |
310 | |
311 define!( | |
312 /// A flag for `__pam_get_authtok`. | |
313 PAM_PROMPT = 1; | |
314 PAM_HANDLE = 2; | |
315 ); | |
316 } |