changeset 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 f71bfffb6de1
children 66e662cde087
files libpam-sys/libpam-sys-consts/src/lib.rs src/libpam/handle.rs src/logging.rs
diffstat 3 files changed, 18 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/libpam-sys/libpam-sys-consts/src/lib.rs	Tue Jul 08 00:42:09 2025 -0400
+++ b/libpam-sys/libpam-sys-consts/src/lib.rs	Tue Jul 08 00:49:38 2025 -0400
@@ -21,7 +21,7 @@
 /// The names that appear in the `cfg` variables are the same as the values
 /// in the [`PamImpl`] enum.
 ///
-/// ```
+/// ```ignore
 /// #[cfg(pam_impl = "OpenPam")]
 /// fn openpam_specific_func(handle: *const libpam_sys::pam_handle) {
 ///     let environ = libpam_sys::pam_getenvlist(handle);
--- 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();
--- a/src/logging.rs	Tue Jul 08 00:42:09 2025 -0400
+++ b/src/logging.rs	Tue Jul 08 00:49:38 2025 -0400
@@ -15,23 +15,6 @@
 //! and may even itself implement `log::Log`, but that interface is not exposed
 //! to the generic PAM user.
 
-#[cfg(pam_impl = "OpenPam")]
-mod levels {
-    use libpam_sys_helpers::constants;
-
-    pub const ERROR: i32 = constants::PAM_LOG_ERROR;
-    pub const WARN: i32 = constants::PAM_LOG_NOTICE;
-    pub const INFO: i32 = constants::PAM_LOG_VERBOSE;
-    pub const DEBUG: i32 = constants::PAM_LOG_DEBUG;
-}
-#[cfg(not(pam_impl = "OpenPam"))]
-mod levels {
-    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.
 ///
 /// The levels are in descending order of importance and correspond roughly
@@ -40,12 +23,11 @@
 /// Their values are ordered monotonically, either increasing or decreasing,
 /// depending upon the implementation.
 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
-#[repr(i32)]
 pub enum Level {
-    Error = levels::ERROR,
-    Warning = levels::WARN,
-    Info = levels::INFO,
-    Debug = levels::DEBUG,
+    Error,
+    Warning,
+    Info,
+    Debug,
 }
 
 /// The location of a log entry. Use [`location!`](crate::location!) to create this.