diff src/libpam/handle.rs @ 169:77470e45e397

Set up stuff to work the way Sun expects it to. This sets up PAM to use pam_authtok_get.so on Sun machines.
author Paul Fisher <paul@pfish.zone>
date Tue, 15 Jul 2025 01:32:21 -0400
parents 2f5913131295
children e27c5c667a5a
line wrap: on
line diff
--- a/src/libpam/handle.rs	Tue Jul 15 00:56:01 2025 -0400
+++ b/src/libpam/handle.rs	Tue Jul 15 01:32:21 2025 -0400
@@ -15,7 +15,6 @@
 use std::any::TypeId;
 use std::cell::Cell;
 use std::ffi::{c_char, c_int, c_void, CString, OsStr, OsString};
-use std::mem::ManuallyDrop;
 use std::os::unix::ffi::OsStrExt;
 use std::ptr::NonNull;
 use std::{any, fmt, ptr};
@@ -139,7 +138,7 @@
     pub fn end_silent(self) {
         #[cfg(pam_impl = "LinuxPam")]
         {
-            let mut me = ManuallyDrop::new(self);
+            let mut me = std::mem::ManuallyDrop::new(self);
             me.end_internal(libpam_sys::PAM_DATA_SILENT);
         }
         // If it's not LinuxPam, we just drop normally.
@@ -494,45 +493,8 @@
     }
 
     #[cfg(pam_impl = "Sun")]
-    fn get_authtok(&mut self, prompt: Option<&OsStr>, item_type: ItemType) -> Result<OsString> {
-        use crate::libpam::memory::CHeapString;
-        use std::os::unix::ffi::OsStringExt;
-        // Sun's __pam_get_authtok function is a little weird and requires
-        // that you specify where you want the authtok to come from.
-        // First we see if there's an authtok already set.
-        let mut output: *mut c_char = ptr::null_mut();
-        let result = unsafe {
-            libpam_sys::__pam_get_authtok(
-                self.inner_mut(),
-                libpam_sys::PAM_HANDLE,
-                item_type.into(),
-                ptr::null(),
-                &mut output,
-            )
-        };
-        let output = unsafe { CHeapString::from_ptr(output) };
-        if result == libpam_sys::PAM_SUCCESS {
-            if let Some(output) = output {
-                return Ok(OsString::from_vec(output.to_bytes().into()));
-            }
-        }
-        drop(output);
-        let mut output: *mut c_char = ptr::null_mut();
-        let prompt = memory::option_cstr_os(prompt);
-        let result = unsafe {
-            libpam_sys::__pam_get_authtok(
-                self.inner_mut(),
-                libpam_sys::PAM_PROMPT,
-                item_type.into(),
-                memory::prompt_ptr(prompt.as_deref()),
-                &mut output,
-            )
-        };
-        let output = unsafe { CHeapString::from_ptr(output) };
-        ErrorCode::result_from(result)?;
-        output
-            .map(|s| OsString::from_vec(s.to_bytes().into()))
-            .ok_or(ErrorCode::ConversationError)
+    fn get_authtok(&mut self, _prompt: Option<&OsStr>, item_type: ItemType) -> Result<OsString> {
+        unsafe { items::get_cstr_item(self, item_type) }?.ok_or(ErrorCode::ConversationError)
     }
 
     /// Gets the `PAM_CONV` item from the handle.