]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
provision: Refactor another usage of create_dns_dir_keytab_link
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Thu, 6 May 2021 03:08:19 +0000 (15:08 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 11 Jun 2021 07:41:38 +0000 (07:41 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14181
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14535

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
python/samba/provision/__init__.py

index 2531f51ffc8463d690c42d7e727fe0373f76e785..1723d9935d4114b07a07d86459402096e03e6408 100644 (file)
@@ -111,6 +111,7 @@ from samba.provision.common import (
 from samba.provision.sambadns import (
     get_dnsadmins_sid,
     setup_ad_dns,
+    create_dns_dir_keytab_link,
     create_dns_update_list
 )
 
@@ -2361,41 +2362,7 @@ def provision(logger, session_info, smbconf=None,
     secrets_ldb.transaction_commit()
 
     # the commit creates the dns.keytab in the private directory
-    private_dns_keytab_path = os.path.join(paths.private_dir, paths.dns_keytab)
-    bind_dns_keytab_path = os.path.join(paths.binddns_dir, paths.dns_keytab)
-
-    if os.path.isfile(private_dns_keytab_path):
-        if os.path.isfile(bind_dns_keytab_path):
-            try:
-                os.unlink(bind_dns_keytab_path)
-            except OSError as e:
-                logger.error("Failed to remove %s: %s" %
-                             (bind_dns_keytab_path, e.strerror))
-
-        # link the dns.keytab to the bind-dns directory
-        try:
-            os.link(private_dns_keytab_path, bind_dns_keytab_path)
-        except OSError as e:
-            logger.error("Failed to create link %s -> %s: %s" %
-                         (private_dns_keytab_path, bind_dns_keytab_path, e.strerror))
-
-        # chown the dns.keytab in the bind-dns directory
-        if paths.bind_gid is not None:
-            try:
-                os.chmod(paths.binddns_dir, 0o770)
-                os.chown(paths.binddns_dir, -1, paths.bind_gid)
-            except OSError:
-                if 'SAMBA_SELFTEST' not in os.environ:
-                    logger.info("Failed to chown %s to bind gid %u",
-                                paths.binddns_dir, paths.bind_gid)
-
-            try:
-                os.chmod(bind_dns_keytab_path, 0o640)
-                os.chown(bind_dns_keytab_path, -1, paths.bind_gid)
-            except OSError:
-                if 'SAMBA_SELFTEST' not in os.environ:
-                    logger.info("Failed to chown %s to bind gid %u",
-                                bind_dns_keytab_path, paths.bind_gid)
+    create_dns_dir_keytab_link(logger, paths)
 
     result = ProvisionResult()
     result.server_role = serverrole