[SCM] Samba Shared Repository - branch master updated

Matthieu Patou mat at samba.org
Wed Jun 22 13:23:02 MDT 2011


The branch, master has been updated
       via  a9e4592 s4-dbcheck: fix uninitialized errstr in err_dn_target_mismatch
       via  ef7940f s4-dbcheck: remove unused include
       via  4d51ddb s4-schema: avoid segfaulting if id3.guid is NULL
       via  249fbd8 s4-samba_dnsupdate: set environment via the env parameter
       via  c2dfaa2 s4-upgradeprovision: Don't forget to populate the non replicated objects, and don't touch rIDPreviousAllocationPool
       via  2f4251c dbchecker: cope with a broken link to Deleted Objects
       via  4fe9ebc dbchecker: fixed argument error for -H and DN
       via  6b939f4 dbchecker: when fixing a bad GUID in a DN, search by the string DN
       via  9676c26 samba-tool: added --attrs option to dbcheck
       via  7fff636 samba-tool: make the dbcheck class available outside of samba-tool
       via  9be9f0e samba-tool: added --quiet option to dbcheck
      from  ae6a7f9 s4:winbind/wb_init_domain: use DCERPC_SCHANNEL_128 in order to work against w2k8r2

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit a9e45923369e3171cb7f42284f52ce3c4c8b0a4b
Author: Matthieu Patou <mat at matws.net>
Date:   Wed Jun 22 21:28:25 2011 +0400

    s4-dbcheck: fix uninitialized errstr in err_dn_target_mismatch
    
    Autobuild-User: Matthieu Patou <mat at samba.org>
    Autobuild-Date: Wed Jun 22 21:22:27 CEST 2011 on sn-devel-104

commit ef7940f7be7de238a693cfba649faf8b67b7da3a
Author: Matthieu Patou <mat at matws.net>
Date:   Wed Jun 22 21:28:00 2011 +0400

    s4-dbcheck: remove unused include

commit 4d51ddbb5c9e4465887d9fcd2c10de3f46c6a12a
Author: Matthieu Patou <mat at matws.net>
Date:   Wed Jun 22 20:54:37 2011 +0400

    s4-schema: avoid segfaulting if id3.guid is NULL

commit 249fbd8a334b4d19f9148e07449fec3f26b8267d
Author: Matthieu Patou <mat at matws.net>
Date:   Tue Jun 21 13:39:28 2011 +0400

    s4-samba_dnsupdate: set environment via the env parameter
    
    I faced a situation where the os.environ("KRB5CCNAME") = ... didn't
    seems to be effective

commit c2dfaa2580918cf31069c1063ff07a819ca0554a
Author: Matthieu Patou <mat at matws.net>
Date:   Tue Jun 21 13:37:26 2011 +0400

    s4-upgradeprovision: Don't forget to populate the non replicated objects, and don't touch rIDPreviousAllocationPool

commit 2f4251c389f5fa92bfba10739677a760f0bdf198
Author: Andrew Tridgell <tridge at samba.org>
Date:   Wed Jun 22 22:06:18 2011 +1000

    dbchecker: cope with a broken link to Deleted Objects
    
    if a DN link to Deleted Objects has a bad GUID, we need to use
    show_deleted

commit 4fe9ebc2e3e09befe8d7a2ce577336eefd9b9694
Author: Andrew Tridgell <tridge at samba.org>
Date:   Wed Jun 22 21:22:39 2011 +1000

    dbchecker: fixed argument error for -H and DN

commit 6b939f4a9c19cd868ac1b6d77cc26662e2726e8c
Author: Andrew Tridgell <tridge at samba.org>
Date:   Wed Jun 22 20:53:44 2011 +1000

    dbchecker: when fixing a bad GUID in a DN, search by the string DN

commit 9676c26fdd7ca53405abd06f58ae40d39d818e4d
Author: Andrew Tridgell <tridge at samba.org>
Date:   Wed Jun 22 20:44:35 2011 +1000

    samba-tool: added --attrs option to dbcheck
    
    this allows checking of a specific list of attributes

commit 7fff636bce2576a63170bf3cc555eb85b8fefd67
Author: Andrew Tridgell <tridge at samba.org>
Date:   Wed Jun 22 20:01:58 2011 +1000

    samba-tool: make the dbcheck class available outside of samba-tool
    
    this will be used in provision, and probably in upgradeprovision as
    well

commit 9be9f0e43c9312094a42efa236791dfcd95dc9f9
Author: Andrew Tridgell <tridge at samba.org>
Date:   Wed Jun 22 19:32:45 2011 +1000

    samba-tool: added --quiet option to dbcheck
    
    this will be used to allow for other tools (such as provision) to call
    into dbcheck without generating a lot of noise

-----------------------------------------------------------------------

Summary of changes:
 source4/dsdb/schema/schema_syntax.c                |    3 +-
 source4/scripting/bin/samba_dnsupdate              |    2 +-
 source4/scripting/bin/upgradeprovision             |    6 +-
 .../samba/{netcmd/dbcheck.py => dbchecker.py}      |  182 +++++-------
 source4/scripting/python/samba/netcmd/dbcheck.py   |  307 ++------------------
 5 files changed, 102 insertions(+), 398 deletions(-)
 copy source4/scripting/python/samba/{netcmd/dbcheck.py => dbchecker.py} (61%)


Changeset truncated at 500 lines:

diff --git a/source4/dsdb/schema/schema_syntax.c b/source4/dsdb/schema/schema_syntax.c
index f542f67..a93cdfa 100644
--- a/source4/dsdb/schema/schema_syntax.c
+++ b/source4/dsdb/schema/schema_syntax.c
@@ -1995,10 +1995,9 @@ static WERROR dsdb_syntax_DN_BINARY_drsuapi_to_ldb(const struct dsdb_syntax_ctx
 				talloc_free(tmp_ctx);
 				return WERR_FOOBAR;
 			}
+			talloc_free(guid_blob.data);
 		}
 
-		talloc_free(guid_blob.data);
-
 		if (id3.__ndr_size_sid) {
 			DATA_BLOB sid_blob;
 			ndr_err = ndr_push_struct_blob(&sid_blob, tmp_ctx, &id3.sid,
diff --git a/source4/scripting/bin/samba_dnsupdate b/source4/scripting/bin/samba_dnsupdate
index 0a13dd7..78d7dc1 100755
--- a/source4/scripting/bin/samba_dnsupdate
+++ b/source4/scripting/bin/samba_dnsupdate
@@ -278,7 +278,7 @@ def call_nsupdate(d):
     try:
         cmd = nsupdate_cmd[:]
         cmd.append(tmpfile)
-        ret = subprocess.call(cmd, shell=False)
+        ret = subprocess.call(cmd, shell=False, env={"KRB5CCNAME": ccachename})
         if ret != 0:
             if opts.fail_immediately:
                 sys.exit(1)
diff --git a/source4/scripting/bin/upgradeprovision b/source4/scripting/bin/upgradeprovision
index f10a9fc..e98b642 100755
--- a/source4/scripting/bin/upgradeprovision
+++ b/source4/scripting/bin/upgradeprovision
@@ -93,7 +93,7 @@ replAttrNotCopied = [   "dn", "whenCreated", "whenChanged", "objectGUID",
                         "sAMAccountType", "oEMInformation", "creationTime" ]
 
 nonreplAttrNotCopied = ["uSNCreated", "replPropertyMetaData", "uSNChanged",
-                        "nextRid" ,"rIDNextRID"]
+                        "nextRid" ,"rIDNextRID", "rIDPreviousAllocationPool"]
 
 nonDSDBAttrNotCopied = ["msDS-KeyVersionNumber", "priorSecret", "priorWhenChanged"]
 
@@ -266,7 +266,8 @@ def populateNotReplicated(samdb, schemadn):
                         str(schemadn)), scope=SCOPE_SUBTREE,
                         attrs=["lDAPDisplayName"])
     for elem in res:
-        not_replicated.append(elem["lDAPDisplayName"])
+        not_replicated.append(str(elem["lDAPDisplayName"]))
+
 
 def populate_dnsyntax(samdb, schemadn):
     """Populate an array with all the attributes that have DN synthax
@@ -1778,6 +1779,7 @@ if __name__ == '__main__':
             new_ldbs = get_ldbs(newpaths, creds, session, lp)
             new_ldbs.startTransactions()
 
+            populateNotReplicated(new_ldbs.sam, names.schemadn)
             # 8) Populate some associative array to ease the update process
             # List of attribute which are link and backlink
             populate_links(new_ldbs.sam, names.schemadn)
diff --git a/source4/scripting/python/samba/netcmd/dbcheck.py b/source4/scripting/python/samba/dbchecker.py
similarity index 61%
copy from source4/scripting/python/samba/netcmd/dbcheck.py
copy to source4/scripting/python/samba/dbchecker.py
index 93fe3f6..88fd0ed 100644
--- a/source4/scripting/python/samba/netcmd/dbcheck.py
+++ b/source4/scripting/python/samba/dbchecker.py
@@ -18,18 +18,10 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
-import ldb, sys
-import samba.getopt as options
+import ldb
 from samba import dsdb
 from samba import common
-from samba.auth import system_session
-from samba.samdb import SamDB
 from samba.dcerpc import misc
-from samba.netcmd import (
-    Command,
-    CommandError,
-    Option
-    )
 
 
 class dsdb_DN(object):
@@ -55,80 +47,36 @@ class dsdb_DN(object):
     def __str__(self):
         return self.prefix + str(self.dn.extended_str(mode=1))
 
+class dbcheck(object):
+    """check a SAM database for errors"""
 
-class cmd_dbcheck(Command):
-    """check local AD database for errors"""
-    synopsis = "dbcheck <DN> [options]"
-
-    takes_optiongroups = {
-        "sambaopts": options.SambaOptions,
-        "versionopts": options.VersionOptions,
-        "credopts": options.CredentialsOptionsDouble,
-    }
-
-    takes_args = ["DN?"]
-
-    takes_options = [
-        Option("--scope", dest="scope", default="SUB",
-            help="Pass search scope that builds DN list. Options: SUB, ONE, BASE"),
-        Option("--fix", dest="fix", default=False, action='store_true',
-               help='Fix any errors found'),
-        Option("--yes", dest="yes", default=False, action='store_true',
-               help="don't confirm changes, just do them all as a single transaction"),
-        Option("--cross-ncs", dest="cross_ncs", default=False, action='store_true',
-               help="cross naming context boundaries"),
-        Option("-v", "--verbose", dest="verbose", action="store_true", default=False,
-            help="Print more details of checking"),
-        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,
-            scope="SUB", credopts=None, sambaopts=None, versionopts=None):
-        self.lp = sambaopts.get_loadparm()
-        self.creds = credopts.get_credentials(self.lp, fallback_machine=True)
-
-        self.samdb = SamDB(session_info=system_session(), url=H,
-                           credentials=self.creds, lp=self.lp)
-        if H is None:
-            self.local_samdb = self.samdb
-        else:
-            self.local_samdb = SamDB(session_info=system_session(), url=None,
-                                     credentials=self.creds, lp=self.lp)
-
+    def __init__(self, samdb, samdb_schema=None, verbose=False, fix=False, yes=False, quiet=False):
+        self.samdb = samdb
+        self.samdb_schema = (samdb_schema or samdb)
         self.verbose = verbose
         self.fix = fix
         self.yes = yes
+        self.quiet = quiet
 
-        scope_map = { "SUB": ldb.SCOPE_SUBTREE, "BASE":ldb.SCOPE_BASE, "ONE":ldb.SCOPE_ONELEVEL }
-        scope = scope.upper()
-        if not scope in scope_map:
-            raise CommandError("Unknown scope %s" % scope)
-        self.search_scope = scope_map[scope]
-
-        controls = []
-        if H is not None:
-            controls.append('paged_results:1:1000')
-        if cross_ncs:
-            controls.append("search_options:1:2")
+    def check_database(self, DN=None, scope=ldb.SCOPE_SUBTREE, controls=[], attrs=['*']):
+        '''perform a database check, returning the number of errors found'''
 
-        if self.yes and self.fix:
-            self.samdb.transaction_start()
-
-        res = self.samdb.search(base=DN, scope=self.search_scope, attrs=['dn'], controls=controls)
-        print('Checking %u objects' % len(res))
+        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:
-            print("Please use --fix to fix these errors")
-        print('Checked %u objects (%u errors)' % (len(res), error_count))
+            self.report("Please use --fix to fix these errors")
+        self.report('Checked %u objects (%u errors)' % (len(res), error_count))
 
-        if self.yes and self.fix:
-            self.samdb.transaction_commit()
+        return error_count
 
-        if error_count != 0:
-            sys.exit(1)
 
+    def report(self, msg):
+        '''print a message unless quiet is set'''
+        if not self.quiet:
+            print(msg)
 
 
     ################################################################
@@ -137,6 +85,8 @@ class cmd_dbcheck(Command):
         '''confirm a change'''
         if not self.fix:
             return False
+        if self.quiet:
+            return self.yes
         return common.confirm(msg, forced=self.yes)
 
 
@@ -144,40 +94,40 @@ class cmd_dbcheck(Command):
     # handle empty attributes
     def err_empty_attribute(self, dn, attrname):
         '''fix empty attributes'''
-        print("ERROR: Empty attribute %s in %s" % (attrname, dn))
+        self.report("ERROR: Empty attribute %s in %s" % (attrname, dn))
         if not self.confirm('Remove empty attribute %s from %s?' % (attrname, dn)):
-            print("Not fixing empty attribute %s" % attrname)
+            self.report("Not fixing empty attribute %s" % attrname)
             return
 
         m = ldb.Message()
         m.dn = dn
         m[attrname] = ldb.MessageElement('', ldb.FLAG_MOD_DELETE, attrname)
         if self.verbose:
-            print(self.samdb.write_ldif(m, ldb.CHANGETYPE_MODIFY))
+            self.report(self.samdb.write_ldif(m, ldb.CHANGETYPE_MODIFY))
         try:
             self.samdb.modify(m, controls=["relax:0"], validate=False)
         except Exception, msg:
-            print("Failed to remove empty attribute %s : %s" % (attrname, msg))
+            self.report("Failed to remove empty attribute %s : %s" % (attrname, msg))
             return
-        print("Removed empty attribute %s" % attrname)
+        self.report("Removed empty attribute %s" % attrname)
 
 
     ################################################################
     # handle normalisation mismatches
     def err_normalise_mismatch(self, dn, attrname, values):
         '''fix attribute normalisation errors'''
-        print("ERROR: Normalisation error for attribute %s in %s" % (attrname, dn))
+        self.report("ERROR: Normalisation error for attribute %s in %s" % (attrname, dn))
         mod_list = []
         for val in values:
-            normalised = self.samdb.dsdb_normalise_attributes(self.local_samdb, attrname, [val])
+            normalised = self.samdb.dsdb_normalise_attributes(self.samdb_schema, attrname, [val])
             if len(normalised) != 1:
-                print("Unable to normalise value '%s'" % val)
+                self.report("Unable to normalise value '%s'" % val)
                 mod_list.append((val, ''))
             elif (normalised[0] != val):
-                print("value '%s' should be '%s'" % (val, normalised[0]))
+                self.report("value '%s' should be '%s'" % (val, normalised[0]))
                 mod_list.append((val, normalised[0]))
         if not self.confirm('Fix normalisation for %s from %s?' % (attrname, dn)):
-            print("Not fixing attribute %s" % attrname)
+            self.report("Not fixing attribute %s" % attrname)
             return
 
         m = ldb.Message()
@@ -189,86 +139,93 @@ class cmd_dbcheck(Command):
                 m['normv_%u' % i] = ldb.MessageElement(nval, ldb.FLAG_MOD_ADD, attrname)
 
         if self.verbose:
-            print(self.samdb.write_ldif(m, ldb.CHANGETYPE_MODIFY))
+            self.report(self.samdb.write_ldif(m, ldb.CHANGETYPE_MODIFY))
         try:
             self.samdb.modify(m, controls=["relax:0"], validate=False)
         except Exception, msg:
-            print("Failed to normalise attribute %s : %s" % (attrname, msg))
+            self.report("Failed to normalise attribute %s : %s" % (attrname, msg))
             return
-        print("Normalised attribute %s" % attrname)
+        self.report("Normalised attribute %s" % attrname)
+
+    def is_deleted_objects_dn(self, dsdb_dn):
+        '''see if a dsdb_DN is the special Deleted Objects DN'''
+        return dsdb_dn.prefix == "B:32:18E2EA80684F11D2B9AA00C04F79F805:"
 
 
     ################################################################
     # handle a missing GUID extended DN component
     def err_incorrect_dn_GUID(self, dn, attrname, val, dsdb_dn, errstr):
-        print("ERROR: %s component for %s in object %s - %s" % (errstr, attrname, dn, val))
+        self.report("ERROR: %s component for %s in object %s - %s" % (errstr, attrname, dn, val))
+        controls=["extended_dn:1:1"]
+        if self.is_deleted_objects_dn(dsdb_dn):
+            controls.append("show_deleted:1")
         try:
-            res = self.samdb.search(base=dsdb_dn.dn, scope=ldb.SCOPE_BASE,
-                                    attrs=[], controls=["extended_dn:1:1"])
+            res = self.samdb.search(base=str(dsdb_dn.dn), scope=ldb.SCOPE_BASE,
+                                    attrs=[], controls=controls)
         except ldb.LdbError, (enum, estr):
-            print("unable to find object for DN %s - cannot fix (%s)" % (dsdb_dn.dn, estr))
+            self.report("unable to find object for DN %s - cannot fix (%s)" % (dsdb_dn.dn, estr))
             return
         dsdb_dn.dn = res[0].dn
 
         if not self.confirm('Change DN to %s?' % str(dsdb_dn)):
-            print("Not fixing %s" % errstr)
+            self.report("Not fixing %s" % errstr)
             return
         m = ldb.Message()
         m.dn = dn
         m['old_value'] = ldb.MessageElement(val, ldb.FLAG_MOD_DELETE, attrname)
         m['new_value'] = ldb.MessageElement(str(dsdb_dn), ldb.FLAG_MOD_ADD, attrname)
         if self.verbose:
-            print(self.samdb.write_ldif(m, ldb.CHANGETYPE_MODIFY))
+            self.report(self.samdb.write_ldif(m, ldb.CHANGETYPE_MODIFY))
         try:
             self.samdb.modify(m)
         except Exception, msg:
-            print("Failed to fix %s on attribute %s : %s" % (errstr, attrname, msg))
+            self.report("Failed to fix %s on attribute %s : %s" % (errstr, attrname, msg))
             return
-        print("Fixed %s on attribute %s" % (errstr, attrname))
+        self.report("Fixed %s on attribute %s" % (errstr, attrname))
 
 
     ################################################################
     # handle a DN pointing to a deleted object
     def err_deleted_dn(self, dn, attrname, val, dsdb_dn, correct_dn):
-        print("ERROR: target DN is deleted for %s in object %s - %s" % (attrname, dn, val))
-        print("Target GUID points at deleted DN %s" % correct_dn)
+        self.report("ERROR: target DN is deleted for %s in object %s - %s" % (attrname, dn, val))
+        self.report("Target GUID points at deleted DN %s" % correct_dn)
         if not self.confirm('Remove DN?'):
-            print("Not removing")
+            self.report("Not removing")
             return
         m = ldb.Message()
         m.dn = dn
         m['old_value'] = ldb.MessageElement(val, ldb.FLAG_MOD_DELETE, attrname)
         if self.verbose:
-            print(self.samdb.write_ldif(m, ldb.CHANGETYPE_MODIFY))
+            self.report(self.samdb.write_ldif(m, ldb.CHANGETYPE_MODIFY))
         try:
             self.samdb.modify(m)
         except Exception, msg:
-            print("Failed to remove deleted DN attribute %s : %s" % (attrname, msg))
+            self.report("Failed to remove deleted DN attribute %s : %s" % (attrname, msg))
             return
-        print("Removed deleted DN on attribute %s" % attrname)
+        self.report("Removed deleted DN on attribute %s" % attrname)
 
 
     ################################################################
     # handle a DN string being incorrect
-    def err_dn_target_mismatch(self, dn, attrname, val, dsdb_dn, correct_dn):
-        print("ERROR: incorrect DN string component for %s in object %s - %s" % (attrname, dn, val))
+    def err_dn_target_mismatch(self, dn, attrname, val, dsdb_dn, correct_dn, errstr):
+        self.report("ERROR: incorrect DN string component for %s in object %s - %s" % (attrname, dn, val))
         dsdb_dn.dn = correct_dn
 
         if not self.confirm('Change DN to %s?' % str(dsdb_dn)):
-            print("Not fixing %s" % errstr)
+            self.report("Not fixing %s" % errstr)
             return
         m = ldb.Message()
         m.dn = dn
         m['old_value'] = ldb.MessageElement(val, ldb.FLAG_MOD_DELETE, attrname)
         m['new_value'] = ldb.MessageElement(str(dsdb_dn), ldb.FLAG_MOD_ADD, attrname)
         if self.verbose:
-            print(self.samdb.write_ldif(m, ldb.CHANGETYPE_MODIFY))
+            self.report(self.samdb.write_ldif(m, ldb.CHANGETYPE_MODIFY))
         try:
             self.samdb.modify(m)
         except Exception, msg:
-            print("Failed to fix incorrect DN string on attribute %s : %s" % (attrname, msg))
+            self.report("Failed to fix incorrect DN string on attribute %s : %s" % (attrname, msg))
             return
-        print("Fixed incorrect DN string on attribute %s" % (attrname))
+        self.report("Fixed incorrect DN string on attribute %s" % (attrname))
 
 
     ################################################################
@@ -298,7 +255,7 @@ class cmd_dbcheck(Command):
                 continue
 
             # the target DN might be deleted
-            if (dsdb_dn.prefix != "B:32:18E2EA80684F11D2B9AA00C04F79F805:" and
+            if ((not self.is_deleted_objects_dn(dsdb_dn)) and
                 'isDeleted' in res[0] and
                 res[0]['isDeleted'][0].upper() == "TRUE"):
                 # note that we don't check this for the special wellKnownObjects prefix
@@ -310,7 +267,8 @@ class cmd_dbcheck(Command):
             # check the DN matches in string form
             if res[0].dn.extended_str() != dsdb_dn.dn.extended_str():
                 error_count += 1
-                self.err_dn_target_mismatch(obj.dn, attrname, val, dsdb_dn, res[0].dn)
+                self.err_dn_target_mismatch(obj.dn, attrname, val, dsdb_dn,
+                                            res[0].dn, "incorrect string version of DN")
                 continue
 
         return error_count
@@ -319,13 +277,13 @@ class cmd_dbcheck(Command):
 
     ################################################################
     # 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:
-            print("Checking object %s" % dn)
-        res = self.samdb.search(base=dn, scope=ldb.SCOPE_BASE, controls=["extended_dn:1:1"], attrs=['*', 'ntSecurityDescriptor'])
+            self.report("Checking object %s" % dn)
+        res = self.samdb.search(base=dn, scope=ldb.SCOPE_BASE, controls=["extended_dn:1:1"], attrs=attrs)
         if len(res) != 1:
-            print("Object %s disappeared during check" % dn)
+            self.report("Object %s disappeared during check" % dn)
             return 1
         obj = res[0]
         error_count = 0
@@ -342,7 +300,7 @@ class cmd_dbcheck(Command):
 
             # get the syntax oid for the attribute, so we can can have
             # special handling for some specific attribute types
-            syntax_oid = self.local_samdb.get_syntax_oid_from_lDAPDisplayName(attrname)
+            syntax_oid = self.samdb_schema.get_syntax_oid_from_lDAPDisplayName(attrname)
 
             if syntax_oid in [ dsdb.DSDB_SYNTAX_BINARY_DN, dsdb.DSDB_SYNTAX_OR_NAME,
                                dsdb.DSDB_SYNTAX_STRING_DN, ldb.LDB_SYNTAX_DN ]:
@@ -351,7 +309,7 @@ class cmd_dbcheck(Command):
 
             # check for incorrectly normalised attributes
             for val in obj[attrname]:
-                normalised = self.samdb.dsdb_normalise_attributes(self.local_samdb, attrname, [val])
+                normalised = self.samdb.dsdb_normalise_attributes(self.samdb_schema, attrname, [val])
                 if len(normalised) != 1 or normalised[0] != val:
                     self.err_normalise_mismatch(dn, attrname, obj[attrname])
                     error_count += 1
diff --git a/source4/scripting/python/samba/netcmd/dbcheck.py b/source4/scripting/python/samba/netcmd/dbcheck.py
index 93fe3f6..3cc50eb 100644
--- a/source4/scripting/python/samba/netcmd/dbcheck.py
+++ b/source4/scripting/python/samba/netcmd/dbcheck.py
@@ -20,40 +20,14 @@
 
 import ldb, sys
 import samba.getopt as options
-from samba import dsdb
-from samba import common
 from samba.auth import system_session
 from samba.samdb import SamDB
-from samba.dcerpc import misc
 from samba.netcmd import (
     Command,
     CommandError,
     Option
     )
-
-
-class dsdb_DN(object):
-    '''a class to manipulate DN components'''
-
-    def __init__(self, samdb, dnstring, syntax_oid):
-        if syntax_oid in [ dsdb.DSDB_SYNTAX_BINARY_DN, dsdb.DSDB_SYNTAX_STRING_DN ]:
-            colons = dnstring.split(':')
-            if len(colons) < 4:
-                raise Exception("invalid DN prefix")
-            prefix_len = 4 + len(colons[1]) + int(colons[1])
-            self.prefix = dnstring[0:prefix_len]
-            self.dnstring = dnstring[prefix_len:]
-        else:
-            self.dnstring = dnstring
-            self.prefix = ''
-        try:
-            self.dn = ldb.Dn(samdb, self.dnstring)
-        except Exception, msg:
-            print("ERROR: bad DN string '%s'" % self.dnstring)
-            raise
-
-    def __str__(self):
-        return self.prefix + str(self.dn.extended_str(mode=1))
+from samba.dbchecker import dbcheck
 
 
 class cmd_dbcheck(Command):
@@ -79,31 +53,31 @@ class cmd_dbcheck(Command):
                help="cross naming context boundaries"),
         Option("-v", "--verbose", dest="verbose", action="store_true", default=False,
             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,
-            scope="SUB", credopts=None, sambaopts=None, versionopts=None):
-        self.lp = sambaopts.get_loadparm()
-        self.creds = credopts.get_credentials(self.lp, fallback_machine=True)
+    def run(self, DN=None, H=None, verbose=False, fix=False, yes=False, cross_ncs=False, quiet=False,
+            scope="SUB", credopts=None, sambaopts=None, versionopts=None, attrs=None):
+
+        lp = sambaopts.get_loadparm()
+        creds = credopts.get_credentials(lp, fallback_machine=True)
 
-        self.samdb = SamDB(session_info=system_session(), url=H,
-                           credentials=self.creds, lp=self.lp)
+        samdb = SamDB(session_info=system_session(), url=H,
+                      credentials=creds, lp=lp)
         if H is None:
-            self.local_samdb = self.samdb
+            samdb_schema = samdb
         else:
-            self.local_samdb = SamDB(session_info=system_session(), url=None,
-                                     credentials=self.creds, lp=self.lp)
-
-        self.verbose = verbose
-        self.fix = fix
-        self.yes = yes
+            samdb_schema = SamDB(session_info=system_session(), url=None,
+                                 credentials=creds, lp=lp)


-- 
Samba Shared Repository


More information about the samba-cvs mailing list