From 3689b068a2713c8df7dd0981908da6504a3160af Mon Sep 17 00:00:00 2001 From: Jake McGinty Date: Mon, 13 Sep 2021 00:43:27 +0900 Subject: [PATCH] shared: create dirs with 700 permissions Closes #150 --- shared/src/lib.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/shared/src/lib.rs b/shared/src/lib.rs index 920114a..402cb6d 100644 --- a/shared/src/lib.rs +++ b/shared/src/lib.rs @@ -1,12 +1,6 @@ pub use anyhow::Error; use lazy_static::lazy_static; -use std::{ - fs::{self, File}, - io, - os::unix::fs::PermissionsExt, - path::Path, - time::Duration, -}; +use std::{fs::{self, File, Permissions}, io, os::unix::fs::PermissionsExt, path::Path, time::Duration}; pub mod interface_config; #[cfg(target_os = "linux")] @@ -31,12 +25,16 @@ pub const INNERNET_PUBKEY_HEADER: &str = "X-Innernet-Server-Key"; pub fn ensure_dirs_exist(dirs: &[&Path]) -> Result<(), WrappedIoError> { for dir in dirs { match fs::create_dir(dir).with_path(dir) { - Err(e) if e.kind() != io::ErrorKind::AlreadyExists => { - return Err(e); + Ok(()) => { + log::debug!("created dir {}", dir.to_string_lossy()); + std::fs::set_permissions(dir, Permissions::from_mode(0o700)).with_path(dir)?; }, - _ => { + Err(e) if e.kind() == io::ErrorKind::AlreadyExists => { warn_on_dangerous_mode(dir).with_path(dir)?; }, + Err(e) => { + return Err(e); + }, } } Ok(())