diff --git a/src/bin/laurel/main.rs b/src/bin/laurel/main.rs index ac76a62..a1a5632 100644 --- a/src/bin/laurel/main.rs +++ b/src/bin/laurel/main.rs @@ -113,11 +113,8 @@ impl Logger { filename.push(p); let mut rot = FileRotate::new(filename); for user in &def.clone().users.unwrap_or_default() { - rot = rot.with_uid( - User::from_name(user)? - .ok_or_else(|| anyhow!("user {user} not found"))? - .uid, - ); + _ = User::from_name(user)?.ok_or_else(|| anyhow!("user {user} not found"))?; + rot = rot.with_user(user); } if let Some(generations) = &def.generations { rot = rot.with_generations(*generations); @@ -243,11 +240,8 @@ fn run_app() -> Result<(), anyhow::Error> { filename.push(&def.file); let mut rot = FileRotate::new(filename); for user in &def.clone().users.unwrap_or_default() { - rot = rot.with_uid( - User::from_name(user)? - .ok_or_else(|| anyhow!("user {user} not found"))? - .uid, - ); + _ = User::from_name(user)?.ok_or_else(|| anyhow!("user {user} not found"))?; + rot = rot.with_user(user); } if let Some(generations) = &def.generations { rot = rot.with_generations(*generations); @@ -297,9 +291,15 @@ fn run_app() -> Result<(), anyhow::Error> { Logger::new(&config.filterlog, &dir).context("can't create filterlog logger")?; emit_fn_log = move |e: &Event| { if e.filter { - filter_logger.log(e).expect("Error writing to filter log"); + filter_logger + .log(e) + .map_err(|e| anyhow!("Error writing to filter log: {e}")) + .unwrap(); } else { - logger.log(e).expect("Error writing to audit log"); + logger + .log(e) + .map_err(|e| anyhow!("Error writing to audit log: {e}")) + .unwrap(); } }; coalesce = Coalesce::new(emit_fn_log); @@ -307,7 +307,10 @@ fn run_app() -> Result<(), anyhow::Error> { log::info!("Dropping filtered audit records"); emit_fn_drop = move |e: &Event| { if !e.filter { - logger.log(e).expect("Error writing to audit log"); + logger + .log(e) + .map_err(|e| anyhow!("Error writing to audit log: {e}")) + .unwrap(); } }; coalesce = Coalesce::new(emit_fn_drop); diff --git a/src/rotate.rs b/src/rotate.rs index 1614393..2347eb2 100644 --- a/src/rotate.rs +++ b/src/rotate.rs @@ -7,7 +7,6 @@ use std::os::unix::io::AsRawFd; use exacl::{setfacl, AclEntry, Perm}; use nix::sys::stat::{fchmod, Mode}; -use nix::unistd::Uid; /// A rotating (log) file writer /// @@ -22,7 +21,7 @@ pub struct FileRotate { /// size, a [`FileRotate::rotate`] operation is triggered. pub filesize: u64, pub generations: u64, - pub uids: Vec, + pub users: Vec, file: Option, offset: u64, } @@ -36,7 +35,7 @@ impl FileRotate { basename: OsString::from(path.as_ref()), filesize: 0, generations: 0, - uids: vec![], + users: vec![], file: None, offset: 0, } @@ -50,8 +49,8 @@ impl FileRotate { self.generations = p; self } - pub fn with_uid(mut self, uid: Uid) -> Self { - self.uids.push(uid); + pub fn with_user(mut self, user: &str) -> Self { + self.users.push(user.into()); self } @@ -86,8 +85,8 @@ impl FileRotate { #[cfg(any(target_os = "linux", target_os = "freebsd"))] AclEntry::allow_other(Perm::empty(), None), ]; - for uid in &self.uids { - acl.push(AclEntry::allow_user(&format!("{uid}"), Perm::READ, None)); + for user in &self.users { + acl.push(AclEntry::allow_user(user, Perm::READ, None)); } if let Ok(mut f) = OpenOptions::new().append(true).open(&self.basename) {