check if SENDMAIL_COMMAND is valid using 'which' crate

This commit is contained in:
soruh 2023-01-25 22:54:50 +01:00
parent b7c4316c77
commit 8cc6dac893
3 changed files with 36 additions and 20 deletions

12
Cargo.lock generated
View File

@ -3230,6 +3230,7 @@ dependencies = [
"url",
"uuid",
"webauthn-rs",
"which",
"yubico",
]
@ -3396,6 +3397,17 @@ dependencies = [
"untrusted",
]
[[package]]
name = "which"
version = "4.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269"
dependencies = [
"either",
"libc",
"once_cell",
]
[[package]]
name = "widestring"
version = "0.5.1"

View File

@ -151,6 +151,7 @@ semver = "1.0.16"
# Allow overriding the default memory allocator
# Mainly used for the musl builds, since the default musl malloc is very slow
mimalloc = { version = "0.1.34", features = ["secure"], default-features = false, optional = true }
which = "4.4.0"
# Strip debuginfo from the release builds
# Also enable thin LTO for some optimizations

View File

@ -749,11 +749,15 @@ fn validate_config(cfg: &ConfigItems) -> Result<(), Error> {
}
if cfg.use_sendmail {
if let Some(ref command) = cfg.sendmail_command {
let path = std::path::Path::new(&command);
let command = cfg.sendmail_command.as_deref().unwrap_or("sendmail");
let mut path = std::path::PathBuf::from(command);
if !path.is_absolute() {
err!(format!("path to sendmail command `{path:?}` is not absolute"));
match which::which(command) {
Ok(result) => path = result,
Err(_) => err!(format!("sendmail command {command:?} not found in $PATH")),
}
}
match path.metadata() {
@ -777,7 +781,6 @@ fn validate_config(cfg: &ConfigItems) -> Result<(), Error> {
}
}
}
}
} else {
if cfg.smtp_host.is_some() == cfg.smtp_from.is_empty() {
err!("Both `SMTP_HOST` and `SMTP_FROM` need to be set for email support without `USE_SENDMAIL`")