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