1
0
mirror of https://github.com/samba-team/samba.git synced 2025-07-23 20:59:10 +03:00

samba-tool: added --attrs option to dbcheck

this allows checking of a specific list of attributes
This commit is contained in:
Andrew Tridgell
2011-06-22 20:44:35 +10:00
committed by Matthieu Patou
parent 7fff636bce
commit 9676c26fdd
2 changed files with 15 additions and 8 deletions

View File

@ -58,15 +58,14 @@ class dbcheck(object):
self.yes = yes self.yes = yes
self.quiet = quiet self.quiet = quiet
def check_database(self, DN=None, scope=ldb.SCOPE_SUBTREE, controls=[]): def check_database(self, DN=None, scope=ldb.SCOPE_SUBTREE, controls=[], attrs=['*']):
'''perform a database check, returning the number of errors found''' '''perform a database check, returning the number of errors found'''
self.search_scope = scope
res = self.samdb.search(base=DN, scope=self.search_scope, attrs=['dn'], controls=controls) res = self.samdb.search(base=DN, scope=scope, attrs=['dn'], controls=controls)
self.report('Checking %u objects' % len(res)) self.report('Checking %u objects' % len(res))
error_count = 0 error_count = 0
for object in res: for object in res:
error_count += self.check_object(object.dn) error_count += self.check_object(object.dn, attrs=attrs)
if error_count != 0 and not self.fix: if error_count != 0 and not self.fix:
self.report("Please use --fix to fix these errors") self.report("Please use --fix to fix these errors")
self.report('Checked %u objects (%u errors)' % (len(res), error_count)) self.report('Checked %u objects (%u errors)' % (len(res), error_count))
@ -86,6 +85,8 @@ class dbcheck(object):
'''confirm a change''' '''confirm a change'''
if not self.fix: if not self.fix:
return False return False
if self.quiet:
return self.yes
return common.confirm(msg, forced=self.yes) return common.confirm(msg, forced=self.yes)
@ -268,11 +269,11 @@ class dbcheck(object):
################################################################ ################################################################
# check one object - calls to individual error handlers above # check one object - calls to individual error handlers above
def check_object(self, dn): def check_object(self, dn, attrs=['*']):
'''check one object''' '''check one object'''
if self.verbose: if self.verbose:
self.report("Checking object %s" % dn) self.report("Checking object %s" % dn)
res = self.samdb.search(base=dn, scope=ldb.SCOPE_BASE, controls=["extended_dn:1:1"], attrs=['*', 'ntSecurityDescriptor']) res = self.samdb.search(base=dn, scope=ldb.SCOPE_BASE, controls=["extended_dn:1:1"], attrs=attrs)
if len(res) != 1: if len(res) != 1:
self.report("Object %s disappeared during check" % dn) self.report("Object %s disappeared during check" % dn)
return 1 return 1

View File

@ -55,11 +55,12 @@ class cmd_dbcheck(Command):
help="Print more details of checking"), help="Print more details of checking"),
Option("--quiet", dest="quiet", action="store_true", default=False, Option("--quiet", dest="quiet", action="store_true", default=False,
help="don't print details of checking"), help="don't print details of checking"),
Option("--attrs", dest="attrs", default=None, help="list of attributes to check (space separated)"),
Option("-H", help="LDB URL for database or target server (defaults to local SAM database)", type=str), Option("-H", help="LDB URL for database or target server (defaults to local SAM database)", type=str),
] ]
def run(self, H=None, DN=None, verbose=False, fix=False, yes=False, cross_ncs=False, quiet=False, def run(self, H=None, DN=None, verbose=False, fix=False, yes=False, cross_ncs=False, quiet=False,
scope="SUB", credopts=None, sambaopts=None, versionopts=None): scope="SUB", credopts=None, sambaopts=None, versionopts=None, attrs=None):
lp = sambaopts.get_loadparm() lp = sambaopts.get_loadparm()
creds = credopts.get_credentials(lp, fallback_machine=True) creds = credopts.get_credentials(lp, fallback_machine=True)
@ -84,11 +85,16 @@ class cmd_dbcheck(Command):
if cross_ncs: if cross_ncs:
controls.append("search_options:1:2") controls.append("search_options:1:2")
if not attrs:
attrs = ['*']
else:
attrs = attrs.split()
if yes and fix: if yes and fix:
samdb.transaction_start() samdb.transaction_start()
chk = dbcheck(samdb, samdb_schema=samdb_schema, verbose=verbose, fix=fix, yes=yes, quiet=quiet) chk = dbcheck(samdb, samdb_schema=samdb_schema, verbose=verbose, fix=fix, yes=yes, quiet=quiet)
error_count = chk.check_database(DN=DN, scope=search_scope, controls=controls) error_count = chk.check_database(DN=DN, scope=search_scope, controls=controls, attrs=attrs)
if yes and fix: if yes and fix:
samdb.transaction_commit() samdb.transaction_commit()