]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
If reading /etc/resolv.conf fails, or finds no servers, raise NoResolverConfiguration
authorBob Halley <halley@dnspython.org>
Sat, 5 Jan 2019 14:46:29 +0000 (06:46 -0800)
committerBob Halley <halley@dnspython.org>
Sat, 5 Jan 2019 14:46:29 +0000 (06:46 -0800)
[Issue #332]

dns/resolver.py

index 74828bd18839ff98210ec791d796c54135923455..dc40efa797a75c18852d1bb094d9955ea2b54468 100644 (file)
@@ -180,6 +180,8 @@ class NoRootSOA(dns.exception.DNSException):
 class NoMetaqueries(dns.exception.DNSException):
     """DNS metaqueries are not allowed."""
 
+class NoResolverConfiguration(dns.exception.DNSException):
+    """Resolver configuration could not be read or specified no nameservers."""
 
 class Answer(object):
     """DNS stub resolver answer.
@@ -576,9 +578,7 @@ class Resolver(object):
                 f = open(f, 'r')
             except IOError:
                 # /etc/resolv.conf doesn't exist, can't be read, etc.
-                # We'll just use the default resolver configuration.
-                self.nameservers = ['127.0.0.1']
-                return
+                raise NoResolverConfiguration
             want_close = True
         else:
             want_close = False
@@ -606,7 +606,7 @@ class Resolver(object):
             if want_close:
                 f.close()
         if len(self.nameservers) == 0:
-            self.nameservers.append('127.0.0.1')
+            raise NoResolverConfiguration
 
     def _determine_split_char(self, entry):
         #