summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTomasz Kramkowski <tomasz@kramkow.ski>2023-01-29 16:55:04 +0000
committerTomasz Kramkowski <tomasz@kramkow.ski>2023-01-29 16:55:04 +0000
commit63aab7ac772622173f38309cc9ed5b0cd11ea58f (patch)
tree28870a03ec7d095a5d08a31147e4777ae6eb3d36 /src
parentf21ec84115a24b1e9a96a6f21c7b3186748b664e (diff)
downloadpam_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.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
+}