]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
join: Support site detection when --server is specified
authorTim Beale <timbeale@catalyst.net.nz>
Tue, 18 Sep 2018 22:44:48 +0000 (10:44 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 26 Sep 2018 05:49:18 +0000 (07:49 +0200)
When a new DC is joined to the domain, samba-tool would automatically
detect an appropriate site for the new DC. However, it only did this if
the --server option wasn't specified. The new DC's site got
automatically updated as part of the finddc() work, however, this step
gets skipped if we already know the server DC to join to.

In other words, if Default-First-Site-Name doesn't exist and you specify
--server in the join, then you have to also specify --site manually,
otherwise the command fails. This is precisely what's happening in the
join_ldapcmp.sh test, now that the backupfromdc testenv no longer has the
Default-First-Site-Name present.

This patch adds a new find_dc_site() function which uses the same
net.finddc() API (except based on the server-address rather than
domain-name). Assigning DEFAULTSITE has been moved so that it only
gets done if finddc() can't determine the site.

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/join.py
selftest/knownfail.d/join_ldapcmp [deleted file]

index 311411302e615a1bad737616912a5fbcfeda1dbc..3869947f73713651adf8ee3397fd6dc6d9e2fe2d 100644 (file)
@@ -68,8 +68,6 @@ class DCJoinContext(object):
                  machinepass=None, use_ntvfs=False, dns_backend=None,
                  promote_existing=False, plaintext_secrets=False,
                  backend_store=None, forced_local_samdb=None):
-        if site is None:
-            site = DEFAULTSITE
 
         ctx.logger = logger
         ctx.creds = creds
@@ -96,7 +94,13 @@ class DCJoinContext(object):
             ctx.samdb = forced_local_samdb
             ctx.server = ctx.samdb.url
         else:
-            if not ctx.server:
+            if ctx.server:
+                # work out the DC's site (if not already specified)
+                if site is None:
+                    ctx.site = ctx.find_dc_site(ctx.server)
+            else:
+                # work out the Primary DC for the domain (as well as an
+                # appropriate site for the new DC)
                 ctx.logger.info("Finding a writeable DC for domain '%s'" % domain)
                 ctx.server = ctx.find_dc(domain)
                 ctx.logger.info("Found DC %s" % ctx.server)
@@ -104,6 +108,9 @@ class DCJoinContext(object):
                               session_info=system_session(),
                               credentials=ctx.creds, lp=ctx.lp)
 
+        if ctx.site is None:
+            ctx.site = DEFAULTSITE
+
         try:
             ctx.samdb.search(scope=ldb.SCOPE_ONELEVEL, attrs=["dn"])
         except ldb.LdbError as e4:
@@ -348,6 +355,14 @@ class DCJoinContext(object):
             ctx.site = ctx.cldap_ret.client_site
         return ctx.cldap_ret.pdc_dns_name
 
+    def find_dc_site(ctx, server):
+        site = None
+        cldap_ret = ctx.net.finddc(address=server,
+                                   flags=nbt.NBT_SERVER_LDAP | nbt.NBT_SERVER_DS)
+        if cldap_ret.client_site is not None and cldap_ret.client_site != "":
+            site = cldap_ret.client_site
+        return site
+
     def get_behavior_version(ctx):
         res = ctx.samdb.search(base=ctx.base_dn, scope=ldb.SCOPE_BASE, attrs=["msDS-Behavior-Version"])
         if "msDS-Behavior-Version" in res[0]:
diff --git a/selftest/knownfail.d/join_ldapcmp b/selftest/knownfail.d/join_ldapcmp
deleted file mode 100644 (file)
index e8404cf..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-# 'samba-tool domain join --server' fails if the domain does not contain the
-# Default-First-Site-Name site
-samba4.blackbox.join_ldapcmp.check_dc_join\(backupfromdc\)
-samba4.blackbox.join_ldapcmp.new_db_matches\(backupfromdc\)
-