s4:dbchecker.py - integrate the "objectClass" fixing code
authorMatthias Dieter Wallnöfer <mdw@samba.org>
Wed, 11 Apr 2012 15:18:37 +0000 (17:18 +0200)
committerAndrew Tridgell <tridge@samba.org>
Wed, 18 Apr 2012 05:48:05 +0000 (07:48 +0200)
Signed-off-by: Andrew Tridgell <tridge@samba.org>
source4/scripting/python/samba/dbchecker.py

index d866b3cbee5974554acb5245778a897fa5c5234b..27bdf3d6b23aac776ccce38c8104714d0f184f0a 100644 (file)
@@ -163,6 +163,26 @@ class dbcheck(object):
                           validate=False):
             self.report("Normalised attribute %s" % attrname)
 
+    def err_normalise_mismatch_replace(self, dn, attrname, values):
+        '''fix attribute normalisation errors'''
+        normalised = self.samdb.dsdb_normalise_attributes(self.samdb_schema, attrname, values)
+        self.report("ERROR: Normalisation error for attribute '%s' in '%s'" % (attrname, dn))
+        self.report("Values/Order of values do/does not match: %s/%s!" % (values, list(normalised)))
+        if list(normalised) == values:
+            return
+        if not self.confirm_all("Fix normalisation for '%s' from '%s'?" % (attrname, dn), 'fix_all_normalisation'):
+            self.report("Not fixing attribute '%s'" % attrname)
+            return
+
+        m = ldb.Message()
+        m.dn = dn
+        m[attrname] = ldb.MessageElement(normalised, ldb.FLAG_MOD_REPLACE, attrname)
+
+        if self.do_modify(m, ["relax:0", "show_recycled:1"],
+                          "Failed to normalise attribute %s" % attrname,
+                          validate=False):
+            self.report("Normalised attribute %s" % attrname)
+
     def is_deleted_objects_dn(self, dsdb_dn):
         '''see if a dsdb_Dn is the special Deleted Objects DN'''
         return dsdb_dn.prefix == "B:32:18E2EA80684F11D2B9AA00C04F79F805:"
@@ -422,6 +442,13 @@ class dbcheck(object):
                 got_repl_property_meta_data = True
                 continue
 
+            if str(attrname).lower() == 'objectclass':
+                normalised = self.samdb.dsdb_normalise_attributes(self.samdb_schema, attrname, list(obj[attrname]))
+                if list(normalised) != list(obj[attrname]):
+                    self.err_normalise_mismatch_replace(dn, attrname, list(obj[attrname]))
+                    error_count += 1
+                continue
+
             # check for empty attributes
             for val in obj[attrname]:
                 if val == '':