[SCM] Samba Shared Repository - branch master updated

Andrew Bartlett abartlet at samba.org
Wed Mar 6 00:49:03 UTC 2019


The branch, master has been updated
       via  1d5583c9131 dns_hub: Add some debug as to what DNS proxying is happening
       via  2cd65a7a4e7 dns_hub: Minor variable rename
       via  327ed9758ab selftest: Map realm to IP address (instead of iface)
       via  cbcd4f8f007 selftest: Pass realm-to-IP mapping to dns_hub as an argument
       via  d6d8ecb5960 selftest: Split out dns_hub's testenv realm-to-IP logic
       via  90ea8c2a99c selftest: Try to tie dns_hub IP mapping to Samba.pm better
       via  d1e145d644c selftest: Cleanup Samba.pm iface mapping
       via  2b60936d912 selftest: Avoid hard-coding client IP address
       via  572f83d62a5 selftest: dns_hub doesn't need to store $swiface
       via  5e09d392115 selftest: Add helper functions to get IP addresses
      from  6a7dd7ab510 tests: Reduce likelihood of auth_log test locking up during CI

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 1d5583c913175ab6a8c44c0f564232195c2c307f
Author: Tim Beale <timbeale at catalyst.net.nz>
Date:   Wed Feb 20 16:51:14 2019 +1300

    dns_hub: Add some debug as to what DNS proxying is happening
    
    This should make it clear at run-time how dns_hub is actually proxying
    DNS requests, which will hopefully aid in debugging problems (i.e.
    forgetting to add a mapping when adding a new DNS realm).
    
    Signed-off-by: Tim Beale <timbeale at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    
    Autobuild-User(master): Andrew Bartlett <abartlet at samba.org>
    Autobuild-Date(master): Wed Mar  6 00:48:43 UTC 2019 on sn-devel-144

commit 2cd65a7a4e7a767ebb9c1b68ba8b3d88797a2165
Author: Tim Beale <timbeale at catalyst.net.nz>
Date:   Wed Feb 20 16:41:47 2019 +1300

    dns_hub: Minor variable rename
    
    We've dropped the iface logic now - this dictionary maps from
    realm-to-IP.
    
    Signed-off-by: Tim Beale <timbeale at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 327ed9758abe29b3f01371bbcb9fb424737835b7
Author: Tim Beale <timbeale at catalyst.net.nz>
Date:   Wed Feb 20 16:34:23 2019 +1300

    selftest: Map realm to IP address (instead of iface)
    
    The code is more readable if the hashmap translates between realm and
    DC-name, rather than realm-to-iface. We already have a function to map
    between DC-name and iface (and since we're doing this, we might as well
    map straight to IP address).
    
    Signed-off-by: Tim Beale <timbeale at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit cbcd4f8f007878ac795046a6f576bba0d009d59f
Author: Tim Beale <timbeale at catalyst.net.nz>
Date:   Wed Feb 20 16:09:54 2019 +1300

    selftest: Pass realm-to-IP mapping to dns_hub as an argument
    
    Instead of storing hashmaps in 2 different files, we can just convert a
    perl hashmap into a string, pass it to dns_hub, and convert it back into
    a python dictionary.
    
    The main reason for doing this is the IP-to-testenv mapping now all
    lives in a single file (Samba.pm). All this logic is right next to each
    other rather than being split across multiple files. Hopefully this will
    make it easier to keep it up to date as we add new testenvs.
    
    Signed-off-by: Tim Beale <timbeale at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit d6d8ecb59606eaee6b25de8639269e0c08e746c6
Author: Tim Beale <timbeale at catalyst.net.nz>
Date:   Thu Feb 14 17:36:40 2019 +1300

    selftest: Split out dns_hub's testenv realm-to-IP logic
    
    Add a separate helper function, as the realm-to-IPv4-addr logic is
    fairly self-contained.
    
    Signed-off-by: Tim Beale <timbeale at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 90ea8c2a99c1feb1c6f789d53f2f97eb0f8175e2
Author: Tim Beale <timbeale at catalyst.net.nz>
Date:   Thu Feb 14 15:38:54 2019 +1300

    selftest: Try to tie dns_hub IP mapping to Samba.pm better
    
    dns_hub.py maps the testenv realm to an IP and Samba.pm maps the testenv
    NetBIOS name to an IP. We need to keep the two places consistent, as we
    add or remove testenvs.
    
    This patch changes dns_hub.py so that it uses a similar hashmap to
    Samba.pm. We now have a hashmap with the same name in 2 different
    places, so hopefully that's easier to tie them together and keep them in
    sync.
    
    Signed-off-by: Tim Beale <timbeale at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit d1e145d644ca15beb4e59213d570922b1dc8881e
Author: Tim Beale <timbeale at catalyst.net.nz>
Date:   Thu Feb 14 16:19:50 2019 +1300

    selftest: Cleanup Samba.pm iface mapping
    
    It looks a bit cleaner if we declare the hash-map in one go, rather than
    adding each entry one at a time. Also added a comment explaining what
    the hash-map is for, and fixed up tab vs spaces inconsistencies.
    
    Signed-off-by: Tim Beale <timbeale at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 2b60936d91268688db8344dfee68766b6494c604
Author: Tim Beale <timbeale at catalyst.net.nz>
Date:   Thu Feb 14 14:37:16 2019 +1300

    selftest: Avoid hard-coding client IP address
    
    We implicitly assume the client IP used by selftest is always
    127.0.0.11. Add an iface entry for the client to make this a little more
    explicit.
    
    Signed-off-by: Tim Beale <timbeale at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 572f83d62a5853634dfa79669393a70d9ce20731
Author: Tim Beale <timbeale at catalyst.net.nz>
Date:   Wed Feb 13 14:21:16 2019 +1300

    selftest: dns_hub doesn't need to store $swiface
    
    dns_hub doesn't need to store $ctx->{swiface}. Other testenvs store this
    and export it as SOCKET_WRAPPER_DEFAULT_IFACE (i.e. for the tests to
    use), but dns_hub doesn't need to do this.
    
    Signed-off-by: Tim Beale <timbeale at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 5e09d392115f2c1655cc0902a940723d9d5b9065
Author: Tim Beale <timbeale at catalyst.net.nz>
Date:   Tue Feb 19 16:18:11 2019 +1300

    selftest: Add helper functions to get IP addresses
    
    Let's centralize these assumptions in one place.
    
    Signed-off-by: Tim Beale <timbeale at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 selftest/target/Samba.pm   | 168 ++++++++++++++++++++++++++++++---------------
 selftest/target/Samba3.pm  |   4 +-
 selftest/target/Samba4.pm  |  26 +++----
 selftest/target/dns_hub.py |  56 ++++++++-------
 4 files changed, 158 insertions(+), 96 deletions(-)


Changeset truncated at 500 lines:

diff --git a/selftest/target/Samba.pm b/selftest/target/Samba.pm
index d74a4438ba4..324e1bfb90d 100644
--- a/selftest/target/Samba.pm
+++ b/selftest/target/Samba.pm
@@ -385,65 +385,121 @@ sub mk_mitkdc_conf($$)
 	close(KDCCONF);
 }
 
+sub realm_to_ip_mappings
+{
+	# this maps the DNS realms for the various testenvs to the corresponding
+	# PDC (i.e. the first DC created for that realm).
+	my %realm_to_pdc_mapping = (
+		'adnonssdom.samba.example.com'    => 'addc_no_nss',
+		'adnontlmdom.samba.example.com'   => 'addc_no_ntlm',
+		'samba2000.example.com'           => 'dc5',
+		'samba2003.example.com'           => 'dc6',
+		'samba2008r2.example.com'         => 'dc7',
+		'addom.samba.example.com'         => 'addc',
+		'sub.samba.example.com'           => 'localsubdc',
+		'chgdcpassword.samba.example.com' => 'chgdcpass',
+		'backupdom.samba.example.com'     => 'backupfromdc',
+		'renamedom.samba.example.com'     => 'renamedc',
+		'labdom.samba.example.com'        => 'labdc',
+		'samba.example.com'               => 'localdc',
+	);
+
+	my @mapping = ();
+
+	# convert the hashmap to a list of key=value strings, where key is the
+	# realm and value is the IP address
+	while (my ($realm, $pdc) = each(%realm_to_pdc_mapping)) {
+		my $ipaddr = get_ipv4_addr($pdc);
+		push(@mapping, "$realm=$ipaddr");
+	}
+	# return the mapping as a single comma-separated string
+	return join(',', @mapping);
+}
+
 sub get_interface($)
 {
-    my ($netbiosname) = @_;
-    $netbiosname = lc($netbiosname);
-
-    my %interfaces = ();
-    $interfaces{"localnt4dc2"} = 3;
-    $interfaces{"localnt4member3"} = 4;
-    $interfaces{"localshare4"} = 5;
-
-    $interfaces{"localktest6"} = 7;
-    $interfaces{"maptoguest"} = 8;
-    $interfaces{"localnt4dc9"} = 9;
-
-    # 11-16 used by selftest.pl for client interfaces
-
-    $interfaces{"addc_no_nss"} = 17;
-    $interfaces{"addc_no_ntlm"} = 18;
-    $interfaces{"idmapadmember"} = 19;
-    $interfaces{"idmapridmember"} = 20;
-    $interfaces{"localdc"} = 21;
-    $interfaces{"localvampiredc"} = 22;
-    $interfaces{"s4member"} = 23;
-    $interfaces{"localrpcproxy"} = 24;
-    $interfaces{"dc5"} = 25;
-    $interfaces{"dc6"} = 26;
-    $interfaces{"dc7"} = 27;
-    $interfaces{"rodc"} = 28;
-    $interfaces{"localadmember"} = 29;
-    $interfaces{"addc"} = 30;
-    $interfaces{"localsubdc"} = 31;
-    $interfaces{"chgdcpass"} = 32;
-    $interfaces{"promotedvdc"} = 33;
-    $interfaces{"rfc2307member"} = 34;
-    $interfaces{"fileserver"} = 35;
-    $interfaces{"fakednsforwarder1"} = 36;
-    $interfaces{"fakednsforwarder2"} = 37;
-    $interfaces{"s4member_dflt"} = 38;
-    $interfaces{"vampire2000dc"} = 39;
-    $interfaces{"backupfromdc"} = 40;
-    $interfaces{"restoredc"} = 41;
-    $interfaces{"renamedc"} = 42;
-    $interfaces{"labdc"} = 43;
-    $interfaces{"offlinebackupdc"} = 44;
-    $interfaces{"customdc"} = 45;
-    $interfaces{"prockilldc"} = 46;
-    $interfaces{"proclimitdc"} = 47;
-
-    $interfaces{"rootdnsforwarder"} = 64;
-
-    # update lib/socket_wrapper/socket_wrapper.c
-    #  #define MAX_WRAPPED_INTERFACES 64
-    # if you wish to have more than 64 interfaces
-
-    if (not defined($interfaces{$netbiosname})) {
-	die();
-    }
+	my ($netbiosname) = @_;
+	$netbiosname = lc($netbiosname);
+
+	# this maps the SOCKET_WRAPPER_DEFAULT_IFACE value for each possible
+	# testenv to the DC's NETBIOS name. This value also corresponds to last
+	# digit of the DC's IP address. Note that the NETBIOS name may differ from
+	# the testenv name.
+	# Note that when adding a DC with a new realm, also update
+	# get_realm_ip_mappings() above.
+	my %testenv_iface_mapping = (
+		localnt4dc2       => 3,
+		localnt4member3   => 4,
+		localshare4       => 5,
+		# 6 is spare
+		localktest6       => 7,
+		maptoguest        => 8,
+		localnt4dc9       => 9,
+		# 10 is spare
+
+		# 11-16 used by selftest.pl for client interfaces
+		client            => 11,
+
+		addc_no_nss       => 17,
+		addc_no_ntlm      => 18,
+		idmapadmember     => 19,
+		idmapridmember    => 20,
+		localdc           => 21,
+		localvampiredc    => 22,
+		s4member          => 23,
+		localrpcproxy     => 24,
+		dc5               => 25,
+		dc6               => 26,
+		dc7               => 27,
+		rodc              => 28,
+		localadmember     => 29,
+		addc              => 30,
+		localsubdc        => 31,
+		chgdcpass         => 32,
+		promotedvdc       => 33,
+		rfc2307member     => 34,
+		fileserver        => 35,
+		fakednsforwarder1 => 36,
+		fakednsforwarder2 => 37,
+		s4member_dflt     => 38,
+		vampire2000dc     => 39,
+		backupfromdc      => 40,
+		restoredc         => 41,
+		renamedc          => 42,
+		labdc             => 43,
+		offlinebackupdc   => 44,
+		customdc          => 45,
+		prockilldc        => 46,
+		proclimitdc       => 47,
+
+		rootdnsforwarder  => 64,
+
+		# update lib/socket_wrapper/socket_wrapper.c
+		#  #define MAX_WRAPPED_INTERFACES 64
+		# if you wish to have more than 64 interfaces
+	);
+
+	if (not defined($testenv_iface_mapping{$netbiosname})) {
+		die();
+	}
+
+	return $testenv_iface_mapping{$netbiosname};
+}
+
+sub get_ipv4_addr
+{
+	(my $hostname) = @_;
+	my $swiface = Samba::get_interface($hostname);
+
+	return "127.0.0.$swiface";
+}
+
+sub get_ipv6_addr
+{
+	(my $hostname) = @_;
+	my $swiface = Samba::get_interface($hostname);
 
-    return $interfaces{$netbiosname};
+	return sprintf("fd00:0000:0000:0000:0000:0000:5357:5f%02x", $swiface);
 }
 
 sub cleanup_child($$)
diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
index 19a2d2fc566..e176e3120c6 100755
--- a/selftest/target/Samba3.pm
+++ b/selftest/target/Samba3.pm
@@ -1459,8 +1459,8 @@ sub provision($$$$$$$$$)
 	my $swiface = Samba::get_interface($server);
 	my %ret = ();
 	my %createuser_env = ();
-	my $server_ip = "127.0.0.$swiface";
-	my $server_ipv6 = sprintf("fd00:0000:0000:0000:0000:0000:5357:5f%02x", $swiface);
+	my $server_ip = Samba::get_ipv4_addr($server);
+	my $server_ipv6 = Samba::get_ipv6_addr($server);
 
 	my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `PATH=/usr/ucb:$ENV{PATH} whoami`);
 	chomp $unix_name;
diff --git a/selftest/target/Samba4.pm b/selftest/target/Samba4.pm
index 8b62c5e9c11..12f1a604c66 100755
--- a/selftest/target/Samba4.pm
+++ b/selftest/target/Samba4.pm
@@ -333,12 +333,13 @@ sub write_ldb_file($$$)
 sub add_wins_config($$)
 {
 	my ($self, $privatedir) = @_;
+	my $client_ip = Samba::get_ipv4_addr("client");
 
 	return $self->write_ldb_file("$privatedir/wins_config.ldb", "
 dn: name=TORTURE_11,CN=PARTNERS
 objectClass: wreplPartner
 name: TORTURE_11
-address: 127.0.0.11
+address: $client_ip
 pullInterval: 0
 pushChangeCount: 0
 type: 0x3
@@ -385,17 +386,14 @@ sub setup_dns_hub_internal($$$)
 		warn("Unable to clean up");
 	}
 
-	my $swiface = Samba::get_interface($hostname);
-
 	my $env = undef;
 	$env->{prefix} = $prefix;
 	$env->{prefix_abs} = $prefix_abs;
 
 	$env->{hostname} = $hostname;
-	$env->{swiface} = $swiface;
 
-	$env->{ipv4} = "127.0.0.$swiface";
-	$env->{ipv6} = sprintf("fd00:0000:0000:0000:0000:0000:5357:5f%02x", $swiface);
+	$env->{ipv4} = Samba::get_ipv4_addr($hostname);
+	$env->{ipv6} = Samba::get_ipv6_addr($hostname);
 
 	$env->{DNS_HUB_LOG} = "$prefix_abs/dns_hub.log";
 
@@ -420,6 +418,7 @@ sub setup_dns_hub_internal($$$)
 		open STDOUT, "| tee $env->{DNS_HUB_LOG} 1>&2";
 		open STDERR, '>&STDOUT';
 
+		my $swiface = Samba::get_interface($hostname);
 		SocketWrapper::set_default_iface($swiface);
 		my $pcap_file = "$ENV{SOCKET_WRAPPER_PCAP_DIR}/env-$hostname$.pcap";
 		SocketWrapper::setup_pcap($pcap_file);
@@ -436,6 +435,7 @@ sub setup_dns_hub_internal($$$)
 		$ENV{MAKE_TEST_BINARY} = "$self->{srcdir}/selftest/target/dns_hub.py";
 		push (@args, "$self->{server_maxtime}");
 		push (@args, "$env->{ipv4}");
+		push (@args, Samba::realm_to_ip_mappings());
 		close($env->{STDIN_PIPE});
 		open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
 
@@ -673,8 +673,8 @@ sub provision_raw_prepare($$$$$$$$$$$$)
 
 	$ctx->{tlsdir} = "$ctx->{privatedir}/tls";
 
-	$ctx->{ipv4} = "127.0.0.$swiface";
-	$ctx->{ipv6} = sprintf("fd00:0000:0000:0000:0000:0000:5357:5f%02x", $swiface);
+	$ctx->{ipv4} = Samba::get_ipv4_addr($hostname);
+	$ctx->{ipv6} = Samba::get_ipv6_addr($hostname);
 	$ctx->{interfaces} = "$ctx->{ipv4}/8 $ctx->{ipv6}/64";
 
 	push(@{$ctx->{directories}}, $ctx->{privatedir});
@@ -1722,14 +1722,14 @@ sub provision_fl2000dc($$)
 sub provision_fl2003dc($$$)
 {
 	my ($self, $prefix, $dcvars) = @_;
-	my $swiface1 = Samba::get_interface("fakednsforwarder1");
-	my $swiface2 = Samba::get_interface("fakednsforwarder2");
+	my $ip_addr1 = Samba::get_ipv4_addr("fakednsforwarder1");
+	my $ip_addr2 = Samba::get_ipv4_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 = 127.0.0.$swiface1 127.0.0.$swiface2";
+	dns forwarder = $ip_addr1 $ip_addr2";
 	my $extra_provision_options = ["--use-ntvfs"];
 	my $ret = $self->provision($prefix,
 				   "domain controller",
@@ -1747,8 +1747,8 @@ sub provision_fl2003dc($$$)
 		return undef;
 	}
 
-	$ret->{DNS_FORWARDER1} = "127.0.0.$swiface1";
-	$ret->{DNS_FORWARDER2} = "127.0.0.$swiface2";
+	$ret->{DNS_FORWARDER1} = $ip_addr1;
+	$ret->{DNS_FORWARDER2} = $ip_addr2;
 
 	my @samba_tool_options;
 	push (@samba_tool_options, Samba::bindir_path($self, "samba-tool"));
diff --git a/selftest/target/dns_hub.py b/selftest/target/dns_hub.py
index e440e72577a..49fbeff7b99 100755
--- a/selftest/target/dns_hub.py
+++ b/selftest/target/dns_hub.py
@@ -69,9 +69,26 @@ class DnsHandler(sserver.BaseRequestHandler):
                 s.close()
         return None
 
+    def get_pdc_ipv4_addr(self, lookup_name):
+        """Maps a DNS realm to the IPv4 address of the PDC for that testenv"""
+
+        realm_to_ip_mappings = self.server.realm_to_ip_mappings
+
+        # sort the realms so we find the longest-match first
+        testenv_realms = sorted(realm_to_ip_mappings.keys(), key=len)
+        testenv_realms.reverse()
+
+        for realm in testenv_realms:
+            if lookup_name.endswith(realm):
+                # return the corresponding IP address for this realm's PDC
+                return realm_to_ip_mappings[realm]
+
+        return None
+
     def forwarder(self, name):
         lname = name.lower()
 
+        # check for special cases used by tests (e.g. dns_forwarder.py)
         if lname.endswith('an-address-that-will-not-resolve'):
             return 'ignore'
         if lname.endswith('dsfsdfs'):
@@ -83,31 +100,9 @@ class DnsHandler(sserver.BaseRequestHandler):
             return 'torture'
         if lname.endswith('torturedom.samba.example.com'):
             return 'torture'
-        if lname.endswith('adnonssdom.samba.example.com'):
-            return '127.0.0.17'
-        if lname.endswith('adnontlmdom.samba.example.com'):
-            return '127.0.0.18'
-        if lname.endswith('samba2000.example.com'):
-            return '127.0.0.25'
-        if lname.endswith('samba2003.example.com'):
-            return '127.0.0.26'
-        if lname.endswith('samba2008r2.example.com'):
-            return '127.0.0.27'
-        if lname.endswith('addom.samba.example.com'):
-            return '127.0.0.30'
-        if lname.endswith('sub.samba.example.com'):
-            return '127.0.0.31'
-        if lname.endswith('chgdcpassword.samba.example.com'):
-            return '127.0.0.32'
-        if lname.endswith('backupdom.samba.example.com'):
-            return '127.0.0.40'
-        if lname.endswith('renamedom.samba.example.com'):
-            return '127.0.0.42'
-        if lname.endswith('labdom.samba.example.com'):
-            return '127.0.0.43'
-        if lname.endswith('samba.example.com'):
-            return '127.0.0.21'
-        return None
+
+        # return the testenv PDC matching the realm being requested
+        return self.get_pdc_ipv4_addr(lname)
 
     def handle(self):
         start = time.monotonic()
@@ -171,7 +166,18 @@ def main():
     timeout = int(sys.argv[1]) * 1000
     timeout = min(timeout, 2**31 - 1)  # poll with 32-bit int can't take more
     host = sys.argv[2]
+
     server = sserver.UDPServer((host, int(53)), DnsHandler)
+
+    # we pass in the realm-to-IP mappings as a comma-separated key=value
+    # string. Convert this back into a dictionary that the DnsHandler can use
+    realm_mapping = dict(kv.split('=') for kv in sys.argv[3].split(','))
+    server.realm_to_ip_mappings = realm_mapping
+
+    print("dns_hub will proxy DNS requests for the following realms:")
+    for realm, ip in server.realm_to_ip_mappings.items():
+        print("  {0} ==> {1}".format(realm, ip))
+
     t = server_thread(server)
     t.start()
     p = select.poll()


-- 
Samba Shared Repository



More information about the samba-cvs mailing list