summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamen Mazdrashki <kamenim@samba.org>2010-05-28 17:59:25 +0300
committerKamen Mazdrashki <kamenim@samba.org>2010-05-28 22:30:09 +0300
commit0f2263016fc7afd949af65e6e84b5c5455250191 (patch)
tree4b59bd8a2e49348646d24850e7131a74ea66a307
parent8dedb4d06ec84224f1b491cb76edb87b37550c56 (diff)
downloadsamba-0f2263016fc7afd949af65e6e84b5c5455250191.tar.gz
samba-0f2263016fc7afd949af65e6e84b5c5455250191.tar.bz2
samba-0f2263016fc7afd949af65e6e84b5c5455250191.zip
s4/test-libnet-utils: refactor test_user_create()
- param names made more clear what they stand for - user RID out param is now optional, so that this function may be used in cases where we don't need user RID - SAMR connection handle is closed as it is not used further (we should play nice with servers)
-rw-r--r--source4/torture/libnet/utils.c52
1 files changed, 39 insertions, 13 deletions
diff --git a/source4/torture/libnet/utils.c b/source4/torture/libnet/utils.c
index 02baf07046..b84e952fc9 100644
--- a/source4/torture/libnet/utils.c
+++ b/source4/torture/libnet/utils.c
@@ -158,50 +158,76 @@ bool test_user_cleanup(struct torture_context *tctx,
}
+/**
+ * Creates new user using SAMR
+ */
+/**
+ * Creates new user using SAMR
+ *
+ * @param name [in] Username for user to create
+ * @param rid [out] If NULL, User's RID is not returned
+ */
bool test_user_create(struct torture_context *tctx,
struct dcerpc_binding_handle *b,
TALLOC_CTX *mem_ctx,
- struct policy_handle *handle, const char *name,
+ struct policy_handle *domain_handle,
+ const char *name,
uint32_t *rid)
{
+ struct policy_handle user_handle;
struct lsa_String username;
struct samr_CreateUser r;
- struct policy_handle user_handle;
+ uint32_t user_rid;
username.string = name;
- r.in.domain_handle = handle;
+ r.in.domain_handle = domain_handle;
r.in.account_name = &username;
r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
r.out.user_handle = &user_handle;
- r.out.rid = rid;
+ r.out.rid = &user_rid;
- torture_comment(tctx, "creating user account %s\n", name);
+ torture_comment(tctx, "creating user '%s'\n", username.string);
torture_assert_ntstatus_ok(tctx,
- dcerpc_samr_CreateUser_r(b, mem_ctx, &r),
- "CreateUser failed");
+ dcerpc_samr_CreateUser_r(b, mem_ctx, &r),
+ "CreateUser RPC call failed");
if (!NT_STATUS_IS_OK(r.out.result)) {
- printf("CreateUser failed - %s\n", nt_errstr(r.out.result));
+ torture_comment(tctx, "CreateUser failed - %s\n", nt_errstr(r.out.result));
+
if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_USER_EXISTS)) {
- torture_comment(tctx, "User (%s) already exists - attempting to delete and recreate account again\n", name);
- if (!test_user_cleanup(tctx, b, mem_ctx, handle, name)) {
+ torture_comment(tctx,
+ "User (%s) already exists - "
+ "attempting to delete and recreate account again\n",
+ username.string);
+ if (!test_user_cleanup(tctx, b, mem_ctx, domain_handle, username.string)) {
return false;
}
torture_comment(tctx, "creating user account\n");
torture_assert_ntstatus_ok(tctx,
- dcerpc_samr_CreateUser_r(b, mem_ctx, &r),
- "CreateUser failed");
+ dcerpc_samr_CreateUser_r(b, mem_ctx, &r),
+ "CreateUser RPC call failed");
torture_assert_ntstatus_ok(tctx, r.out.result,
- "CreateUser failed");
+ "CreateUser failed");
return true;
}
return false;
}
+ torture_comment(tctx, "closing user '%s'\n", username.string);
+
+ if (!test_samr_close_handle(tctx, b, mem_ctx, &user_handle)) {
+ return false;
+ }
+
+ /* return user RID only if requested */
+ if (rid) {
+ *rid = user_rid;
+ }
+
return true;
}