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