1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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"
|