samba-tool: added --attrs option to dbcheck
authorAndrew Tridgell <tridge@samba.org>
Wed, 22 Jun 2011 10:44:35 +0000 (20:44 +1000)
committerMatthieu Patou <mat@samba.org>
Wed, 22 Jun 2011 18:13:08 +0000 (20:13 +0200)
this allows checking of a specific list of attributes

source4/scripting/python/samba/dbchecker.py
source4/scripting/python/samba/netcmd/dbcheck.py

index 1687c82d8331ee546f13051c6bc3006700ffef7f..38c35492457a3a02554c0ff75d027697a3e41200 100644 (file)
@@ -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
index 4a4fe9cb84719edbd4b770b39b79b6f852445df4..b8a0055d3ab997cb8f7d6015060a49ca5e874ac5 100644 (file)
@@ -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()