Index: Cargo.lock ================================================================== --- Cargo.lock +++ Cargo.lock @@ -1,8 +1,8 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 4 +version = 3 [[package]] name = "addr2line" version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -510,13 +510,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "erasable" -version = "1.3.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "437cfb75878119ed8265685c41a115724eae43fb7cc5a0bf0e4ecc3b803af1c4" +checksum = "c18404d99ecdee16598948437ef1a18b94c74f4d3a374cd41f642626c2c57cd8" dependencies = [ "autocfg", "scopeguard", ] @@ -525,11 +525,11 @@ version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" dependencies = [ "libc", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] name = "event-listener" version = "2.5.3" @@ -767,15 +767,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" [[package]] name = "home" -version = "0.5.11" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] name = "http" version = "0.2.12" @@ -1122,11 +1122,11 @@ version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" dependencies = [ "cfg-if", - "windows-targets 0.52.6", + "windows-targets 0.48.5", ] [[package]] name = "linux-raw-sys" version = "0.4.15" @@ -1469,13 +1469,13 @@ "proc-macro2", ] [[package]] name = "rc-box" -version = "1.3.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897fecc9fac6febd4408f9e935e86df739b0023b625e610e0357535b9c8adad0" +checksum = "e0690759eabf094030c2cdabc25ade1395bac02210d920d655053c1d49583fd8" dependencies = [ "erasable", ] [[package]] @@ -1598,11 +1598,11 @@ dependencies = [ "bitflags 2.8.0", "errno", "libc", "linux-raw-sys", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] name = "rustls" version = "0.21.12" @@ -2037,11 +2037,11 @@ "cfg-if", "fastrand", "getrandom", "once_cell", "rustix", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] name = "ternop" version = "1.0.1" Index: src/main.rs ================================================================== --- src/main.rs +++ src/main.rs @@ -6,10 +6,11 @@ anyhow, bail, Result, }; use async_std::{ + fs::metadata, io::Error, task, }; use just_getopt::{ OptFlags, @@ -38,10 +39,11 @@ borrow::Cow, collections::{ HashMap, HashSet, }, + os::unix::fs::PermissionsExt, path::Path, vec::Vec, }; /// `SomeHeaders` object to store data through SMTP session @@ -373,10 +375,19 @@ }); if !config_file.exists() { eprintln!("Error: can't read configuration from {:?}", config_file); std::process::exit(1); }; + { + let meta = metadata(config_file).await?; + if (!0o100600 & meta.permissions().mode()) > 0 { + eprintln!("Error: other users can read or write config file {:?}\n\ + File permissions: {:o}", + config_file, meta.permissions().mode()); + std::process::exit(1); + } + } let settings: config::Config = config::Config::builder() .set_default("fields", vec!["date", "from", "subject"]).unwrap() .set_default("hostname", "smtp.2.tg").unwrap() .set_default("listen_on", "0.0.0.0:1025").unwrap() .set_default("unknown", "relay").unwrap()