From: Garming Sam Date: Tue, 30 Jan 2018 22:52:34 +0000 (+1300) Subject: remove_dc: Allow remove_dns_references to ignore missing server names X-Git-Tag: tevent-0.9.36~196 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d82687e77fc8467fb7a2c845220dde1f90fd30bf;p=thirdparty%2Fsamba.git remove_dc: Allow remove_dns_references to ignore missing server names Signed-off-by: Garming Sam Reviewed-by: Douglas Bagnall --- diff --git a/python/samba/netcmd/dns.py b/python/samba/netcmd/dns.py index 5a5bd14757d..04c3d8bf2d1 100644 --- a/python/samba/netcmd/dns.py +++ b/python/samba/netcmd/dns.py @@ -1111,7 +1111,8 @@ class cmd_cleanup_record(Command): session_info=system_session(), credentials=creds, lp=lp) - remove_dc.remove_dns_references(samdb, logger, dnshostname) + remove_dc.remove_dns_references(samdb, logger, dnshostname, + ignore_no_name=True) class cmd_dns(SuperCommand): diff --git a/python/samba/remove_dc.py b/python/samba/remove_dc.py index 4c8ee892464..f273a515856 100644 --- a/python/samba/remove_dc.py +++ b/python/samba/remove_dc.py @@ -84,7 +84,7 @@ def remove_sysvol_references(samdb, logger, dc_name): raise -def remove_dns_references(samdb, logger, dnsHostName): +def remove_dns_references(samdb, logger, dnsHostName, ignore_no_name=False): # Check we are using in-database DNS zones = samdb.search(base="", scope=ldb.SCOPE_SUBTREE, @@ -100,7 +100,11 @@ def remove_dns_references(samdb, logger, dnsHostName): (dn, primary_recs) = samdb.dns_lookup(dnsHostName) except RuntimeError as (enum, estr): if enum == werror.WERR_DNS_ERROR_NAME_DOES_NOT_EXIST: - return + if ignore_no_name: + remove_hanging_dns_references(samdb, logger, + dnsHostNameUpper, + zones) + return raise DemoteException("lookup of %s failed: %s" % (dnsHostName, estr)) samdb.dns_replace(dnsHostName, []) @@ -154,6 +158,11 @@ def remove_dns_references(samdb, logger, dnsHostName): (a_name, len(a_recs), orig_num_recs - len(a_recs))) samdb.dns_replace(a_name, a_recs) + remove_hanging_dns_references(samdb, logger, dnsHostNameUpper, zones) + + +def remove_hanging_dns_references(samdb, logger, dnsHostNameUpper, zones): + # Find all the CNAME, NS, PTR and SRV records that point at the # name we are removing @@ -194,6 +203,7 @@ def remove_dns_references(samdb, logger, dnsHostName): # has been done in the list comprehension above samdb.dns_replace_by_dn(record.dn, values) + def offline_remove_server(samdb, logger, server_dn, remove_computer_obj=False,