From: Tim Beale Date: Tue, 18 Sep 2018 22:44:48 +0000 (+1200) Subject: join: Support site detection when --server is specified X-Git-Tag: tdb-1.3.17~1502 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=26dd30d6d3e677ce465de174ebbfad38bbb15140;p=thirdparty%2Fsamba.git join: Support site detection when --server is specified 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 Reviewed-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/join.py b/python/samba/join.py index 311411302e6..3869947f737 100644 --- a/python/samba/join.py +++ b/python/samba/join.py @@ -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 index e8404cf7470..00000000000 --- a/selftest/knownfail.d/join_ldapcmp +++ /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\) -