diff options
author | soruh <[email protected]> | 2023-01-25 22:54:50 +0100 |
---|---|---|
committer | soruh <[email protected]> | 2023-02-12 18:55:15 +0100 |
commit | 8cc6dac893e3a7630a6be438ac4331f0f7023dad (patch) | |
tree | 106f99b44711ada89df63be2bc059ad24198803e | |
parent | b7c4316c778568d23cdd7e3922e03cf16a3fec18 (diff) | |
download | vaultwarden-8cc6dac893e3a7630a6be438ac4331f0f7023dad.tar.gz vaultwarden-8cc6dac893e3a7630a6be438ac4331f0f7023dad.zip |
check if SENDMAIL_COMMAND is valid using 'which' crate
-rw-r--r-- | Cargo.lock | 12 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/config.rs | 43 |
3 files changed, 36 insertions, 20 deletions
@@ -3230,6 +3230,7 @@ dependencies = [ "url", "uuid", "webauthn-rs", + "which", "yubico", ] @@ -3397,6 +3398,17 @@ dependencies = [ ] [[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" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -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 diff --git a/src/config.rs b/src/config.rs index b7eabd36..e362464b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -749,31 +749,34 @@ 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"); - if !path.is_absolute() { - err!(format!("path to sendmail command `{path:?}` is not absolute")); + let mut path = std::path::PathBuf::from(command); + + if !path.is_absolute() { + match which::which(command) { + Ok(result) => path = result, + Err(_) => err!(format!("sendmail command {command:?} not found in $PATH")), } + } - match path.metadata() { - Err(err) if err.kind() == std::io::ErrorKind::NotFound => { - err!(format!("sendmail command not found at `{path:?}`")) - } - Err(err) => { - err!(format!("failed to access sendmail command at `{path:?}`: {err}")) + match path.metadata() { + Err(err) if err.kind() == std::io::ErrorKind::NotFound => { + err!(format!("sendmail command not found at `{path:?}`")) + } + Err(err) => { + err!(format!("failed to access sendmail command at `{path:?}`: {err}")) + } + Ok(metadata) => { + if metadata.is_dir() { + err!(format!("sendmail command at `{path:?}` isn't a directory")); } - Ok(metadata) => { - if metadata.is_dir() { - err!(format!("sendmail command at `{path:?}` isn't a directory")); - } - #[cfg(unix)] - { - use std::os::unix::fs::PermissionsExt; - if !metadata.permissions().mode() & 0o111 != 0 { - err!(format!("sendmail command at `{path:?}` isn't executable")); - } + #[cfg(unix)] + { + use std::os::unix::fs::PermissionsExt; + if !metadata.permissions().mode() & 0o111 != 0 { + err!(format!("sendmail command at `{path:?}` isn't executable")); } } } |