From 2a098030977d7720436b7850fa731557eeb70bc2 Mon Sep 17 00:00:00 2001 From: Matthew Grant Date: Sat, 18 Sep 2021 10:05:24 +1200 Subject: [PATCH] libcli/dns.c: dns forwarder port test changes Test harness for the dns fowarder setting in smb.conf. Adds IPv6 forwarder as second target DNS forwarder, listening on port 54. Signed-off-by: Matthew Grant Reviewed-by: Uri Simchoni Reviewed-by: Andrew Bartlett --- python/samba/tests/dns_forwarder.py | 17 +++++++++++------ .../samba/tests/dns_forwarder_helpers/server.py | 10 +++++++++- selftest/target/Samba4.pm | 4 ++-- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/python/samba/tests/dns_forwarder.py b/python/samba/tests/dns_forwarder.py index 62cda9ce178..42995d1f2aa 100644 --- a/python/samba/tests/dns_forwarder.py +++ b/python/samba/tests/dns_forwarder.py @@ -31,6 +31,8 @@ import samba.getopt as options import optparse import subprocess +DNS_PORT2 = 54 + parser = optparse.OptionParser("dns_forwarder.py (dns forwarder)+ [options]") sambaopts = options.SambaOptions(parser) parser.add_option_group(sambaopts) @@ -173,7 +175,10 @@ class TestDnsForwarding(DNSTest): 'dns_forwarder_helpers/server.py'), host, str(port), id]) self.subprocesses.append(p) - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0) + if (host.find(':') != -1): + s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM, 0) + else: + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0) for i in range(300): time.sleep(0.05) s.connect((host, port)) @@ -349,7 +354,7 @@ class TestDnsForwarding(DNSTest): print("Ignoring test_double_forwarder_first_frozen") return s1 = self.start_toy_server(dns_servers[0], 53, 'forwarder1') - s2 = self.start_toy_server(dns_servers[1], 53, 'forwarder2') + s2 = self.start_toy_server(dns_servers[1], DNS_PORT2, 'forwarder2') s1.send(b'timeout 1000', 0) ad = contact_real_server(server_ip, 53) name = "dsfsfds.dsfsdfs" @@ -378,7 +383,7 @@ class TestDnsForwarding(DNSTest): if len(dns_servers) < 2: print("Ignoring test_double_forwarder_first_down") return - s2 = self.start_toy_server(dns_servers[1], 53, 'forwarder2') + s2 = self.start_toy_server(dns_servers[1], DNS_PORT2, 'forwarder2') ad = contact_real_server(server_ip, 53) name = "dsfsfds.dsfsdfs" p = self.make_name_packet(dns.DNS_OPCODE_QUERY) @@ -407,7 +412,7 @@ class TestDnsForwarding(DNSTest): print("Ignoring test_double_forwarder_both_slow") return s1 = self.start_toy_server(dns_servers[0], 53, 'forwarder1') - s2 = self.start_toy_server(dns_servers[1], 53, 'forwarder2') + s2 = self.start_toy_server(dns_servers[1], DNS_PORT2, 'forwarder2') s1.send(b'timeout 1.5', 0) s2.send(b'timeout 1.5', 0) ad = contact_real_server(server_ip, 53) @@ -493,7 +498,7 @@ class TestDnsForwarding(DNSTest): print("Ignoring test_cname_forwarding_with_slow_server") return s1 = self.start_toy_server(dns_servers[0], 53, 'forwarder1') - s2 = self.start_toy_server(dns_servers[1], 53, 'forwarder2') + s2 = self.start_toy_server(dns_servers[1], DNS_PORT2, 'forwarder2') s1.send(b'timeout 10000', 0) name = 'resolve.cname.%s' % self.get_dns_domain() @@ -525,7 +530,7 @@ class TestDnsForwarding(DNSTest): if len(dns_servers) < 2: print("Ignoring test_cname_forwarding_with_server_down") return - s2 = self.start_toy_server(dns_servers[1], 53, 'forwarder2') + s2 = self.start_toy_server(dns_servers[1], DNS_PORT2, 'forwarder2') name1 = 'resolve1.cname.%s' % self.get_dns_domain() name2 = 'resolve2.cname.%s' % self.get_dns_domain() diff --git a/python/samba/tests/dns_forwarder_helpers/server.py b/python/samba/tests/dns_forwarder_helpers/server.py index 5637b42a37e..f6feb0bb690 100644 --- a/python/samba/tests/dns_forwarder_helpers/server.py +++ b/python/samba/tests/dns_forwarder_helpers/server.py @@ -19,6 +19,7 @@ # Based on the EchoServer example from python docs import socketserver as SocketServer +import socket import sys from threading import Timer from samba.dcerpc import dns @@ -85,11 +86,18 @@ class DnsHandler(SocketServer.BaseRequestHandler): t = Timer(timeout, self.really_handle, [data, socket]) t.start() +class TestUDPServer(SocketServer.UDPServer): + def __init__(self, server_address, RequestHandlerClass): + if server_address[0].find(':') != -1: + self.address_family = socket.AF_INET6 + else: + self.address_family = socket.AF_INET + super(SocketServer.UDPServer, self).__init__(server_address, RequestHandlerClass) def main(): global SERVER_ID host, port, SERVER_ID = sys.argv[1:] - server = SocketServer.UDPServer((host, int(port)), DnsHandler) + server = TestUDPServer((host, int(port)), DnsHandler) server.serve_forever() diff --git a/selftest/target/Samba4.pm b/selftest/target/Samba4.pm index cb462794df6..a4f1043ec51 100755 --- a/selftest/target/Samba4.pm +++ b/selftest/target/Samba4.pm @@ -1675,13 +1675,13 @@ sub provision_fl2003dc($$$) { my ($self, $prefix, $dcvars) = @_; my $ip_addr1 = Samba::get_ipv4_addr("fakednsforwarder1"); - my $ip_addr2 = Samba::get_ipv4_addr("fakednsforwarder2"); + my $ip_addr2 = Samba::get_ipv6_addr("fakednsforwarder2"); print "PROVISIONING DC WITH FOREST LEVEL 2003...\n"; my $extra_conf_options = "allow dns updates = nonsecure and secure dcesrv:header signing = no dcesrv:max auth states = 0 - dns forwarder = $ip_addr1 $ip_addr2"; + dns forwarder = $ip_addr1 [$ip_addr2]:54"; my $extra_provision_options = ["--base-schema=2008_R2"]; my $ret = $self->provision($prefix, "domain controller",