diff options
author | Andrew Bartlett <abartlet@samba.org> | 2009-10-13 22:10:28 +1100 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2009-10-21 22:43:51 +1100 |
commit | 27c28d34a7bb80d188782fb073ee5f0a657c9be8 (patch) | |
tree | 90c88708b6b0c8eb9c6b33565947224c563f9190 | |
parent | ff3b60d154fe677339ae66bb5994534d9b898d42 (diff) | |
download | samba-27c28d34a7bb80d188782fb073ee5f0a657c9be8.tar.gz samba-27c28d34a7bb80d188782fb073ee5f0a657c9be8.tar.bz2 samba-27c28d34a7bb80d188782fb073ee5f0a657c9be8.zip |
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
-rw-r--r-- | source4/scripting/python/samba/provision.py | 23 |
1 files 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") |