2 from __future__ import print_function
6 # Find right directory when running from source tree
7 sys.path.insert(0, "bin/python")
14 from samba import getopt as options
15 from samba.samdb import SamDB
16 from samba.dbchecker import dbcheck
17 from samba.credentials import Credentials
18 parser = optparse.OptionParser("sambaundoguididx")
19 sambaopts = options.SambaOptions(parser)
20 parser.add_option_group(options.VersionOptions(parser))
21 parser.add_option("-H", "--URL", help="LDB URL for database",
22 type=str, metavar="URL", dest="H")
23 opts, args = parser.parse_args()
29 lp_ctx = sambaopts.get_loadparm()
30 lp_ctx.set("dsdb:guid index", "false")
33 url = lp_ctx.private_path("sam.ldb")
37 samdb = ldb.Ldb(url=url,
38 flags=ldb.FLG_DONT_CREATE_DB,
41 partitions = samdb.search(base="@PARTITION",
45 modmsg = ldb.Message()
46 modmsg.dn = ldb.Dn(samdb, '@INDEXLIST')
47 modmsg.add(ldb.MessageElement(
49 flags=ldb.FLAG_MOD_REPLACE,
51 modmsg.add(ldb.MessageElement(
53 flags=ldb.FLAG_MOD_REPLACE,
56 samdb.transaction_start()
59 privatedir = os.path.dirname(url)
62 for part in partitions[0]['partition']:
63 dbname = str(part).split(":")[1]
64 dbpath = os.path.join(privatedir, dbname)
65 if os.path.isfile(dbpath):
66 dbpath = "ldb://" + dbpath
67 db = ldb.Ldb(url=dbpath,
69 flags=ldb.FLG_DONT_CREATE_DB)
70 db.transaction_start()
75 db.transaction_commit()
77 samdb.transaction_commit()
79 print("Re-opening with the full DB stack")
80 samdb = SamDB(url=url,
81 flags=ldb.FLG_DONT_CREATE_DB,
83 print("Re-triggering another re-index")
86 chk.reindex_database()
88 print("Your database has been downgraded to DN-based index values.")
90 print("NOTE: Any use of a Samba 4.8 tool including ldbsearch will "
91 "auto-upgrade back to GUID index mode")