s4:provision Remove LDB backend files in provision
authorAndrew Bartlett <abartlet@samba.org>
Fri, 30 Oct 2009 12:42:03 +0000 (23:42 +1100)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 2 Nov 2009 05:36:56 +0000 (16:36 +1100)
Rather than try and remove the records in the LDB files, make the
provision remove the whole file.  This also removes the need to try
and carry forward the old ldb filenames.

Andrew Bartlett

source4/scripting/python/samba/provision.py
source4/scripting/python/samba/provisionbackend.py

index f3af30ce3963307b4e69f56f12296590906c2e5d..d797dc9d212c29c01a7d7a0a9aa225bc924406e9 100644 (file)
@@ -39,7 +39,6 @@ import samba
 import subprocess
 import ldb
 
-import shutil
 
 from auth import system_session, admin_session
 from samba import version, Ldb, substitute_var, valid_netbios_name, setup_file
@@ -518,33 +517,12 @@ def setup_samdb_partitions(samdb_path, setup_path, message, lp, session_info,
     # just want to wipe and re-initialise the database, not start it up
 
     try:
-        samdb = Ldb(url=samdb_path, session_info=session_info, 
-                      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
-
-        if old_partitions is not None:
-            new_partitions = [];
-            for old_partition in old_partitions:
-                new_partition = old_partition
-                if old_partition.endswith(".ldb"):
-                    p = old_partition.split(":")[0]
-                    dn = ldb.Dn(schema.ldb, p)
-                    new_partition = dn.get_casefold()
-                new_partitions.append(new_partition)
-
-        # Wipes the database
-        samdb.erase_except_schema_controlled()
-    except LdbError:
         os.unlink(samdb_path)
-        samdb = Ldb(url=samdb_path, session_info=session_info, 
-                      lp=lp, options=["modules:"])
-         # Wipes the database
-        samdb.erase_except_schema_controlled()
+    except OSError:
+        pass
+
+    samdb = Ldb(url=samdb_path, session_info=session_info, 
+                lp=lp, options=["modules:"])
 
     #Add modules to the list to activate them by default
     #beware often order is important
@@ -628,13 +606,6 @@ def setup_samdb_partitions(samdb_path, setup_path, message, lp, session_info,
         })
 
         
-        if new_partitions is not None:
-            m = ldb.Message()
-            m.dn = ldb.Dn(samdb, "@PARTITION")
-            
-            m["partition"] = ldb.MessageElement(new_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")
@@ -949,13 +920,6 @@ def setup_samdb(path, setup_path, session_info, provision_backend, lp,
         
     samdb.transaction_start()
     try:
-        message("Erasing data from partitions")
-        # Load the schema (again).  This time it will force a reindex,
-        # and will therefore make the erase_partitions() below
-        # computationally sane
-        samdb.set_schema_from_ldb(schema.ldb)
-        samdb.erase_partitions()
-    
         # Set the domain functionality levels onto the database.
         # Various module (the password_hash module in particular) need
         # to know what level of AD we are emulating.
index fc1bac673d9a8175e5ac3187719a0aad982e5929..8f1b94f1bd56ceb5fa3bc270d9fce45d1576e9eb 100644 (file)
@@ -30,6 +30,7 @@ import os
 import sys
 import uuid
 import time
+import shutil
 
 from samba import read_and_sub_file
 from samba import Ldb
@@ -80,6 +81,9 @@ class ProvisionBackend(object):
         if self.type is "ldb":
             self.credentials = None
             self.secrets_credentials = None
+    
+            # Wipe the old sam.ldb databases away
+            shutil.rmtree(paths.samdb + ".d", True)
             return
 
         self.ldapi_uri = "ldapi://" + urllib.quote(os.path.join(paths.ldapdir, "ldapi"), safe="")
@@ -230,6 +234,9 @@ def provision_openldap_backend(result, setup_path=None, names=None,
                                slapd_path=None, nosync=False,
                                ldap_dryrun_mode=False):
 
+    # Wipe the directories so we can start
+    shutil.rmtree(os.path.join(result.paths.ldapdir, "db"), True)
+
     #Allow the test scripts to turn off fsync() for OpenLDAP as for TDB and LDB
     nosync_config = ""
     if nosync: