From 63aab7ac772622173f38309cc9ed5b0cd11ea58f Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Sun, 29 Jan 2023 16:55:04 +0000 Subject: Begin removing pam-bindings dependency --- src/lib.rs | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 3bcc68c..e7b6edc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,9 +2,8 @@ // SPDX-License-Identifier: MIT use cap_std::fs::{Dir, OpenOptions}; -use pam::constants::{PamFlag, PamResultCode}; -use pam::module::{PamHandle, PamHooks}; -use std::ffi::CStr; +use pam::module::PamHandle; +use std::ffi::{c_char, c_int}; use std::io::{ErrorKind, Write}; use std::panic; use std::path::Path; @@ -48,18 +47,25 @@ fn open_session(h: &PamHandle, mountpoint: &str) -> Result<(), SessionError> { const CG_MOUNT: &str = "/sys/fs/cgroup"; -struct PAMUserCG; -pam::pam_hooks!(PAMUserCG); - -impl PamHooks for PAMUserCG { - fn sm_open_session( - h: &mut PamHandle, - _args: Vec<&CStr>, - _flags: PamFlag, - ) -> PamResultCode { - match panic::catch_unwind(|| open_session(h, CG_MOUNT)) { - Ok(Ok(())) => PamResultCode::PAM_SUCCESS, - _ => PamResultCode::PAM_SESSION_ERR, - } +#[no_mangle] +pub extern "C" fn pam_sm_open_session( + h: &mut PamHandle, + _flags: c_int, + _argc: c_int, + _argv: *const *const c_char, +) -> c_int { + match panic::catch_unwind(|| open_session(h, CG_MOUNT)) { + Ok(Ok(())) => 0, + _ => 14, } } + +#[no_mangle] +pub extern "C" fn pam_sm_close_session( + _h: &mut PamHandle, + _flags: c_int, + _argc: c_int, + _argv: *const *const c_char, +) -> c_int { + 0 +} -- cgit v1.2.3-54-g00ecf