mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
scripting: Add script (backportable) to undo a GUID index
This script allows the DB to be read, and re-indexed, by an earlier Samba version, most likely 4.7 with some backported patches. Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz> Autobuild-User(master): Andrew Bartlett <abartlet@samba.org> Autobuild-Date(master): Sat Sep 23 09:16:31 CEST 2017 on sn-devel-144
This commit is contained in:
parent
5d404eaeab
commit
7ddf47951b
84
source4/scripting/bin/sambaundoguididx
Executable file
84
source4/scripting/bin/sambaundoguididx
Executable file
@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env python
|
||||
import optparse
|
||||
import sys
|
||||
|
||||
# Find right directory when running from source tree
|
||||
sys.path.insert(0, "bin/python")
|
||||
|
||||
|
||||
import samba
|
||||
import ldb
|
||||
import urllib
|
||||
import os
|
||||
from samba import getopt as options
|
||||
from samba.samdb import SamDB
|
||||
from samba.dbchecker import dbcheck
|
||||
from samba.credentials import Credentials
|
||||
parser = optparse.OptionParser("sambaundoguididx")
|
||||
sambaopts = options.SambaOptions(parser)
|
||||
parser.add_option_group(options.VersionOptions(parser))
|
||||
parser.add_option("-H", "--URL", help="LDB URL for database",
|
||||
type=str, metavar="URL", dest="H")
|
||||
opts, args = parser.parse_args()
|
||||
|
||||
if len(args) != 0:
|
||||
parser.print_usage()
|
||||
sys.exit(1)
|
||||
|
||||
lp_ctx = sambaopts.get_loadparm()
|
||||
lp_ctx.set("dsdb:guid index", "false")
|
||||
|
||||
if opts.H is None:
|
||||
url = lp_ctx.samdb_url()
|
||||
else:
|
||||
url = opts.H
|
||||
|
||||
samdb = ldb.Ldb(url=url, options=["modules:"])
|
||||
|
||||
partitions = samdb.search(base="@PARTITION",
|
||||
scope=ldb.SCOPE_BASE,
|
||||
attrs=["partition"])
|
||||
|
||||
modmsg = ldb.Message()
|
||||
modmsg.dn = ldb.Dn(samdb, '@INDEXLIST')
|
||||
modmsg.add(ldb.MessageElement(
|
||||
elements=[],
|
||||
flags=ldb.FLAG_MOD_REPLACE,
|
||||
name='@IDXGUID'))
|
||||
modmsg.add(ldb.MessageElement(
|
||||
elements=[],
|
||||
flags=ldb.FLAG_MOD_REPLACE,
|
||||
name='@IDX_DN_GUID'))
|
||||
|
||||
samdb.transaction_start()
|
||||
samdb.modify(modmsg)
|
||||
|
||||
privatedir = os.path.dirname(url)
|
||||
|
||||
dbs = []
|
||||
for part in partitions[0]['partition']:
|
||||
file_quoted = part.split(":")[1]
|
||||
tdbname = urllib.unquote(file_quoted)
|
||||
tdbpath = os.path.join(privatedir, tdbname)
|
||||
|
||||
db = ldb.Ldb(url=tdbpath, options=["modules:"])
|
||||
db.transaction_start()
|
||||
db.modify(modmsg)
|
||||
dbs.append(db)
|
||||
|
||||
for db in dbs:
|
||||
db.transaction_commit()
|
||||
|
||||
samdb.transaction_commit()
|
||||
|
||||
print "Re-opening with the full DB stack"
|
||||
samdb = SamDB(url=url,
|
||||
lp=lp_ctx)
|
||||
print "Re-triggering another re-index"
|
||||
chk = dbcheck(samdb)
|
||||
|
||||
chk.reindex_database()
|
||||
|
||||
print "Your database has been downgraded to DN-based index values."
|
||||
|
||||
print "NOTE: Any use of a Samba 4.8 tool including ldbsearch will auto-upgrade back to GUID index mode"
|
Loading…
Reference in New Issue
Block a user