diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-03-05 10:08:02 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-03-06 13:58:02 -0300 |
| commit | 0ea0e54f838635c91086fafa0a8a8a7b0166d90e (patch) | |
| tree | 079dbecc9a16eb5ba75df25424862db430663641 | |
| parent | 4d41933445d35797744720601b9dec4fe76c17ad (diff) | |
| download | mullvadvpn-0ea0e54f838635c91086fafa0a8a8a7b0166d90e.tar.xz mullvadvpn-0ea0e54f838635c91086fafa0a8a8a7b0166d90e.zip | |
Move user check to start of program
| -rw-r--r-- | mullvad-daemon/src/main.rs | 16 | ||||
| -rw-r--r-- | mullvad-daemon/src/rpc_info.rs | 18 |
2 files changed, 16 insertions, 18 deletions
diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs index eb6ec9d87f..14b3cf0f6f 100644 --- a/mullvad-daemon/src/main.rs +++ b/mullvad-daemon/src/main.rs @@ -768,6 +768,10 @@ fn run() -> Result<()> { .chain_err(|| "Unable to initialize logger")?; log_version(); + if !user_is_root() { + warn!("Running daemon as a non-root user, clients might refuse to connect"); + } + let resource_dir = config.resource_dir.unwrap_or_else(|| get_resource_dir()); let daemon = Daemon::new(config.tunnel_log_file, resource_dir, config.require_auth) .chain_err(|| "Unable to initialize daemon")?; @@ -807,3 +811,15 @@ fn get_resource_dir() -> PathBuf { } } } + +#[cfg(unix)] +fn user_is_root() -> bool { + let uid = unsafe { libc::getuid() }; + uid == 0 +} + +#[cfg(windows)] +fn user_is_root() -> bool { + // TODO: Check if user is administrator correctly on Windows. + true +} diff --git a/mullvad-daemon/src/rpc_info.rs b/mullvad-daemon/src/rpc_info.rs index 7c906672f5..b5b35fa8f7 100644 --- a/mullvad-daemon/src/rpc_info.rs +++ b/mullvad-daemon/src/rpc_info.rs @@ -2,9 +2,6 @@ use std::fs::{self, File, OpenOptions}; use std::io::{self, Write}; use std::path::{Path, PathBuf}; -#[cfg(unix)] -use libc; - error_chain! { errors { WriteFailed(path: PathBuf) { @@ -50,9 +47,6 @@ pub fn remove() -> Result<()> { } fn open_file(path: &Path) -> io::Result<File> { - if !user_is_root() { - warn!("Running daemon as a non-root user, clients might refuse to connect"); - } let file = OpenOptions::new() .write(true) .truncate(true) @@ -63,18 +57,6 @@ fn open_file(path: &Path) -> io::Result<File> { } #[cfg(unix)] -fn user_is_root() -> bool { - let uid = unsafe { libc::getuid() }; - uid == 0 -} - -#[cfg(windows)] -fn user_is_root() -> bool { - // TODO: Check if user is administrator correctly on Windows. - true -} - -#[cfg(unix)] fn set_rpc_file_permissions(file: &File) -> io::Result<()> { use std::os::unix::fs::PermissionsExt; file.set_permissions(PermissionsExt::from_mode(0o644)) |
