]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolve: warn when our stub listener is disabled but resolv.conf uses it
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 28 Jun 2018 06:01:28 +0000 (15:01 +0900)
committerLennart Poettering <lennart@poettering.net>
Thu, 28 Jun 2018 08:06:15 +0000 (10:06 +0200)
Closes #9450.

src/resolve/resolved-resolv-conf.c
src/resolve/resolved-resolv-conf.h
src/resolve/resolved.c

index 5a022507c99a2f3933f07e0f67aae85cf8ec9882..edad569acde9d9c3050715fbf0e6f8e14842f1a7 100644 (file)
 /* A resolv.conf file containing the domain data we learnt from uplink, but our own DNS server address. */
 #define PRIVATE_STUB_RESOLV_CONF "/run/systemd/resolve/stub-resolv.conf"
 
-/* A static resolv.conf file containing no domains, but only our own DNS sever address */
+/* A static resolv.conf file containing no domains, but only our own DNS server address */
 #define PRIVATE_STATIC_RESOLV_CONF ROOTLIBEXECDIR "/resolv.conf"
 
+int manager_check_resolv_conf(const Manager *m) {
+        const char *path;
+        struct stat st;
+        int r;
+
+        assert(m);
+
+        /* This warns only when our stub listener is disabled and /etc/resolv.conf is a symlink to
+         * PRIVATE_STATIC_RESOLV_CONF or PRIVATE_STUB_RESOLV_CONF. */
+
+        if (m->dns_stub_listener_mode != DNS_STUB_LISTENER_NO)
+                return 0;
+
+        r = stat("/etc/resolv.conf", &st);
+        if (r < 0) {
+                if (errno == ENOENT)
+                        return 0;
+
+                return log_warning_errno(errno, "Failed to stat /etc/resolv.conf: %m");
+        }
+
+        FOREACH_STRING(path,
+                       PRIVATE_STUB_RESOLV_CONF,
+                       PRIVATE_STATIC_RESOLV_CONF) {
+
+                struct stat own;
+
+                /* Is it symlinked to our own uplink file? */
+                if (stat(path, &own) >= 0 &&
+                    st.st_dev == own.st_dev &&
+                    st.st_ino == own.st_ino) {
+                        log_warning("In spite of DNSStubListner= is disabled, /etc/resolv.conf is a symlink to %s, "
+                                    "which expects DNSStubListner= is enabled.", path);
+                        return -EOPNOTSUPP;
+                }
+        }
+
+        return 0;
+}
+
 static bool file_is_our_own(const struct stat *st) {
         const char *path;
 
index 105ae4cae82634d2e0bad2c42e16584ab427539f..e60beb40b77a3124c9fa9b5678543309dc0ff829 100644 (file)
@@ -4,5 +4,6 @@
 
 #include "resolved-manager.h"
 
+int manager_check_resolv_conf(const Manager *m);
 int manager_read_resolv_conf(Manager *m);
 int manager_write_resolv_conf(Manager *m);
index c01e53e9daf717c2a1624634dd08644eee862d41..6ff56bc974904fe75096ea1b81d8695841f5a3ea 100644 (file)
@@ -80,6 +80,8 @@ int main(int argc, char *argv[]) {
         /* Write finish default resolv.conf to avoid a dangling symlink */
         (void) manager_write_resolv_conf(m);
 
+        (void) manager_check_resolv_conf(m);
+
         /* Let's drop the remaining caps now */
         r = capability_bounding_set_drop(0, true);
         if (r < 0) {