summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source4/scripting/python/samba/dbchecker.py13
-rw-r--r--source4/scripting/python/samba/netcmd/dbcheck.py10
2 files changed, 15 insertions, 8 deletions
diff --git a/source4/scripting/python/samba/dbchecker.py b/source4/scripting/python/samba/dbchecker.py
index 1687c82d83..38c3549245 100644
--- a/source4/scripting/python/samba/dbchecker.py
+++ b/source4/scripting/python/samba/dbchecker.py
@@ -58,15 +58,14 @@ class dbcheck(object):
self.yes = yes
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'''
- 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))
error_count = 0
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:
self.report("Please use --fix to fix these errors")
self.report('Checked %u objects (%u errors)' % (len(res), error_count))
@@ -86,6 +85,8 @@ class dbcheck(object):
'''confirm a change'''
if not self.fix:
return False
+ if self.quiet:
+ return 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
- def check_object(self, dn):
+ def check_object(self, dn, attrs=['*']):
'''check one object'''
if self.verbose:
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:
self.report("Object %s disappeared during check" % dn)
return 1
diff --git a/source4/scripting/python/samba/netcmd/dbcheck.py b/source4/scripting/python/samba/netcmd/dbcheck.py
index 4a4fe9cb84..b8a0055d3a 100644
--- a/source4/scripting/python/samba/netcmd/dbcheck.py
+++ b/source4/scripting/python/samba/netcmd/dbcheck.py
@@ -55,11 +55,12 @@ class cmd_dbcheck(Command):
help="Print more details of checking"),
Option("--quiet", dest="quiet", action="store_true", default=False,
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),
]
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()
creds = credopts.get_credentials(lp, fallback_machine=True)
@@ -84,11 +85,16 @@ class cmd_dbcheck(Command):
if cross_ncs:
controls.append("search_options:1:2")
+ if not attrs:
+ attrs = ['*']
+ else:
+ attrs = attrs.split()
+
if yes and fix:
samdb.transaction_start()
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:
samdb.transaction_commit()