samba_upgradedns: When we setup the internal dns cleanup bind-dns dir
authorAndreas Schneider <asn@samba.org>
Tue, 5 Sep 2017 09:47:27 +0000 (11:47 +0200)
committerJeremy Allison <jra@samba.org>
Fri, 15 Sep 2017 22:57:25 +0000 (00:57 +0200)
Make sure to remove everything from the bind-dns directory to avoid
possible security issues with the named group having write access to all
AD partions

BUG: https://bugzilla.samba.org/show_bug.cgi?id=12957

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source4/scripting/bin/samba_upgradedns

index 3369bcfed930fe1c67d772924117e456cf5aa2be..261d8a1922daebb41f1fa5bc5cadbf592ec3aaca 100755 (executable)
@@ -553,6 +553,23 @@ if __name__ == '__main__':
                         "updates", paths.namedtxt)
 
     elif opts.dns_backend == "SAMBA_INTERNAL":
+        # Make sure to remove everything from the bind-dns directory to avoid
+        # possible security issues with the named group having write access
+        # to all AD partions
+        cleanup_remove_file(os.path.join(paths.binddns_dir, "dns.keytab"))
+        cleanup_remove_file(os.path.join(paths.binddns_dir, "named.conf"))
+        cleanup_remove_file(os.path.join(paths.binddns_dir, "named.conf.update"))
+        cleanup_remove_file(os.path.join(paths.binddns_dir, "named.txt"))
+
+        cleanup_remove_dir(os.path.dirname(paths.dns))
+
+        try:
+            os.chmod(paths.private_dir, 0o700)
+            os.chown(paths.private_dir, -1, 0)
+        except:
+            logger.warn("Failed to restore owner and permissions for %s",
+                        (paths.private_dir))
+
         # Check if dns-HOSTNAME account exists and delete it if required
         try:
             dn_str = 'samAccountName=dns-%s,CN=Principals' % hostname