diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-03-06 11:57:19 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-03-08 07:16:56 -0300 |
| commit | 806ecbc28b25652637f5b6e7a70102239ca27632 (patch) | |
| tree | a31faee6082fb6c50b1709c1e8aeecb66337652e | |
| parent | 5b0118e589b5b1fb60fd9f3ba8c132bd483db975 (diff) | |
| download | mullvadvpn-806ecbc28b25652637f5b6e7a70102239ca27632.tar.xz mullvadvpn-806ecbc28b25652637f5b6e7a70102239ca27632.zip | |
Use executable path as plugin path
| -rw-r--r-- | talpid-core/src/tunnel/mod.rs | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/talpid-core/src/tunnel/mod.rs b/talpid-core/src/tunnel/mod.rs index 747115564e..a623630106 100644 --- a/talpid-core/src/tunnel/mod.rs +++ b/talpid-core/src/tunnel/mod.rs @@ -5,6 +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::fs; use std::io::{self, Write}; @@ -25,6 +26,14 @@ mod errors { TunnelMonitoringError { description("Error while setting up or processing events from the VPN tunnel") } + /// Failed to get the current executable path. + ExecutablePathInaccessible { + description("Error while reading current executable path") + } + /// Obtained executable path doesn't have a parent directory. + ExecutableHasNoParentDir { + description("Executable path has no directories") + } /// The OpenVPN plugin was not found. PluginNotFound { description("No OpenVPN plugin found") @@ -145,11 +154,8 @@ impl TunnelMonitor { } }; - let monitor = openvpn::OpenVpnMonitor::new( - cmd, - on_openvpn_event, - Self::get_plugin_path(resource_dir)?, - ).chain_err(|| ErrorKind::TunnelMonitoringError)?; + let monitor = openvpn::OpenVpnMonitor::new(cmd, on_openvpn_event, Self::get_plugin_path()?) + .chain_err(|| ErrorKind::TunnelMonitoringError)?; Ok(TunnelMonitor { monitor, _user_pass_file: user_pass_file, @@ -191,9 +197,11 @@ impl TunnelMonitor { } } - fn get_plugin_path(resource_dir: &Path) -> Result<PathBuf> { + fn get_plugin_path() -> Result<PathBuf> { let library = Self::get_library_name().chain_err(|| ErrorKind::PluginNotFound)?; - let path = resource_dir.join(library); + let mut path = Self::get_executable_dir().chain_err(|| ErrorKind::PluginNotFound)?; + + path.push(library); if path.exists() { debug!("Using OpenVPN plugin at {}", path.to_string_lossy()); @@ -203,6 +211,15 @@ impl TunnelMonitor { } } + fn get_executable_dir() -> Result<PathBuf> { + let exe_path = env::current_exe().chain_err(|| ErrorKind::ExecutablePathInaccessible)?; + + exe_path + .parent() + .map(Path::to_path_buf) + .ok_or(ErrorKind::ExecutableHasNoParentDir.into()) + } + fn get_library_name() -> Result<&'static str> { if cfg!(target_os = "macos") { Ok("libtalpid_openvpn_plugin.dylib") |
