mirror of
https://github.com/aphrody-labs/mullvadvpn-app.git
synced 2026-10-17 12:56:19 +00:00
Always return the correct settings path on Windows in mullvad_paths
This commit is contained in:
9 files changed
+31
-45
No files matched your search
Generated
+4
-4
@@ -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",
|
||||
]
|
||||
|
||||
@@ -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",
|
||||
]
|
||||
@@ -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;
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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() };
|
||||
@@ -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",
|
||||
]
|
||||
@@ -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))
|
||||
}
|
||||
@@ -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" }
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in new issue
Block a user