Mercurial > crates > nonstick
annotate src/constants.rs @ 170:f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Wed, 16 Jul 2025 18:45:20 -0400 |
parents | 2f5913131295 |
children | e27c5c667a5a |
rev | line source |
---|---|
60
05cc2c27334f
The Big Refactor: clean up docs and exports.
Paul Fisher <paul@pfish.zone>
parents:
59
diff
changeset
|
1 //! Constants and enum values from the PAM library. |
05cc2c27334f
The Big Refactor: clean up docs and exports.
Paul Fisher <paul@pfish.zone>
parents:
59
diff
changeset
|
2 |
146
1bc52025156b
Split PAM items into their own separate struct.
Paul Fisher <paul@pfish.zone>
parents:
139
diff
changeset
|
3 use crate::_doc::{linklist, man7, manbsd, xsso}; |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
4 use bitflags::bitflags; |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
5 use num_enum::{IntoPrimitive, TryFromPrimitive}; |
90
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
6 use std::error::Error; |
131
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
7 use std::ffi::c_int; |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
8 use std::fmt; |
90
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
9 use std::fmt::{Display, Formatter}; |
71
58f9d2a4df38
Reorganize everything again???
Paul Fisher <paul@pfish.zone>
parents:
70
diff
changeset
|
10 use std::result::Result as StdResult; |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
11 |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
12 #[cfg(features = "link")] |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
13 use libpam_sys_consts::constants as pam_constants; |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
14 |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
15 |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
16 /// The union of constants available in all versions of PAM. |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
17 /// The values here are fictitious and should not be used. |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
18 #[cfg(not(features = "link"))] |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
19 mod pam_constants { |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
20 pub const PAM_SUCCESS: i32 = 0; |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
21 |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
22 /// Generates a sequence of values. |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
23 macro_rules! c_enum { |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
24 ($first:ident = $value:expr, $($rest:ident,)*) => { |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
25 c_enum!(($value) $first, $($rest,)*); |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
26 }; |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
27 (($value:expr) $first:ident, $($rest:ident,)*) => { |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
28 pub const $first: i32 = $value; |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
29 c_enum!(($value+1) $($rest,)*); |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
30 }; |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
31 (($value:expr)) => {}; |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
32 } |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
33 |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
34 // Since all these values are fictitious, we can start them wherever. |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
35 // All the items. |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
36 c_enum!( |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
37 PAM_SERVICE = 64, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
38 PAM_USER, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
39 PAM_TTY, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
40 PAM_RHOST, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
41 PAM_CONV, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
42 PAM_AUTHTOK, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
43 PAM_OLDAUTHTOK, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
44 PAM_RUSER, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
45 PAM_USER_PROMPT, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
46 // Linux-only items. |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
47 PAM_FAIL_DELAY, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
48 PAM_XDISPLAY, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
49 PAM_XAUTHDATA, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
50 PAM_AUTHTOK_TYPE, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
51 // OpenPAM-only items. |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
52 PAM_REPOSITORY, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
53 PAM_AUTHTOK_PROMPT, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
54 PAM_OLDAUTHTOK_PROMPT, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
55 PAM_HOST, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
56 // Sun-only items. |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
57 PAM_RESOURCE, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
58 PAM_AUSER, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
59 ); |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
60 |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
61 // Prompt types. |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
62 c_enum!( |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
63 PAM_PROMPT_ECHO_OFF = 96, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
64 PAM_PROMPT_ECHO_ON, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
65 PAM_ERROR_MSG, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
66 PAM_TEXT_INFO, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
67 PAM_RADIO_TYPE, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
68 PAM_BINARY_PROMPT, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
69 ); |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
70 |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
71 // Errors. |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
72 c_enum!( |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
73 PAM_OPEN_ERR = 128, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
74 PAM_SYMBOL_ERR, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
75 PAM_SERVICE_ERR, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
76 PAM_SYSTEM_ERR, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
77 PAM_BUF_ERR, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
78 PAM_PERM_DENIED, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
79 PAM_AUTH_ERR, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
80 PAM_CRED_INSUFFICIENT, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
81 PAM_AUTHINFO_UNAVAIL, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
82 PAM_USER_UNKNOWN, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
83 PAM_MAXTRIES, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
84 PAM_NEW_AUTHTOK_REQD, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
85 PAM_ACCT_EXPIRED, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
86 PAM_SESSION_ERR, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
87 PAM_CRED_UNAVAIL, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
88 PAM_CRED_EXPIRED, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
89 PAM_CRED_ERR, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
90 PAM_NO_MODULE_DATA, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
91 PAM_CONV_ERR, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
92 PAM_AUTHTOK_ERR, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
93 PAM_AUTHTOK_RECOVERY_ERR, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
94 PAM_AUTHTOK_LOCK_BUSY, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
95 PAM_AUTHTOK_DISABLE_AGING, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
96 PAM_TRY_AGAIN, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
97 PAM_IGNORE, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
98 PAM_ABORT, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
99 PAM_AUTHTOK_EXPIRED, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
100 PAM_MODULE_UNKNOWN, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
101 PAM_BAD_ITEM, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
102 PAM_CONV_AGAIN, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
103 PAM_INCOMPLETE, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
104 // OpenPAM-only errors. |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
105 PAM_DOMAIN_UNKNOWN, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
106 PAM_BAD_HANDLE, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
107 PAM_BAD_FEATURE, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
108 PAM_BAD_CONSTANT, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
109 ); |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
110 |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
111 macro_rules! flag_enum { |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
112 ($first:ident = $value:expr, $($rest:ident,)*) => { |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
113 flag_enum!(($value) $first, $($rest,)*); |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
114 }; |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
115 (($value:expr) $first:ident, $($rest:ident,)*) => { |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
116 pub const $first: i32 = $value; |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
117 flag_enum!(($value*2) $($rest,)*); |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
118 }; |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
119 (($value:expr)) => {}; |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
120 } |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
121 |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
122 flag_enum!( |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
123 PAM_SILENT = 256, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
124 PAM_DISALLOW_NULL_AUTHTOK, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
125 PAM_ESTABLISH_CRED, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
126 PAM_DELETE_CRED, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
127 PAM_REINITIALIZE_CRED, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
128 PAM_REFRESH_CRED, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
129 |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
130 PAM_CHANGE_EXPIRED_AUTHTOK, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
131 |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
132 PAM_PRELIM_CHECK, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
133 PAM_UPDATE_AUTHTOK, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
134 PAM_DATA_REPLACE, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
135 PAM_DATA_SILENT, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
136 ); |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
137 } |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
138 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
139 /// Creates a bitflags! macro, with an extra SILENT element. |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
140 macro_rules! pam_flags { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
141 ( |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
142 $(#[$m:meta])* |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
143 $name:ident { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
144 $($inner:tt)* |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
145 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
146 ) => { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
147 bitflags! { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
148 $(#[$m])* |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
149 #[derive(Clone, Copy, Debug, Default, PartialEq)] |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
150 #[repr(transparent)] |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
151 pub struct $name: c_int { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
152 /// The module should not generate any messages. |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
153 const SILENT = pam_constants::PAM_SILENT; |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
154 $($inner)* |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
155 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
156 } |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
157 } |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
158 } |
130
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
159 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
160 pam_flags! { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
161 /// Flags for authentication and account management. |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
162 AuthnFlags { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
163 /// The module should return [AuthError](ErrorCode::AuthError) |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
164 /// if the user has an empty authentication token, rather than |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
165 /// allowing them to log in. |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
166 const DISALLOW_NULL_AUTHTOK = pam_constants::PAM_DISALLOW_NULL_AUTHTOK; |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
167 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
168 } |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
169 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
170 pam_flags! { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
171 /// Flags for changing the authentication token. |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
172 AuthtokFlags { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
173 /// Indicates that the user's authentication token should |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
174 /// only be changed if it is expired. If not passed, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
175 /// the authentication token should be changed unconditionally. |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
176 const CHANGE_EXPIRED_AUTHTOK = pam_constants::PAM_CHANGE_EXPIRED_AUTHTOK; |
90
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
177 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
178 /// Don't check if the password is any good (Sun only). |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
179 #[cfg(pam_impl = "Sun")] |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
180 const NO_AUTHTOK_CHECK = pam_constants::PAM_NO_AUTHTOK_CHECK; |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
181 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
182 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
183 |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
184 pam_flags! { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
185 /// Common flag(s) shared by all PAM actions. |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
186 BaseFlags {} |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
187 } |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
188 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
189 #[cfg(feature = "openpam-ext")] |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
190 const BAD_CONST: ErrorCode = ErrorCode::BadConstant; |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
191 #[cfg(not(feature = "openpam-ext"))] |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
192 const BAD_CONST: ErrorCode = ErrorCode::SystemError; |
64
bbe84835d6db
More organization; add lots of docs.
Paul Fisher <paul@pfish.zone>
parents:
63
diff
changeset
|
193 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
194 macro_rules! flag_enum { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
195 ( |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
196 $(#[$m:meta])* |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
197 $name:ident { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
198 $( |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
199 $(#[$item_m:meta])* |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
200 $item_name:ident = $item_value:expr, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
201 )* |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
202 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
203 ) => { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
204 $(#[$m])* |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
205 #[derive(Clone, Copy, Debug, PartialEq, TryFromPrimitive, IntoPrimitive)] |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
206 #[repr(i32)] |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
207 pub enum $name { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
208 $( |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
209 $(#[$item_m])* |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
210 $item_name = $item_value, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
211 )* |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
212 } |
64
bbe84835d6db
More organization; add lots of docs.
Paul Fisher <paul@pfish.zone>
parents:
63
diff
changeset
|
213 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
214 impl $name { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
215 const ALL_VALUES: i32 = 0 $( | $item_value)*; |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
216 |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
217 fn split(value: i32) -> Result<(Option<Self>, i32)> { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
218 let me = value & Self::ALL_VALUES; |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
219 let them = value & !Self::ALL_VALUES; |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
220 let me = match me { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
221 0 => None, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
222 n => Some(Self::try_from(n).map_err(|_| BAD_CONST)?), |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
223 }; |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
224 Ok((me, them)) |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
225 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
226 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
227 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
228 } |
64
bbe84835d6db
More organization; add lots of docs.
Paul Fisher <paul@pfish.zone>
parents:
63
diff
changeset
|
229 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
230 flag_enum! { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
231 /// The credential management action that should take place. |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
232 CredAction { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
233 /// Set the user's credentials from this module. Default if unspecified. |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
234 Establish = pam_constants::PAM_ESTABLISH_CRED, |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
235 /// Revoke the user's credentials established by this module. |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
236 Delete = pam_constants::PAM_DELETE_CRED, |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
237 /// Fully reinitialize the user's credentials from this module. |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
238 Reinitialize = pam_constants::PAM_REINITIALIZE_CRED, |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
239 /// Extend the lifetime of the user's credentials from this module. |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
240 Refresh = pam_constants::PAM_REFRESH_CRED, |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
241 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
242 } |
64
bbe84835d6db
More organization; add lots of docs.
Paul Fisher <paul@pfish.zone>
parents:
63
diff
changeset
|
243 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
244 impl CredAction { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
245 /// Separates this enum from the remaining [`BaseFlags`]. |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
246 pub fn extract(value: i32) -> Result<(Self, BaseFlags)> { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
247 Self::split(value) |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
248 .map(|(act, rest)| (act.unwrap_or_default(), BaseFlags::from_bits_retain(rest))) |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
249 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
250 } |
64
bbe84835d6db
More organization; add lots of docs.
Paul Fisher <paul@pfish.zone>
parents:
63
diff
changeset
|
251 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
252 impl Default for CredAction { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
253 fn default() -> Self { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
254 Self::Establish |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
255 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
256 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
257 |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
258 flag_enum! { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
259 AuthtokAction { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
260 /// This is a preliminary call to check if we're ready to change passwords |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
261 /// and that the new password is acceptable. |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
262 PreliminaryCheck = pam_constants::PAM_PRELIM_CHECK, |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
263 /// You should actually update the password. |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
264 Update = pam_constants::PAM_UPDATE_AUTHTOK, |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
265 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
266 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
267 |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
268 impl AuthtokAction { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
269 /// Separates this enum from the remaining [`AuthtokFlags`]. |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
270 pub fn extract(value: i32) -> Result<(Self, AuthtokFlags)> { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
271 match Self::split(value)? { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
272 (Some(act), rest) => Ok((act, AuthtokFlags::from_bits_retain(rest))), |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
273 (None, _) => Err(BAD_CONST), |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
274 } |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
275 } |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
276 } |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
277 |
103
dfcd96a74ac4
write a truly prodigious amount of documentation
Paul Fisher <paul@pfish.zone>
parents:
97
diff
changeset
|
278 /// The PAM error return codes. |
dfcd96a74ac4
write a truly prodigious amount of documentation
Paul Fisher <paul@pfish.zone>
parents:
97
diff
changeset
|
279 /// |
dfcd96a74ac4
write a truly prodigious amount of documentation
Paul Fisher <paul@pfish.zone>
parents:
97
diff
changeset
|
280 /// These are returned by most PAM functions if an error of some kind occurs. |
dfcd96a74ac4
write a truly prodigious amount of documentation
Paul Fisher <paul@pfish.zone>
parents:
97
diff
changeset
|
281 /// |
dfcd96a74ac4
write a truly prodigious amount of documentation
Paul Fisher <paul@pfish.zone>
parents:
97
diff
changeset
|
282 /// Instead of being an error code, success is represented by an Ok [`Result`]. |
60
05cc2c27334f
The Big Refactor: clean up docs and exports.
Paul Fisher <paul@pfish.zone>
parents:
59
diff
changeset
|
283 /// |
103
dfcd96a74ac4
write a truly prodigious amount of documentation
Paul Fisher <paul@pfish.zone>
parents:
97
diff
changeset
|
284 /// # References |
dfcd96a74ac4
write a truly prodigious amount of documentation
Paul Fisher <paul@pfish.zone>
parents:
97
diff
changeset
|
285 /// |
116
a12706e42c9d
Logging, macros, and building:
Paul Fisher <paul@pfish.zone>
parents:
113
diff
changeset
|
286 #[doc = linklist!(pam: man7, manbsd)] |
103
dfcd96a74ac4
write a truly prodigious amount of documentation
Paul Fisher <paul@pfish.zone>
parents:
97
diff
changeset
|
287 /// - [X/SSO error code specification][xsso] |
dfcd96a74ac4
write a truly prodigious amount of documentation
Paul Fisher <paul@pfish.zone>
parents:
97
diff
changeset
|
288 /// |
116
a12706e42c9d
Logging, macros, and building:
Paul Fisher <paul@pfish.zone>
parents:
113
diff
changeset
|
289 #[doc = man7!(3 pam "RETURN_VALUES")] |
a12706e42c9d
Logging, macros, and building:
Paul Fisher <paul@pfish.zone>
parents:
113
diff
changeset
|
290 #[doc = manbsd!(3 pam "RETURN%20VALUES")] |
a12706e42c9d
Logging, macros, and building:
Paul Fisher <paul@pfish.zone>
parents:
113
diff
changeset
|
291 #[doc = xsso!("chap5.htm#tagcjh_06_02")] |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
292 #[allow(non_camel_case_types, dead_code)] |
90
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
293 #[derive(Copy, Clone, Debug, PartialEq, TryFromPrimitive, IntoPrimitive)] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
294 #[non_exhaustive] // C might give us anything! |
113
178310336596
Fix up more constants, make things i32 rather than u32.
Paul Fisher <paul@pfish.zone>
parents:
108
diff
changeset
|
295 #[repr(i32)] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
296 pub enum ErrorCode { |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
297 OpenError = pam_constants::PAM_OPEN_ERR, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
298 SymbolError = pam_constants::PAM_SYMBOL_ERR, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
299 ServiceError = pam_constants::PAM_SERVICE_ERR, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
300 SystemError = pam_constants::PAM_SYSTEM_ERR, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
301 BufferError = pam_constants::PAM_BUF_ERR, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
302 PermissionDenied = pam_constants::PAM_PERM_DENIED, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
303 AuthenticationError = pam_constants::PAM_AUTH_ERR, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
304 CredentialsInsufficient = pam_constants::PAM_CRED_INSUFFICIENT, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
305 AuthInfoUnavailable = pam_constants::PAM_AUTHINFO_UNAVAIL, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
306 UserUnknown = pam_constants::PAM_USER_UNKNOWN, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
307 MaxTries = pam_constants::PAM_MAXTRIES, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
308 NewAuthTokRequired = pam_constants::PAM_NEW_AUTHTOK_REQD, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
309 AccountExpired = pam_constants::PAM_ACCT_EXPIRED, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
310 SessionError = pam_constants::PAM_SESSION_ERR, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
311 CredentialsUnavailable = pam_constants::PAM_CRED_UNAVAIL, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
312 CredentialsExpired = pam_constants::PAM_CRED_EXPIRED, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
313 CredentialsError = pam_constants::PAM_CRED_ERR, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
314 NoModuleData = pam_constants::PAM_NO_MODULE_DATA, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
315 ConversationError = pam_constants::PAM_CONV_ERR, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
316 AuthTokError = pam_constants::PAM_AUTHTOK_ERR, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
317 AuthTokRecoveryError = pam_constants::PAM_AUTHTOK_RECOVERY_ERR, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
318 AuthTokLockBusy = pam_constants::PAM_AUTHTOK_LOCK_BUSY, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
319 AuthTokDisableAging = pam_constants::PAM_AUTHTOK_DISABLE_AGING, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
320 TryAgain = pam_constants::PAM_TRY_AGAIN, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
321 Ignore = pam_constants::PAM_IGNORE, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
322 Abort = pam_constants::PAM_ABORT, |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
323 AuthTokExpired = pam_constants::PAM_AUTHTOK_EXPIRED, |
108
e97534be35e3
Make some proc macros for doing cfg-like stuff for PAM impls.
Paul Fisher <paul@pfish.zone>
parents:
103
diff
changeset
|
324 #[cfg(feature = "basic-ext")] |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
325 ModuleUnknown = pam_constants::PAM_MODULE_UNKNOWN, |
108
e97534be35e3
Make some proc macros for doing cfg-like stuff for PAM impls.
Paul Fisher <paul@pfish.zone>
parents:
103
diff
changeset
|
326 #[cfg(feature = "basic-ext")] |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
327 BadItem = pam_constants::PAM_BAD_ITEM, |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
328 #[cfg(feature = "linux-pam-ext")] |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
329 ConversationAgain = pam_constants::PAM_CONV_AGAIN, |
108
e97534be35e3
Make some proc macros for doing cfg-like stuff for PAM impls.
Paul Fisher <paul@pfish.zone>
parents:
103
diff
changeset
|
330 #[cfg(feature = "linux-pam-ext")] |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
331 Incomplete = pam_constants::PAM_INCOMPLETE, |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
332 #[cfg(feature = "openpam-ext")] |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
333 DomainUnknown = pam_constants::PAM_DOMAIN_UNKNOWN, |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
334 #[cfg(feature = "openpam-ext")] |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
335 BadHandle = pam_constants::PAM_BAD_HANDLE, |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
336 #[cfg(feature = "openpam-ext")] |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
337 BadFeature = pam_constants::PAM_BAD_FEATURE, |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
338 #[cfg(feature = "openpam-ext")] |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
339 BadConstant = pam_constants::PAM_BAD_CONSTANT, |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
340 } |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
341 |
60
05cc2c27334f
The Big Refactor: clean up docs and exports.
Paul Fisher <paul@pfish.zone>
parents:
59
diff
changeset
|
342 /// A PAM-specific Result type with an [ErrorCode] error. |
71
58f9d2a4df38
Reorganize everything again???
Paul Fisher <paul@pfish.zone>
parents:
70
diff
changeset
|
343 pub type Result<T> = StdResult<T, ErrorCode>; |
60
05cc2c27334f
The Big Refactor: clean up docs and exports.
Paul Fisher <paul@pfish.zone>
parents:
59
diff
changeset
|
344 |
90
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
345 impl Display for ErrorCode { |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
346 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { |
130
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
347 match strerror((*self).into()) { |
90
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
348 Some(err) => f.write_str(err), |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
349 None => self.fmt_internal(f), |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
350 } |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
351 } |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
352 } |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
353 |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
354 impl Error for ErrorCode {} |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
355 |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
356 impl ErrorCode { |
60
05cc2c27334f
The Big Refactor: clean up docs and exports.
Paul Fisher <paul@pfish.zone>
parents:
59
diff
changeset
|
357 /// Converts this [Result] into a C-compatible result code. |
05cc2c27334f
The Big Refactor: clean up docs and exports.
Paul Fisher <paul@pfish.zone>
parents:
59
diff
changeset
|
358 pub fn result_to_c<T>(value: Result<T>) -> c_int { |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
359 match value { |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
360 Ok(_) => 0, // PAM_SUCCESS |
113
178310336596
Fix up more constants, make things i32 rather than u32.
Paul Fisher <paul@pfish.zone>
parents:
108
diff
changeset
|
361 Err(otherwise) => otherwise.into(), |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
362 } |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
363 } |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
364 |
60
05cc2c27334f
The Big Refactor: clean up docs and exports.
Paul Fisher <paul@pfish.zone>
parents:
59
diff
changeset
|
365 /// Converts a C result code into a [Result], with success as Ok. |
59
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
366 /// Invalid values are returned as a [Self::SystemError]. |
60
05cc2c27334f
The Big Refactor: clean up docs and exports.
Paul Fisher <paul@pfish.zone>
parents:
59
diff
changeset
|
367 pub fn result_from(value: c_int) -> Result<()> { |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
368 match value { |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
369 0 => Ok(()), |
113
178310336596
Fix up more constants, make things i32 rather than u32.
Paul Fisher <paul@pfish.zone>
parents:
108
diff
changeset
|
370 value => Err(value.try_into().unwrap_or(Self::SystemError)), |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
371 } |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
372 } |
90
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
373 |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
374 /// A basic Display implementation for if we don't link against PAM. |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
375 fn fmt_internal(self, f: &mut Formatter<'_>) -> fmt::Result { |
131
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
376 let n: c_int = self.into(); |
130
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
377 write!(f, "PAM error: {self:?} ({n})") |
90
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
378 } |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
379 } |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
380 |
130
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
381 /// Gets a string version of an error message. |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
382 #[cfg(feature = "link")] |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
383 pub fn strerror(code: c_int) -> Option<&'static str> { |
131
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
384 use std::ffi::CStr; |
130
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
385 use std::ptr; |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
386 // SAFETY: PAM impls don't care about the PAM handle and always return |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
387 // static strings. |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
388 let strerror = unsafe { libpam_sys::pam_strerror(ptr::null(), code as c_int) }; |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
389 // SAFETY: We just got this back from PAM and we checked if it's null. |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
390 (!strerror.is_null()) |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
391 .then(|| unsafe { CStr::from_ptr(strerror) }.to_str().ok()) |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
392 .flatten() |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
393 } |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
394 |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
395 /// Dummy implementation of strerror so that it always returns None. |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
396 #[cfg(not(feature = "link"))] |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
397 pub fn strerror(_: c_int) -> Option<&'static str> { |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
398 None |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
399 } |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
400 |
59
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
401 #[cfg(test)] |
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
402 mod tests { |
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
403 use super::*; |
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
404 |
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
405 #[test] |
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
406 fn test_enums() { |
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
407 assert_eq!(Ok(()), ErrorCode::result_from(0)); |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
408 assert_eq!( |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
409 pam_constants::PAM_SESSION_ERR, |
108
e97534be35e3
Make some proc macros for doing cfg-like stuff for PAM impls.
Paul Fisher <paul@pfish.zone>
parents:
103
diff
changeset
|
410 ErrorCode::result_to_c::<()>(Err(ErrorCode::SessionError)) |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
411 ); |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
412 assert_eq!( |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
413 Err(ErrorCode::Abort), |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
414 ErrorCode::result_from(pam_constants::PAM_ABORT) |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
415 ); |
59
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
416 assert_eq!(Err(ErrorCode::SystemError), ErrorCode::result_from(423)); |
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
417 } |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
418 |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
419 #[test] |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
420 fn test_flag_enums() { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
421 AuthtokAction::extract(-1).expect_err("too many set"); |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
422 AuthtokAction::extract(0).expect_err("too few set"); |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
423 assert_eq!( |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
424 Ok(( |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
425 AuthtokAction::Update, |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
426 AuthtokFlags::from_bits_retain(0x7f000000) |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
427 )), |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
428 AuthtokAction::extract(0x7f000000 | pam_constants::PAM_UPDATE_AUTHTOK) |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
429 ); |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
430 CredAction::extract(0xffff).expect_err("too many set"); |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
431 assert_eq!( |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
432 Ok((CredAction::Establish, BaseFlags::empty())), |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
433 CredAction::extract(0) |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
434 ); |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
435 assert_eq!( |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
436 Ok((CredAction::Delete, BaseFlags::from_bits_retain(0x55000000))), |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
437 CredAction::extract(0x55000000 | pam_constants::PAM_DELETE_CRED) |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
438 ); |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
439 } |
59
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
440 } |