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 9a87edc1ff68043fe007db990490ac8e5cdba2b2
parent a70164ab9463460eede27972db01076413ab8459
Author: Zack Newman <zack@philomathiclife.com>
Date:   Mon,  4 Dec 2023 14:25:37 -0700

fix domain port typo. use local file paths

Diffstat:
Msrc/config.rs | 13+++++--------
Msrc/main.rs | 18+++++++++---------
2 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/src/config.rs b/src/config.rs @@ -6,15 +6,14 @@ use std::error; use std::fs; use std::io::Error; use std::net::IpAddr; -use std::path::PathBuf; use std::sync::OnceLock; use toml::{self, de}; use url::{ParseError, Url}; static CONFIG: OnceLock<Config> = OnceLock::new(); #[inline] -pub fn init_config(cur_dir: &mut PathBuf) { +pub fn init_config() { CONFIG - .set(Config::load(cur_dir).expect("valid TOML config file at 'config.toml'")) + .set(Config::load().expect("valid TOML config file at 'config.toml'")) .expect("CONFIG must only be initialized once"); } #[inline] @@ -97,7 +96,7 @@ pub struct Config { } impl Config { #[inline] - pub fn load(cur_dir: &mut PathBuf) -> Result<Self, ConfigErr> { + pub fn load() -> Result<Self, ConfigErr> { let config_file = toml::from_str::<ConfigFile>(fs::read_to_string("config.toml")?.as_str())?; let mut tls = TlsConfig::from_paths(config_file.tls.cert, config_file.tls.key); @@ -115,7 +114,6 @@ impl Config { Some(prefer) => tls.with_preferred_server_cipher_order(prefer), None => tls, }; - cur_dir.push(Self::TMP_FOLDER); let mut rocket = rocket::Config { address: config_file.ip, cli_colors: false, @@ -125,7 +123,7 @@ impl Config { .limit("file", 525.megabytes()), log_level: LogLevel::Off, port: config_file.port, - temp_dir: cur_dir.into(), + temp_dir: Self::TMP_FOLDER.into(), tls: Some(tls), ..Default::default() }; @@ -139,7 +137,7 @@ impl Config { if config_file.port == 443 { String::new() } else { - config_file.port.to_string() + format!(":{}", config_file.port) } ) .as_str(), @@ -147,7 +145,6 @@ impl Config { if domain.domain().is_none() { return Err(ConfigErr::BadDomain); } - cur_dir.pop(); Ok(Self { database_max_conns: config_file .database_max_conns diff --git a/src/main.rs b/src/main.rs @@ -100,15 +100,13 @@ use config::Config; pub use error::{Error, MapResult}; use priv_sep::unveil_create_read_write; use std::env; -use std::path::PathBuf; use std::{fs::create_dir_all, path::Path, process::exit}; use tokio::runtime::Builder; fn main() -> Result<(), Error> { let mut promises = priv_sep::pledge_init()?; - let cur_dir = env::current_dir()?; - priv_sep::unveil_read(cur_dir.as_path())?; - static_init(cur_dir); + priv_sep::unveil_read(env::current_dir()?)?; + static_init(); check_data_folder(); check_web_vault(); create_dir(Config::ATTACHMENTS_FOLDER, "attachments folder"); @@ -140,11 +138,13 @@ fn main() -> Result<(), Error> { ) } #[inline] -fn static_init(mut cur_dir: PathBuf) { - config::init_config(&mut cur_dir); - cur_dir.push(Config::DATA_FOLDER); - unveil_create_read_write(cur_dir.as_path()).unwrap_or_else(|_| { - panic!("unable to unveil(2) {cur_dir:?} with create, read, and write permissions",) +fn static_init() { + config::init_config(); + unveil_create_read_write(Config::DATA_FOLDER).unwrap_or_else(|_| { + panic!( + "unable to unveil(2) {} with create, read, and write permissions", + Config::DATA_FOLDER + ) }); auth::init_values(); api::init_ws_users();