comparison 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
comparison
equal deleted inserted replaced
158:d5b7b28d754e 159:634cd5f2ac8b
3 use crate::_doc::{guide, linklist, man7, manbsd, stdlinks}; 3 use crate::_doc::{guide, linklist, man7, manbsd, stdlinks};
4 use crate::constants::{Flags, Result}; 4 use crate::constants::{Flags, Result};
5 use crate::conv::Conversation; 5 use crate::conv::Conversation;
6 use crate::environ::{EnvironMap, EnvironMapMut}; 6 use crate::environ::{EnvironMap, EnvironMapMut};
7 use crate::items::{getter, Items, ItemsMut}; 7 use crate::items::{getter, Items, ItemsMut};
8 use crate::logging::{Level, Location}; 8 use crate::logging::Logger;
9 use std::ffi::{OsStr, OsString}; 9 use std::ffi::{OsStr, OsString};
10 use std::fmt;
11 10
12 /// Functionality for both PAM applications and PAM modules. 11 /// Functionality for both PAM applications and PAM modules.
13 /// 12 ///
14 /// This base trait includes features of a PAM handle that are available 13 /// This base trait includes features of a PAM handle that are available
15 /// to both applications and modules. 14 /// to both applications and modules.
16 /// 15 ///
17 /// You probably want [`LibPamTransaction`](crate::libpam::LibPamTransaction). 16 /// You probably want [`LibPamTransaction`](crate::libpam::LibPamTransaction).
18 /// This trait is intended to allow creating mock PAM handle types 17 /// This trait is intended to allow creating mock PAM handle types
19 /// to test PAM modules and applications. 18 /// to test PAM modules and applications.
20 pub trait PamShared { 19 pub trait PamShared: Logger {
21 /// Logs something via this PAM handle.
22 ///
23 /// You probably want to use one of the logging macros,
24 /// like [`error!`](crate::error!),
25 /// [`warn!`](crate::warn!),
26 /// [`info!`](crate::info!),
27 /// or [`debug!`](crate::debug!).
28 ///
29 /// In most PAM implementations, this will go to syslog.
30 /// See [Linux-PAM's `pam_syslog`][man7] or
31 /// [OpenPAM's `openpam_log`][manbsd] for more details.
32 ///
33 /// # Example
34 ///
35 /// ```no_run
36 /// # use nonstick::PamShared;
37 /// use nonstick::logging::Level;
38 /// use nonstick::location;
39 /// # fn _test(pam_hdl: impl PamShared) {
40 /// # let delay_ms = 100;
41 /// # let url = "https://zombo.com";
42 /// // Usually, instead of calling this manually, just use the macros.
43 /// nonstick::error!(pam_hdl, "something bad happened!");
44 /// nonstick::warn!(pam_hdl, "loading information took {delay_ms} ms");
45 /// nonstick::info!(pam_hdl, "using network backend");
46 /// nonstick::debug!(pam_hdl, "sending GET request to {url}");
47 /// // But if you really want to, you can call this yourself:
48 /// pam_hdl.log(Level::Warn, location!(), format_args!("this is unnecessarily verbose"));
49 /// # }
50 /// ```
51 #[doc = man7!(3 pam_syslog)]
52 #[doc = manbsd!(3 openpam_log)]
53 fn log(&self, level: Level, loc: Location<'_>, entry: fmt::Arguments);
54
55 /// Retrieves the name of the user who is authenticating or logging in. 20 /// Retrieves the name of the user who is authenticating or logging in.
56 /// 21 ///
57 /// If the username has previously been obtained, this uses that username; 22 /// If the username has previously been obtained, this uses that username;
58 /// otherwise it prompts the user with the first of these that is present: 23 /// otherwise it prompts the user with the first of these that is present:
59 /// 24 ///