Skip to content

Commit

Permalink
Merge pull request #323 from squidowl/fix/trim-password-file
Browse files Browse the repository at this point in the history
Trim password files to remove leading / trailing whitespace
  • Loading branch information
tarkah committed Apr 5, 2024
2 parents cc8e287 + cb59469 commit 59d2ee4
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions data/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<proto::Message>;

Expand Down Expand Up @@ -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 {
Expand All @@ -85,7 +91,7 @@ impl Map {
..
} => {
let pass = fs::read_to_string(pass_file)?;
*password = Some(pass);
*password = Some(trimmed(pass));
}
_ => {}
}
Expand Down

0 comments on commit 59d2ee4

Please sign in to comment.