diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2018-12-12 14:31:35 +0100 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2018-12-12 14:31:35 +0100 |
| commit | af5ec022bfef751348452a78490ace08eaf5b7d5 (patch) | |
| tree | 28aa6811b16094959b11850b5fd8acbdaa5b96de | |
| parent | 19ed1e0b08de9f32715dfa7f9591fd90922be8e4 (diff) | |
| parent | 9ca6751a0c323c3dc726ad72c195c67bca94eda9 (diff) | |
| download | mullvadvpn-af5ec022bfef751348452a78490ace08eaf5b7d5.tar.xz mullvadvpn-af5ec022bfef751348452a78490ace08eaf5b7d5.zip | |
Merge branch 'capture-resolvconf-stderr'
| -rw-r--r-- | talpid-core/src/security/linux/dns/resolvconf.rs | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/talpid-core/src/security/linux/dns/resolvconf.rs b/talpid-core/src/security/linux/dns/resolvconf.rs index 7d3f1162db..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(); @@ -47,6 +66,8 @@ impl Resolvconf { let output = duct::cmd!(&self.resolvconf, "-a", &record_name) .input(record_contents) + .stderr_capture() + .unchecked() .run() .chain_err(|| ErrorKind::RunResolvconf)?; @@ -65,6 +86,8 @@ impl Resolvconf { for record_name in self.record_names.drain() { let output = duct::cmd!(&self.resolvconf, "-d", &record_name) + .stderr_capture() + .unchecked() .run() .chain_err(|| ErrorKind::RunResolvconf)?; |
