summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2018-05-18 18:32:19 +0200
committerLinus Färnstrand <linus@mullvad.net>2018-05-22 10:19:30 +0200
commit578c5a24f857a8f70038c7c1bf1ca0935d199e05 (patch)
treed5a02effa98844915caaa5e58725442accb68d8f
parent6a89c152e3126c30557c8f36f5f94bc518e01968 (diff)
downloadmullvadvpn-578c5a24f857a8f70038c7c1bf1ca0935d199e05.tar.xz
mullvadvpn-578c5a24f857a8f70038c7c1bf1ca0935d199e05.zip
Make missing OpenVPN binary/plugin error print path
-rw-r--r--talpid-core/src/tunnel/mod.rs95
1 files changed, 43 insertions, 52 deletions
diff --git a/talpid-core/src/tunnel/mod.rs b/talpid-core/src/tunnel/mod.rs
index 533e106db8..3c3e9979f2 100644
--- a/talpid-core/src/tunnel/mod.rs
+++ b/talpid-core/src/tunnel/mod.rs
@@ -5,7 +5,6 @@ use openvpn_plugin::types::OpenVpnPluginEvent;
use process::openvpn::OpenVpnCommand;
use std::collections::HashMap;
-use std::ffi::OsStr;
use std::fs;
use std::io::{self, Write};
use std::net::Ipv4Addr;
@@ -20,37 +19,48 @@ pub mod openvpn;
use self::openvpn::{OpenVpnCloseHandle, OpenVpnMonitor};
-mod errors {
- error_chain!{
- errors {
- /// An error indicating there was an error listening for events from the VPN tunnel.
- 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")
- }
- /// There was an error when writing authentication credentials to temporary file.
- CredentialsWriteError {
- description("Error while writing credentials to temporary file")
- }
- /// Running on an operating system which is not supported yet.
- UnsupportedPlatform {
- description("Running on an unsupported operating system")
- }
- /// This type of VPN tunnel is not supported.
- UnsupportedTunnelProtocol {
- description("This tunnel protocol is not supported")
- }
+#[cfg(target_os = "macos")]
+const OPENVPN_PLUGIN_FILENAME: &str = "libtalpid_openvpn_plugin.dylib";
+#[cfg(target_os = "linux")]
+const OPENVPN_PLUGIN_FILENAME: &str = "libtalpid_openvpn_plugin.so";
+#[cfg(windows)]
+const OPENVPN_PLUGIN_FILENAME: &str = "talpid_openvpn_plugin.dll";
+
+#[cfg(unix)]
+const OPENVPN_BIN_FILENAME: &str = "openvpn";
+#[cfg(windows)]
+const OPENVPN_BIN_FILENAME: &str = "openvpn.exe";
+
+error_chain!{
+ errors {
+ /// An error indicating there was an error listening for events from the VPN tunnel.
+ TunnelMonitoringError {
+ description("Error while setting up or processing events from the VPN tunnel")
+ }
+ /// The OpenVPN binary was not found.
+ OpenVpnNotFound(path: PathBuf) {
+ description("No OpenVPN binary found")
+ display("No OpenVPN binary found at {}", path.display())
+ }
+ /// The OpenVPN plugin was not found.
+ PluginNotFound(path: PathBuf) {
+ description("No OpenVPN plugin found")
+ display("No OpenVPN plugin found at {}", path.display())
+ }
+ /// There was an error when writing authentication credentials to temporary file.
+ CredentialsWriteError {
+ description("Error while writing credentials to temporary file")
+ }
+ /// Running on an operating system which is not supported yet.
+ UnsupportedPlatform {
+ description("Running on an unsupported operating system")
+ }
+ /// This type of VPN tunnel is not supported.
+ UnsupportedTunnelProtocol {
+ description("This tunnel protocol is not supported")
}
}
}
-pub use self::errors::*;
/// Possible events from the VPN tunnel and the child process managing it.
@@ -190,41 +200,22 @@ impl TunnelMonitor {
}
fn get_openvpn_bin(resource_dir: &Path) -> Result<PathBuf> {
- let bin = if cfg!(windows) {
- OsStr::new("openvpn.exe")
- } else {
- OsStr::new("openvpn")
- };
- let path = resource_dir.join(bin);
+ let path = resource_dir.join(OPENVPN_BIN_FILENAME);
if path.exists() {
trace!("Using OpenVPN at {}", path.display());
Ok(path)
} else {
- bail!(ErrorKind::OpenVpnNotFound);
+ bail!(ErrorKind::OpenVpnNotFound(path));
}
}
fn get_plugin_path(resource_dir: &Path) -> Result<PathBuf> {
- let library = Self::get_library_name().chain_err(|| ErrorKind::PluginNotFound)?;
- let path = resource_dir.join(library);
-
+ let path = resource_dir.join(OPENVPN_PLUGIN_FILENAME);
if path.exists() {
trace!("Using OpenVPN plugin at {}", path.display());
Ok(path)
} else {
- bail!(ErrorKind::PluginNotFound);
- }
- }
-
- fn get_library_name() -> Result<&'static str> {
- if cfg!(target_os = "macos") {
- Ok("libtalpid_openvpn_plugin.dylib")
- } else if cfg!(unix) {
- Ok("libtalpid_openvpn_plugin.so")
- } else if cfg!(windows) {
- Ok("talpid_openvpn_plugin.dll")
- } else {
- bail!(ErrorKind::UnsupportedPlatform);
+ bail!(ErrorKind::PluginNotFound(path));
}
}