diff options
| author | Emīls Piņķis <emils@mullvad.net> | 2019-06-03 13:35:44 +0100 |
|---|---|---|
| committer | Emīls Piņķis <emils@mullvad.net> | 2019-06-03 14:40:52 +0100 |
| commit | 3a06309cfe938b0bdae5eda1b56a1a84a0abf0b3 (patch) | |
| tree | 2f38b7579db6caf7d256085fc3b0a13faa4c40cc /talpid-core/src | |
| parent | 30e54d912f9b27fb22dbd6f77eefe6081848d75b (diff) | |
| download | mullvadvpn-3a06309cfe938b0bdae5eda1b56a1a84a0abf0b3.tar.xz mullvadvpn-3a06309cfe938b0bdae5eda1b56a1a84a0abf0b3.zip | |
Fix systemd-resolved resolv.conf detection
Diffstat (limited to 'talpid-core/src')
| -rw-r--r-- | talpid-core/src/dns/linux/systemd_resolved.rs | 29 |
1 files changed, 27 insertions, 2 deletions
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)?; |
