samba-tool domain demote: Remove correct DNs and from the correct locations
authorAndrew Bartlett <abartlet@samba.org>
Fri, 23 Oct 2015 00:05:24 +0000 (13:05 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 26 Oct 2015 04:11:22 +0000 (05:11 +0100)
The previous code missed the CN=DFSR-GlobalSettings children and did
not cope with subdomains.  The root DN may not be the domain DN if
we are a subdomain.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
python/samba/remove_dc.py

index 89502121ad82f56cd75de8f886e560d162065aff..f2777d3a97d9de46893d38a2558c03b17df3bd34 100644 (file)
@@ -33,12 +33,19 @@ class DemoteException(Exception):
 
 def remove_sysvol_references(samdb, rdn):
     realm = samdb.domain_dns_name()
-    for s in ("CN=Enterprise,CN=Microsoft System Volumes,CN=System,CN=Configuration",
-              "CN=%s,CN=Microsoft System Volumes,CN=System,CN=Configuration" % realm,
+    for s in ("CN=Enterprise,CN=Microsoft System Volumes,CN=System",
+              "CN=%s,CN=Microsoft System Volumes,CN=System" % realm):
+        try:
+            samdb.delete(ldb.Dn(samdb,
+                                "%s,%s,%s" % (str(rdn), s, str(samdb.get_config_basedn()))))
+        except ldb.LdbError, l:
+            pass
+
+    for s in ("CN=Topology,CN=Domain System Volume,CN=DFSR-GlobalSettings,CN=System",
               "CN=Domain System Volumes (SYSVOL share),CN=File Replication Service,CN=System"):
         try:
             samdb.delete(ldb.Dn(samdb,
-                                "%s,%s,%s" % (str(rdn), s, str(samdb.get_root_basedn()))))
+                                "%s,%s,%s" % (str(rdn), s, str(samdb.get_default_basedn()))))
         except ldb.LdbError, l:
             pass