changeset 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 82995b4dccee
children 93d423b65555
files libpam-sys/libpam-sys-impls/build.rs libpam-sys/libpam-sys-impls/src/lib.rs libpam-sys/libpam-sys-test/build.rs libpam-sys/libpam-sys-test/tests/test_constants.rs libpam-sys/src/constants.rs src/constants.rs src/libpam/pam_ffi.rs src/libpam/question.rs src/logging.rs
diffstat 9 files changed, 190 insertions(+), 145 deletions(-) [+]
line wrap: on
line diff
--- a/libpam-sys/libpam-sys-impls/build.rs	Sun Jun 29 02:21:26 2025 -0400
+++ b/libpam-sys/libpam-sys-impls/build.rs	Sun Jun 29 03:11:33 2025 -0400
@@ -6,10 +6,10 @@
 //!  2. It detects the current PAM implementation and sets an env var for
 //!     the macros in `libpam-sys-impl`.
 
+use proc_macro2::TokenStream;
+use quote::quote;
 use std::{env, fs};
 use strum::EnumString;
-use proc_macro2::TokenStream;
-use quote::quote;
 
 fn main() {
     let pam_impl = match option_env!("LIBPAMSYS_IMPL") {
@@ -25,10 +25,7 @@
                 target_os = "openbsd"
             )) {
                 PamImpl::OpenPam
-            } else if cfg!(any(
-                target_os = "illumos",
-                target_os = "solaris",
-            )) {
+            } else if cfg!(any(target_os = "illumos", target_os = "solaris",)) {
                 PamImpl::Sun
             } else {
                 PamImpl::MinimalOpenPam
@@ -53,7 +50,11 @@
             Err(_) => panic!("unknown PAM implementation {other:?}"),
         },
     };
-    fs::write(format!("{}/pam_impl_enum.rs", env::var("OUT_DIR").unwrap()), PamImpl::enum_tokens().to_string()).unwrap();
+    fs::write(
+        format!("{}/pam_impl_enum.rs", env::var("OUT_DIR").unwrap()),
+        PamImpl::enum_tokens().to_string(),
+    )
+    .unwrap();
     println!("cargo:rustc-env=LIBPAMSYS_IMPL={pam_impl:?}");
 }
 
--- a/libpam-sys/libpam-sys-impls/src/lib.rs	Sun Jun 29 02:21:26 2025 -0400
+++ b/libpam-sys/libpam-sys-impls/src/lib.rs	Sun Jun 29 03:11:33 2025 -0400
@@ -270,7 +270,7 @@
             ("One", (not(any("One", "Another")))),
             ("Negatory", (not(not("Affirmative")))),
             ("MinimalOpenPam", ("OpenPam")),
-            ("OpenPam", (("MinimalOpenPam"))),
+            ("OpenPam", ("MinimalOpenPam")),
         ];
         for (bad, tree) in nonmatching {
             let pred = parse(tree);
--- a/libpam-sys/libpam-sys-test/build.rs	Sun Jun 29 02:21:26 2025 -0400
+++ b/libpam-sys/libpam-sys-test/build.rs	Sun Jun 29 03:11:33 2025 -0400
@@ -1,9 +1,9 @@
 use bindgen::MacroTypeVariation;
 use libpam_sys_impls::cfg_pam_impl;
-use quote::ToTokens;
+use quote::{format_ident, ToTokens};
 use std::path::PathBuf;
 use std::{env, fs};
-use syn::{Item, ItemConst};
+use syn::{Ident, Item, ItemConst, Path, Type, TypePath};
 
 fn main() {
     generate_const_test();
@@ -31,7 +31,7 @@
             "security/pam_appl.h".into(),
             "security/pam_constants.h".into(),
         ],
-        ignore_consts: vec![],
+        ignore_consts: vec!["OPENPAM_VERSION"],
     }
 }
 
@@ -66,10 +66,15 @@
                 }
             })
             .filter(|item| config.should_check_const(item))
-            .map(|item| {
-                let tokens = item.expr.to_token_stream();
+            .cloned()
+            .map(|mut item| {
+                item.ty = Box::new(Type::Path(TypePath {
+                    qself: None,
+                    path: format_ident!("i32").into(),
+                }));
                 format!(
                     "assert_eq!({tokens}, libpam_sys::{name});",
+                    tokens = item.expr.to_token_stream(),
                     name = item.ident
                 )
             }),
--- a/libpam-sys/libpam-sys-test/tests/test_constants.rs	Sun Jun 29 02:21:26 2025 -0400
+++ b/libpam-sys/libpam-sys-test/tests/test_constants.rs	Sun Jun 29 03:11:33 2025 -0400
@@ -1,4 +1,3 @@
-
 #[test]
 fn check_constants() {
     include!(concat!(env!("OUT_DIR"), "/constant_test.rs"))
--- a/libpam-sys/src/constants.rs	Sun Jun 29 02:21:26 2025 -0400
+++ b/libpam-sys/src/constants.rs	Sun Jun 29 03:11:33 2025 -0400
@@ -10,35 +10,55 @@
     ($(#[$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)+};
 }
 
+/// Macro to make defining C-style enums way easier.
+macro_rules! c_enum {
+    ($(#[$attr:meta])* $($name:ident $(= $value:expr)?,)*) => {
+        c_enum!(
+            (0)
+            $(#[$attr])*
+            $($name $(= $value)?,)*
+        );
+    };
+    (($n:expr) $(#[$attr:meta])* $name:ident, $($rest:ident $(= $rv:expr)?,)*) => {
+        $(#[$attr])* pub const $name: i32 = $n;
+        c_enum!(($n + 1) $(#[$attr])* $($rest $(= $rv)?,)*);
+    };
+    (($n:expr) $(#[$attr:meta])* $name:ident = $value:expr, $($rest:ident $(= $rv:expr)?,)*) => {
+        $(#[$attr])* pub const $name: i32 = $value;
+        c_enum!(($value + 1) $(#[$attr])* $($rest $(= $rv)?,)*);
+    };
+    (($n:expr) $(#[$attr:meta])*) => {};
+}
+
 // There are a few truly universal constants.
 // They are defined here directly.
-pub const PAM_SUCCESS: u32 = 0;
+pub const PAM_SUCCESS: i32 = 0;
 
-define!(
+c_enum!(
     /// An item type.
-    PAM_SERVICE = 1;
-    PAM_USER = 2;
-    PAM_TTY = 3;
-    PAM_RHOST = 4;
-    PAM_CONV = 5;
-    PAM_AUTHTOK = 6;
-    PAM_OLDAUTHTOK = 7;
-    PAM_RUSER = 8;
+    PAM_SERVICE = 1,
+    PAM_USER,
+    PAM_TTY,
+    PAM_RHOST,
+    PAM_CONV,
+    PAM_AUTHTOK,
+    PAM_OLDAUTHTOK,
+    PAM_RUSER,
 );
 
-define!(
+c_enum!(
     /// A message style.
-    PAM_PROMPT_ECHO_OFF = 1;
-    PAM_PROMPT_ECHO_ON = 2;
-    PAM_ERROR_MSG = 3;
-    PAM_TEXT_INFO = 4;
+    PAM_PROMPT_ECHO_OFF = 1,
+    PAM_PROMPT_ECHO_ON,
+    PAM_ERROR_MSG,
+    PAM_TEXT_INFO,
 );
 
 define!(
@@ -52,42 +72,43 @@
 pub use linux_pam::*;
 #[cfg_pam_impl("LinuxPam")]
 mod linux_pam {
-    define!(
+    c_enum!(
         /// An error code.
-        PAM_OPEN_ERR = 1;
-        PAM_SYMBOL_ERR = 2;
-        PAM_SERVICE_ERR = 3;
-        PAM_SYSTEM_ERR = 4;
-        PAM_BUF_ERR = 5;
-        PAM_PERM_DENIED = 6;
-        PAM_AUTH_ERR = 7;
-        PAM_CRED_INSUFFICIENT = 8;
-        PAM_AUTHINFO_UNAVAIL = 9;
-        PAM_USER_UNKNOWN = 10;
-        PAM_MAXTRIES = 11;
-        PAM_NEW_AUTHTOK_REQD = 12;
-        PAM_ACCT_EXPIRED = 13;
-        PAM_SESSION_ERR = 14;
-        PAM_CRED_UNAVAIL = 15;
-        PAM_CRED_EXPIRED = 16;
-        PAM_CRED_ERR = 17;
-        PAM_NO_MODULE_DATA = 18;
-        PAM_CONV_ERR = 19;
-        PAM_AUTHTOK_ERR = 20;
-        PAM_AUTHTOK_RECOVER_ERR = 21;
-        PAM_AUTHTOK_RECOVERY_ERR = 21;
-        PAM_AUTHTOK_LOCK_BUSY = 22;
-        PAM_AUTHTOK_DISABLE_AGING = 23;
-        PAM_TRY_AGAIN = 24;
-        PAM_IGNORE = 25;
-        PAM_ABORT = 26;
-        PAM_AUTHTOK_EXPIRED = 27;
-        PAM_MODULE_UNKNOWN = 28;
-        PAM_BAD_ITEM = 29;
-        PAM_CONV_AGAIN = 30;
-        PAM_INCOMPLETE = 31;
-        _PAM_RETURN_VALUES = 32;
+        PAM_OPEN_ERR = 1,
+        PAM_SYMBOL_ERR,
+        PAM_SERVICE_ERR,
+        PAM_SYSTEM_ERR,
+        PAM_BUF_ERR,
+        PAM_PERM_DENIED,
+        PAM_AUTH_ERR,
+        PAM_CRED_INSUFFICIENT,
+        PAM_AUTHINFO_UNAVAIL,
+        PAM_USER_UNKNOWN,
+        PAM_MAXTRIES,
+        PAM_NEW_AUTHTOK_REQD,
+        PAM_ACCT_EXPIRED,
+        PAM_SESSION_ERR,
+        PAM_CRED_UNAVAIL,
+        PAM_CRED_EXPIRED,
+        PAM_CRED_ERR,
+        PAM_NO_MODULE_DATA,
+        PAM_CONV_ERR,
+        PAM_AUTHTOK_ERR,
+        PAM_AUTHTOK_RECOVERY_ERR,
+        PAM_AUTHTOK_LOCK_BUSY,
+        PAM_AUTHTOK_DISABLE_AGING,
+        PAM_TRY_AGAIN,
+        PAM_IGNORE,
+        PAM_ABORT,
+        PAM_AUTHTOK_EXPIRED,
+        PAM_MODULE_UNKNOWN,
+        PAM_BAD_ITEM,
+        PAM_CONV_AGAIN,
+        PAM_INCOMPLETE,
+        _PAM_RETURN_VALUES,
     );
+    /// An error code.
+    pub const PAM_AUTHTOK_RECOVER_ERR: i32 = 21;
 
     define!(
         /// A flag value.
@@ -105,16 +126,16 @@
         PAM_DATA_REPLACE = 0x20000000;
     );
 
-    define!(
-        PAM_USER_PROMPT = 9;
-        PAM_FAIL_DELAY = 10;
-        PAM_XDISPLAY = 11;
-        PAM_XAUTHDATA = 12;
-        PAM_AUTHTOK_TYPE = 13;
+    c_enum!(
+        PAM_USER_PROMPT = 9,
+        PAM_FAIL_DELAY,
+        PAM_XDISPLAY,
+        PAM_XAUTHDATA,
+        PAM_AUTHTOK_TYPE,
     );
 
     /// To suppress messages in the item cleanup function.
-    pub const PAM_DATA_SILENT: u32 = 0x40000000;
+    pub const PAM_DATA_SILENT: i32 = 0x40000000;
 
     // Message styles
     define!(
@@ -128,35 +149,35 @@
 pub use openpam_sun::*;
 #[cfg_pam_impl(any("OpenPam", "OpenPamMinimal", "Sun"))]
 mod openpam_sun {
-    define!(
+    c_enum!(
         /// An error code.
-        PAM_OPEN_ERR = 1;
-        PAM_SYMBOL_ERR = 2;
-        PAM_SERVICE_ERR = 3;
-        PAM_SYSTEM_ERR = 4;
-        PAM_BUF_ERR = 5;
-        PAM_CONV_ERR = 6;
-        PAM_PERM_DENIED = 7;
-        PAM_MAXTRIES = 8;
-        PAM_AUTH_ERR = 9;
-        PAM_NEW_AUTHTOK_REQD = 10;
-        PAM_CRED_INSUFFICIENT = 11;
-        PAM_AUTHINFO_UNAVAIL = 12;
-        PAM_USER_UNKNOWN = 13;
-        PAM_CRED_UNAVAIL = 14;
-        PAM_CRED_EXPIRED = 15;
-        PAM_CRED_ERR = 16;
-        PAM_ACCT_EXPIRED = 17;
-        PAM_AUTHTOK_EXPIRED = 18;
-        PAM_SESSION_ERR = 19;
-        PAM_AUTHTOK_ERR = 20;
-        PAM_AUTHTOK_RECOVERY_ERR = 21;
-        PAM_AUTHTOK_LOCK_BUSY = 22;
-        PAM_AUTHTOK_DISABLE_AGING = 23;
-        PAM_NO_MODULE_DATA = 24;
-        PAM_IGNORE = 25;
-        PAM_ABORT = 26;
-        PAM_TRY_AGAIN = 27;
+        PAM_OPEN_ERR = 1,
+        PAM_SYMBOL_ERR,
+        PAM_SERVICE_ERR,
+        PAM_SYSTEM_ERR,
+        PAM_BUF_ERR,
+        PAM_CONV_ERR,
+        PAM_PERM_DENIED,
+        PAM_MAXTRIES,
+        PAM_AUTH_ERR,
+        PAM_NEW_AUTHTOK_REQD,
+        PAM_CRED_INSUFFICIENT,
+        PAM_AUTHINFO_UNAVAIL,
+        PAM_USER_UNKNOWN,
+        PAM_CRED_UNAVAIL,
+        PAM_CRED_EXPIRED,
+        PAM_CRED_ERR,
+        PAM_ACCT_EXPIRED,
+        PAM_AUTHTOK_EXPIRED,
+        PAM_SESSION_ERR,
+        PAM_AUTHTOK_ERR,
+        PAM_AUTHTOK_RECOVERY_ERR,
+        PAM_AUTHTOK_LOCK_BUSY,
+        PAM_AUTHTOK_DISABLE_AGING,
+        PAM_NO_MODULE_DATA,
+        PAM_IGNORE,
+        PAM_ABORT,
+        PAM_TRY_AGAIN,
     );
 
     define!(
@@ -166,10 +187,10 @@
     );
 
     /// A general flag for PAM operations.
-    pub const PAM_SILENT: u32 = 0x80000000;
+    pub const PAM_SILENT: i32 = 0x80000000u32 as i32;
 
     /// The password must be non-null.
-    pub const PAM_DISALLOW_NULL_AUTHTOK: u32 = 0b1;
+    pub const PAM_DISALLOW_NULL_AUTHTOK: i32 = 0b1;
 
     define!(
         /// A flag for `pam_setcred`.
@@ -191,26 +212,46 @@
 pub use openpam::*;
 #[cfg_pam_impl("OpenPam")]
 mod openpam {
-    define!(
+    c_enum!(
         /// An error code.
-        PAM_MODULE_UNKNOWN = 28;
-        PAM_DOMAIN_UNKNOWN = 29;
-        PAM_BAD_HANDLE = 30;
-        PAM_BAD_ITEM = 31;
-        PAM_BAD_FEATURE = 32;
-        PAM_BAD_CONSTANT = 33;
+        PAM_MODULE_UNKNOWN = 28,
+        PAM_DOMAIN_UNKNOWN,
+        PAM_BAD_HANDLE,
+        PAM_BAD_ITEM,
+        PAM_BAD_FEATURE,
+        PAM_BAD_CONSTANT,
     );
     /// The total number of PAM error codes.
     pub const PAM_NUM_ERRORS: i32 = 34;
 
-    define!(
+    c_enum!(
         /// An item type.
-        PAM_AUTHTOK_PROMPT = 11;
-        PAM_OLDAUTHTOK_PROMPT = 12;
-        PAM_HOST = 13;
+        PAM_AUTHTOK_PROMPT = 11,
+        PAM_OLDAUTHTOK_PROMPT,
+        PAM_HOST,
     );
     /// The total number of PAM items.
-    pub const PAM_NUM_ITEMS: u32 = 14;
+    pub const PAM_NUM_ITEMS: i32 = 14;
+
+    c_enum!(
+        /// An optional OpenPAM feature.
+        OPENPAM_RESTRICT_SERVICE_NAME,
+        OPENPAM_VERIFY_POLICY_FILE,
+        OPENPAM_RESTRICT_MODULE_NAME,
+        OPENPAM_VERIFY_MODULE_FILE,
+        OPENPAM_FALLBACK_TO_OTHER,
+    );
+    /// The number of optional OpenPAM features.
+    pub const OPENPAM_NUM_FEATURES: i32 = 5;
+
+    c_enum!(
+        /// Log level.
+        PAM_LOG_LIBDEBUG = -1,
+        PAM_LOG_DEBUG,
+        PAM_LOG_VERBOSE,
+        PAM_LOG_NOTICE,
+        PAM_LOG_ERROR,
+    );
 }
 
 /// Constants exclusive to Illumos.
@@ -219,7 +260,7 @@
 #[cfg_pam_impl("Sun")]
 mod sun {
     /// The total number of PAM error codes.
-    pub const PAM_TOTAL_ERRNUM: u32 = 28;
+    pub const PAM_TOTAL_ERRNUM: i32 = 28;
 
     define!(
         /// An item type.
@@ -228,6 +269,5 @@
     );
 
     /// A flag for `pam_chauthtok`.
-    pub const PAM_NO_AUTHTOK_CHECK: u32 = 0b1000;
+    pub const PAM_NO_AUTHTOK_CHECK: i32 = 0b1000;
 }
-
--- 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)),
         }
     }
 
--- a/src/libpam/pam_ffi.rs	Sun Jun 29 02:21:26 2025 -0400
+++ b/src/libpam/pam_ffi.rs	Sun Jun 29 03:11:33 2025 -0400
@@ -3,7 +3,7 @@
 #![allow(non_camel_case_types, non_upper_case_globals)]
 
 use crate::libpam::memory::{CHeapBox, Immovable};
-use std::ffi::{c_int, c_uint, c_void, CStr};
+use std::ffi::{c_int, c_void, CStr};
 use std::marker::PhantomData;
 use std::ptr;
 
@@ -51,7 +51,7 @@
 #[derive(Debug)]
 pub struct Question {
     /// The style of message to request.
-    pub style: c_uint,
+    pub style: c_int,
     /// A description of the data requested.
     ///
     /// For most requests, this will be an owned [`CStr`],
@@ -92,9 +92,9 @@
 }
 
 /// Gets a string version of an error message.
-pub fn strerror(code: c_uint) -> Option<&'static str> {
+pub fn strerror(code: c_int) -> Option<&'static str> {
     // SAFETY: Every single PAM implementation I can find (Linux-PAM, OpenPAM,
-    // Solaris, etc.) returns a static string and ignores the handle value.
+    // Sun, etc.) returns a static string and ignores the handle value.
     let strerror = unsafe { pam_strerror(ptr::null_mut(), code as c_int) };
     if strerror.is_null() {
         None
--- a/src/libpam/question.rs	Sun Jun 29 02:21:26 2025 -0400
+++ b/src/libpam/question.rs	Sun Jun 29 03:11:33 2025 -0400
@@ -177,7 +177,7 @@
 
 /// The C enum values for messages shown to the user.
 #[derive(Debug, PartialEq, TryFromPrimitive, IntoPrimitive)]
-#[repr(u32)]
+#[repr(i32)]
 enum Style {
     /// Requests information from the user; will be masked when typing.
     PromptEchoOff = pam_ffi::PAM_PROMPT_ECHO_OFF,
--- a/src/logging.rs	Sun Jun 29 02:21:26 2025 -0400
+++ b/src/logging.rs	Sun Jun 29 03:11:33 2025 -0400
@@ -18,17 +18,17 @@
 #[cfg(all(feature = "link", pam_impl = "openpam"))]
 mod levels {
     use crate::libpam::pam_ffi;
-    pub const ERROR: u32 = pam_ffi::PAM_LOG_ERROR;
-    pub const WARN: u32 = pam_ffi::PAM_LOG_NOTICE;
-    pub const INFO: u32 = pam_ffi::PAM_LOG_VERBOSE;
-    pub const DEBUG: u32 = pam_ffi::PAM_LOG_DEBUG;
+    pub const ERROR: i32 = pam_ffi::PAM_LOG_ERROR;
+    pub const WARN: i32 = pam_ffi::PAM_LOG_NOTICE;
+    pub const INFO: i32 = pam_ffi::PAM_LOG_VERBOSE;
+    pub const DEBUG: i32 = pam_ffi::PAM_LOG_DEBUG;
 }
 #[cfg(not(all(feature = "link", pam_impl = "openpam")))]
 mod levels {
-    pub const ERROR: u32 = libc::LOG_ERR as u32;
-    pub const WARN: u32 = libc::LOG_WARNING as u32;
-    pub const INFO: u32 = libc::LOG_INFO as u32;
-    pub const DEBUG: u32 = libc::LOG_DEBUG as u32;
+    pub const ERROR: i32 = libc::LOG_ERR;
+    pub const WARN: i32 = libc::LOG_WARNING;
+    pub const INFO: i32 = libc::LOG_INFO;
+    pub const DEBUG: i32 = libc::LOG_DEBUG;
 }
 
 /// An entry to be added to the log.
@@ -39,7 +39,7 @@
 /// In all implementations, these are ordered such that `Error`, `Warning`,
 /// `Info`, and `Debug` are in ascending order.
 #[derive(Debug, PartialEq, Ord, PartialOrd, Eq)]
-#[repr(u32)]
+#[repr(i32)]
 pub enum Level {
     Error = levels::ERROR,
     Warning = levels::WARN,