diff src/libpam/handle.rs @ 155:ab8020566cd9

Only use real PAM constants for logging within `nonstick/libpam`.
author Paul Fisher <paul@pfish.zone>
date Tue, 08 Jul 2025 00:49:38 -0400
parents 3036f2e6a022
children 66e662cde087
line wrap: on
line diff
--- a/src/libpam/handle.rs	Tue Jul 08 00:42:09 2025 -0400
+++ b/src/libpam/handle.rs	Tue Jul 08 00:49:38 2025 -0400
@@ -322,7 +322,6 @@
 }
 
 impl PamShared for LibPamHandle {
-    #[cfg(any())]
     fn log(&self, level: Level, loc: Location<'_>, entry: &str) {
         let entry = match CString::new(entry).or_else(|_| CString::new(dbg!(entry))) {
             Ok(cstr) => cstr,
@@ -330,15 +329,27 @@
         };
         #[cfg(pam_impl = "LinuxPam")]
         {
+            let level = match level {
+                Level::Error => libc::LOG_ERR,
+                Level::Warning => libc::LOG_WARNING,
+                Level::Info => libc::LOG_INFO,
+                Level::Debug => libc::LOG_DEBUG,
+            };
             _ = loc;
             // SAFETY: We're calling this function with a known value.
             unsafe {
-                libpam_sys::pam_syslog(self, level as c_int, "%s\0".as_ptr().cast(), entry.as_ptr())
+                libpam_sys::pam_syslog(self.raw_ref(), level, "%s\0".as_ptr().cast(), entry.as_ptr())
             }
         }
         #[cfg(pam_impl = "OpenPam")]
         {
             let func = CString::new(loc.function).unwrap_or(CString::default());
+            let level = match level {
+                Level::Error => libpam_sys::PAM_LOG_ERROR,
+                Level::Warning => libpam_sys::PAM_LOG_NOTICE,
+                Level::Info => libpam_sys::PAM_LOG_VERBOSE,
+                Level::Debug => libpam_sys::PAM_LOG_DEBUG,
+            };
             // SAFETY: We're calling this function with a known value.
             unsafe {
                 libpam_sys::_openpam_log(
@@ -351,8 +362,6 @@
         }
     }
 
-    fn log(&self, _level: Level, _loc: Location<'_>, _entry: &str) {}
-
     fn username(&mut self, prompt: Option<&OsStr>) -> Result<OsString> {
         let prompt = memory::option_cstr_os(prompt);
         let mut output: *const c_char = ptr::null();