Mercurial > crates > nonstick
comparison libpam-sys/libpam-sys-helpers/src/constants.rs @ 136:efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
This separates the parts of libpam-sys that don't need linking against libpam
from the parts that do need to link against libpam.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Thu, 03 Jul 2025 14:28:04 -0400 |
parents | libpam-sys/src/constants.rs@6c1e1bdb4164 |
children | 88627c057709 |
comparison
equal
deleted
inserted
replaced
135:b52594841480 | 136:efbc235f01d3 |
---|---|
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 #![allow(unused_imports)] | |
8 use num_enum::{IntoPrimitive, TryFromPrimitive}; | |
9 | |
10 /// Macro to make defining a bunch of constants way easier. | |
11 macro_rules! define { | |
12 ($(#[$attr:meta])* $($name:ident = $value:expr);+$(;)?) => { | |
13 define!( | |
14 @meta { $(#[$attr])* } | |
15 $(pub const $name: i32 = $value;)+ | |
16 ); | |
17 }; | |
18 (@meta $m:tt $($i:item)+) => { define!(@expand $($m $i)+); }; | |
19 (@expand $({ $(#[$m:meta])* } $i:item)+) => {$($(#[$m])* $i)+}; | |
20 } | |
21 | |
22 /// Macro to make defining C-style enums way easier. | |
23 macro_rules! c_enum { | |
24 ($(#[$attr:meta])* $($name:ident $(= $value:expr)?,)*) => { | |
25 c_enum!( | |
26 (0) | |
27 $(#[$attr])* | |
28 $($name $(= $value)?,)* | |
29 ); | |
30 }; | |
31 (($n:expr) $(#[$attr:meta])* $name:ident, $($rest:ident $(= $rv:expr)?,)*) => { | |
32 $(#[$attr])* pub const $name: i32 = $n; | |
33 c_enum!(($n + 1) $(#[$attr])* $($rest $(= $rv)?,)*); | |
34 }; | |
35 (($n:expr) $(#[$attr:meta])* $name:ident = $value:expr, $($rest:ident $(= $rv:expr)?,)*) => { | |
36 $(#[$attr])* pub const $name: i32 = $value; | |
37 c_enum!(($value + 1) $(#[$attr])* $($rest $(= $rv)?,)*); | |
38 }; | |
39 (($n:expr) $(#[$attr:meta])*) => {}; | |
40 } | |
41 | |
42 // There are a few truly universal constants. | |
43 // They are defined here directly. | |
44 /// The successful return code. | |
45 pub const PAM_SUCCESS: i32 = 0; | |
46 | |
47 c_enum!( | |
48 /// An item type. | |
49 PAM_SERVICE = 1, | |
50 PAM_USER, | |
51 PAM_TTY, | |
52 PAM_RHOST, | |
53 PAM_CONV, | |
54 PAM_AUTHTOK, | |
55 PAM_OLDAUTHTOK, | |
56 PAM_RUSER, | |
57 PAM_USER_PROMPT, | |
58 ); | |
59 | |
60 c_enum!( | |
61 /// A message style. | |
62 PAM_PROMPT_ECHO_OFF = 1, | |
63 PAM_PROMPT_ECHO_ON, | |
64 PAM_ERROR_MSG, | |
65 PAM_TEXT_INFO, | |
66 ); | |
67 | |
68 define!( | |
69 /// Maximum size of PAM conversation elements (suggested). | |
70 PAM_MAX_NUM_MSG = 32; | |
71 PAM_MAX_MSG_SIZE = 512; | |
72 PAM_MAX_RESP_SIZE = 512; | |
73 ); | |
74 | |
75 #[cfg(pam_impl = "LinuxPam")] | |
76 pub use linux_pam::*; | |
77 #[cfg(pam_impl = "LinuxPam")] | |
78 mod linux_pam { | |
79 use super::{IntoPrimitive, TryFromPrimitive}; | |
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_DISALLOW_NULL_AUTHTOK = 0x0001; | |
120 PAM_ESTABLISH_CRED = 0x0002; | |
121 PAM_DELETE_CRED = 0x0004; | |
122 PAM_REINITIALIZE_CRED = 0x0008; | |
123 PAM_REFRESH_CRED = 0x0010; | |
124 | |
125 PAM_CHANGE_EXPIRED_AUTHTOK = 0x0020; | |
126 | |
127 PAM_PRELIM_CHECK = 0x4000; | |
128 PAM_UPDATE_AUTHTOK = 0x2000; | |
129 PAM_DATA_REPLACE = 0x20000000; | |
130 ); | |
131 | |
132 c_enum!( | |
133 /// An item type (Linux-only). | |
134 PAM_FAIL_DELAY = 10, | |
135 PAM_XDISPLAY, | |
136 PAM_XAUTHDATA, | |
137 PAM_AUTHTOK_TYPE, | |
138 ); | |
139 | |
140 /// To suppress messages in the item cleanup function. | |
141 pub const PAM_DATA_SILENT: i32 = 0x40000000; | |
142 | |
143 // Message styles | |
144 define!( | |
145 /// A message style. | |
146 PAM_RADIO_TYPE = 5; | |
147 PAM_BINARY_PROMPT = 7; | |
148 ); | |
149 | |
150 pub const PAM_MODUTIL_NGROUPS: i32 = 64; | |
151 | |
152 #[derive(Copy, Clone, Debug, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)] | |
153 #[repr(i32)] | |
154 pub enum pam_modutil_redirect_fd { | |
155 PAM_MODUTIL_IGNORE_FD, | |
156 PAM_MODUTIL_PIPE_FD, | |
157 PAM_MODUTIL_NULL_FD, | |
158 } | |
159 | |
160 pub use pam_modutil_redirect_fd::*; | |
161 } | |
162 | |
163 #[cfg(any(pam_impl = "OpenPam", pam_impl = "Sun", pam_impl = "XSso"))] | |
164 pub use xsso_shared::*; | |
165 #[cfg(any(pam_impl = "OpenPam", pam_impl = "Sun", pam_impl = "XSso"))] | |
166 mod xsso_shared { | |
167 c_enum!( | |
168 /// An error return code. | |
169 PAM_OPEN_ERR = 1, | |
170 PAM_SYMBOL_ERR, | |
171 PAM_SERVICE_ERR, | |
172 PAM_SYSTEM_ERR, | |
173 PAM_BUF_ERR, | |
174 PAM_CONV_ERR, | |
175 PAM_PERM_DENIED, | |
176 PAM_MAXTRIES, | |
177 PAM_AUTH_ERR, | |
178 PAM_NEW_AUTHTOK_REQD, | |
179 PAM_CRED_INSUFFICIENT, | |
180 PAM_AUTHINFO_UNAVAIL, | |
181 PAM_USER_UNKNOWN, | |
182 PAM_CRED_UNAVAIL, | |
183 PAM_CRED_EXPIRED, | |
184 PAM_CRED_ERR, | |
185 PAM_ACCT_EXPIRED, | |
186 PAM_AUTHTOK_EXPIRED, | |
187 PAM_SESSION_ERR, | |
188 PAM_AUTHTOK_ERR, | |
189 PAM_AUTHTOK_RECOVERY_ERR, | |
190 PAM_AUTHTOK_LOCK_BUSY, | |
191 PAM_AUTHTOK_DISABLE_AGING, | |
192 PAM_NO_MODULE_DATA, | |
193 PAM_IGNORE, | |
194 PAM_ABORT, | |
195 PAM_TRY_AGAIN, | |
196 ); | |
197 // While `PAM_MODULE_UNKNOWN` and `PAM_DOMAIN_UNKNOWN` are in X/SSO, | |
198 // Sun doesn't use them so we're omitting them here. | |
199 | |
200 /// A general flag for PAM operations. | |
201 pub const PAM_SILENT: i32 = 0x80000000u32 as i32; | |
202 | |
203 /// A flag for `pam_authenticate`. | |
204 pub const PAM_DISALLOW_NULL_AUTHTOK: i32 = 0b1; | |
205 | |
206 define!( | |
207 /// A flag for `pam_setcred`. | |
208 PAM_ESTABLISH_CRED = 0b0001; | |
209 PAM_DELETE_CRED = 0b0010; | |
210 PAM_REINITIALIZE_CRED = 0b0100; | |
211 PAM_REFRESH_CRED = 0b1000; | |
212 ); | |
213 | |
214 define!( | |
215 /// A flag for `pam_sm_chauthtok`. | |
216 PAM_PRELIM_CHECK = 0b0001; | |
217 PAM_UPDATE_AUTHTOK = 0b0010; | |
218 PAM_CHANGE_EXPIRED_AUTHTOK = 0b0100; | |
219 ); | |
220 } | |
221 | |
222 #[cfg(pam_impl = "OpenPam")] | |
223 pub use openpam::*; | |
224 #[cfg(pam_impl = "OpenPam")] | |
225 mod openpam { | |
226 c_enum!( | |
227 /// An error return code. | |
228 PAM_MODULE_UNKNOWN = 28, | |
229 PAM_DOMAIN_UNKNOWN, | |
230 PAM_BAD_HANDLE, | |
231 PAM_BAD_ITEM, | |
232 PAM_BAD_FEATURE, | |
233 PAM_BAD_CONSTANT, | |
234 ); | |
235 /// The total number of PAM error codes (including success). | |
236 pub const PAM_NUM_ERRORS: i32 = 34; | |
237 | |
238 c_enum!( | |
239 /// An item type. | |
240 PAM_REPOSITORY = 10, | |
241 PAM_AUTHTOK_PROMPT, | |
242 PAM_OLDAUTHTOK_PROMPT, | |
243 PAM_HOST, | |
244 ); | |
245 /// The total number of PAM items. | |
246 pub const PAM_NUM_ITEMS: i32 = 14; | |
247 | |
248 c_enum!( | |
249 /// An optional OpenPAM feature. | |
250 OPENPAM_RESTRICT_SERVICE_NAME, | |
251 OPENPAM_VERIFY_POLICY_FILE, | |
252 OPENPAM_RESTRICT_MODULE_NAME, | |
253 OPENPAM_VERIFY_MODULE_FILE, | |
254 OPENPAM_FALLBACK_TO_OTHER, | |
255 ); | |
256 /// The number of optional OpenPAM features. | |
257 pub const OPENPAM_NUM_FEATURES: i32 = 5; | |
258 | |
259 c_enum!( | |
260 /// Log level. | |
261 PAM_LOG_LIBDEBUG = -1, | |
262 PAM_LOG_DEBUG, | |
263 PAM_LOG_VERBOSE, | |
264 PAM_LOG_NOTICE, | |
265 PAM_LOG_ERROR, | |
266 ); | |
267 | |
268 c_enum!( | |
269 /// PAM primitives. | |
270 PAM_SM_AUTHENTICATE, | |
271 PAM_SM_SETCRED, | |
272 PAM_SM_ACCT_MGMT, | |
273 PAM_SM_OPEN_SESSION, | |
274 PAM_SM_CLOSE_SESSION, | |
275 PAM_SM_CHAUTHTOK, | |
276 ); | |
277 /// The number of PAM primitives. | |
278 pub const PAM_NUM_PRIMITIVES: i32 = 6; | |
279 } | |
280 | |
281 /// Constants exclusive to Illumos. | |
282 #[cfg(pam_impl = "Sun")] | |
283 pub use sun::*; | |
284 #[cfg(pam_impl = "Sun")] | |
285 mod sun { | |
286 /// The total number of PAM error codes. | |
287 pub const PAM_TOTAL_ERRNUM: i32 = 28; | |
288 | |
289 c_enum!( | |
290 /// An item type. | |
291 PAM_REPOSITORY = 10, | |
292 PAM_RESOURCE, | |
293 PAM_AUSER, | |
294 ); | |
295 | |
296 /// A flag for `pam_chauthtok`. | |
297 pub const PAM_NO_AUTHTOK_CHECK: i32 = 0b1000; | |
298 } |