s4/test-libnet: Refactor test_group_create() a little to:
authorKamen Mazdrashki <kamenim@samba.org>
Fri, 11 Jun 2010 12:44:34 +0000 (15:44 +0300)
committerKamen Mazdrashki <kamenim@samba.org>
Fri, 11 Jun 2010 12:44:34 +0000 (15:44 +0300)
- Close unused policy handle for created group
- re-align code - it is more readable this way IMHO

source4/torture/libnet/utils.c

index b4b2374acf035d0b4f9261408a126db24216b8ab..fdb4be85910478de9f5ca576390baec1eb5f814a 100644 (file)
@@ -366,8 +366,10 @@ bool test_group_cleanup(struct torture_context *tctx,
  *                  which case RID is not required by caller
  */
 bool test_group_create(struct torture_context *tctx,
-                      struct dcerpc_binding_handle *b, TALLOC_CTX *mem_ctx,
-                      struct policy_handle *handle, const char *name,
+                      struct dcerpc_binding_handle *b,
+                      TALLOC_CTX *mem_ctx,
+                      struct policy_handle *handle,
+                      const char *group_name,
                       uint32_t *rid)
 {
        uint32_t group_rid;
@@ -375,7 +377,7 @@ bool test_group_create(struct torture_context *tctx,
        struct samr_CreateDomainGroup r;
        struct policy_handle group_handle;
 
-       groupname.string = name;
+       groupname.string = group_name;
 
        r.in.domain_handle  = handle;
        r.in.name           = &groupname;
@@ -385,33 +387,42 @@ bool test_group_create(struct torture_context *tctx,
         * don't care about the group RID */
        r.out.rid           = rid ? rid : &group_rid;
 
-       torture_comment(tctx, "creating group account %s\n", name);
+       torture_comment(tctx, "creating group account %s\n", group_name);
 
        torture_assert_ntstatus_ok(tctx,
-               dcerpc_samr_CreateDomainGroup_r(b, mem_ctx, &r),
-               "CreateGroup failed");
+                                  dcerpc_samr_CreateDomainGroup_r(b, mem_ctx, &r),
+                                  "CreateGroup failed");
        if (!NT_STATUS_IS_OK(r.out.result)) {
                torture_comment(tctx, "CreateGroup failed - %s\n", nt_errstr(r.out.result));
 
                if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_GROUP_EXISTS)) {
-                       torture_comment(tctx, "Group (%s) already exists - attempting to delete and recreate group again\n", name);
-                       if (!test_group_cleanup(tctx, b, mem_ctx, handle, name)) {
+                       torture_comment(tctx,
+                                       "Group (%s) already exists - "
+                                       "attempting to delete and recreate group again\n",
+                                       group_name);
+                       if (!test_group_cleanup(tctx, b, mem_ctx, handle, group_name)) {
                                return false;
                        }
 
                        torture_comment(tctx, "creating group account\n");
 
                        torture_assert_ntstatus_ok(tctx,
-                               dcerpc_samr_CreateDomainGroup_r(b, mem_ctx, &r),
-                               "CreateGroup failed");
+                                                  dcerpc_samr_CreateDomainGroup_r(b, mem_ctx, &r),
+                                                  "CreateGroup failed");
                        torture_assert_ntstatus_ok(tctx, r.out.result,
-                               "CreateGroup failed");
+                                                  "CreateGroup failed");
+
+                       /* be nice and close opened handles */
+                       test_samr_close_handle(tctx, b, mem_ctx, &user_handle);
 
                        return true;
                }
                return false;
        }
 
+       /* be nice and close opened handles */
+       test_samr_close_handle(tctx, b, mem_ctx, &user_handle);
+
        return true;
 }