Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass partial answer to NXDOMAIN exception #100

Closed
cluck opened this issue May 26, 2015 · 2 comments
Closed

Pass partial answer to NXDOMAIN exception #100

cluck opened this issue May 26, 2015 · 2 comments

Comments

@cluck
Copy link
Contributor

cluck commented May 26, 2015

When an NXDOMAIN is raised in dns.resolver.Resolver.query() the implementor should still have access to the partial result, specifically to find out a dangling CNAME. This is useful for example when chasing the right PTR record to update for a given IP Address (FreeIPA #5033). I propose to construct an Anwer object also for NXDOMAIN exceptions:

--- dns/resolver.py.2   2015-05-26 14:12:13.658045246 +0200
+++ dns/resolver.py 2015-05-26 15:31:26.459862822 +0200
@@ -44,7 +44,8 @@
     import _winreg

 class NXDOMAIN(dns.exception.DNSException):
-    """The query name does not exist."""
+    """The query name does not exist.
+    The Exception argument is the partial answer."""
     pass

 class YXDOMAIN(dns.exception.DNSException):
@@ -907,7 +908,9 @@
             all_nxdomain = False
             break
         if all_nxdomain:
-            raise NXDOMAIN
+            answer = Answer(qnames_to_try[0], rdtype, rdclass,
+                            response, False)
+            raise NXDOMAIN(answer)
         answer = Answer(qname, rdtype, rdclass, response,
                         raise_on_no_answer)
         if self.cache:
@cluck cluck changed the title Pass partial result to NXRESULT exception Pass partial answer to NXRESULT exception May 26, 2015
@cluck cluck changed the title Pass partial answer to NXRESULT exception Pass partial answer to NXDOMAIN exception May 26, 2015
@spacekpe
Copy link

I generally like the idea but it needs to be polished.

@cluck , beware - the answer might really surprise you if search list in resolv.conf is non-empty. This needs to be carefully tested and documented because search lists make it quite complicated.

Another thing is that raise NXDOMAIN() should use a keyword argument to pass answer to it, please see class NXDOMAIN definition in resolver.py.

Thank you for the idea and your time, @cluck!

@cluck
Copy link
Contributor Author

cluck commented Jun 13, 2016

This is implemented in pull request #109 which is waiting since one year now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants