diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2018-05-18 17:25:04 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2018-05-22 10:19:29 +0200 |
| commit | 37e4d24fcbab957cbe758d2a20a4fc70f4de3edd (patch) | |
| tree | 6bd1a42f084cab6fcea00dfb406ebff905a63c0e | |
| parent | a0f26fa251bac45a7121a71057d776d75313f45c (diff) | |
| download | mullvadvpn-37e4d24fcbab957cbe758d2a20a4fc70f4de3edd.tar.xz mullvadvpn-37e4d24fcbab957cbe758d2a20a4fc70f4de3edd.zip | |
Update TunnelMonitor to use bundled OpenVPN only
| -rw-r--r-- | talpid-core/src/tunnel/mod.rs | 60 |
1 files changed, 24 insertions, 36 deletions
diff --git a/talpid-core/src/tunnel/mod.rs b/talpid-core/src/tunnel/mod.rs index 8ba7ef2740..533e106db8 100644 --- a/talpid-core/src/tunnel/mod.rs +++ b/talpid-core/src/tunnel/mod.rs @@ -5,8 +5,7 @@ use openvpn_plugin::types::OpenVpnPluginEvent; use process::openvpn::OpenVpnCommand; use std::collections::HashMap; -use std::env; -use std::ffi::{OsStr, OsString}; +use std::ffi::OsStr; use std::fs; use std::io::{self, Write}; use std::net::Ipv4Addr; @@ -28,6 +27,10 @@ mod errors { TunnelMonitoringError { description("Error while setting up or processing events from the VPN tunnel") } + /// The OpenVPN binary was not found. + OpenVpnNotFound { + description("No OpenVPN binary found") + } /// The OpenVPN plugin was not found. PluginNotFound { description("No OpenVPN plugin found") @@ -139,7 +142,7 @@ impl TunnelMonitor { user_pass_file.as_ref(), log, resource_dir, - ); + )?; let user_pass_file_path = user_pass_file.to_path_buf(); let on_openvpn_event = move |event, env| { @@ -153,8 +156,11 @@ impl TunnelMonitor { } }; - let monitor = openvpn::OpenVpnMonitor::new(cmd, on_openvpn_event, Self::get_plugin_path()?) - .chain_err(|| ErrorKind::TunnelMonitoringError)?; + let monitor = openvpn::OpenVpnMonitor::new( + cmd, + on_openvpn_event, + Self::get_plugin_path(resource_dir)?, + ).chain_err(|| ErrorKind::TunnelMonitoringError)?; Ok(TunnelMonitor { monitor, _user_pass_file: user_pass_file, @@ -167,8 +173,8 @@ impl TunnelMonitor { user_pass_file: &Path, log: Option<&Path>, resource_dir: &Path, - ) -> OpenVpnCommand { - let mut cmd = OpenVpnCommand::new(Self::get_openvpn_bin(resource_dir)); + ) -> Result<OpenVpnCommand> { + let mut cmd = OpenVpnCommand::new(Self::get_openvpn_bin(resource_dir)?); if let Some(config) = Self::get_config_path(resource_dir) { cmd.config(config); } @@ -180,51 +186,33 @@ impl TunnelMonitor { if let Some(log) = log { cmd.log(log); } - cmd + Ok(cmd) } - fn get_openvpn_bin(resource_dir: &Path) -> OsString { + fn get_openvpn_bin(resource_dir: &Path) -> Result<PathBuf> { let bin = if cfg!(windows) { OsStr::new("openvpn.exe") } else { OsStr::new("openvpn") }; - let bundled_path = resource_dir.join("openvpn-binaries").join(bin); - if bundled_path.exists() { - bundled_path.into_os_string() + let path = resource_dir.join(bin); + if path.exists() { + trace!("Using OpenVPN at {}", path.display()); + Ok(path) } else { - warn!("Did not find a bundled version of OpenVPN, will rely on the PATH instead"); - bin.to_os_string() + bail!(ErrorKind::OpenVpnNotFound); } } - fn get_plugin_path() -> Result<PathBuf> { + fn get_plugin_path(resource_dir: &Path) -> Result<PathBuf> { let library = Self::get_library_name().chain_err(|| ErrorKind::PluginNotFound)?; - let mut path = Self::get_executable_dir(); - - path.push(library); + let path = resource_dir.join(library); if path.exists() { - debug!("Using OpenVPN plugin at {}", path.display()); + trace!("Using OpenVPN plugin at {}", path.display()); Ok(path) } else { - Err(ErrorKind::PluginNotFound.into()) - } - } - - fn get_executable_dir() -> PathBuf { - match env::current_exe() { - Ok(mut path) => { - path.pop(); - path - } - Err(e) => { - error!( - "Failed finding the install directory. Using working directory: {}", - e - ); - PathBuf::from(".") - } + bail!(ErrorKind::PluginNotFound); } } |
