vw_small

Hardened fork of Vaultwarden (https://github.com/dani-garcia/vaultwarden) with fewer features.
git clone https://git.philomathiclife.com/repos/vw_small
Log | Files | Refs | README

commit d1ff1365522696fdbff8a554bc9c81f7a0b6b009
parent 736dbc9553ed5caa928631f032344d2004800240
Author: Daniel GarcĂ­a <dani-garcia@users.noreply.github.com>
Date:   Fri, 14 Oct 2022 17:56:48 +0200

Merge branch 'stefan0xC-check-data-folder-permissions'

Diffstat:
Msrc/main.rs | 4++++
Msrc/util.rs | 13+++++++++++--
2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/main.rs b/src/main.rs @@ -303,6 +303,10 @@ async fn check_data_folder() { } exit(1); } + if !path.is_dir() { + error!("Data folder '{}' is not a directory.", data_folder); + exit(1); + } if is_running_in_docker() && std::env::var("I_REALLY_WANT_VOLATILE_STORAGE").is_err() diff --git a/src/util.rs b/src/util.rs @@ -1,7 +1,7 @@ // // Web Headers and caching // -use std::io::Cursor; +use std::io::{Cursor, ErrorKind}; use rocket::{ fairing::{Fairing, Info, Kind}, @@ -326,7 +326,16 @@ pub fn file_exists(path: &str) -> bool { pub fn write_file(path: &str, content: &[u8]) -> Result<(), crate::error::Error> { use std::io::Write; - let mut f = File::create(path)?; + let mut f = match File::create(path) { + Ok(file) => file, + Err(e) => { + if e.kind() == ErrorKind::PermissionDenied { + error!("Can't create '{}': Permission denied", path); + } + return Err(From::from(e)); + } + }; + f.write_all(content)?; f.flush()?; Ok(())