Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
position.
- Redact all 16 digit numbers from problem report logs. Extra safety against accidentally sending
account numbers.
- Fix OpenVPN plugin search directory to be the installation directory.


## [2018.1] - 2018-03-01
Expand Down
30 changes: 23 additions & 7 deletions talpid-core/src/tunnel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -145,11 +146,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,
Expand Down Expand Up @@ -191,9 +189,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();

path.push(library);

if path.exists() {
debug!("Using OpenVPN plugin at {}", path.to_string_lossy());
Expand All @@ -203,6 +203,22 @@ impl TunnelMonitor {
}
}

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(".")
}
}
}

fn get_library_name() -> Result<&'static str> {
if cfg!(target_os = "macos") {
Ok("libtalpid_openvpn_plugin.dylib")
Expand Down