comparison 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
comparison
equal deleted inserted replaced
91:039aae9a01f7 92:5ddbcada30f2
1 //! The wrapper types and traits for handles into the PAM library. 1 //! The wrapper types and traits for handles into the PAM library.
2 2
3 use crate::constants::Result; 3 use crate::constants::Result;
4 use crate::conv::Conversation; 4 use crate::conv::Conversation;
5 use crate::logging::Level;
5 6
6 macro_rules! trait_item { 7 macro_rules! trait_item {
7 ($(#[$md:meta])* get = $getter:ident, item = $item:literal $(, see = $see:path)?) => { 8 ($(#[$md:meta])* get = $getter:ident, item = $item:literal $(, see = $see:path)?) => {
8 $(#[$md])* 9 $(#[$md])*
9 #[doc = ""] 10 #[doc = ""]
54 /// 55 ///
55 /// You probably want [`LibPamHandle`](crate::libpam::OwnedLibPamHandle). 56 /// You probably want [`LibPamHandle`](crate::libpam::OwnedLibPamHandle).
56 /// This trait is intended to allow creating mock PAM handle types 57 /// This trait is intended to allow creating mock PAM handle types
57 /// to test PAM modules and applications. 58 /// to test PAM modules and applications.
58 pub trait PamShared { 59 pub trait PamShared {
60 /// Logs something via this PAM handle.
61 ///
62 /// You probably want to use one of the logging macros,
63 /// like [`error!`], [`warning!`], [`info!`], or [`debug!`].
64 ///
65 /// In most PAM implementations, this will go to syslog.
66 ///
67 /// # Example
68 ///
69 /// ```no_run
70 /// # use nonstick::{PamShared};
71 /// # use nonstick::logging::Level;
72 /// # let pam_hdl: Box<dyn PamShared> = todo!();
73 /// # let delay_ms = 100;
74 /// # let url = "https://zombo.com";
75 /// // Usually, instead of calling this manually, just use the macros.
76 /// nonstick::error!(pam_hdl, "something bad happened!");
77 /// nonstick::warn!(pam_hdl, "loading information took {delay_ms} ms");
78 /// nonstick::info!(pam_hdl, "using network backend");
79 /// nonstick::debug!(pam_hdl, "sending GET request to {url}");
80 /// // But if you really want to, you can call this yourself:
81 /// pam_hdl.log(Level::Warning, "this is unnecessarily verbose");
82 /// ```
83 fn log(&self, level: Level, entry: &str);
84
59 /// Retrieves the name of the user who is authenticating or logging in. 85 /// Retrieves the name of the user who is authenticating or logging in.
60 /// 86 ///
61 /// If the username has previously been obtained, this uses that username; 87 /// If the username has previously been obtained, this uses that username;
62 /// otherwise it prompts the user with the first of these that is present: 88 /// otherwise it prompts the user with the first of these that is present:
63 /// 89 ///