summaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs38
1 files changed, 22 insertions, 16 deletions
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
+}