Mercurial > crates > nonstick
annotate src/constants.rs @ 180:a1bb1d013567
Remove `syn` from the dependency tree by implementing our own num_enum.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Wed, 30 Jul 2025 18:22:16 -0400 |
parents | 6c75fb621b55 |
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; |
131
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
6 use std::fmt; |
71
58f9d2a4df38
Reorganize everything again???
Paul Fisher <paul@pfish.zone>
parents:
70
diff
changeset
|
7 use std::result::Result as StdResult; |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
8 |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
9 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
|
10 ( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
11 $(#[$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
|
12 $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
|
13 ) => { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
14 $(#[$m])* |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
15 #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
16 #[repr(transparent)] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
17 $viz struct $name(i32); |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
18 |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
19 impl From<i32> 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
|
20 fn from(value: i32) -> Self { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
21 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
|
22 } |
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 impl From<$name> for i32 { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
25 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
|
26 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
|
27 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
28 } |
170
f052e2417195
Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents:
166
diff
changeset
|
29 } |
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 |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
32 wrapper! { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
33 /// Type of the flags that PAM passes to us (or that we pass to PAM). |
175
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
34 pub RawFlags(i32); |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
35 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
36 wrapper! { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
37 /// The error code that we return to PAM. |
175
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
38 pub ReturnCode(i32); |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
39 } |
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 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
|
42 /// 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
|
43 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
|
44 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
45 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
46 macro_rules! pam_flags { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
47 ( |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
48 $(#[$m:meta])* |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
49 $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
|
50 $( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
51 $(#[$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
|
52 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
|
53 )* |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
54 } |
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 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
|
57 #[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
|
58 $(#[$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
|
59 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
|
60 $( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
61 $(#[$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
|
62 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
|
63 )* |
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 #[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
|
68 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
|
69 #[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
|
70 fn from(value: RawFlags) -> Self { |
175
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
71 let value: i32 = 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
|
72 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
|
73 $( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
74 $(#[$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
|
75 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
|
76 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
|
77 } else { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
78 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
|
79 }; |
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 result |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
82 } |
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 #[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
|
86 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
|
87 #[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
|
88 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
|
89 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
|
90 $( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
91 $(#[$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
|
92 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
|
93 $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
|
94 } else { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
95 0 |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
96 }; |
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 Self(result) |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
99 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
100 } |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
101 } |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
102 } |
130
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
103 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
104 pam_flags! { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
105 /// Flags for authentication and account management. |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
106 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
|
107 /// 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
|
108 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
|
109 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
110 /// 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
|
111 /// 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
|
112 /// 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
|
113 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
|
114 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
115 } |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
116 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
117 pam_flags! { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
118 /// Flags for changing the authentication token. |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
119 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
|
120 /// 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
|
121 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
|
122 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
123 /// 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
|
124 /// 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
|
125 /// 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
|
126 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
|
127 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
128 /// 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
|
129 #[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
|
130 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
|
131 } |
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 pam_flags! { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
135 /// 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
|
136 BaseFlags { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
137 /// 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
|
138 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
|
139 } |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
140 } |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
141 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
142 macro_rules! flag_enum { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
143 ( |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
144 $(#[$m:meta])* |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
145 $name:ident { |
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 $(#[$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
|
148 $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
|
149 )* |
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 $(#[$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
|
153 #[derive(Clone, Copy, Debug, PartialEq)] |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
154 pub enum $name { |
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 $(#[$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
|
157 $item_name, |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
158 )* |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
159 } |
64
bbe84835d6db
More organization; add lots of docs.
Paul Fisher <paul@pfish.zone>
parents:
63
diff
changeset
|
160 |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
161 #[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
|
162 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
|
163 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
|
164 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
|
165 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
|
166 $( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
167 $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
|
168 )* |
175
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
169 _ => 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
|
170 } |
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 #[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
|
175 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
|
176 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
|
177 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
|
178 $( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
179 $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
|
180 )* |
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 #[cfg(feature = "link")] |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
186 impl $name { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
187 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
|
188 |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
189 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
|
190 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
|
191 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
|
192 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
|
193 RawFlags(0) => None, |
175
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
194 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
|
195 }; |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
196 Ok((me, them)) |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
197 } |
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 } |
64
bbe84835d6db
More organization; add lots of docs.
Paul Fisher <paul@pfish.zone>
parents:
63
diff
changeset
|
201 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
202 flag_enum! { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
203 /// 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
|
204 CredAction { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
205 /// 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
|
206 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
|
207 /// 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
|
208 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
|
209 /// 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
|
210 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
|
211 /// 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
|
212 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
|
213 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
214 } |
64
bbe84835d6db
More organization; add lots of docs.
Paul Fisher <paul@pfish.zone>
parents:
63
diff
changeset
|
215 |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
216 #[cfg(feature = "link")] |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
217 impl CredAction { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
218 /// 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
|
219 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
|
220 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
|
221 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
222 } |
64
bbe84835d6db
More organization; add lots of docs.
Paul Fisher <paul@pfish.zone>
parents:
63
diff
changeset
|
223 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
224 impl Default for CredAction { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
225 fn default() -> Self { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
226 Self::Establish |
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 } |
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 flag_enum! { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
231 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
|
232 /// 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
|
233 /// 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
|
234 /// |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
235 /// 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
|
236 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
|
237 /// 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
|
238 /// |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
239 /// 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
|
240 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
|
241 } |
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 |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
244 #[cfg(feature = "link")] |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
245 impl AuthtokAction { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
246 /// 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
|
247 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
|
248 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
|
249 (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
|
250 (None, _) => Err(ErrorCode::BAD_CONST), |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
251 } |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
252 } |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
253 } |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
254 |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
255 /// 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
|
256 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
|
257 ( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
258 $(#[$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
|
259 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
|
260 $( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
261 $(#[$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
|
262 $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
|
263 )* |
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 $(#[$om])* |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
267 #[derive(Copy, Clone, Debug, PartialEq, Eq)] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
268 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
|
269 $( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
270 $(#[$im])* |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
271 $key, |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
272 )* |
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 #[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
|
276 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
|
277 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
|
278 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
|
279 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
|
280 $( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
281 $(#[$im])* |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
282 $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
|
283 )* |
175
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
284 _ => 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
|
285 } |
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 #[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
|
290 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
|
291 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
|
292 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
|
293 $( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
294 $(#[$im])* |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
295 $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
|
296 )* |
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 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
|
304 /// 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
|
305 /// |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
306 /// 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
|
307 /// |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
308 /// 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
|
309 /// |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
310 /// **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
|
311 /// 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
|
312 /// 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
|
313 /// 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
|
314 /// |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
315 /// # References |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
316 /// |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
317 #[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
|
318 /// - [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
|
319 /// |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
320 #[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
|
321 #[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
|
322 #[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
|
323 #[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
|
324 #[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
|
325 #[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
|
326 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
|
327 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
|
328 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
|
329 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
|
330 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
|
331 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
|
332 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
|
333 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
|
334 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
|
335 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
|
336 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
|
337 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
|
338 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
|
339 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
|
340 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
|
341 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
|
342 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
|
343 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
|
344 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
|
345 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
|
346 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
|
347 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
|
348 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
|
349 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
|
350 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
|
351 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
|
352 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
|
353 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
|
354 #[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
|
355 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
|
356 #[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
|
357 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
|
358 #[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
|
359 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
|
360 #[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
|
361 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
|
362 #[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
|
363 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
|
364 #[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
|
365 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
|
366 #[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
|
367 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
|
368 #[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
|
369 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
|
370 } |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
371 } |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
372 |
60
05cc2c27334f
The Big Refactor: clean up docs and exports.
Paul Fisher <paul@pfish.zone>
parents:
59
diff
changeset
|
373 /// A PAM-specific Result type with an [ErrorCode] error. |
71
58f9d2a4df38
Reorganize everything again???
Paul Fisher <paul@pfish.zone>
parents:
70
diff
changeset
|
374 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
|
375 |
175
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
376 #[cfg(feature = "link")] |
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
377 impl fmt::Display for ErrorCode { |
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
378 #[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
|
379 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
|
380 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
|
381 use std::ptr; |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
382 // 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
|
383 // static strings. |
175
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
384 let got = unsafe { libpam_sys::pam_strerror(ptr::null(), *self as i32) }; |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
385 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
|
386 // This shouldn't happen. |
175
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
387 write!(f, "PAM error: {self:?} ({:?})", *self as i32) |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
388 } else { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
389 // 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
|
390 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
|
391 } |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
392 } |
175
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
393 #[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
|
394 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
|
395 fmt::Debug::fmt(self, f) |
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
396 } |
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
397 } |
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 #[cfg(not(feature = "link"))] |
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
400 impl fmt::Display for ErrorCode { |
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
401 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
|
402 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
|
403 } |
90
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
404 } |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
405 |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
406 impl Error for ErrorCode {} |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
407 |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
408 #[cfg(feature = "link")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
409 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
|
410 /// 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
|
411 #[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
|
412 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
|
413 /// 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
|
414 #[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
|
415 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
|
416 |
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
417 pub(crate) fn result_from(ret: i32) -> 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
|
418 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
|
419 0 => Ok(()), |
175
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
420 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
|
421 } |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
422 } |
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 |
175
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
425 #[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
|
426 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
|
427 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
|
428 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
|
429 Ok(_) => ReturnCode::SUCCESS, |
172
6727cbe56f4a
Test environment variable setting; minor cleanup.
Paul Fisher <paul@pfish.zone>
parents:
171
diff
changeset
|
430 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
|
431 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
432 } |
130
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
433 } |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
434 |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
435 #[cfg(all(test, feature = "link"))] |
59
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
436 mod tests { |
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
437 use super::*; |
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
438 |
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
439 #[test] |
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
440 fn test_enums() { |
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
441 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
|
442 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
|
443 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
|
444 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
|
445 ); |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
446 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
|
447 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
|
448 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
|
449 ); |
175
e30775c80b49
Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
450 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
|
451 } |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
452 |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
453 #[test] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
454 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
|
455 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
|
456 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
|
457 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
|
458 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
|
459 )) |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
460 ); |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
461 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
|
462 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
|
463 AuthnFlags::DISALLOW_NULL_AUTHTOK.into() |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
464 ); |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
465 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
|
466 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
|
467 (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
|
468 ); |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
469 } |
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 #[test] |
178
6c75fb621b55
remove never-used test and switch to testing against features
Paul Fisher <paul@pfish.zone>
parents:
176
diff
changeset
|
472 #[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
|
473 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
|
474 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
|
475 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
|
476 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
|
477 ); |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
478 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
|
479 RawFlags( |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
480 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
|
481 | 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
|
482 | 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
|
483 ), |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
484 (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
|
485 | 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
|
486 | 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
|
487 .into() |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
488 ); |
59
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
489 } |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
490 |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
491 #[test] |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
492 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
|
493 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
|
494 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
|
495 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
|
496 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
|
497 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
|
498 (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
|
499 ) |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
500 ); |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
170
diff
changeset
|
501 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
|
502 assert_eq!( |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
503 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
|
504 CredAction::extract(0.into()) |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
505 ); |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
506 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
|
507 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
|
508 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
|
509 ); |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
510 } |
59
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
511 } |