changeset 137:88627c057709 default tip

Add Sun PAM functions from Illumos headers.
author Paul Fisher <paul@pfish.zone>
date Thu, 03 Jul 2025 17:33:13 -0400
parents efbc235f01d3
children
files libpam-sys/libpam-sys-helpers/src/constants.rs libpam-sys/libpam-sys-test/build.rs libpam-sys/libpam-sys-test/illumos_pam_impl.h libpam-sys/libpam-sys-test/tests/runner.rs libpam-sys/src/lib.rs
diffstat 5 files changed, 71 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/libpam-sys/libpam-sys-helpers/src/constants.rs	Thu Jul 03 14:28:04 2025 -0400
+++ b/libpam-sys/libpam-sys-helpers/src/constants.rs	Thu Jul 03 17:33:13 2025 -0400
@@ -295,4 +295,10 @@
 
     /// A flag for `pam_chauthtok`.
     pub const PAM_NO_AUTHTOK_CHECK: i32 = 0b1000;
+
+    define!(
+        /// A flag for `__pam_get_authtok`.
+        PAM_PROMPT = 1;
+        PAM_HANDLE = 2;
+    );
 }
--- a/libpam-sys/libpam-sys-test/build.rs	Thu Jul 03 14:28:04 2025 -0400
+++ b/libpam-sys/libpam-sys-test/build.rs	Thu Jul 03 17:33:13 2025 -0400
@@ -41,7 +41,11 @@
             ..Default::default()
         },
         PamImpl::Sun => TestConfig {
-            headers: vec!["<security/pam_appl.h>", "<security/pam_modules.h>"],
+            headers: vec![
+                "<security/pam_appl.h>",
+                "<security/pam_modules.h>",
+                "\"illumos_pam_impl.h\"",
+            ],
             ..Default::default()
         },
         PamImpl::XSso => TestConfig {
@@ -69,15 +73,9 @@
     let generated = builder.generate().unwrap();
     generated.write_to_file(test_file("bindgen.rs")).unwrap();
     let file = syn::parse_file(&generated.to_string()).unwrap();
-    let mut tests = vec!["\
-            #[allow(dead_code, non_camel_case_types, non_upper_case_globals)]
-            mod generated {
-                include!(\"bindgen.rs\");
-            }
-            #[allow(deprecated, overflowing_literals)]
-            fn main() {
-        "
-        .into(),
+    let mut tests = vec![
+        "#[allow(deprecated, overflowing_literals)]".into(),
+        "fn main() {".into(),
         format!(
             "assert_eq!(libpam_sys::pam_impl::PamImpl::CURRENT, libpam_sys::pam_impl::PamImpl::{:?});",
             PamImpl::CURRENT
@@ -134,6 +132,13 @@
             (other, false) => other.into(),
         }
     });
+    test.field_name(|_, name| {
+        match name {
+            "type_" => "type",
+            other => other,
+        }
+        .into()
+    });
 
     //
     // Welcome to THE HACK ZONE.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libpam-sys/libpam-sys-test/illumos_pam_impl.h	Thu Jul 03 17:33:13 2025 -0400
@@ -0,0 +1,21 @@
+/*
+ * Semi-public functions exposed in Sun's `libpam.so`.
+ * https://code.illumos.org/plugins/gitiles/illumos-gate/+/f3a1073761f959966ab629695ee17f4417413796/usr/src/lib/libpam/pam_impl.h
+ */
+
+#define PAM_PROMPT 1
+#define PAM_HANDLE 2
+
+extern int __pam_get_authtok(
+    pam_handle_t *pamh,
+    int source,
+    int type,
+    char *prompt,
+    char **authtok
+);
+
+extern void __pam_log(
+    int priority,
+    const char *format,
+    ...
+);
\ No newline at end of file
--- a/libpam-sys/libpam-sys-test/tests/runner.rs	Thu Jul 03 14:28:04 2025 -0400
+++ b/libpam-sys/libpam-sys-test/tests/runner.rs	Thu Jul 03 17:33:13 2025 -0400
@@ -1,7 +1,18 @@
 #![allow(unused_imports)]
 
+macro_rules! include_test {
+    ($file:literal) => {
+        include!(concat!(env!("OUT_DIR"), "/", $file));
+    };
+}
+
 mod constants {
-    include!(concat!(env!("OUT_DIR"), "/constant_test.rs"));
+    #[allow(dead_code, non_camel_case_types, non_upper_case_globals)]
+    mod generated {
+        include_test!("bindgen.rs");
+    }
+
+    include_test!("constant_test.rs");
 
     #[test]
     fn test_constants() {
@@ -13,7 +24,7 @@
 mod ctest {
     use libc::*;
     use libpam_sys::*;
-    include!(concat!(env!("OUT_DIR"), "/ctest.rs"));
+    include_test!("ctest.rs");
 
     #[test]
     fn test_c() {
--- a/libpam-sys/src/lib.rs	Thu Jul 03 14:28:04 2025 -0400
+++ b/libpam-sys/src/lib.rs	Thu Jul 03 17:33:13 2025 -0400
@@ -170,11 +170,11 @@
     pub dlh: *mut c_void,
 }
 
-#[cfg(pam_impl = "OpenPam")]
+#[cfg(any(pam_impl = "OpenPam", pam_impl = "Sun"))]
 #[derive(Debug)]
 #[repr(C)]
 pub struct pam_repository {
-    pub typ: *mut c_char,
+    pub type_: *mut c_char,
     pub scope: *mut c_void,
     pub scope_len: usize,
 }
@@ -376,7 +376,7 @@
 
     pub fn pam_modutil_audit_write(
         pamh: *mut pam_handle,
-        typ: c_int,
+        type_: c_int,
         message: *const c_char,
         retval: c_int,
     ) -> c_int;
@@ -513,3 +513,16 @@
         _data: *mut AppData,
     ) -> c_int;
 }
+
+#[cfg(pam_impl = "Sun")]
+extern "C" {
+    pub fn __pam_get_authtok(
+        pamh: *mut pam_handle,
+        source: c_int,
+        type_: c_int,
+        prompt: *const c_char,
+        authtok: *mut *mut c_char,
+    ) -> c_int;
+
+    pub fn __pam_log(priority: c_int, format: *const c_char, ...);
+}