From: Ralph Boehme Date: Wed, 24 Jan 2018 19:01:27 +0000 (+0100) Subject: dbcheck: split out check_duplicate_links from check_dn X-Git-Tag: tevent-0.9.36~233 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=44a8782d71676517f0991f279f2472391ecede3b;p=thirdparty%2Fsamba.git dbcheck: split out check_duplicate_links from check_dn Refactoring, no change in behaviour. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13228 Pair-Programmed-With: Stefan Metzmacher Signed-off-by: Ralph Boehme Signed-off-by: Stefan Metzmacher --- diff --git a/python/samba/dbchecker.py b/python/samba/dbchecker.py index 722184faa0d..9185a1d1bed 100644 --- a/python/samba/dbchecker.py +++ b/python/samba/dbchecker.py @@ -889,27 +889,23 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base))) return dsdb_dn return None - def check_dn(self, obj, attrname, syntax_oid): - '''check a DN attribute for correctness''' + def check_duplicate_links(self, obj, forward_attr, forward_syntax, forward_linkID, backlink_attr): + '''check a linked values for duplicate forward links''' error_count = 0 - obj_guid = obj['objectGUID'][0] - - linkID, reverse_link_name = self.get_attr_linkID_and_reverse_name(attrname) - if reverse_link_name is not None: - reverse_syntax_oid = self.samdb_schema.get_syntax_oid_from_lDAPDisplayName(reverse_link_name) - else: - reverse_syntax_oid = None duplicate_dict = dict() unique_dict = dict() - for val in obj[attrname]: - if linkID & 1: - # - # Only cleanup forward links here, - # back links are handled below. - break - dsdb_dn = dsdb_Dn(self.samdb, val, syntax_oid) + # Only forward links can have this problem + if forward_linkID & 1: + # If we got the reverse, skip it + return (error_count, duplicate_dict, unique_dict) + + if backlink_attr is None: + return (error_count, duplicate_dict, unique_dict) + + for val in obj[forward_attr]: + dsdb_dn = dsdb_Dn(self.samdb, val, forward_syntax) # all DNs should have a GUID component guid = dsdb_dn.dn.get_extended_component("GUID") @@ -949,6 +945,23 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base))) duplicate_dict[keystr]["delete"].append(unique_dict[keystr]) unique_dict[keystr] = dsdb_dn + + return (error_count, duplicate_dict, unique_dict) + + def check_dn(self, obj, attrname, syntax_oid): + '''check a DN attribute for correctness''' + error_count = 0 + obj_guid = obj['objectGUID'][0] + + linkID, reverse_link_name = self.get_attr_linkID_and_reverse_name(attrname) + if reverse_link_name is not None: + reverse_syntax_oid = self.samdb_schema.get_syntax_oid_from_lDAPDisplayName(reverse_link_name) + else: + reverse_syntax_oid = None + + error_count, duplicate_dict, unique_dict = \ + self.check_duplicate_links(obj, attrname, syntax_oid, linkID, reverse_link_name) + if len(duplicate_dict) != 0: self.report("ERROR: Duplicate forward link values for attribute '%s' in '%s'" % (attrname, obj.dn)) for keystr in duplicate_dict.keys():