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:
@@ -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"
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user