[SCM] Samba Shared Repository - branch master updated

Andrew Tridgell tridge at samba.org
Wed Aug 17 18:59:03 MDT 2011


The branch, master has been updated
       via  5f33017 s4-test: use dbcheck on more of our selftest databases
       via  97b2f30 s4-test: only check one database in quickcheck
       via  46a76bc s4-dsdb: fixed deletion of backlinks for fl2000 DCs
       via  c5dc26b s4-dsdb: added comments and fixed backlink check in repl_meta_data
       via  16fa0f6 s4-dirsync: use dsdb_module_dn_by_guid() not dsdb_find_dn_by_guid() in modules
       via  23b1d09 samba-tool: changed samba-tool user delete to use samdb instead of Net()
       via  75a90a9 s4-samdb: added deleteuser() to samdb
       via  8c52caa s4-test: prevent the utable test from crashing
      from  fe66abd Adapt del_sid_from_array to Samba coding style

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


- Log -----------------------------------------------------------------
commit 5f3301759e33a498803748f30e57712ac67a9965
Author: Andrew Tridgell <tridge at samba.org>
Date:   Mon Aug 15 15:58:27 2011 +1000

    s4-test: use dbcheck on more of our selftest databases
    
    Pair-Programmed-With: Andrew Bartlett <abartlet at samba.org>
    
    Autobuild-User: Andrew Tridgell <tridge at samba.org>
    Autobuild-Date: Thu Aug 18 02:58:55 CEST 2011 on sn-devel-104

commit 97b2f30b9e8b8440d12dedf4fdf0309edf6f2036
Author: Andrew Tridgell <tridge at samba.org>
Date:   Mon Aug 15 16:20:21 2011 +1000

    s4-test: only check one database in quickcheck

commit 46a76bc2298db0434ff9e75796c8aaad9f0b2970
Author: Andrew Tridgell <tridge at samba.org>
Date:   Mon Aug 15 16:03:11 2011 +1000

    s4-dsdb: fixed deletion of backlinks for fl2000 DCs
    
    when in FL 2000 we were not correctly deleting backlinks as we uses
    dsdb_find_dn_by_guid() which doesn't find deleted objects. Modules
    should use dsdb_module_dn_by_guid() which prevents going to the top
    level, and finds deleted objects
    
    Pair-Programmed-With: Andrew Bartlett <abartlet at samba.org>

commit c5dc26b9769bbaf2883a8cc8fc6fbe3168ff1c9b
Author: Andrew Tridgell <tridge at samba.org>
Date:   Mon Aug 15 16:01:39 2011 +1000

    s4-dsdb: added comments and fixed backlink check in repl_meta_data
    
    added comments explaining the backlink deletion code, plus fix a use
    of a bitwise operation in a boolean expression, and avoid calling
    dsdb_functional_level() inside a loop
    
    Pair-Programmed-With: Andrew Bartlett <abartlet at samba.org>

commit 16fa0f68bdce39eb19f0fa5486ff231467662b12
Author: Andrew Tridgell <tridge at samba.org>
Date:   Mon Aug 15 15:59:23 2011 +1000

    s4-dirsync: use dsdb_module_dn_by_guid() not dsdb_find_dn_by_guid() in modules
    
    this prevents us going to the top level of the module stack
    
    Pair-Programmed-With: Andrew Bartlett <abartlet at samba.org>

commit 23b1d09a5fd9825786343a98f9aab756dd749f95
Author: Andrew Tridgell <tridge at samba.org>
Date:   Mon Aug 15 12:07:50 2011 +1000

    samba-tool: changed samba-tool user delete to use samdb instead of Net()
    
    this makes it possible to use with -H, so you can delete users on
    remote DCs or against local databases

commit 75a90a952b8d65329c7f8cb055b5bb685d4e0b7d
Author: Andrew Tridgell <tridge at samba.org>
Date:   Mon Aug 15 12:06:59 2011 +1000

    s4-samdb: added deleteuser() to samdb
    
    This is similar to deletegroup()

commit 8c52caa83c3487463e3457e96bd4f600c0ef87fc
Author: Andrew Tridgell <tridge at samba.org>
Date:   Mon Aug 15 09:53:45 2011 +1000

    s4-test: prevent the utable test from crashing

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

Summary of changes:
 source4/dsdb/samdb/ldb_modules/dirsync.c           |    2 +-
 source4/dsdb/samdb/ldb_modules/linked_attributes.c |   31 ++++++++-----------
 source4/dsdb/samdb/ldb_modules/repl_meta_data.c    |   19 +++++++++++-
 source4/scripting/python/samba/netcmd/user.py      |   26 +++++++++++------
 source4/scripting/python/samba/samdb.py            |   23 ++++++++++++++
 source4/selftest/quick                             |    2 +-
 source4/selftest/tests.py                          |    5 ++-
 source4/torture/basic/utable.c                     |    8 +++--
 8 files changed, 80 insertions(+), 36 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source4/dsdb/samdb/ldb_modules/dirsync.c b/source4/dsdb/samdb/ldb_modules/dirsync.c
index 7ed1ed3..6a5703a 100644
--- a/source4/dsdb/samdb/ldb_modules/dirsync.c
+++ b/source4/dsdb/samdb/ldb_modules/dirsync.c
@@ -522,7 +522,7 @@ skip:
 									el->name, ldb_dn_get_linearized(copydn)));
 								return ldb_operr(ldb);
 							}
-							ret = dsdb_find_dn_by_guid(ldb, newmsg, &guid, &tdn);
+							ret = dsdb_module_dn_by_guid(dsc->module, newmsg, &guid, &tdn, req);
 							if (ret == LDB_ERR_NO_SUCH_OBJECT) {
 								DEBUG(2, (" Search of guid %s returned 0 objects, skipping it !\n",
 											GUID_string(newmsg, &guid)));
diff --git a/source4/dsdb/samdb/ldb_modules/linked_attributes.c b/source4/dsdb/samdb/ldb_modules/linked_attributes.c
index cc6a489..3ad6f0c 100644
--- a/source4/dsdb/samdb/ldb_modules/linked_attributes.c
+++ b/source4/dsdb/samdb/ldb_modules/linked_attributes.c
@@ -105,7 +105,7 @@ static int la_guid_from_dn(struct la_context *ac, struct ldb_dn *dn, struct GUID
 		return ldb_operr(ldb_module_get_ctx(ac->module));
 	}
 
-	ret = dsdb_find_guid_by_dn(ldb_module_get_ctx(ac->module), dn, guid);
+	ret = dsdb_module_guid_by_dn(ac->module, dn, guid, ac->req);
 	if (ret != LDB_SUCCESS) {
 		DEBUG(4,(__location__ ": Failed to find GUID for dn %s\n",
 			 ldb_dn_get_linearized(dn)));
@@ -227,20 +227,18 @@ static int linked_attributes_add(struct ldb_module *module, struct ldb_request *
 					       el->name);
 			return LDB_ERR_OBJECT_CLASS_VIOLATION;
 		}
-		/* We have a valid attribute, now find out if it is a forward link */
-		if ((schema_attr->linkID == 0)) {
+
+		/* this could be a link with no partner, in which case
+		   there is no special work to do */
+		if (schema_attr->linkID == 0) {
 			continue;
 		}
 
-		if ((schema_attr->linkID & 1) == 1) {
-			unsigned int functional_level;
-
-			functional_level = dsdb_functional_level(ldb);
-			SMB_ASSERT(functional_level > DS_DOMAIN_FUNCTION_2000);
-		}
+		/* this part of the code should only be handling forward links */
+		SMB_ASSERT((schema_attr->linkID & 1) == 0);
 
 		/* Even link IDs are for the originating attribute */
-		target_attr = dsdb_attribute_by_linkID(ac->schema, schema_attr->linkID + 1);
+		target_attr = dsdb_attribute_by_linkID(ac->schema, schema_attr->linkID ^ 1);
 		if (!target_attr) {
 			/*
 			 * windows 2003 has a broken schema where
@@ -344,7 +342,7 @@ static int la_mod_search_callback(struct ldb_request *req, struct ldb_reply *are
 				continue;
 			}
 
-			target_attr = dsdb_attribute_by_linkID(ac->schema, schema_attr->linkID + 1);
+			target_attr = dsdb_attribute_by_linkID(ac->schema, schema_attr->linkID ^ 1);
 			if (!target_attr) {
 				/*
 				 * windows 2003 has a broken schema where
@@ -467,14 +465,11 @@ static int linked_attributes_modify(struct ldb_module *module, struct ldb_reques
 			continue;
 		}
 
-		if ((schema_attr->linkID & 1) == 1) {
-			unsigned int functional_level;
+		/* this part of the code should only be handling forward links */
+		SMB_ASSERT((schema_attr->linkID & 1) == 0);
 
-			functional_level = dsdb_functional_level(ldb);
-			SMB_ASSERT(functional_level > DS_DOMAIN_FUNCTION_2000);
-		}
 		/* Now find the target attribute */
-		target_attr = dsdb_attribute_by_linkID(ac->schema, schema_attr->linkID + 1);
+		target_attr = dsdb_attribute_by_linkID(ac->schema, schema_attr->linkID ^ 1);
 		if (!target_attr) {
 			/*
 			 * windows 2003 has a broken schema where
@@ -929,7 +924,7 @@ static int la_down_req(struct la_context *ac)
 static int la_find_dn_target(struct ldb_module *module, struct la_context *ac,
 			     struct GUID *guid, struct ldb_dn **dn)
 {
-	return dsdb_find_dn_by_guid(ldb_module_get_ctx(ac->module), ac, guid, dn);
+	return dsdb_module_dn_by_guid(ac->module, ac, guid, dn, ac->req);
 }
 
 /* apply one la_context op change */
diff --git a/source4/dsdb/samdb/ldb_modules/repl_meta_data.c b/source4/dsdb/samdb/ldb_modules/repl_meta_data.c
index 54741e6..e50e2a0 100644
--- a/source4/dsdb/samdb/ldb_modules/repl_meta_data.c
+++ b/source4/dsdb/samdb/ldb_modules/repl_meta_data.c
@@ -2724,6 +2724,7 @@ static int replmd_delete(struct ldb_module *module, struct ldb_request *req)
 						OBJECT_TOMBSTONE=4, OBJECT_REMOVED=5 };
 	enum deletion_state deletion_state, next_deletion_state;
 	bool enabled;
+	int functional_level;
 
 	if (ldb_dn_is_special(req->op.del.dn)) {
 		return ldb_next_request(module, req);
@@ -2740,6 +2741,8 @@ static int replmd_delete(struct ldb_module *module, struct ldb_request *req)
 		return LDB_ERR_OPERATIONS_ERROR;
 	}
 
+	functional_level = dsdb_functional_level(ldb);
+
 	old_dn = ldb_dn_copy(tmp_ctx, req->op.del.dn);
 
 	/* we need the complete msg off disk, so we can work out which
@@ -2940,7 +2943,7 @@ static int replmd_delete(struct ldb_module *module, struct ldb_request *req)
 
 		/* we also mark it as recycled, meaning this object can't be
 		   recovered (we are stripping its attributes) */
-		if (dsdb_functional_level(ldb) >= DS_DOMAIN_FUNCTION_2008_R2) {
+		if (functional_level >= DS_DOMAIN_FUNCTION_2008_R2) {
 			ret = ldb_msg_add_string(msg, "isRecycled", "TRUE");
 			if (ret != LDB_SUCCESS) {
 				DEBUG(0,(__location__ ": Failed to add isRecycled string to the msg\n"));
@@ -2964,12 +2967,24 @@ static int replmd_delete(struct ldb_module *module, struct ldb_request *req)
 				/* don't remove the rDN */
 				continue;
 			}
-			if (sa->linkID && sa->linkID & 1) {
+			if (sa->linkID && (sa->linkID & 1)) {
+				/*
+				  we have a backlink in this object
+				  that needs to be removed. We're not
+				  allowed to remove it directly
+				  however, so we instead setup a
+				  modify to delete the corresponding
+				  forward link
+				 */
 				ret = replmd_delete_remove_link(module, schema, old_dn, el, sa, req);
 				if (ret != LDB_SUCCESS) {
 					talloc_free(tmp_ctx);
 					return LDB_ERR_OPERATIONS_ERROR;
 				}
+				/* now we continue, which means we
+				   won't remove this backlink
+				   directly
+				*/
 				continue;
 			}
 			if (!sa->linkID && ldb_attr_in_list(preserved_attrs, el->name)) {
diff --git a/source4/scripting/python/samba/netcmd/user.py b/source4/scripting/python/samba/netcmd/user.py
index 88d93e3..b9c562d 100644
--- a/source4/scripting/python/samba/netcmd/user.py
+++ b/source4/scripting/python/samba/netcmd/user.py
@@ -106,21 +106,29 @@ class cmd_user_add(Command):
 
 
 class cmd_user_delete(Command):
-    """Delete a user."""
+    """Delete a user"""
 
-    synopsis = "%prog user delete <username> [options]"
+    synopsis = "%prog user delete <username>"
 
-    takes_args = ["name"]
+    takes_options = [
+        Option("-H", "--URL", help="LDB URL for database or target server", type=str,
+               metavar="URL", dest="H"),
+    ]
+
+    takes_args = ["username"]
+
+    def run(self, username, credopts=None, sambaopts=None, versionopts=None, H=None):
 
-    def run(self, name, credopts=None, sambaopts=None, versionopts=None):
         lp = sambaopts.get_loadparm()
         creds = credopts.get_credentials(lp, fallback_machine=True)
-        net = Net(creds, lp, server=credopts.ipaddress)
-        try:
-            net.delete_user(name)
-        except RuntimeError, msg:
-            raise CommandError("Failed to delete user '%s': %s" % (name, msg))
 
+        try:
+            samdb = SamDB(url=H, session_info=system_session(),
+                          credentials=creds, lp=lp)
+            samdb.deleteuser(username)
+        except Exception, e:
+            raise CommandError('Failed to remove user "%s"' % username, e)
+        print("Deleted user %s" % username)
 
 
 class cmd_user_enable(Command):
diff --git a/source4/scripting/python/samba/samdb.py b/source4/scripting/python/samba/samdb.py
index 70f73da..f8369d6 100644
--- a/source4/scripting/python/samba/samdb.py
+++ b/source4/scripting/python/samba/samdb.py
@@ -393,6 +393,29 @@ member: %s
         else:
             self.transaction_commit()
 
+
+    def deleteuser(self, username):
+        """Deletes a user
+
+        :param username: Name of the target user
+        """
+
+        filter = "(&(sAMAccountName=%s)(objectCategory=%s,%s))" % (ldb.binary_encode(username), "CN=Person,CN=Schema,CN=Configuration", self.domain_dn())
+        self.transaction_start()
+        try:
+            target = self.search(base=self.domain_dn(), scope=ldb.SCOPE_SUBTREE,
+                                 expression=filter, attrs=[])
+            if len(target) == 0:
+                raise Exception('Unable to find user "%s"' % username)
+            assert(len(target) == 1)
+            self.delete(target[0].dn)
+        except Exception:
+            self.transaction_cancel()
+            raise
+        else:
+            self.transaction_commit()
+
+
     def setpassword(self, search_filter, password,
             force_change_at_next_login=False, username=None):
         """Sets the password for a user
diff --git a/source4/selftest/quick b/source4/selftest/quick
index aa602fd..2097085 100644
--- a/source4/selftest/quick
+++ b/source4/selftest/quick
@@ -34,4 +34,4 @@ rpc.handles
 rpc.echo
 smb.signing
 drs.unit
-samba4.blackbox.dbcheck
+samba4.blackbox.dbcheck.dc
diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py
index 0ef59b2..2a7d3f0 100755
--- a/source4/selftest/tests.py
+++ b/source4/selftest/tests.py
@@ -467,5 +467,6 @@ plantestsuite("samba4.blackbox.provision-backend.py", "none", ["PYTHON=%s" % pyt
 # Test renaming the DC
 plantestsuite("samba4.blackbox.renamedc.sh", "none", ["PYTHON=%s" % python, os.path.join(bbdir, "renamedc.sh"), '$PREFIX/provision'])
 
-# check the database is all OK. PLEASE LEAVE THIS AS THE LAST TEST
-plantestsuite("samba4.blackbox.dbcheck.sh", "dc:local", ["PYTHON=%s" % python, os.path.join(bbdir, "dbcheck.sh"), '$PREFIX/provision', configuration])
+# check the databases are all OK. PLEASE LEAVE THIS AS THE LAST TEST
+for env in ["dc", "fl2000dc", "fl2003dc", "fl2008r2dc"]:
+    plantestsuite("samba4.blackbox.dbcheck(%s)" % env, env + ":local" , ["PYTHON=%s" % python, os.path.join(bbdir, "dbcheck.sh"), '$PREFIX/provision', configuration])
diff --git a/source4/torture/basic/utable.c b/source4/torture/basic/utable.c
index d5b8082..0b45692 100644
--- a/source4/torture/basic/utable.c
+++ b/source4/torture/basic/utable.c
@@ -148,6 +148,7 @@ bool torture_casetable(struct torture_context *tctx,
 		torture_comment(tctx, "%04x (%c)\n", c, isprint(c)?c:'.');
 
 		fname = form_name(c);
+		if (fname == NULL) continue;
 		fnum = smbcli_nt_create_full(cli->tree, fname, 0,
 #if 0
 					     SEC_RIGHT_MAXIMUM_ALLOWED, 
@@ -158,9 +159,10 @@ bool torture_casetable(struct torture_context *tctx,
 					     NTCREATEX_SHARE_ACCESS_NONE,
 					     NTCREATEX_DISP_OPEN_IF, 0, 0);
 
-		torture_assert(tctx, fnum != -1, 
-					   talloc_asprintf(tctx, 
-			"Failed to create file with char %04x\n", c));
+		if (fnum == -1) {
+			torture_comment(tctx, "Failed to create file with char %04x\n", c);
+			continue;
+		}
 
 		size = 0;
 


-- 
Samba Shared Repository


More information about the samba-cvs mailing list