diff src/libpam/handle.rs @ 90:f6186e41399b

Miscellaneous fixes and cleanup: - Rename `get_user` to `username` and `get_authtok` to `authtok`. - Use pam_strerror for error messages. - Add library linkage to build.rs (it was missing???).
author Paul Fisher <paul@pfish.zone>
date Sat, 14 Jun 2025 09:30:16 -0400
parents 5aa1a010f1e8
children 5ddbcada30f2
line wrap: on
line diff
--- a/src/libpam/handle.rs	Fri Jun 13 05:22:48 2025 -0400
+++ b/src/libpam/handle.rs	Sat Jun 14 09:30:16 2025 -0400
@@ -8,6 +8,7 @@
 use num_enum::{IntoPrimitive, TryFromPrimitive};
 use std::cell::Cell;
 use std::ffi::{c_char, c_int};
+use std::marker::PhantomData;
 use std::ops::{Deref, DerefMut};
 use std::ptr;
 
@@ -27,9 +28,10 @@
 }
 
 /// An owned PAM handle.
-pub struct OwnedLibPamHandle {
+pub struct OwnedLibPamHandle<'a> {
     handle: HandleWrap,
     last_return: Cell<Result<()>>,
+    _conversation_lifetime: PhantomData<&'a mut ()>,
 }
 
 // TODO: pam_authenticate - app
@@ -42,7 +44,7 @@
 //       pam_getenv - shared
 //       pam_getenvlist - shared
 
-impl Drop for OwnedLibPamHandle {
+impl Drop for OwnedLibPamHandle<'_> {
     /// Closes the PAM session on an owned PAM handle.
     ///
     /// See the [`pam_end` manual page][man] for more information.
@@ -72,7 +74,7 @@
 }
 
 impl PamShared for LibPamHandle {
-    fn get_user(&mut self, prompt: Option<&str>) -> Result<&str> {
+    fn username(&mut self, prompt: Option<&str>) -> Result<&str> {
         let prompt = memory::option_cstr(prompt)?;
         let mut output: *const c_char = ptr::null();
         let ret = unsafe {
@@ -114,7 +116,7 @@
 }
 
 impl PamHandleModule for LibPamHandle {
-    fn get_authtok(&mut self, prompt: Option<&str>) -> Result<&str> {
+    fn authtok(&mut self, prompt: Option<&str>) -> Result<&str> {
         let prompt = memory::option_cstr(prompt)?;
         let mut output: *const c_char = ptr::null_mut();
         // SAFETY: We're calling this with known-good values.
@@ -221,8 +223,8 @@
     result.as_ref().map(drop).map_err(|&e| e)
 }
 
-impl PamShared for OwnedLibPamHandle {
-    delegate!(fn get_user(&mut self, prompt: Option<&str>) -> Result<&str>);
+impl PamShared for OwnedLibPamHandle<'_> {
+    delegate!(fn username(&mut self, prompt: Option<&str>) -> Result<&str>);
     delegate!(get = user_item, set = set_user_item);
     delegate!(get = service, set = set_service);
     delegate!(get = user_prompt, set = set_user_prompt);