diff options
| author | David Lönnhager <david.l@mullvad.net> | 2021-11-05 10:48:26 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2021-11-05 10:48:26 +0100 |
| commit | 44a4d522af9e8b529a720aae67f2b1c1ad2d5c5b (patch) | |
| tree | 8c5a046059c0b30b457daa7e5f7a2813abab12cb | |
| parent | 04f7ed89afbd709b1fc1ea5838a0f9ca6f2e9483 (diff) | |
| parent | 8f3cfeb2e18cd2da23d8eeb21b0024067590ff41 (diff) | |
| download | mullvadvpn-44a4d522af9e8b529a720aae67f2b1c1ad2d5c5b.tar.xz mullvadvpn-44a4d522af9e8b529a720aae67f2b1c1ad2d5c5b.zip | |
Merge branch 'win-remove-dns-backup'
| -rw-r--r-- | mullvad-daemon/src/lib.rs | 1 | ||||
| -rw-r--r-- | talpid-core/src/dns/android.rs | 7 | ||||
| -rw-r--r-- | talpid-core/src/dns/linux/mod.rs | 8 | ||||
| -rw-r--r-- | talpid-core/src/dns/macos.rs | 3 | ||||
| -rw-r--r-- | talpid-core/src/dns/mod.rs | 14 | ||||
| -rw-r--r-- | talpid-core/src/dns/windows/mod.rs | 14 | ||||
| -rw-r--r-- | talpid-core/src/dns/windows/system_state.rs | 69 | ||||
| -rw-r--r-- | talpid-core/src/tunnel_state_machine/mod.rs | 7 |
8 files changed, 16 insertions, 107 deletions
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs index 21ca9298b8..aa78abbd2a 100644 --- a/mullvad-daemon/src/lib.rs +++ b/mullvad-daemon/src/lib.rs @@ -664,7 +664,6 @@ where tunnel_parameters_generator, log_dir, resource_dir.clone(), - cache_dir.clone(), internal_event_tx.to_specialized_sender(), offline_state_tx, tunnel_state_machine_shutdown_tx, diff --git a/talpid-core/src/dns/android.rs b/talpid-core/src/dns/android.rs index 517c311113..3e9e0ef81b 100644 --- a/talpid-core/src/dns/android.rs +++ b/talpid-core/src/dns/android.rs @@ -1,4 +1,4 @@ -use std::{net::IpAddr, path::Path}; +use std::net::IpAddr; /// Stub error type for DNS errors on Android. #[derive(Debug, err_derive::Error)] @@ -10,10 +10,7 @@ pub struct DnsMonitor; impl super::DnsMonitorT for DnsMonitor { type Error = Error; - fn new( - _handle: tokio::runtime::Handle, - _cache_dir: impl AsRef<Path>, - ) -> Result<Self, Self::Error> { + fn new() -> Result<Self, Self::Error> { Ok(DnsMonitor) } diff --git a/talpid-core/src/dns/linux/mod.rs b/talpid-core/src/dns/linux/mod.rs index e56ca1c208..7ab5b43d03 100644 --- a/talpid-core/src/dns/linux/mod.rs +++ b/talpid-core/src/dns/linux/mod.rs @@ -8,7 +8,7 @@ use self::{ systemd_resolved::SystemdResolved, }; use crate::routing::RouteManagerHandle; -use std::{env, fmt, net::IpAddr, path::Path}; +use std::{env, fmt, net::IpAddr}; const RESOLV_CONF_PATH: &str = "/etc/resolv.conf"; @@ -48,11 +48,7 @@ pub struct DnsMonitor { impl super::DnsMonitorT for DnsMonitor { type Error = Error; - fn new( - handle: tokio::runtime::Handle, - _cache_dir: impl AsRef<Path>, - route_manager: RouteManagerHandle, - ) -> Result<Self> { + fn new(handle: tokio::runtime::Handle, route_manager: RouteManagerHandle) -> Result<Self> { Ok(DnsMonitor { route_manager, handle, diff --git a/talpid-core/src/dns/macos.rs b/talpid-core/src/dns/macos.rs index 44ba949f59..b58e47eada 100644 --- a/talpid-core/src/dns/macos.rs +++ b/talpid-core/src/dns/macos.rs @@ -4,7 +4,6 @@ use std::{ collections::HashMap, fmt, net::IpAddr, - path::Path, sync::{mpsc, Arc}, thread, }; @@ -140,7 +139,7 @@ impl super::DnsMonitorT for DnsMonitor { /// DNS settings for all network interfaces. If any changes occur it will instantly reset /// the DNS settings for that interface back to the last server list set to this instance /// with `set_dns`. - fn new(_handle: tokio::runtime::Handle, _cache_dir: impl AsRef<Path>) -> Result<Self> { + fn new() -> Result<Self> { let state = Arc::new(Mutex::new(None)); Self::spawn(state.clone())?; Ok(DnsMonitor { diff --git a/talpid-core/src/dns/mod.rs b/talpid-core/src/dns/mod.rs index 229896cf98..f60b38a862 100644 --- a/talpid-core/src/dns/mod.rs +++ b/talpid-core/src/dns/mod.rs @@ -1,6 +1,6 @@ #[cfg(target_os = "linux")] use crate::routing::RouteManagerHandle; -use std::{net::IpAddr, path::Path}; +use std::net::IpAddr; #[cfg(target_os = "macos")] #[path = "macos.rs"] @@ -31,14 +31,13 @@ pub struct DnsMonitor { impl DnsMonitor { /// Returns a new `DnsMonitor` that can set and monitor the system DNS. pub fn new( - handle: tokio::runtime::Handle, - cache_dir: impl AsRef<Path>, + #[cfg(target_os = "linux")] handle: tokio::runtime::Handle, #[cfg(target_os = "linux")] route_manager: RouteManagerHandle, ) -> Result<Self, Error> { Ok(DnsMonitor { inner: imp::DnsMonitor::new( + #[cfg(target_os = "linux")] handle, - cache_dir, #[cfg(target_os = "linux")] route_manager, )?, @@ -69,12 +68,15 @@ impl DnsMonitor { trait DnsMonitorT: Sized { type Error: std::error::Error; + #[cfg(target_os = "linux")] fn new( handle: tokio::runtime::Handle, - cache_dir: impl AsRef<Path>, - #[cfg(target_os = "linux")] route_manager: RouteManagerHandle, + route_manager: RouteManagerHandle, ) -> Result<Self, Self::Error>; + #[cfg(not(target_os = "linux"))] + fn new() -> Result<Self, Self::Error>; + fn set(&mut self, interface: &str, servers: &[IpAddr]) -> Result<(), Self::Error>; fn reset(&mut self) -> Result<(), Self::Error>; diff --git a/talpid-core/src/dns/windows/mod.rs b/talpid-core/src/dns/windows/mod.rs index 90ef7552b7..f56b52e924 100644 --- a/talpid-core/src/dns/windows/mod.rs +++ b/talpid-core/src/dns/windows/mod.rs @@ -11,11 +11,7 @@ use winreg::{ RegKey, RegValue, }; -mod system_state; -use self::system_state::SystemStateWriter; - -const DNS_STATE_FILENAME: &'static str = "dns-state-backup"; const DNS_CACHE_POLICY_GUID: &str = "{d57d2750-f971-408e-8e55-cfddb37e60ae}"; lazy_static! { @@ -50,17 +46,9 @@ pub struct DnsMonitor {} impl super::DnsMonitorT for DnsMonitor { type Error = Error; - fn new(_handle: tokio::runtime::Handle, cache_dir: impl AsRef<Path>) -> Result<Self, Error> { + fn new() -> Result<Self, Error> { unsafe { WinDns_Initialize(Some(log_sink), b"WinDns\0".as_ptr()).into_result()? }; - let backup_writer = SystemStateWriter::new( - cache_dir - .as_ref() - .join(DNS_STATE_FILENAME) - .into_boxed_path(), - ); - let _ = backup_writer.remove_backup(); - let mut monitor = DnsMonitor {}; monitor.reset()?; diff --git a/talpid-core/src/dns/windows/system_state.rs b/talpid-core/src/dns/windows/system_state.rs deleted file mode 100644 index 36ad49793b..0000000000 --- a/talpid-core/src/dns/windows/system_state.rs +++ /dev/null @@ -1,69 +0,0 @@ -//! A writer for a blob that would persistently store the system state. Useful -//! for when the application of a secuirty policy proves to be persistent across -//! reboots -use std::{fs, io, path::Path}; - -/// This struct is responsible for saving a binary blob to disk. The binary blob is intended to -/// store system DNS settings that should be restored when the DNS settings are reset. -pub struct SystemStateWriter { - /// Full path to the system state backup file - pub backup_path: Box<Path>, -} - -impl SystemStateWriter { - /// Creates a new SystemStateWriter which will use a file in the cache directory to store system - /// DNS state that has to be restored. - pub fn new<P: AsRef<Path>>(backup_path: P) -> Self { - Self { - backup_path: backup_path.as_ref().to_owned().into_boxed_path(), - } - } - - /// Removes a previously created state backup if it exists. - pub fn remove_backup(&self) -> io::Result<()> { - match fs::remove_file(&self.backup_path) { - Err(e) => { - if e.kind() != io::ErrorKind::NotFound { - Err(e) - } else { - Ok(()) - } - } - _ => Ok(()), - } - } -} - -#[cfg(test)] -mod tests { - use super::*; - use fs::{self, File}; - use std::io::prelude::*; - - #[test] - fn can_remove_backup() { - let temp_dir = tempfile::tempdir().expect("failed to create temp dir"); - let temp_file = temp_dir.path().join("test_file"); - - let mut file_handle = File::create(&temp_file).expect("failed to create dummy backup file"); - file_handle - .write_all(b"Hello, world!") - .expect("failed to write to dummy backup file"); - - let writer = SystemStateWriter::new(&temp_file); - writer - .remove_backup() - .expect("failed to remove backup file"); - } - - #[test] - fn can_remove_when_no_backup_exists() { - let temp_dir = tempfile::tempdir().expect("failed to create temp dir"); - let temp_file = temp_dir.path().join("test_file"); - - let writer = SystemStateWriter::new(&temp_file); - writer - .remove_backup() - .expect("Encountered IO error when running remove_backup when no state file exists"); - } -} diff --git a/talpid-core/src/tunnel_state_machine/mod.rs b/talpid-core/src/tunnel_state_machine/mod.rs index c871998a71..fbc3e05622 100644 --- a/talpid-core/src/tunnel_state_machine/mod.rs +++ b/talpid-core/src/tunnel_state_machine/mod.rs @@ -34,7 +34,7 @@ use std::{ collections::HashSet, io, net::IpAddr, - path::{Path, PathBuf}, + path::PathBuf, sync::{mpsc as sync_mpsc, Arc}, }; #[cfg(target_os = "android")] @@ -102,7 +102,6 @@ pub async fn spawn( tunnel_parameters_generator: impl TunnelParametersGenerator, log_dir: Option<PathBuf>, resource_dir: PathBuf, - cache_dir: impl AsRef<Path> + Send + 'static, state_change_listener: impl Sender<TunnelStateTransition> + Send + 'static, offline_state_listener: mpsc::UnboundedSender<bool>, shutdown_tx: oneshot::Sender<()>, @@ -134,7 +133,6 @@ pub async fn spawn( tun_provider, log_dir, resource_dir, - cache_dir, command_rx, #[cfg(target_os = "android")] android_context, @@ -223,7 +221,6 @@ impl TunnelStateMachine { tun_provider: TunProvider, log_dir: Option<PathBuf>, resource_dir: PathBuf, - cache_dir: impl AsRef<Path>, commands_rx: mpsc::UnboundedReceiver<TunnelCommand>, #[cfg(target_os = "android")] android_context: AndroidContext, ) -> Result<Self, Error> { @@ -242,8 +239,8 @@ impl TunnelStateMachine { .await .map_err(Error::InitRouteManagerError)?; let dns_monitor = DnsMonitor::new( + #[cfg(target_os = "linux")] runtime.clone(), - cache_dir, #[cfg(target_os = "linux")] route_manager .handle() |
