summaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs34
1 files changed, 30 insertions, 4 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 3ffbb69..42a9c1b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -3,14 +3,16 @@
mod pam;
mod passwd;
+mod syslog;
use cap_std::fs::{Dir, OpenOptions};
use pam::PAMHandle;
-use std::ffi::{c_char, c_int, CStr};
+use std::ffi::{c_char, c_int, CStr, CString};
use std::io::{ErrorKind, Write};
use std::panic;
use std::path::Path;
use std::process;
+use syslog::{Facility, Level, Priority};
fn create_and_open_dir<P: AsRef<Path> + ?Sized>(
d: &Dir,
@@ -32,10 +34,34 @@ impl From<std::io::Error> for SessionError {
}
}
+const PRIORITY: Priority = Priority {
+ level: Level::Debug,
+ facility: Facility::Auth,
+};
+
fn open_session(h: &PAMHandle, mountpoint: &str) -> Result<(), SessionError> {
- let user = h.get_user::<CStr>(None).or(Err(SessionError))?;
- let uid = passwd::get_uid_by_name(&user).ok_or(SessionError)?;
- let uid = uid.to_string();
+ let user = match h.get_user::<CStr>(None) {
+ Ok(user) => user,
+ Err(e) => {
+ if let Ok(message) =
+ CString::new(format!("Failure to get username: {e}"))
+ {
+ h.syslog(PRIORITY, &message);
+ }
+ return Err(SessionError);
+ }
+ };
+ let uid = match passwd::get_uid_by_name(&user) {
+ Some(uid) => uid.to_string(),
+ None => {
+ if let Ok(message) =
+ CString::new(format!("Failure to map user {user:?} to passwd entry"))
+ {
+ h.syslog(PRIORITY, &message);
+ }
+ return Err(SessionError);
+ }
+ };
let d = Dir::open_ambient_dir(mountpoint, cap_std::ambient_authority())?;
let d = create_and_open_dir(&d, "user")?;
let d = create_and_open_dir(&d, &uid)?;