diff options
| author | David Lönnhager <david.l@mullvad.net> | 2022-11-21 11:53:25 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2022-11-21 11:53:25 +0100 |
| commit | 4116ebc192d34a6d6e2246c5c153a5fb657d3353 (patch) | |
| tree | 8673ca9906488e9b9055dbfab53fcb1a5e238226 | |
| parent | 0c2399a4c77db5707b022588b1e1b75aa8c4d483 (diff) | |
| parent | b3462ce28bb838708732ab6ab67cad4d91251980 (diff) | |
| download | mullvadvpn-4116ebc192d34a6d6e2246c5c153a5fb657d3353.tar.xz mullvadvpn-4116ebc192d34a6d6e2246c5c153a5fb657d3353.zip | |
Merge branch 'return-correct-settings-path'
| -rw-r--r-- | Cargo.lock | 8 | ||||
| -rw-r--r-- | mullvad-paths/Cargo.toml | 13 | ||||
| -rw-r--r-- | mullvad-paths/src/lib.rs | 3 | ||||
| -rw-r--r-- | mullvad-paths/src/settings.rs | 5 | ||||
| -rw-r--r-- | mullvad-paths/src/windows.rs (renamed from mullvad-setup/src/daemon_paths.rs) | 9 | ||||
| -rw-r--r-- | mullvad-setup/Cargo.toml | 14 | ||||
| -rw-r--r-- | mullvad-setup/src/main.rs | 20 | ||||
| -rw-r--r-- | talpid-openvpn/Cargo.toml | 2 | ||||
| -rw-r--r-- | talpid-wireguard/Cargo.toml | 2 |
9 files changed, 31 insertions, 45 deletions
diff --git a/Cargo.lock b/Cargo.lock index ade60ce467..fd3deb1aab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1722,6 +1722,8 @@ dependencies = [ "dirs-next", "err-derive", "log", + "widestring 1.0.2", + "windows-sys 0.42.0", ] [[package]] @@ -1786,8 +1788,6 @@ dependencies = [ "talpid-core", "talpid-types", "tokio", - "widestring 0.5.1", - "windows-sys 0.42.0", ] [[package]] @@ -3211,7 +3211,7 @@ dependencies = [ "triggered", "uuid", "which", - "widestring 0.5.1", + "widestring 1.0.2", "winapi", "windows-sys 0.42.0", "winreg", @@ -3373,7 +3373,7 @@ dependencies = [ "tokio", "tokio-stream", "tunnel-obfuscation", - "widestring 0.5.1", + "widestring 1.0.2", "windows-sys 0.42.0", "zeroize", ] diff --git a/mullvad-paths/Cargo.toml b/mullvad-paths/Cargo.toml index 57690210bb..8ab2e9fe22 100644 --- a/mullvad-paths/Cargo.toml +++ b/mullvad-paths/Cargo.toml @@ -13,3 +13,16 @@ log = "0.4" [target.'cfg(windows)'.dependencies] dirs-next = "2.0" +widestring = "1.0" + +[target.'cfg(target_os = "windows")'.dependencies.windows-sys] +version = "0.42.0" +features = [ + "Win32_Foundation", + "Win32_Security", + "Win32_System_Com", + "Win32_System_ProcessStatus", + "Win32_System_SystemServices", + "Win32_System_Threading", + "Win32_UI_Shell", +] diff --git a/mullvad-paths/src/lib.rs b/mullvad-paths/src/lib.rs index 39cf486b52..88bd23d74b 100644 --- a/mullvad-paths/src/lib.rs +++ b/mullvad-paths/src/lib.rs @@ -69,3 +69,6 @@ pub use crate::rpc_socket::{get_default_rpc_socket_path, get_rpc_socket_path}; mod settings; pub use crate::settings::{get_default_settings_dir, settings_dir}; + +#[cfg(windows)] +mod windows; diff --git a/mullvad-paths/src/settings.rs b/mullvad-paths/src/settings.rs index 76f8b993a8..b62acf2254 100644 --- a/mullvad-paths/src/settings.rs +++ b/mullvad-paths/src/settings.rs @@ -24,7 +24,10 @@ pub fn get_default_settings_dir() -> Result<PathBuf> { } #[cfg(windows)] { - dir = dirs_next::data_local_dir().ok_or_else(|| crate::Error::FindDirError); + dir = crate::windows::get_system_service_appdata().map_err(|error| { + log::error!("Failed to obtain system app data path: {error}"); + crate::Error::FindDirError + }) } dir.map(|dir| dir.join(crate::PRODUCT_NAME)) } diff --git a/mullvad-setup/src/daemon_paths.rs b/mullvad-paths/src/windows.rs index fdb683f2e3..ea9fe2b64e 100644 --- a/mullvad-setup/src/daemon_paths.rs +++ b/mullvad-paths/src/windows.rs @@ -31,9 +31,8 @@ use windows_sys::{ }, }; -pub fn get_mullvad_daemon_settings_path() -> io::Result<PathBuf> { +pub(crate) fn get_system_service_appdata() -> io::Result<PathBuf> { get_system_service_known_folder(&FOLDERID_LocalAppData) - .map(|settings| settings.join(mullvad_paths::PRODUCT_NAME)) } /// Get local AppData path for the system service user. Requires elevated privileges to work. @@ -82,7 +81,7 @@ fn get_system_service_known_folder(known_folder_id: *const GUID) -> std::io::Res })(); if let Err(err) = adjust_current_thread_token_privilege(&system_debug_priv, false) { - eprintln!("Failed to drop system privileges: {}", err); + eprintln!("Failed to drop SeDebugPrivilege: {}", err); } if unsafe { RevertToSelf() } == 0 { return Err(io::Error::last_os_error()); @@ -92,7 +91,7 @@ fn get_system_service_known_folder(known_folder_id: *const GUID) -> std::io::Res } fn adjust_current_thread_token_privilege( - privilege: &WideCString, + privilege: &WideCStr, enable: bool, ) -> std::io::Result<()> { let mut token_handle: HANDLE = 0; @@ -134,7 +133,7 @@ fn adjust_current_thread_token_privilege( fn adjust_token_privilege( token_handle: HANDLE, - privilege: &WideCString, + privilege: &WideCStr, enable: bool, ) -> std::io::Result<()> { let mut privilege_luid: LUID = unsafe { mem::zeroed() }; diff --git a/mullvad-setup/Cargo.toml b/mullvad-setup/Cargo.toml index d47ed796ed..ed4c2e2fca 100644 --- a/mullvad-setup/Cargo.toml +++ b/mullvad-setup/Cargo.toml @@ -28,17 +28,3 @@ mullvad-types = { path = "../mullvad-types" } mullvad-version = { path = "../mullvad-version" } talpid-core = { path = "../talpid-core" } talpid-types = { path = "../talpid-types" } - -[target.'cfg(windows)'.dependencies] -widestring = "0.5" - -[target.'cfg(windows)'.dependencies.windows-sys] -version = "0.42.0" -features = [ - "Win32_Foundation", - "Win32_Security", - "Win32_System_Com", - "Win32_System_ProcessStatus", - "Win32_System_Threading", - "Win32_UI_Shell", -] diff --git a/mullvad-setup/src/main.rs b/mullvad-setup/src/main.rs index c5ef3f3000..822d1451ff 100644 --- a/mullvad-setup/src/main.rs +++ b/mullvad-setup/src/main.rs @@ -34,15 +34,6 @@ impl From<Error> for ExitStatus { } } -#[cfg(windows)] -mod daemon_paths; - -#[cfg(windows)] -type SettingsPathErrorType = std::io::Error; - -#[cfg(not(windows))] -type SettingsPathErrorType = mullvad_paths::Error; - #[derive(err_derive::Error, Debug)] #[error(no_from)] pub enum Error { @@ -65,7 +56,7 @@ pub enum Error { RemoveDeviceError(#[error(source)] mullvad_api::rest::Error), #[error(display = "Failed to obtain settings directory path")] - SettingsPathError(#[error(source)] SettingsPathErrorType), + SettingsPathError(#[error(source)] mullvad_paths::Error), #[error(display = "Failed to obtain cache directory path")] CachePathError(#[error(source)] mullvad_paths::Error), @@ -204,17 +195,8 @@ async fn remove_device() -> Result<(), Error> { Ok(()) } -#[cfg(not(windows))] fn get_paths() -> Result<(PathBuf, PathBuf), Error> { let cache_path = mullvad_paths::cache_dir().map_err(Error::CachePathError)?; let settings_path = mullvad_paths::settings_dir().map_err(Error::SettingsPathError)?; Ok((cache_path, settings_path)) } - -#[cfg(windows)] -fn get_paths() -> Result<(PathBuf, PathBuf), Error> { - let cache_path = mullvad_paths::cache_dir().map_err(Error::CachePathError)?; - let settings_path = - daemon_paths::get_mullvad_daemon_settings_path().map_err(Error::SettingsPathError)?; - Ok((cache_path, settings_path)) -} diff --git a/talpid-openvpn/Cargo.toml b/talpid-openvpn/Cargo.toml index 1e701506a6..b936832a93 100644 --- a/talpid-openvpn/Cargo.toml +++ b/talpid-openvpn/Cargo.toml @@ -40,7 +40,7 @@ prost = "0.11" which = { version = "4.0", default-features = false } [target.'cfg(windows)'.dependencies] -widestring = "0.5" +widestring = "1.0" winreg = { version = "0.7", features = ["transactions"] } winapi = { version = "0.3.6", features = ["ws2def"] } talpid-windows-net = { path = "../talpid-windows-net" } diff --git a/talpid-wireguard/Cargo.toml b/talpid-wireguard/Cargo.toml index 162492e8cb..233141db96 100644 --- a/talpid-wireguard/Cargo.toml +++ b/talpid-wireguard/Cargo.toml @@ -50,7 +50,7 @@ tokio-stream = { version = "0.1", features = ["io-util"] } [target.'cfg(windows)'.dependencies] bitflags = "1.2" talpid-windows-net = { path = "../talpid-windows-net" } -widestring = "0.5" +widestring = "1.0" # Figure out which features are needed and which are not [target.'cfg(windows)'.dependencies.windows-sys] |
