diff src/constants.rs @ 113:178310336596

Fix up more constants, make things i32 rather than u32.
author Paul Fisher <paul@pfish.zone>
date Sun, 29 Jun 2025 03:11:33 -0400
parents e97534be35e3
children
line wrap: on
line diff
--- a/src/constants.rs	Sun Jun 29 02:21:26 2025 -0400
+++ b/src/constants.rs	Sun Jun 29 03:11:33 2025 -0400
@@ -29,13 +29,13 @@
         ($(#[$attr:meta])* $($name:ident = $value:expr),+) => {
             define!(
                 @meta { $(#[$attr])* }
-                $(pub const $name: u32 = $value;)+
+                $(pub const $name: i32 = $value;)+
             );
         };
         (@meta $m:tt $($i:item)+) => { define!(@expand $($m $i)+); };
         (@expand $({ $(#[$m:meta])* } $i:item)+) => {$($(#[$m])* $i)+};
     }
-    const fn bit(n: u8) -> u32 {
+    const fn bit(n: u8) -> i32 {
         1 << n
     }
     define!(
@@ -98,26 +98,26 @@
     /// See `/usr/include/security/pam_modules.h` for more details.
     #[derive(Debug, Default, PartialEq)]
     #[repr(transparent)]
-    pub struct Flags: c_uint {
+    pub struct Flags: c_int {
         /// The module should not generate any messages.
-        const SILENT = pam_ffi::PAM_SILENT as u32;
+        const SILENT = pam_ffi::PAM_SILENT;
 
         /// The module should return [ErrorCode::AuthError]
         /// if the user has an empty authentication token
         /// rather than immediately accepting them.
-        const DISALLOW_NULL_AUTHTOK = pam_ffi::PAM_DISALLOW_NULL_AUTHTOK as u32;
+        const DISALLOW_NULL_AUTHTOK = pam_ffi::PAM_DISALLOW_NULL_AUTHTOK;
 
         // Flag used for `set_credentials`.
 
         /// Set user credentials for an authentication service.
-        const ESTABLISH_CREDENTIALS = pam_ffi::PAM_ESTABLISH_CRED as u32;
+        const ESTABLISH_CREDENTIALS = pam_ffi::PAM_ESTABLISH_CRED;
         /// Delete user credentials associated with
         /// an authentication service.
-        const DELETE_CREDENTIALS = pam_ffi::PAM_DELETE_CRED as u32;
+        const DELETE_CREDENTIALS = pam_ffi::PAM_DELETE_CRED;
         /// Reinitialize user credentials.
-        const REINITIALIZE_CREDENTIALS = pam_ffi::PAM_REINITIALIZE_CRED as u32;
+        const REINITIALIZE_CREDENTIALS = pam_ffi::PAM_REINITIALIZE_CRED;
         /// Extend the lifetime of user credentials.
-        const REFRESH_CREDENTIALS = pam_ffi::PAM_REFRESH_CRED as u32;
+        const REFRESH_CREDENTIALS = pam_ffi::PAM_REFRESH_CRED;
 
         // Flags used for password changing.
 
@@ -126,7 +126,7 @@
         /// the password service should update all passwords.
         ///
         /// This flag is only used by `change_authtok`.
-        const CHANGE_EXPIRED_AUTHTOK = pam_ffi::PAM_CHANGE_EXPIRED_AUTHTOK as u32;
+        const CHANGE_EXPIRED_AUTHTOK = pam_ffi::PAM_CHANGE_EXPIRED_AUTHTOK;
         /// This is a preliminary check for password changing.
         /// The password should not be changed.
         ///
@@ -134,7 +134,7 @@
         /// Applications may not use this flag.
         ///
         /// This flag is only used by `change_authtok`.
-        const PRELIMINARY_CHECK = pam_ffi::PAM_PRELIM_CHECK as u32;
+        const PRELIMINARY_CHECK = pam_ffi::PAM_PRELIM_CHECK;
         /// The password should actuallyPR be updated.
         /// This and [Self::PRELIMINARY_CHECK] are mutually exclusive.
         ///
@@ -142,7 +142,7 @@
         /// Applications may not use this flag.
         ///
         /// This flag is only used by `change_authtok`.
-        const UPDATE_AUTHTOK = pam_ffi::PAM_UPDATE_AUTHTOK as u32;
+        const UPDATE_AUTHTOK = pam_ffi::PAM_UPDATE_AUTHTOK;
     }
 }
 
@@ -163,7 +163,7 @@
 #[allow(non_camel_case_types, dead_code)]
 #[derive(Copy, Clone, Debug, PartialEq, TryFromPrimitive, IntoPrimitive)]
 #[non_exhaustive] // C might give us anything!
-#[repr(u32)]
+#[repr(i32)]
 pub enum ErrorCode {
     OpenError = pam_ffi::PAM_OPEN_ERR,
     SymbolError = pam_ffi::PAM_SYMBOL_ERR,
@@ -221,7 +221,7 @@
     pub fn result_to_c<T>(value: Result<T>) -> c_int {
         match value {
             Ok(_) => 0, // PAM_SUCCESS
-            Err(otherwise) => u32::from(otherwise) as i32,
+            Err(otherwise) => otherwise.into(),
         }
     }
 
@@ -230,7 +230,7 @@
     pub fn result_from(value: c_int) -> Result<()> {
         match value {
             0 => Ok(()),
-            value => Err((value as u32).try_into().unwrap_or(Self::SystemError)),
+            value => Err(value.try_into().unwrap_or(Self::SystemError)),
         }
     }