From cb59469b414ac521b2cbf60776a8c8363864f950 Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Fri, 5 Apr 2024 08:34:50 -0700 Subject: [PATCH] Trim password files to remove leading / trailing whitespace --- data/src/server.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/data/src/server.rs b/data/src/server.rs index 6307ee9b..b993ebd8 100644 --- a/data/src/server.rs +++ b/data/src/server.rs @@ -7,8 +7,8 @@ use irc::proto; use serde::{Deserialize, Serialize}; use crate::config; -use crate::config::Error; use crate::config::server::Sasl; +use crate::config::Error; pub type Handle = Sender; @@ -55,20 +55,26 @@ impl Map { } pub fn read_password_files(&mut self) -> Result<(), Error> { + let trimmed = |s: String| s.trim().to_string(); + for (_, config) in self.0.iter_mut() { if let Some(pass_file) = &config.password_file { if config.password.is_some() { - return Err(Error::Parse("Only one of password and password_file can be set.".to_string())); + return Err(Error::Parse( + "Only one of password and password_file can be set.".to_string(), + )); } let pass = fs::read_to_string(pass_file)?; - config.password = Some(pass); + config.password = Some(trimmed(pass)); } if let Some(nick_pass_file) = &config.nick_password_file { if config.nick_password.is_some() { - return Err(Error::Parse("Only one of nick_password and nick_password_file can be set.".to_string())); + return Err(Error::Parse( + "Only one of nick_password and nick_password_file can be set.".to_string(), + )); } let nick_pass = fs::read_to_string(nick_pass_file)?; - config.nick_password = Some(nick_pass); + config.nick_password = Some(trimmed(nick_pass)); } if let Some(sasl) = &mut config.sasl { match sasl { @@ -85,7 +91,7 @@ impl Map { .. } => { let pass = fs::read_to_string(pass_file)?; - *password = Some(pass); + *password = Some(trimmed(pass)); } _ => {} }