Mercurial > crates > nonstick
annotate src/constants.rs @ 166:2f5913131295
Separate flag/action flags into flags and action.
This also individualizes the type of flag for each PAM function,
so that you can only call a function with the right flags and values.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Tue, 15 Jul 2025 00:32:24 -0400 |
parents | 4b3a5095f68c |
children | f052e2417195 |
rev | line source |
---|---|
60
05cc2c27334f
The Big Refactor: clean up docs and exports.
Paul Fisher <paul@pfish.zone>
parents:
59
diff
changeset
|
1 //! Constants and enum values from the PAM library. |
05cc2c27334f
The Big Refactor: clean up docs and exports.
Paul Fisher <paul@pfish.zone>
parents:
59
diff
changeset
|
2 |
146
1bc52025156b
Split PAM items into their own separate struct.
Paul Fisher <paul@pfish.zone>
parents:
139
diff
changeset
|
3 use crate::_doc::{linklist, man7, manbsd, xsso}; |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
4 use bitflags::bitflags; |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
5 use libpam_sys_consts::constants; |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
6 use num_enum::{IntoPrimitive, TryFromPrimitive}; |
90
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
7 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
|
8 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
|
9 use std::fmt; |
90
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
10 use std::fmt::{Display, Formatter}; |
71
58f9d2a4df38
Reorganize everything again???
Paul Fisher <paul@pfish.zone>
parents:
70
diff
changeset
|
11 use std::result::Result as StdResult; |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
12 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
13 /// Creates a bitflags! macro, with an extra SILENT element. |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
14 macro_rules! pam_flags { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
15 ( |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
16 $(#[$m:meta])* |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
17 $name:ident { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
18 $($inner:tt)* |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
19 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
20 ) => { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
21 bitflags! { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
22 $(#[$m])* |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
23 #[derive(Clone, Copy, Debug, Default, PartialEq)] |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
24 #[repr(transparent)] |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
25 pub struct $name: c_int { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
26 /// The module should not generate any messages. |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
27 const SILENT = constants::PAM_SILENT; |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
28 $($inner)* |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
29 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
30 } |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
31 } |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
32 } |
130
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
33 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
34 pam_flags! { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
35 /// Flags for authentication and account management. |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
36 AuthnFlags { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
37 /// 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
|
38 /// 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
|
39 /// allowing them to log in. |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
40 const DISALLOW_NULL_AUTHTOK = constants::PAM_DISALLOW_NULL_AUTHTOK; |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
41 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
42 } |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
43 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
44 pam_flags! { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
45 /// Flags for changing the authentication token. |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
46 AuthtokFlags { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
47 /// 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
|
48 /// 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
|
49 /// the authentication token should be changed unconditionally. |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
50 const CHANGE_EXPIRED_AUTHTOK = constants::PAM_CHANGE_EXPIRED_AUTHTOK; |
90
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
51 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
52 /// 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
|
53 #[cfg(pam_impl = "Sun")] |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
54 const NO_AUTHTOK_CHECK = constants::PAM_NO_AUTHTOK_CHECK; |
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 |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
58 pam_flags! { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
59 /// Common flag(s) shared by all PAM actions. |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
60 BaseFlags {} |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
61 } |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
62 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
63 #[cfg(feature = "openpam-ext")] |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
64 const BAD_CONST: ErrorCode = ErrorCode::BadConstant; |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
65 #[cfg(not(feature = "openpam-ext"))] |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
66 const BAD_CONST: ErrorCode = ErrorCode::SystemError; |
64
bbe84835d6db
More organization; add lots of docs.
Paul Fisher <paul@pfish.zone>
parents:
63
diff
changeset
|
67 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
68 macro_rules! flag_enum { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
69 ( |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
70 $(#[$m:meta])* |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
71 $name:ident { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
72 $( |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
73 $(#[$item_m:meta])* |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
74 $item_name:ident = $item_value:expr, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
75 )* |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
76 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
77 ) => { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
78 $(#[$m])* |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
79 #[derive(Clone, Copy, Debug, PartialEq, TryFromPrimitive, IntoPrimitive)] |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
80 #[repr(i32)] |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
81 pub enum $name { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
82 $( |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
83 $(#[$item_m])* |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
84 $item_name = $item_value, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
85 )* |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
86 } |
64
bbe84835d6db
More organization; add lots of docs.
Paul Fisher <paul@pfish.zone>
parents:
63
diff
changeset
|
87 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
88 impl $name { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
89 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
|
90 |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
91 fn split(value: i32) -> Result<(Option<Self>, i32)> { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
92 let me = value & Self::ALL_VALUES; |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
93 let them = value & !Self::ALL_VALUES; |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
94 let me = match me { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
95 0 => None, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
96 n => Some(Self::try_from(n).map_err(|_| BAD_CONST)?), |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
97 }; |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
98 Ok((me, them)) |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
99 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
100 } |
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 } |
64
bbe84835d6db
More organization; add lots of docs.
Paul Fisher <paul@pfish.zone>
parents:
63
diff
changeset
|
103 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
104 flag_enum! { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
105 /// 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
|
106 CredAction { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
107 /// Set the user's credentials from this module. Default if unspecified. |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
108 Establish = constants::PAM_ESTABLISH_CRED, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
109 /// Revoke the user's credentials established by this module. |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
110 Delete = constants::PAM_DELETE_CRED, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
111 /// Fully reinitialize the user's credentials from this module. |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
112 Reinitialize = constants::PAM_REINITIALIZE_CRED, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
113 /// Extend the lifetime of the user's credentials from this module. |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
114 Refresh = constants::PAM_REFRESH_CRED, |
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 } |
64
bbe84835d6db
More organization; add lots of docs.
Paul Fisher <paul@pfish.zone>
parents:
63
diff
changeset
|
117 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
118 impl CredAction { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
119 /// Separates this enum from the remaining [`BaseFlags`]. |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
120 pub fn extract(value: i32) -> Result<(Self, BaseFlags)> { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
121 Self::split(value) |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
122 .map(|(act, rest)| (act.unwrap_or_default(), BaseFlags::from_bits_retain(rest))) |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
123 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
124 } |
64
bbe84835d6db
More organization; add lots of docs.
Paul Fisher <paul@pfish.zone>
parents:
63
diff
changeset
|
125 |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
126 impl Default for CredAction { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
127 fn default() -> Self { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
128 Self::Establish |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
129 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
130 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
131 |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
132 flag_enum! { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
133 AuthtokAction { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
134 /// This is a preliminary call to check if we're ready to change passwords |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
135 /// and that the new password is acceptable. |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
136 PreliminaryCheck = constants::PAM_PRELIM_CHECK, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
137 /// You should actually update the password. |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
138 Update = constants::PAM_UPDATE_AUTHTOK, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
139 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
140 } |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
141 |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
142 impl AuthtokAction { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
143 /// Separates this enum from the remaining [`AuthtokFlags`]. |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
144 pub fn extract(value: i32) -> Result<(Self, AuthtokFlags)> { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
145 match Self::split(value)? { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
146 (Some(act), rest) => Ok((act, AuthtokFlags::from_bits_retain(rest))), |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
147 (None, _) => Err(BAD_CONST), |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
148 } |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
149 } |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
150 } |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
151 |
103
dfcd96a74ac4
write a truly prodigious amount of documentation
Paul Fisher <paul@pfish.zone>
parents:
97
diff
changeset
|
152 /// The PAM error return codes. |
dfcd96a74ac4
write a truly prodigious amount of documentation
Paul Fisher <paul@pfish.zone>
parents:
97
diff
changeset
|
153 /// |
dfcd96a74ac4
write a truly prodigious amount of documentation
Paul Fisher <paul@pfish.zone>
parents:
97
diff
changeset
|
154 /// These are returned by most PAM functions if an error of some kind occurs. |
dfcd96a74ac4
write a truly prodigious amount of documentation
Paul Fisher <paul@pfish.zone>
parents:
97
diff
changeset
|
155 /// |
dfcd96a74ac4
write a truly prodigious amount of documentation
Paul Fisher <paul@pfish.zone>
parents:
97
diff
changeset
|
156 /// Instead of being an error code, success is represented by an Ok [`Result`]. |
60
05cc2c27334f
The Big Refactor: clean up docs and exports.
Paul Fisher <paul@pfish.zone>
parents:
59
diff
changeset
|
157 /// |
103
dfcd96a74ac4
write a truly prodigious amount of documentation
Paul Fisher <paul@pfish.zone>
parents:
97
diff
changeset
|
158 /// # References |
dfcd96a74ac4
write a truly prodigious amount of documentation
Paul Fisher <paul@pfish.zone>
parents:
97
diff
changeset
|
159 /// |
116
a12706e42c9d
Logging, macros, and building:
Paul Fisher <paul@pfish.zone>
parents:
113
diff
changeset
|
160 #[doc = linklist!(pam: man7, manbsd)] |
103
dfcd96a74ac4
write a truly prodigious amount of documentation
Paul Fisher <paul@pfish.zone>
parents:
97
diff
changeset
|
161 /// - [X/SSO error code specification][xsso] |
dfcd96a74ac4
write a truly prodigious amount of documentation
Paul Fisher <paul@pfish.zone>
parents:
97
diff
changeset
|
162 /// |
116
a12706e42c9d
Logging, macros, and building:
Paul Fisher <paul@pfish.zone>
parents:
113
diff
changeset
|
163 #[doc = man7!(3 pam "RETURN_VALUES")] |
a12706e42c9d
Logging, macros, and building:
Paul Fisher <paul@pfish.zone>
parents:
113
diff
changeset
|
164 #[doc = manbsd!(3 pam "RETURN%20VALUES")] |
a12706e42c9d
Logging, macros, and building:
Paul Fisher <paul@pfish.zone>
parents:
113
diff
changeset
|
165 #[doc = xsso!("chap5.htm#tagcjh_06_02")] |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
166 #[allow(non_camel_case_types, dead_code)] |
90
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
167 #[derive(Copy, Clone, Debug, PartialEq, TryFromPrimitive, IntoPrimitive)] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
168 #[non_exhaustive] // C might give us anything! |
113
178310336596
Fix up more constants, make things i32 rather than u32.
Paul Fisher <paul@pfish.zone>
parents:
108
diff
changeset
|
169 #[repr(i32)] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
170 pub enum ErrorCode { |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
171 OpenError = constants::PAM_OPEN_ERR, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
172 SymbolError = constants::PAM_SYMBOL_ERR, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
173 ServiceError = constants::PAM_SERVICE_ERR, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
174 SystemError = constants::PAM_SYSTEM_ERR, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
175 BufferError = constants::PAM_BUF_ERR, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
176 PermissionDenied = constants::PAM_PERM_DENIED, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
177 AuthenticationError = constants::PAM_AUTH_ERR, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
178 CredentialsInsufficient = constants::PAM_CRED_INSUFFICIENT, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
179 AuthInfoUnavailable = constants::PAM_AUTHINFO_UNAVAIL, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
180 UserUnknown = constants::PAM_USER_UNKNOWN, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
181 MaxTries = constants::PAM_MAXTRIES, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
182 NewAuthTokRequired = constants::PAM_NEW_AUTHTOK_REQD, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
183 AccountExpired = constants::PAM_ACCT_EXPIRED, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
184 SessionError = constants::PAM_SESSION_ERR, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
185 CredentialsUnavailable = constants::PAM_CRED_UNAVAIL, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
186 CredentialsExpired = constants::PAM_CRED_EXPIRED, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
187 CredentialsError = constants::PAM_CRED_ERR, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
188 NoModuleData = constants::PAM_NO_MODULE_DATA, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
189 ConversationError = constants::PAM_CONV_ERR, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
190 AuthTokError = constants::PAM_AUTHTOK_ERR, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
191 AuthTokRecoveryError = constants::PAM_AUTHTOK_RECOVERY_ERR, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
192 AuthTokLockBusy = constants::PAM_AUTHTOK_LOCK_BUSY, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
193 AuthTokDisableAging = constants::PAM_AUTHTOK_DISABLE_AGING, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
194 TryAgain = constants::PAM_TRY_AGAIN, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
195 Ignore = constants::PAM_IGNORE, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
196 Abort = constants::PAM_ABORT, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
197 AuthTokExpired = constants::PAM_AUTHTOK_EXPIRED, |
108
e97534be35e3
Make some proc macros for doing cfg-like stuff for PAM impls.
Paul Fisher <paul@pfish.zone>
parents:
103
diff
changeset
|
198 #[cfg(feature = "basic-ext")] |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
199 ModuleUnknown = constants::PAM_MODULE_UNKNOWN, |
108
e97534be35e3
Make some proc macros for doing cfg-like stuff for PAM impls.
Paul Fisher <paul@pfish.zone>
parents:
103
diff
changeset
|
200 #[cfg(feature = "basic-ext")] |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
201 BadItem = constants::PAM_BAD_ITEM, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
202 #[cfg(feature = "linux-pam-ext")] |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
203 ConversationAgain = constants::PAM_CONV_AGAIN, |
108
e97534be35e3
Make some proc macros for doing cfg-like stuff for PAM impls.
Paul Fisher <paul@pfish.zone>
parents:
103
diff
changeset
|
204 #[cfg(feature = "linux-pam-ext")] |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
205 Incomplete = constants::PAM_INCOMPLETE, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
206 #[cfg(feature = "openpam-ext")] |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
207 DomainUnknown = constants::PAM_DOMAIN_UNKNOWN, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
208 #[cfg(feature = "openpam-ext")] |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
209 BadHandle = constants::PAM_BAD_HANDLE, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
210 #[cfg(feature = "openpam-ext")] |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
211 BadFeature = constants::PAM_BAD_FEATURE, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
212 #[cfg(feature = "openpam-ext")] |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
213 BadConstant = constants::PAM_BAD_CONSTANT, |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
214 } |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
215 |
60
05cc2c27334f
The Big Refactor: clean up docs and exports.
Paul Fisher <paul@pfish.zone>
parents:
59
diff
changeset
|
216 /// A PAM-specific Result type with an [ErrorCode] error. |
71
58f9d2a4df38
Reorganize everything again???
Paul Fisher <paul@pfish.zone>
parents:
70
diff
changeset
|
217 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
|
218 |
90
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
219 impl Display for ErrorCode { |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
220 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { |
130
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
221 match strerror((*self).into()) { |
90
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
222 Some(err) => f.write_str(err), |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
223 None => self.fmt_internal(f), |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
224 } |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
225 } |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
226 } |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
227 |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
228 impl Error for ErrorCode {} |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
229 |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
230 impl ErrorCode { |
60
05cc2c27334f
The Big Refactor: clean up docs and exports.
Paul Fisher <paul@pfish.zone>
parents:
59
diff
changeset
|
231 /// Converts this [Result] into a C-compatible result code. |
05cc2c27334f
The Big Refactor: clean up docs and exports.
Paul Fisher <paul@pfish.zone>
parents:
59
diff
changeset
|
232 pub fn result_to_c<T>(value: Result<T>) -> c_int { |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
233 match value { |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
234 Ok(_) => 0, // PAM_SUCCESS |
113
178310336596
Fix up more constants, make things i32 rather than u32.
Paul Fisher <paul@pfish.zone>
parents:
108
diff
changeset
|
235 Err(otherwise) => otherwise.into(), |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
236 } |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
237 } |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
238 |
60
05cc2c27334f
The Big Refactor: clean up docs and exports.
Paul Fisher <paul@pfish.zone>
parents:
59
diff
changeset
|
239 /// Converts a C result code into a [Result], with success as Ok. |
59
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
240 /// Invalid values are returned as a [Self::SystemError]. |
60
05cc2c27334f
The Big Refactor: clean up docs and exports.
Paul Fisher <paul@pfish.zone>
parents:
59
diff
changeset
|
241 pub fn result_from(value: c_int) -> Result<()> { |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
242 match value { |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
243 0 => Ok(()), |
113
178310336596
Fix up more constants, make things i32 rather than u32.
Paul Fisher <paul@pfish.zone>
parents:
108
diff
changeset
|
244 value => Err(value.try_into().unwrap_or(Self::SystemError)), |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
245 } |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
246 } |
90
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
247 |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
248 /// A basic Display implementation for if we don't link against PAM. |
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
249 fn fmt_internal(self, f: &mut Formatter<'_>) -> fmt::Result { |
131
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
250 let n: c_int = self.into(); |
130
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
251 write!(f, "PAM error: {self:?} ({n})") |
90
f6186e41399b
Miscellaneous fixes and cleanup:
Paul Fisher <paul@pfish.zone>
parents:
87
diff
changeset
|
252 } |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
253 } |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
254 |
130
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
255 /// Gets a string version of an error message. |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
256 #[cfg(feature = "link")] |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
257 pub fn strerror(code: c_int) -> Option<&'static str> { |
131
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
258 use std::ffi::CStr; |
130
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
259 use std::ptr; |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
260 // SAFETY: PAM impls don't care about the PAM handle and always return |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
261 // static strings. |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
262 let strerror = unsafe { libpam_sys::pam_strerror(ptr::null(), code as c_int) }; |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
263 // SAFETY: We just got this back from PAM and we checked if it's null. |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
264 (!strerror.is_null()) |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
265 .then(|| unsafe { CStr::from_ptr(strerror) }.to_str().ok()) |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
266 .flatten() |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
267 } |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
268 |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
269 /// Dummy implementation of strerror so that it always returns None. |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
270 #[cfg(not(feature = "link"))] |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
271 pub fn strerror(_: c_int) -> Option<&'static str> { |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
272 None |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
273 } |
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
116
diff
changeset
|
274 |
59
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
275 #[cfg(test)] |
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
276 mod tests { |
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
277 use super::*; |
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
278 |
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
279 #[test] |
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
280 fn test_enums() { |
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
281 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
|
282 assert_eq!( |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
283 constants::PAM_SESSION_ERR, |
108
e97534be35e3
Make some proc macros for doing cfg-like stuff for PAM impls.
Paul Fisher <paul@pfish.zone>
parents:
103
diff
changeset
|
284 ErrorCode::result_to_c::<()>(Err(ErrorCode::SessionError)) |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
285 ); |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
286 assert_eq!( |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
287 Err(ErrorCode::Abort), |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
288 ErrorCode::result_from(constants::PAM_ABORT) |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
77
diff
changeset
|
289 ); |
59
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
290 assert_eq!(Err(ErrorCode::SystemError), ErrorCode::result_from(423)); |
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
291 } |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
292 |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
293 #[test] |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
294 fn test_flag_enums() { |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
295 AuthtokAction::extract(-1).expect_err("too many set"); |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
296 AuthtokAction::extract(0).expect_err("too few set"); |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
297 assert_eq!( |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
298 Ok(( |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
299 AuthtokAction::Update, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
300 AuthtokFlags::from_bits_retain(0x7fff0000) |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
301 )), |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
302 AuthtokAction::extract(0x7fff0000 | constants::PAM_UPDATE_AUTHTOK) |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
303 ); |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
304 CredAction::extract(0xffff).expect_err("too many set"); |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
305 assert_eq!( |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
306 Ok((CredAction::Establish, BaseFlags::empty())), |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
307 CredAction::extract(0) |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
308 ); |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
309 assert_eq!( |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
310 Ok((CredAction::Delete, BaseFlags::from_bits_retain(0x55000000))), |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
311 CredAction::extract(0x55000000 | constants::PAM_DELETE_CRED) |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
312 ); |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
313 } |
59
3f4a77aa88be
Fix string copyting and improve error situation.
Paul Fisher <paul@pfish.zone>
parents:
56
diff
changeset
|
314 } |