5 # Find right directory when running from source tree
6 sys.path.insert(0, "bin/python")
13 from samba import getopt as options
14 from samba.samdb import SamDB
15 from samba.dbchecker import dbcheck
16 from samba.credentials import Credentials
17 parser = optparse.OptionParser("sambaundoguididx")
18 sambaopts = options.SambaOptions(parser)
19 parser.add_option_group(options.VersionOptions(parser))
20 parser.add_option("-H", "--URL", help="LDB URL for database",
21 type=str, metavar="URL", dest="H")
22 opts, args = parser.parse_args()
28 lp_ctx = sambaopts.get_loadparm()
29 lp_ctx.set("dsdb:guid index", "false")
32 url = lp_ctx.samdb_url()
36 samdb = ldb.Ldb(url=url, options=["modules:"])
38 partitions = samdb.search(base="@PARTITION",
42 modmsg = ldb.Message()
43 modmsg.dn = ldb.Dn(samdb, '@INDEXLIST')
44 modmsg.add(ldb.MessageElement(
46 flags=ldb.FLAG_MOD_REPLACE,
48 modmsg.add(ldb.MessageElement(
50 flags=ldb.FLAG_MOD_REPLACE,
53 samdb.transaction_start()
56 privatedir = os.path.dirname(url)
59 for part in partitions[0]['partition']:
60 file_quoted = part.split(":")[1]
61 tdbname = urllib.unquote(file_quoted)
62 tdbpath = os.path.join(privatedir, tdbname)
64 db = ldb.Ldb(url=tdbpath, options=["modules:"])
65 db.transaction_start()
70 db.transaction_commit()
72 samdb.transaction_commit()
74 print "Re-opening with the full DB stack"
75 samdb = SamDB(url=url,
77 print "Re-triggering another re-index"
80 chk.reindex_database()
82 print "Your database has been downgraded to DN-based index values."
84 print "NOTE: Any use of a Samba 4.8 tool including ldbsearch will auto-upgrade back to GUID index mode"