diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2018-12-12 14:11:57 +0100 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2018-12-12 14:17:05 +0100 |
| commit | 9ca6751a0c323c3dc726ad72c195c67bca94eda9 (patch) | |
| tree | 28aa6811b16094959b11850b5fd8acbdaa5b96de | |
| parent | 893b15bfb5bf5d588ee7c0f6d98bcffe7d67ab96 (diff) | |
| download | mullvadvpn-9ca6751a0c323c3dc726ad72c195c67bca94eda9.tar.xz mullvadvpn-9ca6751a0c323c3dc726ad72c195c67bca94eda9.zip | |
Check if resolvconf is a symlink to resolvectl
| -rw-r--r-- | talpid-core/src/security/linux/dns/resolvconf.rs | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/talpid-core/src/security/linux/dns/resolvconf.rs b/talpid-core/src/security/linux/dns/resolvconf.rs index 5c844c3355..32b8fcd6b9 100644 --- a/talpid-core/src/security/linux/dns/resolvconf.rs +++ b/talpid-core/src/security/linux/dns/resolvconf.rs @@ -1,7 +1,10 @@ -use std::collections::HashSet; -use std::net::IpAddr; -use std::path::PathBuf; - +use std::{ + collections::HashSet, + ffi::OsStr, + fs, + net::IpAddr, + path::{Path, PathBuf}, +}; use which::which; error_chain! { @@ -9,6 +12,9 @@ error_chain! { NoResolvconf { description("Failed to detect 'resolvconf' program") } + ResolvconfUsesResolved { + description("The existing resolvconf binary is just a symlink to systemd-resolved") + } RunResolvconf { description("Failed to execute 'resolvconf' program") } @@ -29,12 +35,25 @@ pub struct Resolvconf { impl Resolvconf { pub fn new() -> Result<Self> { + let resolvconf_path = + which("resolvconf").map_err(|_| Error::from(ErrorKind::NoResolvconf))?; + if Self::resolvconf_is_resolved_symlink(&resolvconf_path) { + bail!(ErrorKind::ResolvconfUsesResolved); + } Ok(Resolvconf { record_names: HashSet::new(), - resolvconf: which("resolvconf").map_err(|_| Error::from(ErrorKind::NoResolvconf))?, + resolvconf: resolvconf_path, }) } + fn resolvconf_is_resolved_symlink(resolvconf_path: &Path) -> bool { + fs::read_link(resolvconf_path) + .map(|resolvconf_target| { + resolvconf_target.file_name() == Some(OsStr::new("resolvectl")) + }) + .unwrap_or_else(|_| false) + } + pub fn set_dns(&mut self, interface: &str, servers: &[IpAddr]) -> Result<()> { let record_name = format!("{}.mullvad", interface); let mut record_contents = String::new(); |
