mirror of
https://github.com/samba-team/samba.git
synced 2025-07-29 15:42:04 +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] ')
|
v = raw_input(msg + ' [y/N] ')
|
||||||
return v.upper() in ['Y', 'YES']
|
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):
|
class cmd_dbcheck(Command):
|
||||||
"""check local AD database for errors"""
|
"""check local AD database for errors"""
|
||||||
synopsis = "dbcheck <DN> [options]"
|
synopsis = "dbcheck <DN> [options]"
|
||||||
@ -122,7 +87,7 @@ class cmd_dbcheck(Command):
|
|||||||
print('Checking %u objects' % len(res))
|
print('Checking %u objects' % len(res))
|
||||||
error_count = 0
|
error_count = 0
|
||||||
for object in res:
|
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:
|
if error_count != 0 and not self.fix:
|
||||||
print("Please use --fix to fix these errors")
|
print("Please use --fix to fix these errors")
|
||||||
print('Checked %u objects (%u errors)' % (len(res), error_count))
|
print('Checked %u objects (%u errors)' % (len(res), error_count))
|
||||||
@ -148,6 +113,35 @@ class cmd_dbcheck(Command):
|
|||||||
return
|
return
|
||||||
print("Removed empty attribute %s" % attrname)
|
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):
|
def normalise_mismatch(self, dn, attrname, values):
|
||||||
'''fix attribute normalisation errors'''
|
'''fix attribute normalisation errors'''
|
||||||
@ -163,7 +157,7 @@ class cmd_dbcheck(Command):
|
|||||||
mod_list.append((val, normalised[0]))
|
mod_list.append((val, normalised[0]))
|
||||||
if not self.fix:
|
if not self.fix:
|
||||||
return
|
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)
|
print("Not fixing attribute %s" % attrname)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user