bla...
authorStefan Metzmacher <metze@samba.org>
Thu, 13 Mar 2014 22:12:39 +0000 (23:12 +0100)
committerStefan Metzmacher <metze@samba.org>
Fri, 14 Mar 2014 16:34:51 +0000 (17:34 +0100)
python/samba/dbchecker.py

index 4281e6bcbc3e87f92e1ad3ba072541199516beb1..58aec11fd36959f66e4e246998fc8cae4632b207 100644 (file)
@@ -463,6 +463,20 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base)))
         else:
             self.samdb.transaction_cancel()
 
+    def err_wrong_rdn(self, obj, new_dn, rdn2_attr, rdn2_val, name_val):
+        '''handle a wrong rdn'''
+
+        self.report("ERROR: wrong dn[%s] %s=%r name=%r new_dn[%s]" % (obj.dn, rdn2_attr, rdn2_val, name_val, new_dn))
+        if not self.confirm_all("Change %s from %r to %r on %s?" % (rdn2_attr, obj[rdn2_attr][0], name_val, obj.dn), 'fix_rdn'):
+            self.report("Not changing %s from %r to %r on %s" % (rdn2_attr, obj[rdn2_attr][0], name_val, obj.dn))
+            return
+
+       # m = ldb.Message()
+       # m.dn = obj.dn
+       # m['value'] = ldb.MessageElement(val, ldb.FLAG_MOD_REPLACE, attr)
+       # if self.do_modify(m, ["local_oid:%s:0" % dsdb.DSDB_CONTROL_DBCHECK_MODIFY_RO_REPLICA],
+       #                   "Failed to correct %s on %s by setting" % (attr, obj.dn)):
+       #     self.report("Corrected %s on %s by setting" % (attr, obj.dn))
 
     def err_wrong_instancetype(self, obj, calculated_instancetype):
         '''handle a wrong instanceType'''
@@ -1019,10 +1033,33 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base)))
         list_attrs_seen = []
         got_repl_property_meta_data = False
 
+        nc_dn = self.samdb.get_nc_root(obj.dn)
+        deleted_objects_dn = self.samdb.get_wellknown_dn(nc_dn,
+                                                 samba.dsdb.DS_GUID_DELETED_OBJECTS_CONTAINER)
+
+        rdn1 = (str(obj.dn).split(",", 1))[0]
+        rdn1_attr = (str(rdn1).split("=", 1))[0]
+        rdn1_vale = (str(rdn1).split("=", 1))[1]
+        rdn1_val = ldb.binary_decode(rdn1_vale)
+
+        rdn2_attr = None
+        isDeleted = False
+        systemFlags = 0
+
         for attrname in obj:
             if attrname == 'dn':
                 continue
 
+            if str(attrname).lower() == str(rdn1_attr).lower():
+                rdn2_attr = attrname
+
+            if str(attrname).lower() == 'isdeleted':
+                if obj[attrname][0] != "FALSE":
+                    isDeleted = True
+
+            if str(attrname).lower() == 'systemflags':
+                systemFlags = int(obj[attrname][0])
+
             if str(attrname).lower() == 'replpropertymetadata':
                 if self.has_replmetadata_zero_invocationid(dn, obj[attrname]):
                     error_count += 1
@@ -1110,10 +1147,41 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base)))
                     error_count += 1
                     self.err_wrong_instancetype(obj, calculated_instancetype)
 
+        name_attr = "name"
+        if len(obj[name_attr]) != 1:
+            error_count += 1
+            self.report("ERROR: Not fixing num_values(%d) for 'name' on '%s'" % (len(obj[name_attr]), str(obj.dn)))
+            return
+        name_val = obj[name_attr][0]
+
+        parent_dn = None
+        if isDeleted:
+            if not (systemFlags & samba.dsdb.SYSTEM_FLAG_DISALLOW_MOVE_ON_DELETE):
+                parent_dn = deleted_objects_dn
+        if parent_dn is None:
+            parent_dn = obj.dn.parent()
+        expected_dn = ldb.Dn(self.samdb, "%s=%s,%s" % (rdn1_attr, ldb.binary_encode(name_val), parent_dn))
+
+        if obj.dn == deleted_objects_dn:
+            expected_dn = obj.dn
+
+        if rdn2_attr is None:
+            error_count += 1
+            self.report("ERROR: Not fixing missing RDN attribute '%s' on '%s'" % (rdn1_attr, str(obj.dn)))
+            return
+        if len(obj[rdn2_attr]) != 1:
+            error_count += 1
+            self.report("ERROR: Not fixing '%s' attributes(%d) on '%s'" % (rdn2_attr, len(obj[rdn2_attr]), str(obj.dn)))
+            return
+        rdn2_val = obj[rdn2_attr][0]
+
+        if expected_dn != obj.dn or rdn2_val != name_val:
+            error_count += 1
+            self.err_wrong_rdn(obj, expected_dn, rdn2_attr, rdn2_val, name_val)
+
         show_dn = True
         if got_repl_property_meta_data:
-            rdn = (str(dn).split(","))[0]
-            if rdn == "CN=Deleted Objects":
+            if obj.dn == deleted_objects_dn:
                 isDeletedAttId = 131120
                 # It's 29/12/9999 at 23:59:59 UTC as specified in MS-ADTS 7.1.1.4.2 Deleted Objects Container