[SCM] Samba Shared Repository - branch master updated

Kamen Mazdrashki kamenim at samba.org
Wed May 26 05:38:36 MDT 2010


The branch, master has been updated
       via  c2021e4... s4/test: Connect SAMR and LDARPC pipes before calling libnet_ functions
       via  de60cbb... s4/test: remove unused code
       via  5444272... s4/test: make test_cleanup() in libnet_user library more robust
       via  bbdb838... s4/test: rename enum test_fields{} member names to be more descriptive
       via  644593d... s4/test: Replace hand-made field count to test
      from  2bca048... s3:configure: use the right AC_CACHE_CHECK variable

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


- Log -----------------------------------------------------------------
commit c2021e4211ee1c4d840995d3adaf3e2494e35719
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Wed May 26 04:22:34 2010 +0300

    s4/test: Connect SAMR and LDARPC pipes before calling libnet_ functions
    
    In multi-DC environment, NBT name resolution may resolv
    domain name to any of DCs.
    This make this test to fail, as we are modifying the user account
    on one DC and query user info immediately after that on another DC.

commit de60cbb6e75fb1f6fe42fd0e86204d304911d30c
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Wed May 26 13:32:13 2010 +0300

    s4/test: remove unused code
    
    There is no need anymore to modify samAccountName
    of the testing user to original value as test_cleanup()
    will spot the right samAccountName to delete

commit 5444272f89785b9c7a63b197b89bf8fc40c39284
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Wed May 26 13:27:07 2010 +0300

    s4/test: make test_cleanup() in libnet_user library more robust
    
    test_cleanup() is called always with RDN name of the user to be deleted.
    When modify-user test fails however, we end up with a user
    with RDN = libnetusertest and samAccountName = random_name.
    This way we can not delete the user and the error message is
    quite misleading (I've spent a *lot* of time trying to figure out
    if the database is corrupted because of this error).

commit bbdb8384220f3fa51ded65d89fdab0496ad3da25
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Tue May 25 17:24:45 2010 +0300

    s4/test: rename enum test_fields{} member names to be more descriptive

commit 644593d30ecddec27f0a48340d74db7cf164bfc3
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Sat May 22 05:03:16 2010 +0300

    s4/test: Replace hand-made field count to test
    
    This patch replaces hand-make count of fields to be tested
    with defines for FIRST-LAST value for corresponding fields
    to test with.
    
    As a side-effect, 'acct_flags' is now included in tests.

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

Summary of changes:
 source4/torture/libnet/libnet_user.c |  170 ++++++++++++++++++++++++----------
 source4/torture/libnet/userman.c     |   22 ++--
 source4/torture/libnet/usertest.h    |   10 ++-
 3 files changed, 140 insertions(+), 62 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source4/torture/libnet/libnet_user.c b/source4/torture/libnet/libnet_user.c
index 140282b..4bda763 100644
--- a/source4/torture/libnet/libnet_user.c
+++ b/source4/torture/libnet/libnet_user.c
@@ -27,8 +27,70 @@
 #include "torture/rpc/torture_rpc.h"
 #include "torture/libnet/usertest.h"
 #include "param/param.h"
+#include "lib/ldb_wrap.h"
+
+
+/**
+ * Find out user's samAccountName for given
+ * user RDN. We need samAccountName value
+ * when deleting users.
+ */
+static bool _get_account_name_for_user_rdn(struct torture_context *tctx,
+					   struct dcerpc_binding_handle *b,
+					   const char *user_rdn,
+					   TALLOC_CTX *mem_ctx,
+					   const char **_account_name)
+{
+	const char *url;
+	struct ldb_context *ldb;
+	TALLOC_CTX *tmp_ctx;
+	bool test_res = true;
+	struct dcerpc_pipe *p = talloc_get_type_abort(b->private_data, struct dcerpc_pipe);
+	int ldb_ret;
+	struct ldb_result *ldb_res;
+	const char *account_name = NULL;
+	static const char *attrs[] = {
+		"samAccountName",
+		NULL
+	};
+
+	tmp_ctx = talloc_new(tctx);
+	torture_assert(tctx, tmp_ctx != NULL, "Failed to create temporary mem context");
+
+	url = talloc_asprintf(tmp_ctx, "ldap://%s/", p->binding->target_hostname);
+	torture_assert_goto(tctx, url != NULL, test_res, done, "Failed to allocate URL for ldb");
+
+	ldb = ldb_wrap_connect(tmp_ctx,
+	                       tctx->ev, tctx->lp_ctx,
+	                       url, NULL, cmdline_credentials, 0);
+	torture_assert_goto(tctx, ldb != NULL, test_res, done, "Failed to make LDB connection");
+
+	ldb_ret = ldb_search(ldb, tmp_ctx, &ldb_res,
+	                     ldb_get_default_basedn(ldb), LDB_SCOPE_SUBTREE,
+	                     attrs,
+	                     "(&(objectClass=user)(name=%s))", user_rdn);
+	if (LDB_SUCCESS == ldb_ret && 1 == ldb_res->count) {
+		account_name = ldb_msg_find_attr_as_string(ldb_res->msgs[0], "samAccountName", NULL);
+	}
 
+	/* return user_rdn by default */
+	if (!account_name) {
+		account_name = user_rdn;
+	}
 
+	/* duplicate memory in parent context */
+	*_account_name = talloc_strdup(mem_ctx, account_name);
+
+done:
+	talloc_free(tmp_ctx);
+	return test_res;
+}
+
+/**
+ * Deletes a user account when given user RDN name
+ *
+ * @param username RDN for the user to be deleted
+ */
 static bool test_cleanup(struct torture_context *tctx,
 			 struct dcerpc_binding_handle *b, TALLOC_CTX *mem_ctx,
 			 struct policy_handle *domain_handle, const char *username)
@@ -40,8 +102,15 @@ static bool test_cleanup(struct torture_context *tctx,
 	uint32_t rid;
 	struct policy_handle user_handle;
 	struct samr_Ids rids, types;
+	const char *account_name;
 
-	names[0].string = username;
+	if (!_get_account_name_for_user_rdn(tctx, b, username, mem_ctx, &account_name)) {
+		torture_result(tctx, TORTURE_FAIL,
+		               __location__": Failed to find samAccountName for %s", username);
+		return false;
+	}
+
+	names[0].string = account_name;
 
 	r1.in.domain_handle  = domain_handle;
 	r1.in.num_names      = 1;
@@ -49,7 +118,7 @@ static bool test_cleanup(struct torture_context *tctx,
 	r1.out.rids          = &rids;
 	r1.out.types         = &types;
 
-	torture_comment(tctx, "user account lookup '%s'\n", username);
+	torture_comment(tctx, "user account lookup '%s'\n", account_name);
 
 	torture_assert_ntstatus_ok(tctx,
 		dcerpc_samr_LookupNames_r(b, mem_ctx, &r1),
@@ -206,7 +275,7 @@ static bool test_createuser(struct torture_context *tctx,
 
 		if (NT_STATUS_EQUAL(r1.out.result, NT_STATUS_USER_EXISTS)) {
 			torture_comment(tctx, "User (%s) already exists - attempting to delete and recreate account again\n", user);
-			if (!test_cleanup(tctx, b, mem_ctx, handle, TEST_USERNAME)) {
+			if (!test_cleanup(tctx, b, mem_ctx, handle, user)) {
 				return false;
 			}
 
@@ -356,16 +425,16 @@ static void set_test_changes(struct torture_context *tctx,
 
 	torture_comment(tctx, "Fields to change: [");
 
-	for (i = 0; i < num_changes && i < FIELDS_NUM; i++) {
+	for (i = 0; i < num_changes && i <= USER_FIELD_LAST; i++) {
 		const char *fldname;
 
-		testfld = (req_change == none) ? (random() % FIELDS_NUM) : req_change;
+		testfld = (req_change == none) ? (random() % USER_FIELD_LAST) + 1 : req_change;
 
 		/* get one in case we hit time field this time */
 		gettimeofday(&now, NULL);
 
 		switch (testfld) {
-		case account_name:
+		case acct_name:
 			continue_if_field_set(r->in.account_name);
 			r->in.account_name = talloc_asprintf(mem_ctx, TEST_CHG_ACCOUNTNAME,
 							     (int)(random() % 100));
@@ -375,49 +444,49 @@ static void set_test_changes(struct torture_context *tctx,
 			*user_name = talloc_strdup(mem_ctx, r->in.account_name);
 			break;
 
-		case full_name:
+		case acct_full_name:
 			continue_if_field_set(r->in.full_name);
 			r->in.full_name = talloc_asprintf(mem_ctx, TEST_CHG_FULLNAME,
 							  (unsigned int)random(), (unsigned int)random());
 			fldname = "full_name";
 			break;
 
-		case description:
+		case acct_description:
 			continue_if_field_set(r->in.description);
 			r->in.description = talloc_asprintf(mem_ctx, TEST_CHG_DESCRIPTION,
 							    (long)random());
 			fldname = "description";
 			break;
 
-		case home_directory:
+		case acct_home_directory:
 			continue_if_field_set(r->in.home_directory);
 			homedir = home_dirs[random() % ARRAY_SIZE(home_dirs)];
 			r->in.home_directory = talloc_strdup(mem_ctx, homedir);
 			fldname = "home_dir";
 			break;
 
-		case home_drive:
+		case acct_home_drive:
 			continue_if_field_set(r->in.home_drive);
 			homedrive = home_drives[random() % ARRAY_SIZE(home_drives)];
 			r->in.home_drive = talloc_strdup(mem_ctx, homedrive);
 			fldname = "home_drive";
 			break;
 
-		case comment:
+		case acct_comment:
 			continue_if_field_set(r->in.comment);
 			r->in.comment = talloc_asprintf(mem_ctx, TEST_CHG_COMMENT,
 							(unsigned long)random(), (unsigned long)random());
 			fldname = "comment";
 			break;
 
-		case logon_script:
+		case acct_logon_script:
 			continue_if_field_set(r->in.logon_script);
 			logonscript = logon_scripts[random() % ARRAY_SIZE(logon_scripts)];
 			r->in.logon_script = talloc_strdup(mem_ctx, logonscript);
 			fldname = "logon_script";
 			break;
 
-		case profile_path:
+		case acct_profile_path:
 			continue_if_field_set(r->in.profile_path);
 			r->in.profile_path = talloc_asprintf(mem_ctx, TEST_CHG_PROFILEPATH,
 							     (unsigned long)random(), (unsigned int)random());
@@ -473,10 +542,34 @@ static void set_test_changes(struct torture_context *tctx,
 	}
 
 
+static bool _libnet_context_init_pipes(struct torture_context *tctx,
+				       struct libnet_context *libnet_ctx)
+{
+	NTSTATUS status;
+
+	/* connect SAMR pipe */
+	status = torture_rpc_connection(tctx,
+					&libnet_ctx->samr.pipe,
+					&ndr_table_samr);
+	torture_assert_ntstatus_ok(tctx, status, "Failed to open SAMR pipe");
+
+	libnet_ctx->samr.samr_handle = libnet_ctx->samr.pipe->binding_handle;
+
+
+	/* connect LSARPC pipe */
+	status = torture_rpc_connection(tctx,
+					&libnet_ctx->lsa.pipe,
+					&ndr_table_lsarpc);
+	torture_assert_ntstatus_ok(tctx, status, "Failed to open LSA pipe");
+
+	libnet_ctx->lsa.lsa_handle = libnet_ctx->lsa.pipe->binding_handle;
+
+	return true;
+}
+
 bool torture_modifyuser(struct torture_context *torture)
 {
 	NTSTATUS status;
-	struct dcerpc_binding *binding;
 	struct dcerpc_pipe *p;
 	TALLOC_CTX *prep_mem_ctx;
 	struct policy_handle h;
@@ -516,15 +609,13 @@ bool torture_modifyuser(struct torture_context *torture)
 		goto done;
 	}
 
-	status = torture_rpc_binding(torture, &binding);
-	if (!NT_STATUS_IS_OK(status)) {
-		ret = false;
-		goto done;
-	}
-
 	torture_comment(torture, "Testing change of all fields - each single one in turn\n");
 
-	for (fld = 1; fld < FIELDS_NUM - 1; fld++) {
+	if (!_libnet_context_init_pipes(torture, ctx)) {
+		return false;
+	}
+
+	for (fld = USER_FIELD_FIRST; fld <= USER_FIELD_LAST; fld++) {
 		ZERO_STRUCT(req);
 		req.in.domain_name = lp_workgroup(torture->lp_ctx);
 		req.in.user_name = name;
@@ -551,21 +642,21 @@ bool torture_modifyuser(struct torture_context *torture)
 		}
 
 		switch (fld) {
-		case account_name: TEST_STR_FLD(account_name);
+		case acct_name: TEST_STR_FLD(account_name);
 			break;
-		case full_name: TEST_STR_FLD(full_name);
+		case acct_full_name: TEST_STR_FLD(full_name);
 			break;
-		case comment: TEST_STR_FLD(comment);
+		case acct_comment: TEST_STR_FLD(comment);
 			break;
-		case description: TEST_STR_FLD(description);
+		case acct_description: TEST_STR_FLD(description);
 			break;
-		case home_directory: TEST_STR_FLD(home_directory);
+		case acct_home_directory: TEST_STR_FLD(home_directory);
 			break;
-		case home_drive: TEST_STR_FLD(home_drive);
+		case acct_home_drive: TEST_STR_FLD(home_drive);
 			break;
-		case logon_script: TEST_STR_FLD(logon_script);
+		case acct_logon_script: TEST_STR_FLD(logon_script);
 			break;
-		case profile_path: TEST_STR_FLD(profile_path);
+		case acct_profile_path: TEST_STR_FLD(profile_path);
 			break;
 		case acct_expiry: TEST_TIME_FLD(acct_expiry);
 			break;
@@ -574,28 +665,11 @@ bool torture_modifyuser(struct torture_context *torture)
 		default:
 			break;
 		}
-
-		if (fld == account_name) {
-			/* restore original testing username - it's useful when test fails
-			   because it prevents from problems with recreating account */
-			ZERO_STRUCT(req);
-			req.in.domain_name = lp_workgroup(torture->lp_ctx);
-			req.in.user_name = name;
-			req.in.account_name = TEST_USERNAME;
-
-			status = libnet_ModifyUser(ctx, torture, &req);
-			if (!NT_STATUS_IS_OK(status)) {
-				torture_comment(torture, "libnet_ModifyUser call failed: %s\n", nt_errstr(status));
-				ret = false;
-				goto done;
-			}
-
-			name = talloc_strdup(torture, TEST_USERNAME);
-		}
 	}
 
 cleanup:
-	if (!test_cleanup(torture, ctx->samr.pipe->binding_handle, torture, &ctx->samr.handle, name)) {
+	if (!test_cleanup(torture, ctx->samr.pipe->binding_handle,
+	                  torture, &ctx->samr.handle, TEST_USERNAME)) {
 		torture_comment(torture, "cleanup failed\n");
 		ret = false;
 		goto done;
diff --git a/source4/torture/libnet/userman.c b/source4/torture/libnet/userman.c
index c1d67fb..b1699cf 100644
--- a/source4/torture/libnet/userman.c
+++ b/source4/torture/libnet/userman.c
@@ -110,15 +110,15 @@ static bool test_usermod(struct torture_context *tctx, struct dcerpc_pipe *p,
 
 	torture_comment(tctx, "fields to change: [");
 
-	for (i = 0; i < num_changes && i < FIELDS_NUM - 1; i++) {
+	for (i = 0; i < num_changes && i <= USER_FIELD_LAST; i++) {
 		const char *fldname;
 
-		testfld = (random() % (FIELDS_NUM - 1)) + 1;
+		testfld = (random() % USER_FIELD_LAST) + 1;
 
 		gettimeofday(&now, NULL);
 
 		switch (testfld) {
-		case account_name:
+		case acct_name:
 			continue_if_field_set(mod->in.change.account_name);
 			mod->in.change.account_name = talloc_asprintf(mem_ctx, TEST_CHG_ACCOUNTNAME,
 								      (int)(random() % 100));
@@ -127,7 +127,7 @@ static bool test_usermod(struct torture_context *tctx, struct dcerpc_pipe *p,
 			*username = talloc_strdup(mem_ctx, mod->in.change.account_name);
 			break;
 
-		case full_name:
+		case acct_full_name:
 			continue_if_field_set(mod->in.change.full_name);
 			mod->in.change.full_name = talloc_asprintf(mem_ctx, TEST_CHG_FULLNAME,
 								  (int)random(), (int)random());
@@ -135,7 +135,7 @@ static bool test_usermod(struct torture_context *tctx, struct dcerpc_pipe *p,
 			fldname = "full_name";
 			break;
 
-		case description:
+		case acct_description:
 			continue_if_field_set(mod->in.change.description);
 			mod->in.change.description = talloc_asprintf(mem_ctx, TEST_CHG_DESCRIPTION,
 								    random());
@@ -143,7 +143,7 @@ static bool test_usermod(struct torture_context *tctx, struct dcerpc_pipe *p,
 			fldname = "description";
 			break;
 
-		case home_directory:
+		case acct_home_directory:
 			continue_if_field_set(mod->in.change.home_directory);
 			homedir = home_dirs[random() % (sizeof(home_dirs)/sizeof(char*))];
 			mod->in.change.home_directory = talloc_strdup(mem_ctx, homedir);
@@ -151,7 +151,7 @@ static bool test_usermod(struct torture_context *tctx, struct dcerpc_pipe *p,
 			fldname = "home_directory";
 			break;
 
-		case home_drive:
+		case acct_home_drive:
 			continue_if_field_set(mod->in.change.home_drive);
 			homedrive = home_drives[random() % (sizeof(home_drives)/sizeof(char*))];
 			mod->in.change.home_drive = talloc_strdup(mem_ctx, homedrive);
@@ -159,7 +159,7 @@ static bool test_usermod(struct torture_context *tctx, struct dcerpc_pipe *p,
 			fldname = "home_drive";
 			break;
 
-		case comment:
+		case acct_comment:
 			continue_if_field_set(mod->in.change.comment);
 			mod->in.change.comment = talloc_asprintf(mem_ctx, TEST_CHG_COMMENT,
 								random(), random());
@@ -167,7 +167,7 @@ static bool test_usermod(struct torture_context *tctx, struct dcerpc_pipe *p,
 			fldname = "comment";
 			break;
 
-		case logon_script:
+		case acct_logon_script:
 			continue_if_field_set(mod->in.change.logon_script);
 			logonscript = logon_scripts[random() % (sizeof(logon_scripts)/sizeof(char*))];
 			mod->in.change.logon_script = talloc_strdup(mem_ctx, logonscript);
@@ -175,7 +175,7 @@ static bool test_usermod(struct torture_context *tctx, struct dcerpc_pipe *p,
 			fldname = "logon_script";
 			break;
 
-		case profile_path:
+		case acct_profile_path:
 			continue_if_field_set(mod->in.change.profile_path);
 			mod->in.change.profile_path = talloc_asprintf(mem_ctx, TEST_CHG_PROFILEPATH,
 								     (long int)random(), (unsigned int)random());
@@ -444,7 +444,7 @@ bool torture_usermod(struct torture_context *torture)
 		goto done;
 	}
 
-	for (i = 1; i < FIELDS_NUM; i++) {
+	for (i = USER_FIELD_FIRST; i <= USER_FIELD_LAST; i++) {
 		struct libnet_rpc_usermod m;
 
 		if (!test_usermod(torture, p, mem_ctx, &h, i, &m, &name)) {
diff --git a/source4/torture/libnet/usertest.h b/source4/torture/libnet/usertest.h
index 19d5641..b3b2dc1 100644
--- a/source4/torture/libnet/usertest.h
+++ b/source4/torture/libnet/usertest.h
@@ -26,9 +26,13 @@
 	}
 
 
-#define FIELDS_NUM 11
-enum test_fields { none = 0, account_name, full_name, description, home_directory, home_drive,
-		   comment, logon_script, profile_path, acct_expiry, acct_flags };
+#define USER_FIELD_FIRST	acct_name
+#define USER_FIELD_LAST 	acct_flags
+
+enum test_fields { none = 0,
+		   acct_name, acct_full_name, acct_description,
+		   acct_home_directory, acct_home_drive, acct_comment,
+		   acct_logon_script, acct_profile_path, acct_expiry, acct_flags };
 
 
 #define TEST_CHG_ACCOUNTNAME   "newlibnetusertest%02d"


-- 
Samba Shared Repository


More information about the samba-cvs mailing list