Bug 9485 - DNS server does not support MX queries
Summary: DNS server does not support MX queries
Status: RESOLVED FIXED
Alias: None
Product: Samba 4.0
Classification: Unclassified
Component: DNS server (show other bugs)
Version: 4.0.0rc6
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Karolin Seeger
QA Contact: Samba QA Contact
URL:
Keywords:
: 9958 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-12-09 19:47 UTC by Kai Blin
Modified: 2013-06-18 10:34 UTC (History)
6 users (show)

See Also:


Attachments
Implement MX query support (3.25 KB, patch)
2012-12-09 19:53 UTC, Kai Blin
metze: review-
Details
Fix for dns tests (1.28 KB, patch)
2013-04-12 08:32 UTC, Amitay Isaacs
no flags Details
Updated patch adding MX support, for v4-0-test (3.22 KB, patch)
2013-05-17 10:03 UTC, Kai Blin
amitay: review+
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kai Blin 2012-12-09 19:47:47 UTC
The internal DNS server misses the code to handle MX queries, but supports MX updates.
Comment 1 Kai Blin 2012-12-09 19:53:11 UTC
Created attachment 8314 [details]
Implement MX query support
Comment 2 Karolin Seeger 2012-12-09 20:12:39 UTC
Should this one be included in the final release or does the first bugfix release make more sense?
Comment 3 Stefan Metzmacher 2012-12-10 08:03:59 UTC
Comment on attachment 8314 [details]
Implement MX query support

It fails autobuild with:

[1407/1555 in 1h10m10s] samba.tests.dns(fl2003dc)
UNEXPECTED(failure): samba.tests.dns.TestDNSUpdates.test_update_add_mx_record
REASON: _StringException: Content-Type: text/x-traceback;charset=utf8,language=python
traceback
127
Traceback (most recent call last):
  File "/memdisk/mat/a/b899184/samba/bin/python/samba/tests/dns.py", line 553, in test_update_add_mx_record
    self.assertEqual(response.answers[0].rdata.exchange, 'mail.%s' % self.get_dns_domain())
MismatchError: '@\xc74\x02' != 'mail.samba2003.example.com'
0

FAILED (1 failures, 0 errors and 0 unexpected successes in 0 testsuites)

A summary with detailed information can be found in:
  ./bin/ab/summary
ERROR: test failed with exit code 1
Comment 4 Kai Blin 2013-01-17 12:52:27 UTC
I still don't understand what's going on there. No garbage in that piece of memory on my system. :(
Comment 5 Amitay Isaacs 2013-04-12 08:32:09 UTC
Created attachment 8767 [details]
Fix for dns tests
Comment 6 Amitay Isaacs 2013-04-12 08:32:57 UTC
With the attached patch (Fix for dns tests) all the DNS tests now pass.
Comment 7 Guenter Kukkukk 2013-04-16 04:18:29 UTC
Here on a 32Bit system, it's _not_ fixed!
(i'm using Amitay's recent patch)

I'm not sure whether 32 vs 64 Bit plays a role here.

Kai has added some ndrdump/hexdump features - see latest commits in:
https://git.samba.org/?p=kai/samba.git;a=shortlog;h=refs/heads/master

When using it, i get:
   make test TESTS=samba.tests.dns
....
samba: EOF on stdin - terminating
    dns_name_packet: struct dns_name_packet
        id                       : 0x2a06 (10758)
        operation                : 0x2800 (10240)
            0x00: DNS_RCODE                 (0)
               0: DNS_FLAG_BROADCAST       
               0: DNS_FLAG_RECURSION_AVAIL 
               0: DNS_FLAG_RECURSION_DESIRED
               0: DNS_FLAG_TRUNCATION      
               0: DNS_FLAG_AUTHORITATIVE   
            0x05: DNS_OPCODE                (5)
               0: DNS_FLAG_REPLY           
        qdcount                  : 0x0001 (1)
        ancount                  : 0x0000 (0)
        nscount                  : 0x0001 (1)
        arcount                  : 0x0000 (0)
        questions: ARRAY(1)
            questions: struct dns_name_question
                name                     : 'samba2003.example.com'
                question_type            : DNS_QTYPE_SOA (0x6)
                question_class           : DNS_QCLASS_IN (0x1)
        answers: ARRAY(0)
        nsrecs: ARRAY(1)
            nsrecs: struct dns_res_rec
                name                     : 'samba2003.example.com'
                rr_type                  : DNS_QTYPE_MX (0xF)
                rr_class                 : DNS_QCLASS_IN (0x1)
                ttl                      : 0x00000384 (900)
                length                   : 0xffff (65535)
                rdata                    : union dns_rdata(case 0xF)
                mx_record: struct dns_mx_record
                    preference               : 0x000a (10)
                    exchange                 : ''
                unexpected               : DATA_BLOB length=0
        additional: ARRAY(0)

0000   2A 06 28 00 00 01 00 00    *.(.....
0008   00 01 00 00 09 73 61 6D    .....sam
0010   62 61 32 30 30 33 07 65    ba2003.e
0018   78 61 6D 70 6C 65 03 63    xample.c
0020   6F 6D 00 00 06 00 01 C0    om......
0028   0C 00 0F 00 01 00 00 03    ........
0030   84 00 05 00 0A 01 03 00    ........

0000   2A 06 A8 00 00 01 00 00    *.......
0008   00 01 00 00 09 73 61 6D    .....sam
0010   62 61 32 30 30 33 07 65    ba2003.e
0018   78 61 6D 70 6C 65 03 63    xample.c
0020   6F 6D 00 00 06 00 01 C0    om......
0028   0C 00 0F 00 01 00 00 03    ........
0030   84 00 05 00 0A 01 03 00    ........

    dns_name_packet: struct dns_name_packet
        id                       : 0x2a06 (10758)
        operation                : 0xa800 (43008)
            0x00: DNS_RCODE                 (0)
               0: DNS_FLAG_BROADCAST       
               0: DNS_FLAG_RECURSION_AVAIL 
               0: DNS_FLAG_RECURSION_DESIRED
               0: DNS_FLAG_TRUNCATION      
               0: DNS_FLAG_AUTHORITATIVE   
            0x05: DNS_OPCODE                (5)
               1: DNS_FLAG_REPLY           
        qdcount                  : 0x0001 (1)
        ancount                  : 0x0000 (0)
        nscount                  : 0x0001 (1)
        arcount                  : 0x0000 (0)
        questions: ARRAY(1)
            questions: struct dns_name_question
                name                     : 'samba2003.example.com'
                question_type            : DNS_QTYPE_SOA (0x6)
                question_class           : DNS_QCLASS_IN (0x1)
        answers: ARRAY(0)
        nsrecs: ARRAY(1)
            nsrecs: struct dns_res_rec
                name                     : 'samba2003.example.com'
                rr_type                  : DNS_QTYPE_MX (0xF)
                rr_class                 : DNS_QCLASS_IN (0x1)
                ttl                      : 0x00000384 (900)
                length                   : 0x0005 (5)
                rdata                    : union dns_rdata(case 0xF)
                mx_record: struct dns_mx_record
                    preference               : 0x000a (10)
                    exchange                 : ''
                unexpected               : DATA_BLOB length=0
        additional: ARRAY(0)
........
Traceback (most recent call last):
  File "/home/gk/samba/master/bin/python/samba/tests/dns.py", line 583, in test_update_add_mx_record
    self.assertEqual(ans.rdata.exchange, 'mail.%s.' % self.get_dns_domain())
MismatchError: '\x03' != 'mail.samba2003.example.com.'
-----

The "exchange" string is just random here...

Is it an IDL/ndr problem? (using 32 vs 64 Bit) ?

I'll also dig deeper....

Cheers, Günter

(btw - i've modified dns.py - so line numbers cannot match ..)
Comment 8 Kai Blin 2013-04-16 09:28:47 UTC
(In reply to comment #6)
> With the attached patch (Fix for dns tests) all the DNS tests now pass.

I'm not quite sure how that actually fixes the "garbage in memory" problem.
I've never seen a test fail because None was returned from the dns_transaction_udp() function.
Comment 9 Amitay Isaacs 2013-04-17 14:01:28 UTC
Sorry, that was a false alarm.  Apparently it's the debug statements which I added, that made the test work. Go figure! :) And worst thing is if I remove any of those statements the tests fail. (Of course I haven't tried all permutations, but it's definitely weird.)

--- a/python/samba/tests/dns.py
+++ b/python/samba/tests/dns.py
@@ -547,6 +547,10 @@ class TestDNSUpdates(DNSTest):
 
         self.finish_name_packet(p, questions)
         response = self.dns_transaction_udp(p)
+        print response
+        print dir(response)
+        print response.answers
+        print dir(response.answers)
         self.assert_dns_rcode_equals(response, dns.DNS_RCODE_OK)
         self.assertEqual(response.ancount, 1)
         self.assertEqual(response.answers[0].rdata.preference, 10)

I have had some problems when working with python NDR generated code.  Specially when trying to set string values for C strings from python.  As soon as the python variable went out of scope, the memory got corrupted.  May be it's a similar issue.  I had to maintain a copy of the string as long as the C structure was in use.
Comment 10 Guenter Kukkukk 2013-04-23 02:17:16 UTC
Amitay,

your comment in our 2nd dns.py (here more samba-tool related):
  - python/samba/netcmd/dns.py
....
#
# Always create a copy of strings when creating DNS_RPC_RECORDs
# to overcome the bug in pidl generated python bindings.
#
....
should have already "ring some bells" to other developers.

Here python code is implementing some "kind of workaround",
not solving the real problem ...

Back to
   - python/samba/tests/dns.py
when adding some debug info:
....
        r.rdata = dns.mx_record()
        r.rdata.preference = 10
        r.rdata.exchange = 'mail.%s.' % self.get_dns_domain()

        print 'GK0: "%s"' % r.rdata.exchange
        updates.append(r)
        print 'GK1: "%s"' % r.rdata.exchange
        p.nscount = len(updates)
        p.nsrecs = updates

        print 'GK2: "%s"' % r.rdata.exchange
        print ndr.ndr_print(p)
        print 'GK3: "%s"' % r.rdata.exchange

        response = self.dns_transaction_udp(p, dump=True)
 ....

result:
GK0: "mail.samba2003.example.com."
GK1: "mail.samba2003.example.com."
GK2: "mail.samba2003.example.com."
    dns_name_packet: struct dns_name_packet
        id                       : 0x8c31 (35889)
.... snip
        nsrecs: ARRAY(1)
            nsrecs: struct dns_res_rec
                name                     : 'samba2003.example.com'
                rr_type                  : DNS_QTYPE_MX (0xF)
                rr_class                 : DNS_QCLASS_IN (0x1)
                ttl                      : 0x00000384 (900)
                length                   : 0xffff (65535)
                rdata                    : union dns_rdata(case 0xF)
                mx_record: struct dns_mx_record
                    preference               : 0x000a (10)
                    exchange                 : ''
                unexpected               : DATA_BLOB length=0
        additional: ARRAY(0)

GK3: ""   <--- already corrupted here!
....
librpc/ndr/ndr_dns.* might play some role here.

... or some related python bindings ?

I'm still debugging this one...

Cheers, Günter
Comment 11 Guenter Kukkukk 2013-05-04 15:24:13 UTC
All I can say is "that the python string used here
looks like random", any new python (debug) statement just
changes it....

Jelmer noted, that
https://bugzilla.samba.org/show_bug.cgi?id=7902
might be related here.

The MX query fix is out since December 2012, but due to
this not working testcase it isn't applied.

What can we do here ?

Cheers, Günter
Comment 12 Kai Blin 2013-05-17 10:03:43 UTC
Created attachment 8903 [details]
Updated patch adding MX support, for v4-0-test

Here's the updated patch that still fixes the issue and also passes the test
Comment 13 Amitay Isaacs 2013-05-17 10:07:37 UTC
Karolin, please pick this for next release.
Comment 14 Karolin Seeger 2013-05-27 11:56:58 UTC
Pushed to autobuild-v4-0-test.
Comment 15 Karolin Seeger 2013-05-29 09:41:58 UTC
Pushed to v4-0-test.
Closing out bug report.

Thanks!
Comment 16 Kai Blin 2013-06-18 10:34:41 UTC
*** Bug 9958 has been marked as a duplicate of this bug. ***