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
This commit is contained in:
finga 2020-07-07 17:34:09 +02:00
parent 7b0e4b4a31
commit 592fed030d

View file

@ -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<FlashMessage>) -> Template {
#[post("/reset", data = "<email>")]
fn reset_email(
config: State<Ldap0rConfig>,
remote_address: SocketAddr,
keys: State<Keys>,
email: Form<EmailForm>,
) -> Flash<Redirect> {
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<Keys>, key: String, flash: Option<FlashMessage>) -> Opt
#[post("/reset/<key>", data = "<passwords>")]
fn reset_password(
config: State<Ldap0rConfig>,
remote_address: SocketAddr,
keys: State<Keys>,
key: String,
passwords: Form<PasswordsForm>,
@ -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",