From 27c28d34a7bb80d188782fb073ee5f0a657c9be8 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 13 Oct 2009 22:10:28 +1100 Subject: s4:Handle reprovision with existing partitions The issue here is that if we don't put the partitions metadata in the database before we wipe it, we won't wipe the partitions contents, and so the provision will later fail (entry already exists) Andrew Bartlett --- source4/scripting/python/samba/provision.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py index 1a7a3865d8..49736641b6 100644 --- a/source4/scripting/python/samba/provision.py +++ b/source4/scripting/python/samba/provision.py @@ -598,15 +598,25 @@ def setup_samdb_partitions(samdb_path, setup_path, message, lp, session_info, :note: This function always removes the local SAM LDB file. The erase parameter controls whether to erase the existing data, which may not be stored locally but in LDAP. + """ assert session_info is not None + old_partitions = None + # We use options=["modules:"] to stop the modules loading - we # just want to wipe and re-initialise the database, not start it up try: samdb = Ldb(url=samdb_path, session_info=session_info, credentials=credentials, lp=lp, options=["modules:"]) + res = samdb.search(base="@PARTITION", scope=SCOPE_BASE, attrs=["partition"], expression="partition=*") + if len(res) == 1: + try: + old_partitions = res[0]["partition"] + except KeyError: + pass + # Wipes the database samdb.erase_except_schema_controlled() except LdbError: @@ -615,7 +625,6 @@ def setup_samdb_partitions(samdb_path, setup_path, message, lp, session_info, credentials=credentials, lp=lp, options=["modules:"]) # Wipes the database samdb.erase_except_schema_controlled() - #Add modules to the list to activate them by default #beware often order is important @@ -696,6 +705,13 @@ def setup_samdb_partitions(samdb_path, setup_path, message, lp, session_info, "LDAP_BACKEND_LINE": ldap_backend_line, }) + + if old_partitions is not None: + m = ldb.Message() + m.dn = ldb.Dn(samdb, "@PARTITION") + m["partition"] = ldb.MessageElement(old_partitions, ldb.FLAG_MOD_ADD, "partition") + samdb.modify(m) + samdb.load_ldif_file_add(setup_path("provision_init.ldif")) message("Setting up sam.ldb rootDSE") @@ -706,7 +722,8 @@ def setup_samdb_partitions(samdb_path, setup_path, message, lp, session_info, raise samdb.transaction_commit() - + + def secretsdb_self_join(secretsdb, domain, netbiosname, domainsid, machinepass, realm=None, dnsdomain=None, @@ -1006,7 +1023,7 @@ def setup_samdb(path, setup_path, session_info, credentials, lp, if fill == FILL_DRS: return samdb - + samdb.transaction_start() try: message("Erasing data from partitions") -- cgit