1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-27 14:04:05 +03:00

s4:provision Remove LDB backend files in provision

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
This commit is contained in:
Andrew Bartlett 2009-10-30 23:42:03 +11:00
parent 6439bdeb3a
commit 371afc47dc
2 changed files with 12 additions and 41 deletions

View 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.

View 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: