s4-samba-tool: use correct object notation ie. obj.method rather than method(obj...
authorMatthieu Patou <mat@matws.net>
Sun, 19 Jun 2011 17:26:48 +0000 (21:26 +0400)
committerMatthieu Patou <mat@samba.org>
Sun, 19 Jun 2011 21:21:08 +0000 (23:21 +0200)
source4/scripting/python/samba/netcmd/dbcheck.py

index f433be5a95c50451a5a203df2ae06775c3ae4e60..c1321d0f4633d2448d54bd0fd4ca45e366c272a6 100644 (file)
@@ -37,41 +37,6 @@ def confirm(self, msg):
     v = raw_input(msg + ' [y/N] ')
     return v.upper() in ['Y', 'YES']
 
     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]"
 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:
         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))
         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)
 
             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'''
 
     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
                 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
 
             print("Not fixing attribute %s" % attrname)
             return