s4-dbcheck: Allow forcing an override of an old @MODULES record
authorAndrew Bartlett <abartlet@samba.org>
Thu, 23 Aug 2012 05:18:13 +0000 (15:18 +1000)
committerStefan Metzmacher <metze@samba.org>
Thu, 10 Jan 2013 13:52:45 +0000 (14:52 +0100)
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source4/scripting/python/samba/dbchecker.py
source4/scripting/python/samba/netcmd/dbcheck.py
testprogs/blackbox/dbcheck.sh

index e1be6c4faa4051c30ac8d6c1db38a99cc1b95371..91ae0b68ea6308d829261c6cbe28fea4f078cd09 100644 (file)
@@ -749,3 +749,12 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base)))
         m['add']    = ldb.MessageElement('NONE', ldb.FLAG_MOD_ADD, 'force_reindex')
         m['delete'] = ldb.MessageElement('NONE', ldb.FLAG_MOD_DELETE, 'force_reindex')
         return self.do_modify(m, [], 're-indexed database', validate=False)
+
+    ###############################################
+    # reset @MODULES
+    def reset_modules(self):
+        '''reset @MODULES to that needed for current sam.ldb (to read a very old database)'''
+        m = ldb.Message()
+        m.dn = ldb.Dn(self.samdb, "@MODULES")
+        m['@LIST'] = ldb.MessageElement('samba_dsdb', ldb.FLAG_MOD_REPLACE, '@LIST')
+        return self.do_modify(m, [], 'reset @MODULES on database', validate=False)
index e4ec6b303a4c2fad91c1030cd50ea87c39662706..889b0ff075c3d44acc48db56ad865bef397164ff 100644 (file)
@@ -55,6 +55,7 @@ class cmd_dbcheck(Command):
             help="don't print details of checking"),
         Option("--attrs", dest="attrs", default=None, help="list of attributes to check (space separated)"),
         Option("--reindex", dest="reindex", default=False, action="store_true", help="force database re-index"),
+        Option("--force-modules", dest="force_modules", default=False, action="store_true", help="force loading of Samba modules and ignore the @MODULES record (for very old databases)"),
         Option("-H", "--URL", help="LDB URL for database or target server (defaults to local SAM database)",
                type=str, metavar="URL", dest="H"),
         ]
@@ -62,7 +63,7 @@ class cmd_dbcheck(Command):
     def run(self, DN=None, H=None, verbose=False, fix=False, yes=False,
             cross_ncs=False, quiet=False,
             scope="SUB", credopts=None, sambaopts=None, versionopts=None,
-            attrs=None, reindex=False):
+            attrs=None, reindex=False, force_modules=False):
 
         lp = sambaopts.get_loadparm()
 
@@ -73,8 +74,16 @@ class cmd_dbcheck(Command):
         else:
             creds = None
 
-        samdb = SamDB(session_info=system_session(), url=H,
-                      credentials=creds, lp=lp)
+        if force_modules:
+            samdb = SamDB(session_info=system_session(), url=H,
+                          credentials=creds, lp=lp, options=["modules=samba_dsdb"])
+        else:
+            try:
+                samdb = SamDB(session_info=system_session(), url=H,
+                              credentials=creds, lp=lp)
+            except:
+                raise CommandError("Failed to connect to DB at %s.  If this is a really old sam.ldb (before alpha9), then try again with --force-modules" % H)
+
 
         if H is None or not over_ldap:
             samdb_schema = samdb
@@ -105,13 +114,20 @@ class cmd_dbcheck(Command):
             started_transaction = True
         try:
             chk = dbcheck(samdb, samdb_schema=samdb_schema, verbose=verbose,
-                    fix=fix, yes=yes, quiet=quiet, in_transaction=started_transaction)
+                          fix=fix, yes=yes, quiet=quiet, in_transaction=started_transaction)
 
             if reindex:
                 self.outf.write("Re-indexing...\n")
                 error_count = 0
                 if chk.reindex_database():
                     self.outf.write("completed re-index OK\n")
+
+            elif force_modules:
+                self.outf.write("Resetting @MODULES...\n")
+                error_count = 0
+                if chk.reset_modules():
+                    self.outf.write("completed @MODULES reset OK\n")
+
             else:
                 error_count = chk.check_database(DN=DN, scope=search_scope,
                         controls=controls, attrs=attrs)
index 1ea7811df612bd470f97d7ac758ecb40f6a8495c..faf6fab82e9ed557ebf3e0cb71fa2796584561eb 100755 (executable)
@@ -20,7 +20,12 @@ reindex() {
        $BINDIR/samba-tool dbcheck --reindex
 }
 
+force_modules() {
+       $BINDIR/samba-tool dbcheck --force-modules
+}
+
 testit "dbcheck" dbcheck
 testit "reindex" reindex
+testit "force_modules" force_modules
 
 exit $failed