debug test

This commit is contained in:
2026-03-17 16:35:15 +11:00
parent bdbd94eda2
commit 793a643731
2 changed files with 35 additions and 6 deletions

View File

@@ -9,6 +9,20 @@ use std::os::raw::c_char;
use std::panic::{catch_unwind, AssertUnwindSafe};
use std::env;
// Formatting macros for crate-local logging.
// Define these in the crate root so any module can invoke them as `crate::log!(...)`.
macro_rules! pam_log_with_level {
($level:expr, $($arg:tt)+) => {
crate::logging::log_event_with_level($level, &format!($($arg)+));
};
}
macro_rules! pam_log {
($($arg:tt)+) => {
crate::logging::log_event_with_level(crate::logging::LogLevel::Info, &format!($($arg)+));
};
}
mod auth;
mod logging;
mod error;
@@ -42,7 +56,7 @@ pub extern "C" fn rust_log_event(event: *const c_char) {
CStr::from_ptr(event).to_str().unwrap_or("")
};
// Legacy wrapper: default to INFO
logging::log_event_with_level(logging::LogLevel::Info, msg);
pam_log_with_level!(logging::LogLevel::Info, "{}", msg);
}));
}
@@ -56,25 +70,29 @@ pub extern "C" fn rust_log_event_with_level(event: *const c_char, level: i32) {
CStr::from_ptr(event).to_str().unwrap_or("")
};
let lvl = logging::LogLevel::from(level);
logging::log_event_with_level(lvl, msg);
pam_log_with_level!(lvl, "{}", msg);
}));
}
#[no_mangle]
pub extern "C" fn rust_auth_user(user: *const c_char, password: *const c_char) -> i32 {
catch_unwind(AssertUnwindSafe(|| {
let u = unsafe {
if user.is_null() {
pam_log_with_level!(logging::LogLevel::Error, "Null pointer for username"); // Log error
return error::ERR_INVALID_INPUT;
}
CStr::from_ptr(user).to_str().unwrap_or("")
};
let p = unsafe {
if password.is_null() {
pam_log_with_level!(logging::LogLevel::Error, "Null pointer for password"); // Log error
return error::ERR_INVALID_INPUT;
}
CStr::from_ptr(password).to_str().unwrap_or("")
};
match auth::authenticate(u, p) {
Ok(_) => error::SUCCESS,
Err(_) => error::ERR_AUTH_FAILED,