diff src/handle.rs @ 98:b87100c5eed4

Start on environment variables, and make pointers nicer. This starts work on the PAM environment handling, and in so doing, introduces the CHeapBox and CHeapString structs. These are analogous to Box and CString, but they're located on the C heap rather than being Rust-managed memory. This is because environment variables deal with even more pointers and it turns out we can lose a lot of manual freeing using homemade smart pointers.
author Paul Fisher <paul@pfish.zone>
date Tue, 24 Jun 2025 04:25:25 -0400
parents efe2f5f8b5b2
children 3f11b8d30f63
line wrap: on
line diff
--- a/src/handle.rs	Mon Jun 23 19:10:34 2025 -0400
+++ b/src/handle.rs	Tue Jun 24 04:25:25 2025 -0400
@@ -2,6 +2,7 @@
 
 use crate::constants::{Flags, Result};
 use crate::conv::Conversation;
+use crate::environ::{EnvironMap, EnvironMapMut};
 use crate::logging::Level;
 
 macro_rules! trait_item {
@@ -69,7 +70,7 @@
     /// ```no_run
     /// # use nonstick::{PamShared};
     /// # use nonstick::logging::Level;
-    /// # let pam_hdl: Box<dyn PamShared> = unimplemented!();
+    /// # 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.
@@ -79,6 +80,7 @@
     /// 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);
 
@@ -113,6 +115,12 @@
     /// [mwg]: https://www.chiark.greenend.org.uk/doc/libpam-doc/html/mwg-expected-by-module-item.html#mwg-pam_get_user
     fn username(&mut self, prompt: Option<&str>) -> Result<String>;
 
+    /// The contents of the environment to set, read-only.
+    fn environ(&self) -> impl EnvironMap;
+
+    /// A writable version of the environment.
+    fn environ_mut(&mut self) -> impl EnvironMapMut;
+
     trait_item!(
         /// The identity of the user for whom service is being requested.
         ///
@@ -250,10 +258,10 @@
 pub trait PamHandleApplication: PamShared {
     /// Starts the authentication process for the user.
     fn authenticate(&mut self, flags: Flags) -> Result<()>;
-    
+
     /// Does "account management".
     fn account_management(&mut self, flags: Flags) -> Result<()>;
-    
+
     /// Changes the authentication token.
     fn change_authtok(&mut self, flags: Flags) -> Result<()>;
 }