From 592fed030d5bfe030aa5c6f8198598be964421b0 Mon Sep 17 00:00:00 2001 From: finga Date: Tue, 7 Jul 2020 17:34:09 +0200 Subject: [PATCH] Print remote address in Errors In order to be able to filter in IDS/IPS the source address is now printed in the logs when an error occurs --- src/main.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index abfc45e..5f5fd23 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,9 +4,10 @@ extern crate rocket; use std::collections::{HashMap, HashSet}; +use std::net::SocketAddr; use std::sync::{Arc, Mutex}; -use anyhow::{anyhow, Result}; +use anyhow::{anyhow, bail, Result}; use ldap3::{ controls::{MakeCritical, RelaxRules}, LdapConn, Mod, Scope, SearchEntry, @@ -89,16 +90,16 @@ fn reset_prepare(config: &Ldap0rConfig, keys: &Keys, email_address: &str) -> Res if result.is_ok() { info!("Password reset email was sent to '{}'", email_address); } else { - error!( + bail!( "Sending password reset email with reset URL to '{}' failed", email_address ); } } else { - error!("Could not aquire lock for keys"); + bail!("Could not aquire lock for keys"); }; } else { - error!("Invalid password reset request for '{}'", email_address); + bail!("Invalid password reset request for '{}'", email_address); } Ok(()) @@ -117,7 +118,8 @@ fn set_password( if let Ok(mut keys) = keys.lock() { let email = keys .get(key) - .ok_or_else(|| anyhow!("Could not extract email"))?.to_string(); + .ok_or_else(|| anyhow!("Could not extract email"))? + .to_string(); // ldap lookup let mut ldap = LdapConn::new(&config.ldap.server)?; @@ -215,11 +217,12 @@ fn reset(flash: Option) -> Template { #[post("/reset", data = "")] fn reset_email( config: State, + remote_address: SocketAddr, keys: State, email: Form, ) -> Flash { if let Err(e) = reset_prepare(&config, &keys, &email.email) { - error!("{}", e); + error!("{} from {}", e, remote_address); } Flash::success( @@ -254,6 +257,7 @@ fn reset_key(keys: State, key: String, flash: Option) -> Opt #[post("/reset/", data = "")] fn reset_password( config: State, + remote_address: SocketAddr, keys: State, key: String, passwords: Form, @@ -261,7 +265,7 @@ fn reset_password( match set_password(&config, &keys, &key, &passwords) { Ok(flash) => flash, Err(e) => { - error!("{}", e); + error!("{} from {}", e, remote_address); Flash::error( Redirect::to(uri!(reset_key: key)), "Setting new password failed",