diff src/handle.rs @ 141:a508a69c068a

Remove a lot of Results from functions. Many functions are documented to only return failing Results when given improper inputs or when there is a memory allocation failure (which can be verified by looking at the source). In cases where we know our input is correct, we don't need to check for memory allocation errors for the same reason that Rust doesn't do so when you, e.g., create a new Vec.
author Paul Fisher <paul@pfish.zone>
date Sat, 05 Jul 2025 17:16:56 -0400
parents a12706e42c9d
children ebb71a412b58
line wrap: on
line diff
--- a/src/handle.rs	Sat Jul 05 17:11:33 2025 -0400
+++ b/src/handle.rs	Sat Jul 05 17:16:56 2025 -0400
@@ -317,8 +317,7 @@
     /// Retrieves the authentication token from the user.
     ///
     /// This should only be used by *authentication* and *password-change*
-    /// PAM modules. This is an extension provided by
-    /// both Linux-PAM and OpenPAM.
+    /// PAM modules.
     ///
     /// # References
     ///
@@ -340,6 +339,11 @@
     #[doc = manbsd!(3 pam_get_authtok)]
     fn authtok(&mut self, prompt: Option<&str>) -> Result<String>;
 
+    /// Retrieves the user's old authentication token when changing passwords.
+    ///
+    ///
+    fn old_authtok(&mut self, prompt: Option<&str>) -> Result<String>;
+
     trait_item!(
         /// Gets the user's authentication token (e.g., password).
         ///
@@ -356,44 +360,12 @@
     trait_item!(
         /// Gets the user's old authentication token when changing passwords.
         ///
+        /// This is normally set automatically by PAM when calling
+        /// [`old_authtok`](Self::old_authtok), but can be set explicitly.
+        ///
         /// This should only ever be called by *password-change* PAM modules.
         get = old_authtok_item,
         item = "PAM_OLDAUTHTOK",
         see = PamShared::set_old_authtok_item
     );
-
-    /*
-    TODO: Re-enable this at some point.
-        /// Gets some pointer, identified by `key`, that has been set previously
-        /// using [`set_data`](Self::set_data).
-        ///
-        /// The data, if present, is still owned by the current PAM session.
-        ///
-        /// See the [`pam_get_data` manual page][man]
-        /// or [`pam_get_data` in the Module Writer's Guide][mwg].
-        ///
-        /// # Safety
-        ///
-        /// The data stored under the provided key must be of type `T`,
-        /// otherwise you'll get back a completely invalid `&T`
-        /// and further behavior is undefined.
-        ///
-        /// [man]: https://www.man7.org/linux/man-pages/man3/pam_get_data.3.html
-        /// [mwg]: https://www.chiark.greenend.org.uk/doc/libpam-doc/html/mwg-expected-by-module-item.html#mwg-pam_get_data
-        unsafe fn get_data<T>(&mut self, key: &str) -> Result<Option<&T>>;
-
-        /// Stores a pointer that can be retrieved later with [`get_data`](Self::get_data).
-        ///
-        /// This data is accessible to this module and other PAM modules
-        /// (using the provided `key`), but is *not* accessible to the application.
-        /// The PAM session takes ownership of the data, and it will be dropped
-        /// when the session ends.
-        ///
-        /// See the [`pam_set_data` manual page][man]
-        /// or [`pam_set_data` in the Module Writer's Guide][mwg].
-        ///
-        /// [man]: https://www.man7.org/linux/man-pages/man3/pam_set_data.3.html
-        /// [mwg]: https://www.chiark.greenend.org.uk/doc/libpam-doc/html/mwg-expected-by-module-item.html#mwg-pam_set_data
-        fn set_data<T>(&mut self, key: &str, data: Box<T>) -> Result<()>;
-     */
 }