From 1c524c18d10daf8b273189b58c51ed57290c51c7 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Wed, 24 Jan 2018 22:24:15 +0100 Subject: dbcheck: add a helper function that checks is a value has duplicate links Will be used in a subsequent commit. 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 (cherry picked from commit e258b4fb281d8577c425e05b35ce05cf128617ea) --- python/samba/dbchecker.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'python') diff --git a/python/samba/dbchecker.py b/python/samba/dbchecker.py index 787cea2de48..d4c653aab6d 100644 --- a/python/samba/dbchecker.py +++ b/python/samba/dbchecker.py @@ -955,6 +955,38 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base))) return (error_count, duplicate_dict, unique_dict) + def has_duplicate_links(self, dn, forward_attr, forward_syntax): + '''check a linked values for duplicate forward links''' + error_count = 0 + + duplicate_cache_key = "%s:%s" % (str(dn), forward_attr) + if duplicate_cache_key in self.duplicate_link_cache: + return self.duplicate_link_cache[duplicate_cache_key] + + forward_linkID, backlink_attr = self.get_attr_linkID_and_reverse_name(forward_attr) + + attrs = [forward_attr] + controls = ["extended_dn:1:1", "reveal_internals:0"] + + # check its the right GUID + try: + res = self.samdb.search(base=str(dn), scope=ldb.SCOPE_BASE, + attrs=attrs, controls=controls) + except ldb.LdbError, (enum, estr): + if enum != ldb.ERR_NO_SUCH_OBJECT: + raise + + return False + + obj = res[0] + error_count, duplicate_dict, unique_dict = \ + self.check_duplicate_links(obj, forward_attr, forward_syntax, forward_linkID, backlink_attr) + + if duplicate_cache_key in self.duplicate_link_cache: + return self.duplicate_link_cache[duplicate_cache_key] + + return False + def check_dn(self, obj, attrname, syntax_oid): '''check a DN attribute for correctness''' error_count = 0 -- cgit v1.2.1