From 2d0e13837d8c6fab3fb296aafcabdf2a2973b96d Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Wed, 23 Aug 2017 15:36:23 +0200 Subject: python:samba: Add code to remove obsolete files in the private dir BUG: https://bugzilla.samba.org/show_bug.cgi?id=12957 Signed-off-by: Andreas Schneider Reviewed-by: Andrew Bartlet Autobuild-User(master): Jeremy Allison Autobuild-Date(master): Wed Sep 6 03:54:19 CEST 2017 on sn-devel-144 --- source4/scripting/bin/samba_upgradedns | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/samba_upgradedns b/source4/scripting/bin/samba_upgradedns index 231e05fca9a..2582da0f6bc 100755 --- a/source4/scripting/bin/samba_upgradedns +++ b/source4/scripting/bin/samba_upgradedns @@ -20,6 +20,7 @@ import sys import os +import errno import optparse import logging import grp @@ -209,6 +210,36 @@ def import_zone_data(samdb, logger, zone, serial, domaindn, forestdn, raise logger.debug("Added DNS record %s" % (fqdn)) +def cleanup_remove_file(file_path): + try: + os.remove(file_path) + except OSError as e: + if e.errno not in [errno.EEXIST, errno.ENOENT]: + pass + else: + logger.debug("Could not remove %s: %s" % (file_path, e.strerror)) + +def cleanup_remove_dir(dir_path): + try: + for root, dirs, files in os.walk(dir_path, topdown=False): + for name in files: + os.remove(os.path.join(root, name)) + for name in dirs: + os.rmdir(os.path.join(root, name)) + os.rmdir(dir_path) + except OSError as e: + if e.errno not in [errno.EEXIST, errno.ENOENT]: + pass + else: + logger.debug("Could not delete dir %s: %s" % (dir_path, e.strerror)) + +def cleanup_obsolete_dns_files(paths): + cleanup_remove_file(os.path.join(paths.private_dir, "named.conf")) + cleanup_remove_file(os.path.join(paths.private_dir, "named.conf.update")) + cleanup_remove_file(os.path.join(paths.private_dir, "named.txt")) + + cleanup_remove_dir(os.path.join(paths.private_dir, "dns")) + # dnsprovision creates application partitions for AD based DNS mainly if the existing # provision was created using earlier snapshots of samba4 which did not have support @@ -496,6 +527,9 @@ if __name__ == '__main__': create_named_txt(paths.namedtxt, names.realm, dnsdomain, dnsname, paths.binddns_dir, paths.dns_keytab) + + cleanup_obsolete_dns_files(paths) + 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) -- cgit v1.2.1