]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: beef up logic to detect our own configuration files
authorLennart Poettering <lennart@poettering.net>
Fri, 8 Dec 2017 16:01:47 +0000 (17:01 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 8 Dec 2017 16:25:08 +0000 (17:25 +0100)
Let's also check for the static resolv.conf, so that we filter all three
of our own files out.

src/resolve/resolved-resolv-conf.c

index f681efd00d36db6e510ece75e8268a6daf66fe10..b7c43d6ec47a0499ef37fd355aa0f4289d0addb0 100644 (file)
 #include "string-util.h"
 #include "strv.h"
 
+/* A resolv.conf file containing the DNS server and domain data we learnt from uplink, i.e. the full uplink data */
 #define PRIVATE_UPLINK_RESOLV_CONF "/run/systemd/resolve/resolv.conf"
+
+/* 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 */
+#define PRIVATE_STATIC_RESOLV_CONF ROOTLIBEXECDIR "/resolv.conf"
+
 static bool file_is_our_own(const struct stat *st) {
-        struct stat own1, own2;
+        const char *path;
 
         assert(st);
 
-        /* Is it symlinked to our own file? */
-        if (stat(PRIVATE_UPLINK_RESOLV_CONF, &own1) >= 0 &&
-            st->st_dev == own1.st_dev &&
-            st->st_ino == own1.st_ino)
-                return true;
-
-        /* Is it symlinked to our own stub file? */
-        if (stat(PRIVATE_STUB_RESOLV_CONF, &own2) >= 0 &&
-            st->st_dev == own2.st_dev &&
-            st->st_ino == own2.st_ino)
-                return true;
+        FOREACH_STRING(path,
+                       PRIVATE_UPLINK_RESOLV_CONF,
+                       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)
+                        return true;
+        }
 
         return false;
 }