view libpam-sys/src/structs.rs @ 118:39760dfc9b3b

Detect PAM library based only on system lib; rename minimal lib to XSso. Also formats and assorted other cleanup.
author Paul Fisher <paul@pfish.zone>
date Sun, 29 Jun 2025 20:13:03 -0400
parents 20f7712a6857
children 476a22db8639
line wrap: on
line source

use std::ffi::{c_int, c_void};
use std::fmt;
use std::marker::{PhantomData, PhantomPinned};

/// A marker struct to make whatever it's in `!Sync`, `!Send`, and `!Unpin`.
#[derive(Default, PartialOrd, PartialEq, Ord, Eq)]
#[repr(transparent)]
struct ExtremelyUnsafe(PhantomData<(PhantomPinned, *mut c_void)>);

impl fmt::Debug for ExtremelyUnsafe {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str("ExtremelyUnsafe")
    }
}

/// An opaque structure that PAM uses to communicate.
///
/// This is only ever returned in pointer form and cannot be constructed.
#[repr(C)]
pub struct PamHandle {
    _marker: ExtremelyUnsafe,
}

impl fmt::Debug for PamHandle {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "PamHandle({self:p}")
    }
}

/// An opaque structure that is passed through PAM in a conversation.
pub struct AppData {
    _marker: ExtremelyUnsafe,
}

impl fmt::Debug for AppData {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "AppData({self:p}")
    }
}

/// The callback that PAM uses to get information in a conversation.
///
/// For important details about the format of `messages`,
/// see the [`helpers`](crate::helpers) module.
pub type ConversationCallback = unsafe extern "C" fn(
    num_msg: c_int,
    messages: *const *const Message,
    responses: &mut *mut Response,
    appdata: *const AppData,
) -> c_int;

/// Used by PAM to communicate between the module and the application.
#[repr(C)]
pub struct Conversation {
    pub callback: ConversationCallback,
    pub appdata: *const AppData,
}

/// A message sent into a PAM conversation.
#[repr(C)]
pub struct Message {
    pub style: c_int,
    pub data: *const c_void,
}

/// A response returned from a PAM conversation.
#[repr(C)]
pub struct Response {
    pub data: *mut c_void,
    pub _unused: c_int,
}