s4:samba_upgradedns: delete dns-HOSTNAME account if using the internal dns server
authorStefan Metzmacher <metze@samba.org>
Wed, 12 Sep 2012 06:53:18 +0000 (08:53 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 12 Sep 2012 14:51:29 +0000 (16:51 +0200)
metze

source4/scripting/bin/samba_upgradedns

index efda448d480c6e9ce19a2cb7c27458f67d90effc..8304134161e3a40b8a85de6f604f4063454e4e38 100755 (executable)
@@ -472,5 +472,33 @@ if __name__ == '__main__':
         logger.info("See %s for an example configuration include file for BIND", paths.namedconf)
         logger.info("and %s for further documentation required for secure DNS "
                     "updates", paths.namedtxt)
+    elif opts.dns_backend == "SAMBA_INTERNAL":
+        # Check if dns-HOSTNAME account exists and delete it if required
+        try:
+            dn_str = 'samAccountName=dns-%s,CN=Principals' % hostname
+            msg = ldbs.secrets.search(expression='(dn=%s)' % dn_str, attrs=['secret'])
+            dn = msg[0].dn
+        except Exception:
+            dn = None
+
+        if dn is not None:
+            try:
+                ldbs.secrets.delete(dn)
+            except Exception:
+                logger.info("Failed to delete %s from secrets.ldb" % dn)
+
+        try:
+            msg = ldbs.sam.search(base=domaindn, scope=ldb.SCOPE_DEFAULT,
+                                  expression='(sAMAccountName=dns-%s)' % (hostname),
+                                  attrs=['clearTextPassword'])
+            dn = msg[0].dn
+        except Exception:
+            dn = None
+
+        if dn is not None:
+            try:
+                ldbs.sam.delete(dn)
+            except Exception:
+                logger.info("Failed to delete %s from sam.ldb" % dn)
 
     logger.info("Finished upgrading DNS")