diff options
| author | Emīls Piņķis <emils@mullvad.net> | 2019-06-03 15:06:14 +0100 |
|---|---|---|
| committer | Emīls Piņķis <emils@mullvad.net> | 2019-06-03 15:06:14 +0100 |
| commit | 520e06ad77b96ac16d0d1b38f35c4b90cec59af3 (patch) | |
| tree | 2f38b7579db6caf7d256085fc3b0a13faa4c40cc | |
| parent | 30e54d912f9b27fb22dbd6f77eefe6081848d75b (diff) | |
| parent | 3a06309cfe938b0bdae5eda1b56a1a84a0abf0b3 (diff) | |
| download | mullvadvpn-520e06ad77b96ac16d0d1b38f35c4b90cec59af3.tar.xz mullvadvpn-520e06ad77b96ac16d0d1b38f35c4b90cec59af3.zip | |
Merge branch 'fix-systemd-resolved-detection'
| -rw-r--r-- | CHANGELOG.md | 3 | ||||
| -rw-r--r-- | talpid-core/src/dns/linux/systemd_resolved.rs | 29 |
2 files changed, 30 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 91d202aeaa..b5c2b0abdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,9 @@ Line wrap the file at 100 chars. Th #### Windows - Add better offline detection +#### Linux +- Fix `systemd-resolved` detection by better compraing `/etc/resolv.conf` symlinks. + ## [2019.4] - 2019-05-08 This release is identical to 2019.4-beta1 diff --git a/talpid-core/src/dns/linux/systemd_resolved.rs b/talpid-core/src/dns/linux/systemd_resolved.rs index a633cea91e..1cd953bea6 100644 --- a/talpid-core/src/dns/linux/systemd_resolved.rs +++ b/talpid-core/src/dns/linux/systemd_resolved.rs @@ -54,7 +54,13 @@ pub enum Error { MatchDBusTypeError(#[error(cause)] dbus::arg::TypeMismatchError), } -const DYNAMIC_RESOLV_CONF_PATH: &str = "/run/systemd/resolve/resolv.conf"; +lazy_static! { + static ref RESOLVED_PATHS: Vec<&'static Path> = vec![ + Path::new("/run/systemd/resolve/stub-resolv.conf"), + Path::new("/run/systemd/resolve/resolv.conf"), + ]; +} + const RESOLVED_DNS_SERVER_ADDRESS: [u8; 4] = [127, 0, 0, 53]; const RESOLVED_BUS: &str = "org.freedesktop.resolve1"; @@ -103,7 +109,7 @@ impl SystemdResolved { fn ensure_resolv_conf_is_resolved_symlink() -> Result<()> { let is_correct_symlink = fs::read_link(RESOLV_CONF_PATH) - .map(|resolv_conf_target| resolv_conf_target == Path::new(DYNAMIC_RESOLV_CONF_PATH)) + .map(|resolv_conf_target| Self::compare_resolvconf_symlink(&resolv_conf_target)) .unwrap_or_else(|_| false); if is_correct_symlink { Ok(()) @@ -112,6 +118,25 @@ impl SystemdResolved { } } + fn compare_resolvconf_symlink(link_path: &Path) -> bool { + // if link path is relative to /etc/resolv.conf, resolve the path and compare it. + if link_path.is_relative() { + match Path::new("/etc/").join(link_path).canonicalize() { + Ok(link_destination) => RESOLVED_PATHS.contains(&link_destination.as_ref()), + Err(e) => { + log::error!( + "Failed to canonicalize resolv conf path {} - {}", + link_path.display(), + e + ); + false + } + } + } else { + RESOLVED_PATHS.contains(&link_path) + } + } + fn ensure_resolv_conf_has_resolved_dns() -> Result<()> { let resolv_conf_contents = fs::read_to_string(RESOLV_CONF_PATH).map_err(Error::ReadResolvConfFailed)?; |
