downgradedatabase: adding special case for MDB
authorAaron Haslett <aaronhaslett@catalyst.net.nz>
Thu, 23 May 2019 08:06:56 +0000 (20:06 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 29 May 2019 04:41:25 +0000 (04:41 +0000)
Though this script was initially written for undoing GUID indexing on
TDB databases, we're repurposing it to do a full downgrade of any
database. MDB databases can't be DN indexed, but they can have pack
format version 2 and ORDERED_INTEGER data types, which must be removed
during a downgrade.

Signed-off-by: Aaron Haslett <aaronhaslett@catalyst.net.nz>
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>

source4/scripting/bin/sambadowngradedatabase

index 0d182820902e6d85881e6b619291bc04ef6d87e6..9d1e2b8cc76eb7451997251b5fd352cadf986056 100755 (executable)
@@ -27,7 +27,6 @@ if len(args) != 0:
     sys.exit(1)
 
 lp_ctx = sambaopts.get_loadparm()
-lp_ctx.set("dsdb:guid index", "false")
 
 if opts.H is None:
     url = lp_ctx.private_path("sam.ldb")
@@ -40,7 +39,33 @@ samdb = ldb.Ldb(url=url,
 
 partitions = samdb.search(base="@PARTITION",
                          scope=ldb.SCOPE_BASE,
-                          attrs=["partition"])
+                          attrs=["backendStore", "partition"])
+    
+backend = str(partitions[0].get('backendStore', 'tdb'))
+
+if backend == "mdb":
+    samdb = None
+    options = ["pack_format_override=%d" % ldb.PACKING_FORMAT]
+    # We can't remove GUID indexes from LMDB in case there are very
+    # long DNs, so we just move down the pack format, which also removes
+    # references to ORDERED_INTEGER in @ATTRIBUTES.
+
+    # Reopen the DB with pack_format_override set
+    samdb = SamDB(url=url,
+                  flags=ldb.FLG_DONT_CREATE_DB,
+                  lp=lp_ctx,
+                  options=options)
+    samdb.transaction_start()
+    samdb.transaction_commit()
+    print("Your database has been downgraded to LDB pack format version %0x (v1)." % ldb.PACKING_FORMAT)
+
+    print("NOTE: Any use of a Samba 4.11 tool that modifies the DB will "
+          "auto-upgrade back to pack format version %0x (v2)" %
+          ldb.PACKING_FORMAT_V2)
+    exit(0);
+
+# This is needed to force the @ATTRIBUTES and @INDEXLIST to be correct
+lp_ctx.set("dsdb:guid index", "false")
 
 modmsg = ldb.Message()
 modmsg.dn = ldb.Dn(samdb, '@INDEXLIST')