diff options
author | Tomasz Kramkowski <tomasz@kramkow.ski> | 2023-01-29 16:55:04 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tomasz@kramkow.ski> | 2023-01-29 16:55:04 +0000 |
commit | 63aab7ac772622173f38309cc9ed5b0cd11ea58f (patch) | |
tree | 28870a03ec7d095a5d08a31147e4777ae6eb3d36 /src | |
parent | f21ec84115a24b1e9a96a6f21c7b3186748b664e (diff) | |
download | pam_usercg_rust-63aab7ac772622173f38309cc9ed5b0cd11ea58f.tar.gz pam_usercg_rust-63aab7ac772622173f38309cc9ed5b0cd11ea58f.tar.xz pam_usercg_rust-63aab7ac772622173f38309cc9ed5b0cd11ea58f.zip |
Begin removing pam-bindings dependency
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 38 |
1 files changed, 22 insertions, 16 deletions
@@ -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 +} |