summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2017-06-19 15:15:18 +0200
committerLinus Färnstrand <linus@mullvad.net>2017-06-19 15:34:07 +0200
commit98140cfbdcf62177d8c86c4cb01c15db5c7eb6ae (patch)
treecd8b7c6877b616c20062c67bd9b6130c8874d691
parente1ff9a3c72d06f20c4e47517cf0f65f11ceb7d66 (diff)
downloadmullvadvpn-98140cfbdcf62177d8c86c4cb01c15db5c7eb6ae.tar.xz
mullvadvpn-98140cfbdcf62177d8c86c4cb01c15db5c7eb6ae.zip
Add looking for OpenVPN plugin at ./ also
-rw-r--r--talpid_core/src/tunnel/mod.rs32
1 files changed, 24 insertions, 8 deletions
diff --git a/talpid_core/src/tunnel/mod.rs b/talpid_core/src/tunnel/mod.rs
index aead09b13b..ce4d361814 100644
--- a/talpid_core/src/tunnel/mod.rs
+++ b/talpid_core/src/tunnel/mod.rs
@@ -2,6 +2,7 @@ use net;
use openvpn_ffi::OpenVpnPluginEvent;
use process::openvpn::OpenVpnCommand;
use std::io;
+use std::path::PathBuf;
/// A module for all OpenVPN related tunnel management.
pub mod openvpn;
@@ -15,6 +16,10 @@ mod errors {
TunnelMonitoringError {
description("Error while setting up or processing events from the VPN tunnel")
}
+ /// The OpenVPN plugin was not found.
+ PluginNotFound {
+ description("No OpenVPN plugin found")
+ }
}
}
}
@@ -59,7 +64,7 @@ impl TunnelMonitor {
None => debug!("Ignoring OpenVpnEvent {:?}", event),
};
let cmd = Self::create_openvpn_cmd(remote);
- let monitor = openvpn::OpenVpnMonitor::new(cmd, on_openvpn_event, get_plugin_path())
+ let monitor = openvpn::OpenVpnMonitor::new(cmd, on_openvpn_event, get_plugin_path()?)
.chain_err(|| ErrorKind::TunnelMonitoringError)?;
Ok(TunnelMonitor { monitor })
}
@@ -97,16 +102,27 @@ impl CloseHandle {
// TODO(linus): Temporary implementation for getting plugin path during development.
-fn get_plugin_path() -> &'static str {
- if cfg!(all(unix, not(target_os = "macos"))) {
- "./target/debug/libtalpid_openvpn_plugin.so"
- } else if cfg!(target_os = "macos") {
- "./target/debug/libtalpid_openvpn_plugin.dylib"
+fn get_plugin_path() -> Result<PathBuf> {
+ let dirs = &["./target/debug", "."];
+ let filename = if cfg!(target_os = "macos") {
+ "libtalpid_openvpn_plugin.dylib"
+ } else if cfg!(unix) {
+ "libtalpid_openvpn_plugin.so"
} else if cfg!(windows) {
- "./target/debug/libtalpid_openvpn_plugin.dll"
+ "libtalpid_openvpn_plugin.dll"
} else {
- panic!("Unsupported platform");
+ bail!(ErrorKind::PluginNotFound);
+ };
+
+ for dir in dirs {
+ let mut path = PathBuf::from(dir);
+ path.push(filename);
+ if path.exists() {
+ debug!("Using OpenVPN plugin at {}", path.to_string_lossy());
+ return Ok(path);
+ }
}
+ Err(ErrorKind::PluginNotFound.into())
}
// TODO(linus): Temporary implementation for getting hold of a config location.