tmpdir = tempfile.mkdtemp(dir=targetdir)
- # Clone and rename the remote server
+ # setup a join-context for cloning the remote server
lp = sambaopts.get_loadparm()
- old_domain = lp.get('workgroup')
creds = credopts.get_credentials(lp)
include_secrets = not no_secrets
ctx = DCCloneAndRenameContext(new_base_dn, new_domain_name,
include_secrets=include_secrets,
dns_backend='SAMBA_INTERNAL',
server=server, targetdir=tmpdir)
+
+ # sanity-check we're not "renaming" the domain to the same values
+ old_domain = ctx.domain_name
+ if old_domain == new_domain_name:
+ shutil.rmtree(tmpdir)
+ raise CommandError("Cannot use the current domain NetBIOS name.")
+
+ old_realm = ctx.realm
+ if old_realm == new_dns_realm:
+ shutil.rmtree(tmpdir)
+ raise CommandError("Cannot use the current domain DNS realm.")
+
+ # do the clone/rename
ctx.do_join()
# get the paths used for the clone, then drop the old samdb connection
remote_sam = SamDB(url='ldap://' + server, credentials=creds,
session_info=system_session(), lp=lp)
new_sid = get_sid_for_restore(remote_sam)
- old_realm = remote_sam.domain_dns_name()
# Grab the remote DC's sysvol files and bundle them into a tar file.
# Note we end up with 2 sysvol dirs - the original domain's files (that
import os
import shutil
from samba.tests.samba_tool.base import SambaToolCmdTest
-from samba.tests import TestCaseInTempDir, env_loadparm, create_test_ou
+from samba.tests import (TestCaseInTempDir, env_loadparm, create_test_ou,
+ BlackboxProcessError)
import ldb
from samba.samdb import SamDB
from samba.auth import system_session
def test_backup_restore_no_secrets(self):
self._test_backup_restore_no_secrets()
+ def test_backup_invalid_args(self):
+ """Checks that rename commands with invalid args are rejected"""
+
+ # try a "rename" using the same realm as the DC currently has
+ self.base_cmd = ["domain", "backup", "rename", self.restore_domain,
+ os.environ["REALM"]]
+ self.assertRaises(BlackboxProcessError, self.create_backup)
+
+ # try a "rename" using the same domain as the DC currently has
+ self.base_cmd = ["domain", "backup", "rename", os.environ["DOMAIN"],
+ self.restore_realm]
+ self.assertRaises(BlackboxProcessError, self.create_backup)
+
def add_link(self, attr, source, target):
m = ldb.Message()
m.dn = ldb.Dn(self.ldb, source)