annotate src/constants.rs @ 197:705d633e4966 default tip

Added tag libpam-sys/v0.2.0 for changeset 568faf823f34
author Paul Fisher <paul@pfish.zone>
date Sun, 03 Aug 2025 01:10:19 -0400
parents 5074d8e00560
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
60
05cc2c27334f The Big Refactor: clean up docs and exports.
Paul Fisher <paul@pfish.zone>
parents: 59
diff changeset
1 //! Constants and enum values from the PAM library.
05cc2c27334f The Big Refactor: clean up docs and exports.
Paul Fisher <paul@pfish.zone>
parents: 59
diff changeset
2
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
3 use crate::_doc::{linklist, man7, manbsd, mansun, xsso};
56
daa2cde64601 Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents: 55
diff changeset
4 use bitflags::bitflags;
90
f6186e41399b Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents: 87
diff changeset
5 use std::error::Error;
185
fb8b547b36b7 Banish al(most al)l use of `i32` in favor of `c_int`.
Paul Fisher <paul@pfish.zone>
parents: 180
diff changeset
6 use std::ffi::c_int;
131
a632a8874131 Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents: 130
diff changeset
7 use std::fmt;
71
58f9d2a4df38 Reorganize everything again???
Paul Fisher <paul@pfish.zone>
parents: 70
diff changeset
8 use std::result::Result as StdResult;
15
27730595f1ea Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff changeset
9
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
10 macro_rules! wrapper {
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
11 (
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
12 $(#[$m:meta])*
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
13 $viz:vis $name:ident($wraps:ty);
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
14 ) => {
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
15 $(#[$m])*
186
5e4ea9650f87 Derive `hash` where it makes sense.
Paul Fisher <paul@pfish.zone>
parents: 185
diff changeset
16 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
17 #[repr(transparent)]
185
fb8b547b36b7 Banish al(most al)l use of `i32` in favor of `c_int`.
Paul Fisher <paul@pfish.zone>
parents: 180
diff changeset
18 $viz struct $name($wraps);
170
f052e2417195 Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents: 166
diff changeset
19
185
fb8b547b36b7 Banish al(most al)l use of `i32` in favor of `c_int`.
Paul Fisher <paul@pfish.zone>
parents: 180
diff changeset
20 impl From<$wraps> for $name {
fb8b547b36b7 Banish al(most al)l use of `i32` in favor of `c_int`.
Paul Fisher <paul@pfish.zone>
parents: 180
diff changeset
21 fn from(value: $wraps) -> Self {
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
22 Self(value)
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
23 }
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
24 }
185
fb8b547b36b7 Banish al(most al)l use of `i32` in favor of `c_int`.
Paul Fisher <paul@pfish.zone>
parents: 180
diff changeset
25 impl From<$name> for $wraps {
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
26 fn from(value: $name) -> Self {
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
27 value.0
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
28 }
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
29 }
170
f052e2417195 Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents: 166
diff changeset
30 }
f052e2417195 Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents: 166
diff changeset
31 }
f052e2417195 Completely avoid using libpam_sys if we're not actually linking.
Paul Fisher <paul@pfish.zone>
parents: 166
diff changeset
32
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
33 wrapper! {
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
34 /// Type of the flags that PAM passes to us (or that we pass to PAM).
185
fb8b547b36b7 Banish al(most al)l use of `i32` in favor of `c_int`.
Paul Fisher <paul@pfish.zone>
parents: 180
diff changeset
35 pub RawFlags(c_int);
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
36 }
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
37 wrapper! {
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
38 /// The error code that we return to PAM.
185
fb8b547b36b7 Banish al(most al)l use of `i32` in favor of `c_int`.
Paul Fisher <paul@pfish.zone>
parents: 180
diff changeset
39 pub ReturnCode(c_int);
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
40 }
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
41
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
42 impl ReturnCode {
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
43 /// A successful return.
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
44 pub const SUCCESS: Self = Self(0);
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
45 }
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
46
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
47 macro_rules! pam_flags {
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
48 (
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
49 $(#[$m:meta])*
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
50 $name:ident {
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
51 $(
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
52 $(#[$m_ident:ident $($m_arg:tt)*])*
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
53 const $item_name:ident = (link = $value_value:expr, else = $other_value:expr);
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
54 )*
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
55 }
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
56 ) => {
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
57 bitflags! {
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
58 #[derive(Clone, Copy, Debug, Default, PartialEq)]
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
59 $(#[$m])*
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
60 pub struct $name: u16 {
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
61 $(
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
62 $(#[$m_ident $($m_arg)*])*
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
63 const $item_name = $other_value;
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
64 )*
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
65 }
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
66 }
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
67
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
68 #[cfg(feature = "link")]
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
69 impl From<RawFlags> for $name {
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
70 #[allow(unused_doc_comments)]
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
71 fn from(value: RawFlags) -> Self {
185
fb8b547b36b7 Banish al(most al)l use of `i32` in favor of `c_int`.
Paul Fisher <paul@pfish.zone>
parents: 180
diff changeset
72 let value: c_int = value.into();
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
73 let result = Self::empty();
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
74 $(
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
75 $(#[$m_ident $($m_arg)*])*
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
76 let result = result | if value & $value_value == 0 {
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
77 Self::empty()
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
78 } else {
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
79 Self::$item_name
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
80 };
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
81 )*
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
82 result
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
83 }
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
84 }
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
85
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
86 #[cfg(feature = "link")]
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
87 impl From<$name> for RawFlags {
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
88 #[allow(unused_doc_comments)]
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
89 fn from(value: $name) -> Self {
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
90 let result = 0;
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
91 $(
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
92 $(#[$m_ident $($m_arg)*])*
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
93 let result = result | if value.contains($name::$item_name) {
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
94 $value_value
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
95 } else {
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
96 0
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
97 };
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
98 )*
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
99 Self(result)
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
100 }
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
101 }
80
5aa1a010f1e8 Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents: 77
diff changeset
102 }
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
103 }
130
80c07e5ab22f Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents: 116
diff changeset
104
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
105 pam_flags! {
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
106 /// Flags for authentication and account management.
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
107 AuthnFlags {
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
108 /// The PAM module should not generate any messages.
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
109 const SILENT = (link = libpam_sys::PAM_SILENT, else = 0x8000);
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
110
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
111 /// The module should return [AuthError](ErrorCode::AuthError)
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
112 /// if the user has an empty authentication token, rather than
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
113 /// allowing them to log in.
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
114 const DISALLOW_NULL_AUTHTOK = (link = libpam_sys::PAM_DISALLOW_NULL_AUTHTOK, else = 0b1);
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
115 }
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
116 }
80
5aa1a010f1e8 Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents: 77
diff changeset
117
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
118 pam_flags! {
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
119 /// Flags for changing the authentication token.
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
120 AuthtokFlags {
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
121 /// The PAM module should not generate any messages.
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
122 const SILENT = (link = libpam_sys::PAM_SILENT, else = 0x8000);
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
123
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
124 /// Indicates that the user's authentication token should
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
125 /// only be changed if it is expired. If not passed,
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
126 /// the authentication token should be changed unconditionally.
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
127 const CHANGE_EXPIRED_AUTHTOK = (link = libpam_sys::PAM_CHANGE_EXPIRED_AUTHTOK, else = 0b10);
90
f6186e41399b Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents: 87
diff changeset
128
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
129 /// Don't check if the password is any good (Sun only).
175
e30775c80b49 Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents: 172
diff changeset
130 #[cfg(feature = "sun-ext")]
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
131 const NO_AUTHTOK_CHECK = (link = libpam_sys::PAM_NO_AUTHTOK_CHECK, else = 0b100);
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
132 }
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
133 }
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
134
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
135 pam_flags! {
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
136 /// Common flag(s) shared by all PAM actions.
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
137 BaseFlags {
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
138 /// The PAM module should not generate any messages.
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
139 const SILENT = (link = libpam_sys::PAM_SILENT, else = 0x8000);
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
140 }
80
5aa1a010f1e8 Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents: 77
diff changeset
141 }
5aa1a010f1e8 Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents: 77
diff changeset
142
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
143 macro_rules! flag_enum {
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
144 (
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
145 $(#[$m:meta])*
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
146 $name:ident {
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
147 $(
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
148 $(#[$item_m:meta])*
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
149 $item_name:ident = $item_value:path,
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
150 )*
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
151 }
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
152 ) => {
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
153 $(#[$m])*
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
154 #[derive(Clone, Copy, Debug, PartialEq)]
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
155 pub enum $name {
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
156 $(
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
157 $(#[$item_m])*
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
158 $item_name,
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
159 )*
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
160 }
64
bbe84835d6db More organization; add lots of docs.
Paul Fisher <paul@pfish.zone>
parents: 63
diff changeset
161
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
162 #[cfg(feature = "link")]
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
163 impl TryFrom<RawFlags> for $name {
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
164 type Error = ErrorCode;
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
165 fn try_from(value: RawFlags) -> Result<$name> {
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
166 match value.0 {
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
167 $(
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
168 $item_value => Ok(Self::$item_name),
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
169 )*
175
e30775c80b49 Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents: 172
diff changeset
170 _ => Err(ErrorCode::BAD_CONST),
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
171 }
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
172 }
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
173 }
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
174
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
175 #[cfg(feature = "link")]
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
176 impl From<$name> for RawFlags {
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
177 fn from(value: $name) -> Self {
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
178 match value {
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
179 $(
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
180 $name::$item_name => $item_value.into(),
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
181 )*
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
182 }
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
183 }
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
184 }
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
185
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
186 #[cfg(feature = "link")]
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
187 impl $name {
185
fb8b547b36b7 Banish al(most al)l use of `i32` in favor of `c_int`.
Paul Fisher <paul@pfish.zone>
parents: 180
diff changeset
188 const ALL_VALUES: c_int = 0 $( | $item_value)*;
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
189
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
190 fn split(value: RawFlags) -> Result<(Option<Self>, RawFlags)> {
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
191 let me = value.0 & Self::ALL_VALUES;
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
192 let them = (value.0 & !Self::ALL_VALUES).into();
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
193 let me = match RawFlags(me) {
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
194 RawFlags(0) => None,
175
e30775c80b49 Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents: 172
diff changeset
195 other => Some(Self::try_from(other).map_err(|_| ErrorCode::BAD_CONST)?),
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
196 };
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
197 Ok((me, them))
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
198 }
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
199 }
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
200 }
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
201 }
64
bbe84835d6db More organization; add lots of docs.
Paul Fisher <paul@pfish.zone>
parents: 63
diff changeset
202
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
203 flag_enum! {
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
204 /// The credential management action that should take place.
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
205 CredAction {
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
206 /// Set the user's credentials from this module. Default if unspecified.
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
207 Establish = libpam_sys::PAM_ESTABLISH_CRED,
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
208 /// Revoke the user's credentials established by this module.
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
209 Delete = libpam_sys::PAM_DELETE_CRED,
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
210 /// Fully reinitialize the user's credentials from this module.
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
211 Reinitialize = libpam_sys::PAM_REINITIALIZE_CRED,
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
212 /// Extend the lifetime of the user's credentials from this module.
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
213 Refresh = libpam_sys::PAM_REFRESH_CRED,
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
214 }
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
215 }
64
bbe84835d6db More organization; add lots of docs.
Paul Fisher <paul@pfish.zone>
parents: 63
diff changeset
216
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
217 #[cfg(feature = "link")]
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
218 impl CredAction {
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
219 /// Separates this enum from the remaining [`BaseFlags`].
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
220 pub(crate) fn extract(value: RawFlags) -> Result<(Self, BaseFlags)> {
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
221 Self::split(value).map(|(act, rest)| (act.unwrap_or_default(), BaseFlags::from(rest)))
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
222 }
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
223 }
64
bbe84835d6db More organization; add lots of docs.
Paul Fisher <paul@pfish.zone>
parents: 63
diff changeset
224
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
225 impl Default for CredAction {
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
226 fn default() -> Self {
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
227 Self::Establish
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
228 }
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
229 }
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
230
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
231 flag_enum! {
193
5074d8e00560 Doc improvements.
Paul Fisher <paul@pfish.zone>
parents: 186
diff changeset
232 /// The action that a module should take during a [`change_authtok`] call.
5074d8e00560 Doc improvements.
Paul Fisher <paul@pfish.zone>
parents: 186
diff changeset
233 ///
5074d8e00560 Doc improvements.
Paul Fisher <paul@pfish.zone>
parents: 186
diff changeset
234 /// [`change_authtok`]: crate::PamModule::change_authtok
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
235 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
236 /// 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
237 /// 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
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_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
240 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
241 /// 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
242 ///
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
243 /// 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
244 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
245 }
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
246 }
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
247
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
248 #[cfg(feature = "link")]
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
249 impl AuthtokAction {
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
250 /// 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
251 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
252 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
253 (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
254 (None, _) => Err(ErrorCode::BAD_CONST),
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
255 }
56
daa2cde64601 Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents: 55
diff changeset
256 }
daa2cde64601 Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents: 55
diff changeset
257 }
15
27730595f1ea Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff changeset
258
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
259 /// 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
260 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
261 (
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
262 $(#[$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
263 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
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 $(#[$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
266 $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
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 }
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 $(#[$om])*
186
5e4ea9650f87 Derive `hash` where it makes sense.
Paul Fisher <paul@pfish.zone>
parents: 185
diff changeset
271 #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
272 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
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 $(#[$im])*
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
275 $key,
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 }
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
278
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
279 #[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
280 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
281 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
282 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
283 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
284 $(
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
285 $(#[$im])*
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
286 $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
287 )*
175
e30775c80b49 Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents: 172
diff changeset
288 _ => 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
289 }
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
290 }
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
291 }
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 #[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
294 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
295 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
296 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
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 $(#[$im])*
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
299 $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
300 )*
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
301 }
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
302 }
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
303 }
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
304 }
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 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
308 /// 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
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 /// 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
311 ///
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
312 /// 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
313 ///
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
314 /// **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
315 /// 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
316 /// 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
317 /// 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
318 ///
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
319 /// # References
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
320 ///
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
321 #[doc = 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
322 /// - [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
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 = 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
325 #[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
326 #[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
327 #[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
328 #[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
329 #[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
330 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
331 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
332 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
333 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
334 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
335 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
336 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
337 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
338 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
339 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
340 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
341 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
342 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
343 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
344 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
345 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
346 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
347 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
348 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
349 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
350 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
351 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
352 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
353 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
354 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
355 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
356 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
357 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
358 #[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
359 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
360 #[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
361 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
362 #[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
363 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
364 #[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
365 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
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 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
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 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
370 #[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
371 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
372 #[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
373 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
374 }
15
27730595f1ea Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff changeset
375 }
56
daa2cde64601 Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents: 55
diff changeset
376
60
05cc2c27334f The Big Refactor: clean up docs and exports.
Paul Fisher <paul@pfish.zone>
parents: 59
diff changeset
377 /// A PAM-specific Result type with an [ErrorCode] error.
71
58f9d2a4df38 Reorganize everything again???
Paul Fisher <paul@pfish.zone>
parents: 70
diff changeset
378 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
379
175
e30775c80b49 Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents: 172
diff changeset
380 #[cfg(feature = "link")]
e30775c80b49 Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents: 172
diff changeset
381 impl fmt::Display for ErrorCode {
e30775c80b49 Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents: 172
diff changeset
382 #[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
383 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
384 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
385 use std::ptr;
185
fb8b547b36b7 Banish al(most al)l use of `i32` in favor of `c_int`.
Paul Fisher <paul@pfish.zone>
parents: 180
diff changeset
386 let retcode: ReturnCode = (*self).into();
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
387 // 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
388 // static strings.
185
fb8b547b36b7 Banish al(most al)l use of `i32` in favor of `c_int`.
Paul Fisher <paul@pfish.zone>
parents: 180
diff changeset
389 let got = unsafe { libpam_sys::pam_strerror(ptr::null(), retcode.into()) };
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
390 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
391 // This shouldn't happen.
185
fb8b547b36b7 Banish al(most al)l use of `i32` in favor of `c_int`.
Paul Fisher <paul@pfish.zone>
parents: 180
diff changeset
392 write!(f, "PAM error: {self:?} ({:?})", retcode)
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
393 } else {
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
394 // 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
395 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
396 }
f6186e41399b Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents: 87
diff changeset
397 }
175
e30775c80b49 Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents: 172
diff changeset
398 #[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
399 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
400 fmt::Debug::fmt(self, f)
e30775c80b49 Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents: 172
diff changeset
401 }
e30775c80b49 Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents: 172
diff changeset
402 }
e30775c80b49 Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents: 172
diff changeset
403
e30775c80b49 Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents: 172
diff changeset
404 #[cfg(not(feature = "link"))]
e30775c80b49 Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents: 172
diff changeset
405 impl fmt::Display for ErrorCode {
e30775c80b49 Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents: 172
diff changeset
406 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
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 {
180
a1bb1d013567 Remove `syn` from the dependency tree by implementing our own num_enum.
Paul Fisher <paul@pfish.zone>
parents: 178
diff changeset
415 /// Returned when an invalid constant is used.
175
e30775c80b49 Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents: 172
diff changeset
416 #[cfg(feature = "openpam-ext")]
180
a1bb1d013567 Remove `syn` from the dependency tree by implementing our own num_enum.
Paul Fisher <paul@pfish.zone>
parents: 178
diff changeset
417 pub const BAD_CONST: ErrorCode = ErrorCode::BadConstant;
a1bb1d013567 Remove `syn` from the dependency tree by implementing our own num_enum.
Paul Fisher <paul@pfish.zone>
parents: 178
diff changeset
418 /// 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
419 #[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
420 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
421
185
fb8b547b36b7 Banish al(most al)l use of `i32` in favor of `c_int`.
Paul Fisher <paul@pfish.zone>
parents: 180
diff changeset
422 pub(crate) fn result_from(ret: c_int) -> Result<()> {
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
423 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
424 0 => Ok(()),
175
e30775c80b49 Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents: 172
diff changeset
425 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
426 }
daa2cde64601 Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents: 55
diff changeset
427 }
daa2cde64601 Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents: 55
diff changeset
428 }
daa2cde64601 Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents: 55
diff changeset
429
175
e30775c80b49 Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents: 172
diff changeset
430 #[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
431 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
432 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
433 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
434 Ok(_) => ReturnCode::SUCCESS,
172
6727cbe56f4a Test environment variable setting; minor cleanup.
Paul Fisher <paul@pfish.zone>
parents: 171
diff changeset
435 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
436 }
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
437 }
130
80c07e5ab22f Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents: 116
diff changeset
438 }
80c07e5ab22f Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents: 116
diff changeset
439
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 #[cfg(all(test, feature = "link"))]
59
3f4a77aa88be Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents: 56
diff changeset
441 mod tests {
3f4a77aa88be Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents: 56
diff changeset
442 use super::*;
3f4a77aa88be Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents: 56
diff changeset
443
3f4a77aa88be Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents: 56
diff changeset
444 #[test]
3f4a77aa88be Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents: 56
diff changeset
445 fn test_enums() {
3f4a77aa88be Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents: 56
diff changeset
446 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
447 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
448 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
449 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
450 );
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
451 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
452 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
453 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
454 );
175
e30775c80b49 Separate #[cfg(feature = "link")] from other features.
Paul Fisher <paul@pfish.zone>
parents: 172
diff changeset
455 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
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 #[test]
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
459 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
460 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
461 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
462 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
463 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 ))
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 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
467 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
468 AuthnFlags::DISALLOW_NULL_AUTHTOK.into()
80
5aa1a010f1e8 Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents: 77
diff changeset
469 );
5aa1a010f1e8 Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents: 77
diff changeset
470 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
471 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
472 (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
473 );
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
474 }
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
475
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
476 #[test]
178
6c75fb621b55 remove never-used test and switch to testing against features
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
477 #[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
478 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
479 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
480 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
481 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
482 );
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
483 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
484 RawFlags(
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
485 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
486 | 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
487 | 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
488 ),
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
489 (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
490 | 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
491 | 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
492 .into()
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
493 );
59
3f4a77aa88be Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents: 56
diff changeset
494 }
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
495
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
496 #[test]
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
497 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
498 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
499 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
500 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
501 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
502 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
503 (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
504 )
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
505 );
171
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 170
diff changeset
506 CredAction::extract(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
507 assert_eq!(
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
508 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
509 CredAction::extract(0.into())
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
510 );
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
511 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
512 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
513 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
514 );
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
515 }
59
3f4a77aa88be Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents: 56
diff changeset
516 }