diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-10-11 15:07:27 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-10-11 15:10:31 -0300 |
| commit | 5e6a3e1195ea2a106be7ce9693dc42f3c16516f7 (patch) | |
| tree | 0329f4bc95156c44d3411438943e326c0c462fc8 | |
| parent | 8ec80b7009dd97d93aed5c4989edca6e46db5280 (diff) | |
| download | mullvadvpn-5e6a3e1195ea2a106be7ce9693dc42f3c16516f7.tar.xz mullvadvpn-5e6a3e1195ea2a106be7ce9693dc42f3c16516f7.zip | |
Check resolve.conf for systemd-resolved DNS server
| -rw-r--r-- | talpid-core/src/security/linux/dns/systemd_resolved.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/talpid-core/src/security/linux/dns/systemd_resolved.rs b/talpid-core/src/security/linux/dns/systemd_resolved.rs index 72743d8913..78e55a048b 100644 --- a/talpid-core/src/security/linux/dns/systemd_resolved.rs +++ b/talpid-core/src/security/linux/dns/systemd_resolved.rs @@ -14,6 +14,7 @@ use self::dbus::{BusType, Interface, Member, MessageItem, MessageItemArray, Sign use super::super::iface_index; use super::{resolv_conf, RESOLV_CONF_PATH}; + error_chain! { errors { NoSystemdResolved { @@ -42,6 +43,8 @@ error_chain! { } const DYNAMIC_RESOLV_CONF_PATH: &str = "/run/systemd/resolve/resolv.conf"; +const RESOLVED_DNS_SERVER_ADDRESS: [u8; 4] = [127, 0, 0, 53]; + const RESOLVED_BUS: &str = "org.freedesktop.resolve1"; const RPC_TIMEOUT_MS: i32 = 1000; @@ -86,7 +89,7 @@ impl SystemdResolved { fn ensure_resolved_is_active() -> Result<()> { ensure!( - Self::resolv_conf_is_resolved_symlink(), + Self::resolv_conf_is_resolved_symlink() || Self::resolv_conf_has_resolved_dns()?, ErrorKind::NoSystemdResolved ); @@ -99,6 +102,20 @@ impl SystemdResolved { .unwrap_or_else(|_| false) } + fn resolv_conf_has_resolved_dns() -> Result<bool> { + let resolv_conf_contents = + fs::read_to_string(RESOLV_CONF_PATH).chain_err(|| ErrorKind::NoSystemdResolved)?; + let parsed_resolv_conf = resolv_conf::Config::parse(resolv_conf_contents) + .chain_err(|| ErrorKind::NoSystemdResolved)?; + let resolved_dns_server = + resolv_conf::ScopedIp::V4(Ipv4Addr::from(RESOLVED_DNS_SERVER_ADDRESS)); + + Ok(parsed_resolv_conf + .nameservers + .into_iter() + .any(|nameserver| nameserver == resolved_dns_server)) + } + fn as_manager_object<'a>(&'a self) -> dbus::ConnPath<'a, &'a dbus::Connection> { self.dbus_connection .with_path(RESOLVED_BUS, "/org/freedesktop/resolve1", RPC_TIMEOUT_MS) |
