Mercurial > crates > nonstick
annotate src/constants.rs @ 57:2a5c83d04b93 v0.0.4
Update some docs; bump to v0.0.4.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Mon, 05 May 2025 00:16:00 -0400 |
parents | daa2cde64601 |
children | 3f4a77aa88be |
rev | line source |
---|---|
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
1 use bitflags::bitflags; |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
2 use libc::{c_int, c_uint}; |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
3 use num_derive::{FromPrimitive, ToPrimitive}; |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
4 use num_traits::{FromPrimitive, ToPrimitive}; |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
5 // TODO: Import constants from C header file at compile time. |
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
6 |
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
7 // The Linux-PAM flags |
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
8 // see /usr/include/security/_pam_types.h |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
9 bitflags! { |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
10 #[derive(Debug, PartialEq)] |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
11 #[repr(transparent)] |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
12 pub struct Flags: c_uint { |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
13 const SILENT = 0x8000; |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
14 const DISALLOW_NULL_AUTHTOK = 0x0001; |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
15 const ESTABLISH_CRED = 0x0002; |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
16 const DELETE_CRED = 0x0004; |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
17 const REINITIALIZE_CRED = 0x0008; |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
18 const REFRESH_CRED = 0x0010; |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
19 const CHANGE_EXPIRED_AUTHTOK= 0x0020; |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
20 } |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
21 } |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
22 |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
23 /// Styles of message that are shown to the user. |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
24 #[derive(Debug, PartialEq, FromPrimitive, ToPrimitive)] |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
25 #[non_exhaustive] // non-exhaustive because C might give us back anything! |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
26 pub enum MessageStyle { |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
27 /// Requests information from the user; will be masked when typing. |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
28 PromptEchoOff = 1, |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
29 /// Requests information from the user; will not be masked. |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
30 PromptEchoOn = 2, |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
31 /// An error message. |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
32 ErrorMsg = 3, |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
33 /// An informational message. |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
34 TextInfo = 4, |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
35 /// Yes/No/Maybe conditionals. Linux-PAM specific. |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
36 RadioType = 5, |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
37 /// For server–client non-human interaction. |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
38 /// NOT part of the X/Open PAM specification. |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
39 BinaryPrompt = 7, |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
40 } |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
41 |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
42 impl From<MessageStyle> for c_int { |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
43 fn from(val: MessageStyle) -> Self { |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
44 val.to_i32().unwrap_or(0) |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
45 } |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
46 } |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
47 |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
48 /// The Linux-PAM error return values. |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
49 /// Success is instead represented by the `Ok` entry of a `Result`. |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
50 /// Most abbreviations (except `AuthTok` and `Max`) are now full words. |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
51 /// For more detailed information, see |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
52 /// `/usr/include/security/_pam_types.h`. |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
53 #[allow(non_camel_case_types, dead_code)] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
54 #[derive(Copy, Clone, Debug, PartialEq, thiserror::Error, FromPrimitive, ToPrimitive)] |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
55 #[non_exhaustive] // C might give us anything! |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
56 pub enum ErrorCode { |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
57 #[error("dlopen() failure when dynamically loading a service module")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
58 OpenError = 1, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
59 #[error("symbol not found")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
60 SymbolError = 2, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
61 #[error("error in service module")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
62 ServiceError = 3, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
63 #[error("system error")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
64 SystemError = 4, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
65 #[error("memory buffer error")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
66 BufferError = 5, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
67 #[error("permission denied")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
68 PermissionDenied = 6, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
69 #[error("authentication failure")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
70 AuthenticationError = 7, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
71 #[error("cannot access authentication data due to insufficient credentials")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
72 CredentialsInsufficient = 8, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
73 #[error("underlying authentication service cannot retrieve authentication information")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
74 AuthInfoUnavailable = 9, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
75 #[error("user not known to the underlying authentication module")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
76 UserUnknown = 10, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
77 #[error("retry limit reached; do not attempt further")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
78 MaxTries = 11, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
79 #[error("new authentication token required")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
80 NewAuthTokRequired = 12, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
81 #[error("user account has expired")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
82 AccountExpired = 13, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
83 #[error("cannot make/remove an entry for the specified session")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
84 SessionError = 14, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
85 #[error("underlying authentication service cannot retrieve user credentials")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
86 CredentialsUnavailable = 15, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
87 #[error("user credentials expired")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
88 CredentialsExpired = 16, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
89 #[error("failure setting user credentials")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
90 CredentialsError = 17, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
91 #[error("no module-specific data is present")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
92 NoModuleData = 18, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
93 #[error("conversation error")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
94 ConversationError = 19, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
95 #[error("authentication token manipulation error")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
96 AuthTokError = 20, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
97 #[error("authentication information cannot be recovered")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
98 AuthTokRecoveryError = 21, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
99 #[error("authentication token lock busy")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
100 AuthTokLockBusy = 22, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
101 #[error("authentication token aging disabled")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
102 AuthTokDisableAging = 23, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
103 #[error("preliminary check by password service")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
104 TryAgain = 24, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
105 #[error("ignore underlying account module, regardless of control flag")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
106 Ignore = 25, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
107 #[error("critical error; this module should fail now")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
108 Abort = 26, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
109 #[error("authentication token has expired")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
110 AuthTokExpired = 27, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
111 #[error("module is not known")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
112 ModuleUnknown = 28, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
113 #[error("bad item passed to pam_[whatever]_item")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
114 BadItem = 29, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
115 #[error("conversation function is event-driven and data is not available yet")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
116 ConversationAgain = 30, |
55
676675c3d434
Make PamResultCode implement Error.
Paul Fisher <paul@pfish.zone>
parents:
45
diff
changeset
|
117 #[error("call this function again to complete authentication stack")] |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
118 Incomplete = 31, |
15
27730595f1ea
Adding pam-http module
Anthony Nowell <anthony@algorithmia.com>
parents:
diff
changeset
|
119 } |
56
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
120 |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
121 pub type PamResult<T> = Result<T, ErrorCode>; |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
122 impl ErrorCode { |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
123 /// Converts a PamResult into the result code that C wants. |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
124 pub fn result_to_c(value: PamResult<()>) -> c_int { |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
125 match value { |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
126 Ok(_) => 0, // PAM_SUCCESS |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
127 Err(otherwise) => otherwise.into(), |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
128 } |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
129 } |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
130 |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
131 /// Converts a C result code into a PamResult, with success as Ok. |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
132 pub fn result_from(value: c_int) -> PamResult<()> { |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
133 match value { |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
134 0 => Ok(()), |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
135 value => Err(Self::from_i64(value as i64).unwrap_or(Self::ConversationError)) |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
136 } |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
137 } |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
138 } |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
139 |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
140 impl From<ErrorCode> for c_int { |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
141 fn from(val: ErrorCode) -> Self { |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
142 val.to_i32().unwrap_or(0) |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
143 } |
daa2cde64601
Big big refactor. Probably should have been multiple changes.
Paul Fisher <paul@pfish.zone>
parents:
55
diff
changeset
|
144 } |