Add some logging so that with the env variable RUST_LOG=debug or similar, there is timestamped output to stderr

This commit is contained in:
Barry Pederson
2026-02-03 15:57:11 -08:00
parent 83d437c9ce
commit 1de0fa16db
6 changed files with 151 additions and 5 deletions
Generated
+134
View File
@@ -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]]
+2
View File
@@ -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"
+7 -4
View File
@@ -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<S: Read + Write> Handler<S> {
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}");
}
}
}
+2
View File
@@ -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()
+4
View File
@@ -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<String>, 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<String>, password: &str) -> bool {
info!(" looking for plain password");
let mut result = false;
for line in lines {
+2 -1
View File
@@ -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");
}
}