diff options
author | Andrew Tridgell <tridge@samba.org> | 2011-06-22 12:23:05 +1000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2011-06-22 14:47:07 +1000 |
commit | c4a7908f46e7005f323eeca5fd38ec9e88a54aa9 (patch) | |
tree | b56ccc9ce64d7fe08e1d9d403e018f85fbf58972 /source4/scripting/python | |
parent | c46f80824b649647b5a61364a1b8fe26267bbdd9 (diff) | |
download | samba-c4a7908f46e7005f323eeca5fd38ec9e88a54aa9.tar.gz samba-c4a7908f46e7005f323eeca5fd38ec9e88a54aa9.tar.bz2 samba-c4a7908f46e7005f323eeca5fd38ec9e88a54aa9.zip |
samba-tool: try to keep dbcheck.py in a logical ordering
keep individual error handlers together and separate from driver code
Diffstat (limited to 'source4/scripting/python')
-rw-r--r-- | source4/scripting/python/samba/netcmd/dbcheck.py | 67 |
1 files changed, 38 insertions, 29 deletions
diff --git a/source4/scripting/python/samba/netcmd/dbcheck.py b/source4/scripting/python/samba/netcmd/dbcheck.py index f28f9c6bbf..4ec1365f14 100644 --- a/source4/scripting/python/samba/netcmd/dbcheck.py +++ b/source4/scripting/python/samba/netcmd/dbcheck.py @@ -86,6 +86,9 @@ class cmd_dbcheck(Command): if error_count != 0: sys.exit(1) + + ################################################################ + # handle empty attributes def empty_attribute(self, dn, attrname): '''fix empty attributes''' print("ERROR: Empty attribute %s in %s" % (attrname, dn)) @@ -105,36 +108,9 @@ class cmd_dbcheck(Command): return print("Removed empty attribute %s" % attrname) - def check_object(self, dn): - '''check one object''' - if self.verbose: - print("Checking object %s" % dn) - res = self.samdb.search(base=dn, scope=ldb.SCOPE_BASE, controls=["extended_dn:1:1"], attrs=['*', 'ntSecurityDescriptor']) - if len(res) != 1: - print("Object %s disappeared during check" % dn) - return 1 - obj = res[0] - error_count = 0 - for attrname in obj: - if attrname == 'dn': - continue - - # check for empty attributes - for val in obj[attrname]: - if val == '': - self.empty_attribute(dn, attrname) - error_count += 1 - continue - - # check for incorrectly normalised attributes - for val in obj[attrname]: - normalised = self.samdb.dsdb_normalise_attributes(self.samdb, attrname, [val]) - if len(normalised) != 1 or normalised[0] != val: - self.normalise_mismatch(dn, attrname, obj[attrname]) - error_count += 1 - break - return error_count + ################################################################ + # handle normalisation mismatches def normalise_mismatch(self, dn, attrname, values): '''fix attribute normalisation errors''' print("ERROR: Normalisation error for attribute %s in %s" % (attrname, dn)) @@ -167,3 +143,36 @@ class cmd_dbcheck(Command): print("Failed to normalise attribute %s : %s" % (attrname, msg)) return print("Normalised attribute %s" % attrname) + + + ################################################################ + # check one object - calls to individual error handlers above + def check_object(self, dn): + '''check one object''' + if self.verbose: + print("Checking object %s" % dn) + res = self.samdb.search(base=dn, scope=ldb.SCOPE_BASE, controls=["extended_dn:1:1"], attrs=['*', 'ntSecurityDescriptor']) + if len(res) != 1: + print("Object %s disappeared during check" % dn) + return 1 + obj = res[0] + error_count = 0 + for attrname in obj: + if attrname == 'dn': + continue + + # check for empty attributes + for val in obj[attrname]: + if val == '': + self.empty_attribute(dn, attrname) + error_count += 1 + continue + + # check for incorrectly normalised attributes + for val in obj[attrname]: + normalised = self.samdb.dsdb_normalise_attributes(self.samdb, attrname, [val]) + if len(normalised) != 1 or normalised[0] != val: + self.normalise_mismatch(dn, attrname, obj[attrname]) + error_count += 1 + break + return error_count |