diff src/handle.rs @ 92:5ddbcada30f2

Add the ability to log against a PAM handle. PAM impls provide a way to log to syslog. This exposes it via nonstick.
author Paul Fisher <paul@pfish.zone>
date Sun, 22 Jun 2025 19:29:32 -0400
parents 039aae9a01f7
children db167f96ba46
line wrap: on
line diff
--- a/src/handle.rs	Wed Jun 18 16:30:41 2025 -0400
+++ b/src/handle.rs	Sun Jun 22 19:29:32 2025 -0400
@@ -2,6 +2,7 @@
 
 use crate::constants::Result;
 use crate::conv::Conversation;
+use crate::logging::Level;
 
 macro_rules! trait_item {
     ($(#[$md:meta])* get = $getter:ident, item = $item:literal $(, see = $see:path)?) => {
@@ -56,6 +57,31 @@
 /// This trait is intended to allow creating mock PAM handle types
 /// to test PAM modules and applications.
 pub trait PamShared {
+    /// Logs something via this PAM handle.
+    ///
+    /// You probably want to use one of the logging macros,
+    /// like [`error!`], [`warning!`], [`info!`], or [`debug!`].
+    ///
+    /// In most PAM implementations, this will go to syslog.
+    ///
+    /// # Example
+    ///
+    /// ```no_run
+    /// # use nonstick::{PamShared};
+    /// # use nonstick::logging::Level;
+    /// # let pam_hdl: Box<dyn PamShared> = todo!();
+    /// # let delay_ms = 100;
+    /// # let url = "https://zombo.com";
+    /// // Usually, instead of calling this manually, just use the macros.
+    /// nonstick::error!(pam_hdl, "something bad happened!");
+    /// nonstick::warn!(pam_hdl, "loading information took {delay_ms} ms");
+    /// nonstick::info!(pam_hdl, "using network backend");
+    /// nonstick::debug!(pam_hdl, "sending GET request to {url}");
+    /// // But if you really want to, you can call this yourself:
+    /// pam_hdl.log(Level::Warning, "this is unnecessarily verbose");
+    /// ```
+    fn log(&self, level: Level, entry: &str);
+
     /// Retrieves the name of the user who is authenticating or logging in.
     ///
     /// If the username has previously been obtained, this uses that username;