view src/pam_ffi.rs @ 68:e4e7d68234d0 default tip

Added tag v0.0.6 for changeset 71e432a213ee
author Paul Fisher <paul@pfish.zone>
date Tue, 27 May 2025 16:40:49 -0400
parents a674799a5cd3
children
line wrap: on
line source

//! FFI to the PAM library.

use libc::c_char;
use std::ffi::c_int;
use std::marker::{PhantomData, PhantomPinned};

/// An opaque pointer given to us by PAM.
#[repr(C)]
pub struct Handle {
    _data: (),
    _marker: PhantomData<(*mut u8, PhantomPinned)>,
}

#[link(name = "pam")]
extern "C" {
    pub fn pam_get_data(
        pamh: *const Handle,
        module_data_name: *const c_char,
        data: &mut *const libc::c_void,
    ) -> c_int;

    pub fn pam_set_data(
        pamh: *mut Handle,
        module_data_name: *const c_char,
        data: *const libc::c_void,
        cleanup: extern "C" fn(
            pamh: *const libc::c_void,
            data: *mut libc::c_void,
            error_status: c_int,
        ),
    ) -> c_int;

    pub fn pam_get_item(
        pamh: *const Handle,
        item_type: c_int,
        item: &mut *const libc::c_void,
    ) -> c_int;

    pub fn pam_set_item(pamh: *mut Handle, item_type: c_int, item: *const libc::c_void) -> c_int;

    pub fn pam_get_user(
        pamh: *const Handle,
        user: &mut *const c_char,
        prompt: *const c_char,
    ) -> c_int;

    pub fn pam_get_authtok(
        pamh: *const Handle,
        item_type: c_int,
        data: &mut *const c_char,
        prompt: *const c_char,
    ) -> c_int;

    pub fn pam_end(pamh: *mut Handle, status: c_int) -> c_int;
}