From db0309160740afcdfb192cb55d15f906b15e0481 Mon Sep 17 00:00:00 2001 From: Matthieu Patou Date: Sun, 19 Jun 2011 21:26:48 +0400 Subject: s4-samba-tool: use correct object notation ie. obj.method rather than method(obj, ...) --- source4/scripting/python/samba/netcmd/dbcheck.py | 68 +++++++++++------------- 1 file changed, 31 insertions(+), 37 deletions(-) (limited to 'source4/scripting/python') diff --git a/source4/scripting/python/samba/netcmd/dbcheck.py b/source4/scripting/python/samba/netcmd/dbcheck.py index f433be5a95..c1321d0f46 100644 --- a/source4/scripting/python/samba/netcmd/dbcheck.py +++ b/source4/scripting/python/samba/netcmd/dbcheck.py @@ -37,41 +37,6 @@ def confirm(self, msg): v = raw_input(msg + ' [y/N] ') return v.upper() in ['Y', 'YES'] - - - - -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 == '': - empty_attribute(self, 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: - normalise_mismatch(self, dn, attrname, obj[attrname]) - error_count += 1 - break - return error_count - - class cmd_dbcheck(Command): """check local AD database for errors""" synopsis = "dbcheck [options]" @@ -122,7 +87,7 @@ class cmd_dbcheck(Command): print('Checking %u objects' % len(res)) error_count = 0 for object in res: - error_count += self.check_object(self, object.dn) + error_count += self.check_object(object.dn) if error_count != 0 and not self.fix: print("Please use --fix to fix these errors") print('Checked %u objects (%u errors)' % (len(res), error_count)) @@ -148,6 +113,35 @@ 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 def normalise_mismatch(self, dn, attrname, values): '''fix attribute normalisation errors''' @@ -163,7 +157,7 @@ class cmd_dbcheck(Command): mod_list.append((val, normalised[0])) if not self.fix: return - if not confirm(self, 'Fix normalisation for %s from %s?' % (attrname, dn)): + if not self.confirm(self, 'Fix normalisation for %s from %s?' % (attrname, dn)): print("Not fixing attribute %s" % attrname) return -- cgit