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