Mercurial > crates > nonstick
diff src/handle.rs @ 159:634cd5f2ac8b
Separate logging into its own trait apart from the rest of PAM.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Sat, 12 Jul 2025 18:16:18 -0400 |
parents | 0099f2f79f86 |
children | 2f5913131295 |
line wrap: on
line diff
--- a/src/handle.rs Sat Jul 12 17:17:37 2025 -0400 +++ b/src/handle.rs Sat Jul 12 18:16:18 2025 -0400 @@ -5,9 +5,8 @@ use crate::conv::Conversation; use crate::environ::{EnvironMap, EnvironMapMut}; use crate::items::{getter, Items, ItemsMut}; -use crate::logging::{Level, Location}; +use crate::logging::Logger; use std::ffi::{OsStr, OsString}; -use std::fmt; /// Functionality for both PAM applications and PAM modules. /// @@ -17,41 +16,7 @@ /// You probably want [`LibPamTransaction`](crate::libpam::LibPamTransaction). /// 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!`](crate::error!), - /// [`warn!`](crate::warn!), - /// [`info!`](crate::info!), - /// or [`debug!`](crate::debug!). - /// - /// In most PAM implementations, this will go to syslog. - /// See [Linux-PAM's `pam_syslog`][man7] or - /// [OpenPAM's `openpam_log`][manbsd] for more details. - /// - /// # Example - /// - /// ```no_run - /// # use nonstick::PamShared; - /// use nonstick::logging::Level; - /// use nonstick::location; - /// # fn _test(pam_hdl: impl PamShared) { - /// # 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::Warn, location!(), format_args!("this is unnecessarily verbose")); - /// # } - /// ``` - #[doc = man7!(3 pam_syslog)] - #[doc = manbsd!(3 openpam_log)] - fn log(&self, level: Level, loc: Location<'_>, entry: fmt::Arguments); - +pub trait PamShared: Logger { /// Retrieves the name of the user who is authenticating or logging in. /// /// If the username has previously been obtained, this uses that username;