Mercurial > crates > nonstick
annotate src/constants.rs @ 189:b2456d274576 default tip
Add line breaks that rustfmt ate back to documentation.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Thu, 31 Jul 2025 15:42:12 -0400 |
parents | 5e4ea9650f87 |
children |
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 |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
3 use crate::_doc::{linklist, man7, manbsd, mansun, 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; |
90
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
5 use std::error::Error; |
185
fb8b547b36b7
Banish al(most al)l use of `i32` in favor of `c_int`.
Paul Fisher <paul@pfish.zone>
parents:
180
diff
changeset
|
6 use std::ffi::c_int; |
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::fmt; |
71
58f9d2a4df38
Reorganize everything again???
Paul Fisher <paul@pfish.zone>
parents:
70
diff
changeset
|
8 use std::result::Result as StdResult; |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
9 |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
10 macro_rules! wrapper { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
11 ( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
12 $(#[$m:meta])* |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
13 $viz:vis $name:ident($wraps:ty); |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
14 ) => { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
15 $(#[$m])* |
186
5e4ea9650f87
Derive `hash` where it makes sense.
Paul Fisher <paul@pfish.zone>
parents:
185
diff
changeset
|
16 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
17 #[repr(transparent)] |
185
fb8b547b36b7
Banish al(most al)l use of `i32` in favor of `c_int`.
Paul Fisher <paul@pfish.zone>
parents:
180
diff
changeset
|
18 $viz struct $name($wraps); |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
19 |
185
fb8b547b36b7
Banish al(most al)l use of `i32` in favor of `c_int`.
Paul Fisher <paul@pfish.zone>
parents:
180
diff
changeset
|
20 impl From<$wraps> for $name { |
fb8b547b36b7
Banish al(most al)l use of `i32` in favor of `c_int`.
Paul Fisher <paul@pfish.zone>
parents:
180
diff
changeset
|
21 fn from(value: $wraps) -> Self { |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
22 Self(value) |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
23 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
24 } |
185
fb8b547b36b7
Banish al(most al)l use of `i32` in favor of `c_int`.
Paul Fisher <paul@pfish.zone>
parents:
180
diff
changeset
|
25 impl From<$name> for $wraps { |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
26 fn from(value: $name) -> Self { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
27 value.0 |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
28 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
29 } |
170
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 } |
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
32 |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
33 wrapper! { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
34 /// Type of the flags that PAM passes to us (or that we pass to PAM). |
185
fb8b547b36b7
Banish al(most al)l use of `i32` in favor of `c_int`.
Paul Fisher <paul@pfish.zone>
parents:
180
diff
changeset
|
35 pub RawFlags(c_int); |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
36 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
37 wrapper! { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
38 /// The error code that we return to PAM. |
185
fb8b547b36b7
Banish al(most al)l use of `i32` in favor of `c_int`.
Paul Fisher <paul@pfish.zone>
parents:
180
diff
changeset
|
39 pub ReturnCode(c_int); |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
40 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
41 |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
42 impl ReturnCode { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
43 /// A successful return. |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
44 pub const SUCCESS: Self = Self(0); |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
45 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
46 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
47 macro_rules! pam_flags { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
48 ( |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
49 $(#[$m:meta])* |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
50 $name:ident { |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
51 $( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
52 $(#[$m_ident:ident $($m_arg:tt)*])* |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
53 const $item_name:ident = (link = $value_value:expr, else = $other_value:expr); |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
54 )* |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
55 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
56 ) => { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
57 bitflags! { |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
58 #[derive(Clone, Copy, Debug, Default, PartialEq)] |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
59 $(#[$m])* |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
60 pub struct $name: u16 { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
61 $( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
62 $(#[$m_ident $($m_arg)*])* |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
63 const $item_name = $other_value; |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
64 )* |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
65 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
66 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
67 |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
68 #[cfg(feature = "link")] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
69 impl From<RawFlags> for $name { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
70 #[allow(unused_doc_comments)] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
71 fn from(value: RawFlags) -> Self { |
185
fb8b547b36b7
Banish al(most al)l use of `i32` in favor of `c_int`.
Paul Fisher <paul@pfish.zone>
parents:
180
diff
changeset
|
72 let value: c_int = value.into(); |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
73 let result = Self::empty(); |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
74 $( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
75 $(#[$m_ident $($m_arg)*])* |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
76 let result = result | if value & $value_value == 0 { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
77 Self::empty() |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
78 } else { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
79 Self::$item_name |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
80 }; |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
81 )* |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
82 result |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
83 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
84 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
85 |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
86 #[cfg(feature = "link")] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
87 impl From<$name> for RawFlags { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
88 #[allow(unused_doc_comments)] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
89 fn from(value: $name) -> Self { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
90 let result = 0; |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
91 $( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
92 $(#[$m_ident $($m_arg)*])* |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
93 let result = result | if value.contains($name::$item_name) { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
94 $value_value |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
95 } else { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
96 0 |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
97 }; |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
98 )* |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
99 Self(result) |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
100 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
101 } |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
102 } |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
103 } |
130
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
104 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
105 pam_flags! { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
106 /// Flags for authentication and account management. |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
107 AuthnFlags { |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
108 /// The PAM module should not generate any messages. |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
109 const SILENT = (link = libpam_sys::PAM_SILENT, else = 0x8000); |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
110 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
111 /// 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
|
112 /// 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
|
113 /// allowing them to log in. |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
114 const DISALLOW_NULL_AUTHTOK = (link = libpam_sys::PAM_DISALLOW_NULL_AUTHTOK, else = 0b1); |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
115 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
116 } |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
117 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
118 pam_flags! { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
119 /// Flags for changing the authentication token. |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
120 AuthtokFlags { |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
121 /// The PAM module should not generate any messages. |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
122 const SILENT = (link = libpam_sys::PAM_SILENT, else = 0x8000); |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
123 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
124 /// 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
|
125 /// 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
|
126 /// the authentication token should be changed unconditionally. |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
127 const CHANGE_EXPIRED_AUTHTOK = (link = libpam_sys::PAM_CHANGE_EXPIRED_AUTHTOK, else = 0b10); |
90
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
128 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
129 /// Don't check if the password is any good (Sun only). |
175
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
130 #[cfg(feature = "sun-ext")] |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
131 const NO_AUTHTOK_CHECK = (link = libpam_sys::PAM_NO_AUTHTOK_CHECK, else = 0b100); |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
132 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
133 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
134 |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
135 pam_flags! { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
136 /// Common flag(s) shared by all PAM actions. |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
137 BaseFlags { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
138 /// The PAM module should not generate any messages. |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
139 const SILENT = (link = libpam_sys::PAM_SILENT, else = 0x8000); |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
140 } |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
141 } |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
142 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
143 macro_rules! flag_enum { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
144 ( |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
145 $(#[$m:meta])* |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
146 $name:ident { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
147 $( |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
148 $(#[$item_m:meta])* |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
149 $item_name:ident = $item_value:path, |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
150 )* |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
151 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
152 ) => { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
153 $(#[$m])* |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
154 #[derive(Clone, Copy, Debug, PartialEq)] |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
155 pub enum $name { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
156 $( |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
157 $(#[$item_m])* |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
158 $item_name, |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
159 )* |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
160 } |
64
bbe84835d6db
More organization; add lots of docs.
Paul Fisher <paul@pfish.zone>
parents:
63
diff
changeset
|
161 |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
162 #[cfg(feature = "link")] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
163 impl TryFrom<RawFlags> for $name { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
164 type Error = ErrorCode; |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
165 fn try_from(value: RawFlags) -> Result<$name> { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
166 match value.0 { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
167 $( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
168 $item_value => Ok(Self::$item_name), |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
169 )* |
175
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
170 _ => Err(ErrorCode::BAD_CONST), |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
171 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
172 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
173 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
174 |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
175 #[cfg(feature = "link")] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
176 impl From<$name> for RawFlags { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
177 fn from(value: $name) -> Self { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
178 match value { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
179 $( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
180 $name::$item_name => $item_value.into(), |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
181 )* |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
182 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
183 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
184 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
185 |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
186 #[cfg(feature = "link")] |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
187 impl $name { |
185
fb8b547b36b7
Banish al(most al)l use of `i32` in favor of `c_int`.
Paul Fisher <paul@pfish.zone>
parents:
180
diff
changeset
|
188 const ALL_VALUES: c_int = 0 $( | $item_value)*; |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
189 |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
190 fn split(value: RawFlags) -> Result<(Option<Self>, RawFlags)> { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
191 let me = value.0 & Self::ALL_VALUES; |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
192 let them = (value.0 & !Self::ALL_VALUES).into(); |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
193 let me = match RawFlags(me) { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
194 RawFlags(0) => None, |
175
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
195 other => Some(Self::try_from(other).map_err(|_| ErrorCode::BAD_CONST)?), |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
196 }; |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
197 Ok((me, them)) |
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 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
200 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
201 } |
64
bbe84835d6db
More organization; add lots of docs.
Paul Fisher <paul@pfish.zone>
parents:
63
diff
changeset
|
202 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
203 flag_enum! { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
204 /// 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
|
205 CredAction { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
206 /// Set the user's credentials from this module. Default if unspecified. |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
207 Establish = libpam_sys::PAM_ESTABLISH_CRED, |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
208 /// Revoke the user's credentials established by this module. |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
209 Delete = libpam_sys::PAM_DELETE_CRED, |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
210 /// Fully reinitialize the user's credentials from this module. |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
211 Reinitialize = libpam_sys::PAM_REINITIALIZE_CRED, |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
212 /// Extend the lifetime of the user's credentials from this module. |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
213 Refresh = libpam_sys::PAM_REFRESH_CRED, |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
214 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
215 } |
64
bbe84835d6db
More organization; add lots of docs.
Paul Fisher <paul@pfish.zone>
parents:
63
diff
changeset
|
216 |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
217 #[cfg(feature = "link")] |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
218 impl CredAction { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
219 /// Separates this enum from the remaining [`BaseFlags`]. |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
220 pub(crate) fn extract(value: RawFlags) -> Result<(Self, BaseFlags)> { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
221 Self::split(value).map(|(act, rest)| (act.unwrap_or_default(), BaseFlags::from(rest))) |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
222 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
223 } |
64
bbe84835d6db
More organization; add lots of docs.
Paul Fisher <paul@pfish.zone>
parents:
63
diff
changeset
|
224 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
225 impl Default for CredAction { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
226 fn default() -> Self { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
227 Self::Establish |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
228 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
229 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
230 |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
231 flag_enum! { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
232 AuthtokAction { |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
233 /// On this call, just validate that the password is acceptable |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
234 /// and that you have all the resources you need to change it. |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
235 /// |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
236 /// This corresponds to the constant `PAM_PRELIM_CHECK`. |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
237 Validate = libpam_sys::PAM_PRELIM_CHECK, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
238 /// Actually perform the update. |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
239 /// |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
240 /// This corresponds to the constant `PAM_UPDATE_AUTHTOK`. |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
241 Update = libpam_sys::PAM_UPDATE_AUTHTOK, |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
242 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
243 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
244 |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
245 #[cfg(feature = "link")] |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
246 impl AuthtokAction { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
247 /// Separates this enum from the remaining [`AuthtokFlags`]. |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
248 pub(crate) fn extract(value: RawFlags) -> Result<(Self, AuthtokFlags)> { |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
249 match Self::split(value)? { |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
250 (Some(act), rest) => Ok((act, AuthtokFlags::from(rest))), |
175
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
251 (None, _) => Err(ErrorCode::BAD_CONST), |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
252 } |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
253 } |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
254 } |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
255 |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
256 /// Constructs an enum which has the values if it's linked |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
257 macro_rules! linky_enum { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
258 ( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
259 $(#[$om:meta])* |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
260 pub enum $name:ident($wrap:ty) { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
261 $( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
262 $(#[$im:meta])* |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
263 $key:ident = $value:path, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
264 )* |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
265 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
266 ) => { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
267 $(#[$om])* |
186
5e4ea9650f87
Derive `hash` where it makes sense.
Paul Fisher <paul@pfish.zone>
parents:
185
diff
changeset
|
268 #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
269 pub enum $name { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
270 $( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
271 $(#[$im])* |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
272 $key, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
273 )* |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
274 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
275 |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
276 #[cfg(feature = "link")] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
277 impl TryFrom<$wrap> for $name { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
278 type Error = ErrorCode; |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
279 fn try_from(value: $wrap) -> Result<Self> { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
280 match value.into() { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
281 $( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
282 $(#[$im])* |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
283 $value => Ok(Self::$key), |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
284 )* |
175
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
285 _ => Err(ErrorCode::BAD_CONST), |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
286 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
287 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
288 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
289 |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
290 #[cfg(feature = "link")] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
291 impl From<$name> for $wrap { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
292 fn from(value: $name) -> Self { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
293 match value { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
294 $( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
295 $(#[$im])* |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
296 $name::$key => $value.into(), |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
297 )* |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
298 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
299 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
300 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
301 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
302 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
303 |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
304 linky_enum! { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
305 /// The PAM error return codes. |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
306 /// |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
307 /// These are returned by most PAM functions if an error of some kind occurs. |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
308 /// |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
309 /// Instead of being an error code, success is represented by an Ok [`Result`]. |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
310 /// |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
311 /// **Do not depend upon the numerical value of these error codes, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
312 /// or the enum's representation type. |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
313 /// The available codes and their values will vary depending upon |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
314 /// PAM implementation.** |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
315 /// |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
316 /// # References |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
317 /// |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
318 #[doc = linklist!(pam: man7, manbsd, mansun)] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
319 /// - [X/SSO error code specification][xsso] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
320 /// |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
321 #[doc = man7!(3 pam "RETURN_VALUES")] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
322 #[doc = manbsd!(3 pam "RETURN%20VALUES")] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
323 #[doc = mansun!([3 "pam"] pam "return-values")] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
324 #[doc = xsso!("chap5.htm#tagcjh_06_02")] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
325 #[allow(non_camel_case_types, dead_code)] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
326 #[non_exhaustive] // Different PAMs have different error code sets. |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
327 pub enum ErrorCode(ReturnCode) { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
328 OpenError = libpam_sys::PAM_OPEN_ERR, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
329 SymbolError = libpam_sys::PAM_SYMBOL_ERR, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
330 ServiceError = libpam_sys::PAM_SERVICE_ERR, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
331 SystemError = libpam_sys::PAM_SYSTEM_ERR, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
332 BufferError = libpam_sys::PAM_BUF_ERR, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
333 PermissionDenied = libpam_sys::PAM_PERM_DENIED, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
334 AuthenticationError = libpam_sys::PAM_AUTH_ERR, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
335 CredentialsInsufficient = libpam_sys::PAM_CRED_INSUFFICIENT, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
336 AuthInfoUnavailable = libpam_sys::PAM_AUTHINFO_UNAVAIL, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
337 UserUnknown = libpam_sys::PAM_USER_UNKNOWN, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
338 MaxTries = libpam_sys::PAM_MAXTRIES, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
339 NewAuthTokRequired = libpam_sys::PAM_NEW_AUTHTOK_REQD, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
340 AccountExpired = libpam_sys::PAM_ACCT_EXPIRED, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
341 SessionError = libpam_sys::PAM_SESSION_ERR, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
342 CredentialsUnavailable = libpam_sys::PAM_CRED_UNAVAIL, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
343 CredentialsExpired = libpam_sys::PAM_CRED_EXPIRED, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
344 CredentialsError = libpam_sys::PAM_CRED_ERR, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
345 NoModuleData = libpam_sys::PAM_NO_MODULE_DATA, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
346 ConversationError = libpam_sys::PAM_CONV_ERR, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
347 AuthTokError = libpam_sys::PAM_AUTHTOK_ERR, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
348 AuthTokRecoveryError = libpam_sys::PAM_AUTHTOK_RECOVERY_ERR, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
349 AuthTokLockBusy = libpam_sys::PAM_AUTHTOK_LOCK_BUSY, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
350 AuthTokDisableAging = libpam_sys::PAM_AUTHTOK_DISABLE_AGING, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
351 TryAgain = libpam_sys::PAM_TRY_AGAIN, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
352 Ignore = libpam_sys::PAM_IGNORE, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
353 Abort = libpam_sys::PAM_ABORT, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
354 AuthTokExpired = libpam_sys::PAM_AUTHTOK_EXPIRED, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
355 #[cfg(feature = "basic-ext")] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
356 ModuleUnknown = libpam_sys::PAM_MODULE_UNKNOWN, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
357 #[cfg(feature = "basic-ext")] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
358 BadItem = libpam_sys::PAM_BAD_ITEM, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
359 #[cfg(feature = "linux-pam-ext")] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
360 ConversationAgain = libpam_sys::PAM_CONV_AGAIN, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
361 #[cfg(feature = "linux-pam-ext")] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
362 Incomplete = libpam_sys::PAM_INCOMPLETE, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
363 #[cfg(feature = "openpam-ext")] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
364 DomainUnknown = libpam_sys::PAM_DOMAIN_UNKNOWN, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
365 #[cfg(feature = "openpam-ext")] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
366 BadHandle = libpam_sys::PAM_BAD_HANDLE, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
367 #[cfg(feature = "openpam-ext")] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
368 BadFeature = libpam_sys::PAM_BAD_FEATURE, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
369 #[cfg(feature = "openpam-ext")] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
370 BadConstant = libpam_sys::PAM_BAD_CONSTANT, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
371 } |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
372 } |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
373 |
60
05cc2c27334f
The Big Refactor: clean up docs and exports.
Paul Fisher <paul@pfish.zone>
parents:
59
diff
changeset
|
374 /// A PAM-specific Result type with an [ErrorCode] error. |
71
58f9d2a4df38
Reorganize everything again???
Paul Fisher <paul@pfish.zone>
parents:
70
diff
changeset
|
375 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
|
376 |
175
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
377 #[cfg(feature = "link")] |
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
378 impl fmt::Display for ErrorCode { |
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
379 #[cfg(any(pam_impl = "LinuxPam", pam_impl = "OpenPam", pam_impl = "Sun"))] |
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
380 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
381 use std::ffi::CStr; |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
382 use std::ptr; |
185
fb8b547b36b7
Banish al(most al)l use of `i32` in favor of `c_int`.
Paul Fisher <paul@pfish.zone>
parents:
180
diff
changeset
|
383 let retcode: ReturnCode = (*self).into(); |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
384 // SAFETY: PAM impls don't care about the PAM handle and always return |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
385 // static strings. |
185
fb8b547b36b7
Banish al(most al)l use of `i32` in favor of `c_int`.
Paul Fisher <paul@pfish.zone>
parents:
180
diff
changeset
|
386 let got = unsafe { libpam_sys::pam_strerror(ptr::null(), retcode.into()) }; |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
387 if got.is_null() { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
388 // This shouldn't happen. |
185
fb8b547b36b7
Banish al(most al)l use of `i32` in favor of `c_int`.
Paul Fisher <paul@pfish.zone>
parents:
180
diff
changeset
|
389 write!(f, "PAM error: {self:?} ({:?})", retcode) |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
390 } else { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
391 // SAFETY: We just got this back from PAM and we checked if it's null. |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
392 f.write_str(&unsafe { CStr::from_ptr(got) }.to_string_lossy()) |
90
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
393 } |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
394 } |
175
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
395 #[cfg(not(any(pam_impl = "LinuxPam", pam_impl = "OpenPam", pam_impl = "Sun")))] |
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
396 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
397 fmt::Debug::fmt(self, f) |
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
398 } |
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
399 } |
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
400 |
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
401 #[cfg(not(feature = "link"))] |
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
402 impl fmt::Display for ErrorCode { |
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
403 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
404 fmt::Debug::fmt(self, f) |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
405 } |
90
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
406 } |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
407 |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
408 impl Error for ErrorCode {} |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
409 |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
410 #[cfg(feature = "link")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
411 impl ErrorCode { |
180
a1bb1d013567
Remove `syn` from the dependency tree by implementing our own num_enum.
Paul Fisher <paul@pfish.zone>
parents:
178
diff
changeset
|
412 /// Returned when an invalid constant is used. |
175
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
413 #[cfg(feature = "openpam-ext")] |
180
a1bb1d013567
Remove `syn` from the dependency tree by implementing our own num_enum.
Paul Fisher <paul@pfish.zone>
parents:
178
diff
changeset
|
414 pub const BAD_CONST: ErrorCode = ErrorCode::BadConstant; |
a1bb1d013567
Remove `syn` from the dependency tree by implementing our own num_enum.
Paul Fisher <paul@pfish.zone>
parents:
178
diff
changeset
|
415 /// Returned when an invalid constant is used. |
175
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
416 #[cfg(not(feature = "openpam-ext"))] |
180
a1bb1d013567
Remove `syn` from the dependency tree by implementing our own num_enum.
Paul Fisher <paul@pfish.zone>
parents:
178
diff
changeset
|
417 pub const BAD_CONST: ErrorCode = ErrorCode::SystemError; |
175
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
418 |
185
fb8b547b36b7
Banish al(most al)l use of `i32` in favor of `c_int`.
Paul Fisher <paul@pfish.zone>
parents:
180
diff
changeset
|
419 pub(crate) fn result_from(ret: c_int) -> Result<()> { |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
420 match ret { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
421 0 => Ok(()), |
175
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
422 value => Err(ReturnCode(value).try_into().unwrap_or(Self::BAD_CONST)), |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
423 } |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
424 } |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
425 } |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
426 |
175
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
427 #[cfg(feature = "link")] |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
428 impl<T> From<Result<T>> for ReturnCode { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
429 fn from(value: Result<T>) -> Self { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
430 match value { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
431 Ok(_) => ReturnCode::SUCCESS, |
172
6727cbe56f4a
Test environment variable setting; minor cleanup.
Paul Fisher <paul@pfish.zone>
parents:
171
diff
changeset
|
432 Err(otherwise) => otherwise.into(), |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
433 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
434 } |
130
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
435 } |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
436 |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
437 #[cfg(all(test, feature = "link"))] |
59
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
438 mod tests { |
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
439 use super::*; |
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
440 |
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
441 #[test] |
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
442 fn test_enums() { |
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
443 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
|
444 assert_eq!( |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
445 ReturnCode(libpam_sys::PAM_SESSION_ERR), |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
446 Result::<()>::Err(ErrorCode::SessionError).into() |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
447 ); |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
448 assert_eq!( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
449 Result::<()>::Err(ErrorCode::Abort), |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
450 ErrorCode::result_from(libpam_sys::PAM_ABORT) |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
451 ); |
175
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
452 assert_eq!(Err(ErrorCode::BAD_CONST), ErrorCode::result_from(423)); |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
453 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
454 |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
455 #[test] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
456 fn test_flags() { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
457 assert_eq!( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
458 AuthtokFlags::CHANGE_EXPIRED_AUTHTOK | AuthtokFlags::SILENT, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
459 AuthtokFlags::from(RawFlags( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
460 libpam_sys::PAM_SILENT | libpam_sys::PAM_CHANGE_EXPIRED_AUTHTOK |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
461 )) |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
462 ); |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
463 assert_eq!( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
464 RawFlags(libpam_sys::PAM_DISALLOW_NULL_AUTHTOK), |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
465 AuthnFlags::DISALLOW_NULL_AUTHTOK.into() |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
466 ); |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
467 assert_eq!( |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
468 RawFlags(libpam_sys::PAM_SILENT | libpam_sys::PAM_CHANGE_EXPIRED_AUTHTOK), |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
469 (AuthtokFlags::SILENT | AuthtokFlags::CHANGE_EXPIRED_AUTHTOK).into() |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
470 ); |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
471 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
472 |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
473 #[test] |
178
6c75fb621b55
remove never-used test and switch to testing against features
Paul Fisher <paul@pfish.zone>
parents:
176
diff
changeset
|
474 #[cfg(feature = "sun-ext")] |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
475 fn test_flags_sun() { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
476 assert_eq!( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
477 AuthtokFlags::NO_AUTHTOK_CHECK, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
478 AuthtokFlags::from(RawFlags(libpam_sys::PAM_NO_AUTHTOK_CHECK)) |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
479 ); |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
480 assert_eq!( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
481 RawFlags( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
482 libpam_sys::PAM_SILENT |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
483 | libpam_sys::PAM_CHANGE_EXPIRED_AUTHTOK |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
484 | libpam_sys::PAM_NO_AUTHTOK_CHECK |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
485 ), |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
486 (AuthtokFlags::SILENT |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
487 | AuthtokFlags::CHANGE_EXPIRED_AUTHTOK |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
488 | AuthtokFlags::NO_AUTHTOK_CHECK) |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
489 .into() |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
490 ); |
59
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
491 } |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
492 |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
493 #[test] |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
494 fn test_flag_enums() { |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
495 AuthtokAction::extract((-1).into()).expect_err("too many set"); |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
496 AuthtokAction::extract(0.into()).expect_err("too few set"); |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
497 assert_eq!( |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
498 Ok((AuthtokAction::Update, AuthtokFlags::SILENT,)), |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
499 AuthtokAction::extract( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
500 (libpam_sys::PAM_SILENT | libpam_sys::PAM_UPDATE_AUTHTOK).into() |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
501 ) |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
502 ); |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
503 CredAction::extract(0xffff.into()).expect_err("too many set"); |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
504 assert_eq!( |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
505 Ok((CredAction::Establish, BaseFlags::empty())), |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
506 CredAction::extract(0.into()) |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
507 ); |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
508 assert_eq!( |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
509 Ok((CredAction::Delete, BaseFlags::SILENT)), |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
510 CredAction::extract((libpam_sys::PAM_SILENT | libpam_sys::PAM_DELETE_CRED).into()) |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
511 ); |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
512 } |
59
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
513 } |