mirror of
https://github.com/samba-team/samba.git
synced 2025-07-15 16:59:09 +03:00
s4-samba-tool: use correct object notation ie. obj.method rather than method(obj, ...)
This commit is contained in:
committed by
Matthieu Patou
parent
8a04863f0d
commit
db03091607
@ -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 <DN> [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
|
||||
|
||||
|
Reference in New Issue
Block a user