From 1de0fa16dbce18710721e5d0b110c68eb62d4dc8 Mon Sep 17 00:00:00 2001 From: Barry Pederson Date: Tue, 3 Feb 2026 15:57:11 -0800 Subject: [PATCH] Add some logging so that with the env variable RUST_LOG=debug or similar, there is timestamped output to stderr --- Cargo.lock | 134 +++++++++++++++++++++++++++++++++++++++ server/Cargo.toml | 2 + server/src/handler.rs | 11 ++-- server/src/main.rs | 2 + server/src/repository.rs | 4 ++ server/src/server.rs | 3 +- 6 files changed, 151 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 582d11c..6f641d4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] + [[package]] name = "anstream" version = "0.6.21" @@ -176,6 +185,29 @@ dependencies = [ "subtle", ] +[[package]] +name = "env_filter" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bf3c259d255ca70051b30e2e95b5446cdb8949ac4cd22c0d7fd634d89f568e2" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c863f0904021b108aa8b2f55046443e6b1ebde8fd4a15c399893aae4fa069f" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "jiff", + "log", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -198,12 +230,48 @@ version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" +[[package]] +name = "jiff" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e67e8da4c49d6d9909fe03361f9b620f58898859f5c7aded68351e85e71ecf50" +dependencies = [ + "jiff-static", + "log", + "portable-atomic", + "portable-atomic-util", + "serde_core", +] + +[[package]] +name = "jiff-static" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0c84ee7f197eca9a86c6fd6cb771e55eb991632f15f2bc3ca6ec838929e6e78" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "libc" version = "0.2.180" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] +name = "memchr" +version = "2.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" + [[package]] name = "once_cell_polyfill" version = "1.70.2" @@ -221,6 +289,21 @@ dependencies = [ "subtle", ] +[[package]] +name = "portable-atomic" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49" + +[[package]] +name = "portable-atomic-util" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a9db96d7fa8782dd8c15ce32ffe8680bbd1e978a43bf51a34d39483540495f5" +dependencies = [ + "portable-atomic", +] + [[package]] name = "proc-macro2" version = "1.0.106" @@ -245,6 +328,55 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +[[package]] +name = "regex" +version = "1.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a96887878f22d7bad8a3b6dc5b7440e0ada9a245242924394987b21cf2210a4c" + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "server" version = "0.3.1" @@ -252,6 +384,8 @@ dependencies = [ "argon2", "clap", "common", + "env_logger", + "log", ] [[package]] diff --git a/server/Cargo.toml b/server/Cargo.toml index 2c87cc8..e85aa48 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -7,6 +7,8 @@ edition.workspace = true clap = { workspace = true } common = { workspace = true } argon2 = "0.5.3" +env_logger = "0.11.8" +log = "0.4.29" [[bin]] name = "saslauthd" diff --git a/server/src/handler.rs b/server/src/handler.rs index 9181e77..da16c50 100644 --- a/server/src/handler.rs +++ b/server/src/handler.rs @@ -1,5 +1,6 @@ use crate::repository::PasswordDirectory; use common::request::Request; +use log::{error, info}; use std::io::{Error, Read, Write}; pub const RESPONSE_NO: [u8; 4] = [0x0, 0x2, b'N', b'O']; @@ -18,19 +19,21 @@ impl Handler { fn communicate(&mut self) -> Result<(), Error> { let request = Request::from_stream(&mut self.stream)?; - println!("userid: {}", request.userid); if self.repository.check_auth(&request) { - self.stream.write_all(&RESPONSE_OK)? + self.stream.write_all(&RESPONSE_OK)?; + info!("userid: {}, service: {}, realm: {} - OK", request.userid, request.service, request.realm); } else { - self.stream.write_all(&RESPONSE_NO)? + self.stream.write_all(&RESPONSE_NO)?; + info!("userid: {}, service: {}, realm: {} - FAIL", request.userid, request.service, request.realm); } + Ok(()) } pub fn handle_client(&mut self) { if let Err(error) = self.communicate() { - eprint!("{error}"); + error!("{error}"); } } } diff --git a/server/src/main.rs b/server/src/main.rs index 414957c..39f45be 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -8,6 +8,8 @@ use crate::repository::PasswordDirectory; use crate::server::Server; fn main() -> std::io::Result<()> { + env_logger::init(); + let repository = PasswordDirectory::new(&OPTIONS.password_dir); let mut server = Server::new(&OPTIONS.socket_name, repository)?; server.run() diff --git a/server/src/repository.rs b/server/src/repository.rs index 532394d..3bf680a 100644 --- a/server/src/repository.rs +++ b/server/src/repository.rs @@ -8,6 +8,7 @@ use argon2::{ use std::fs::File; use std::io::{BufRead, BufReader}; use std::path::PathBuf; +use log::info; #[derive(Clone)] pub struct PasswordDirectory { @@ -49,6 +50,7 @@ impl PasswordDirectory { /// fn check_hashed_password(&self, lines: &Vec, password: &str) -> bool { let (key, split_password) = password.strip_prefix('[').unwrap().split_once(']').unwrap(); + info!(" looking for password-key: [{}]", key); let mut result = false; @@ -72,6 +74,8 @@ impl PasswordDirectory { } fn check_plain_password(&self, lines: &Vec, password: &str) -> bool { + info!(" looking for plain password"); + let mut result = false; for line in lines { diff --git a/server/src/server.rs b/server/src/server.rs index b937b24..cc7a2e0 100644 --- a/server/src/server.rs +++ b/server/src/server.rs @@ -6,6 +6,7 @@ use std::os::unix::fs::PermissionsExt; use std::os::unix::net::UnixListener; use std::path::PathBuf; use std::thread; +use log::info; pub struct Server { listener: UnixListener, @@ -56,6 +57,6 @@ impl Server { impl Drop for Server { fn drop(&mut self) { let _result = std::fs::remove_file(&self.socket_name); - println!("Shutting down"); + info!("Shutting down"); } }