chore: import MCTF services

- Added all seven issued service trees without omissions.
- Preserved the supplied runtime configuration, binaries, and assets.
This commit is contained in:
TakuyaYagam1 committed 2026-11-29 12:25:29 +03:00
commit 13f936bee9
1222 files changed
+21280

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
[package]
name = "pam_pamsave_authz"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib"]
[dependencies]
libc = "0.2"
+72
View File
@@ -0,0 +1,72 @@
use std::ffi::CStr;
use std::fs;
use libc::{c_char, c_int};
const DEFAULT_MEMBERSHIPS_PATH: &str = "/etc/pamsave/memberships";
#[no_mangle]
pub unsafe extern "C" fn pamsave_authz_check(
user: *const c_char,
workspace: *const c_char,
file: *const c_char,
) -> c_int {
let Ok(user) = CStr::from_ptr(user).to_str() else {
return 0;
};
let Ok(workspace) = CStr::from_ptr(workspace).to_str() else {
return 0;
};
let file = (!file.is_null())
.then(|| CStr::from_ptr(file).to_str().ok())
.flatten();
match check(user, workspace, file) {
true => 1,
false => 0,
}
}
fn check(user: &str, workspace: &str, file: Option<&str>) -> bool {
match fs::read_to_string(memberships_path()) {
Ok(content) => content_allows(&content, user, workspace, file),
Err(_) => false,
}
}
fn content_allows(content: &str, user: &str, workspace: &str, file: Option<&str>) -> bool {
content.lines().any(|line| {
let mut fields = line.split(':');
let Some(member) = fields.next() else {
return false;
};
let Some(member_workspace) = fields.next() else {
return false;
};
let granted_file = fields.next();
if fields.next().is_some() {
return false;
}
if member != user || member_workspace != workspace {
return false;
}
match (file, granted_file) {
(None, None) => true,
(Some(_), None) => true,
(Some(wanted), Some(granted)) => granted == wanted,
(None, Some(_)) => false,
}
})
}
fn memberships_path() -> String {
std::env::var("PAMSAVE_MEMBERSHIPS_PATH").unwrap_or_else(|_| DEFAULT_MEMBERSHIPS_PATH.into())
}