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 <DN> [options]"
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))
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'''
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