s4/test: use test_libnet_context_init() function to create libnet_context
authorKamen Mazdrashki <kamenim@samba.org>
Thu, 10 Jun 2010 15:23:06 +0000 (18:23 +0300)
committerKamen Mazdrashki <kamenim@samba.org>
Thu, 10 Jun 2010 22:20:10 +0000 (01:20 +0300)
This way we ensure that LIBNET call will be issued against
the DC we are testing against

source4/torture/libnet/libnet_group.c
source4/torture/libnet/libnet_user.c

index ddc5630af6927ac3c91deb6fcf9da8664d78fc2a..0d8249f9f3aa5bdd66f863016d0074d432d14323 100644 (file)
@@ -57,7 +57,7 @@ bool torture_groupinfo_api(struct torture_context *torture)
        bool ret = true;
        NTSTATUS status;
        TALLOC_CTX *mem_ctx = NULL, *prep_mem_ctx;
-       struct libnet_context *ctx;
+       struct libnet_context *ctx = NULL;
        struct dcerpc_pipe *p;
        struct policy_handle h;
        struct lsa_String domain_name;
@@ -65,9 +65,6 @@ bool torture_groupinfo_api(struct torture_context *torture)
 
        prep_mem_ctx = talloc_init("prepare torture group info");
 
-       ctx = libnet_context_init(torture->ev, torture->lp_ctx);
-       ctx->cred = cmdline_credentials;
-
        status = torture_rpc_connection(torture,
                                        &p,
                                        &ndr_table_samr);
@@ -88,6 +85,10 @@ bool torture_groupinfo_api(struct torture_context *torture)
 
        mem_ctx = talloc_init("torture group info");
 
+       if (!test_libnet_context_init(torture, true, &ctx)) {
+               return false;
+       }
+
        ZERO_STRUCT(req);
 
        req.in.domain_name = domain_name.string;
@@ -113,9 +114,8 @@ bool torture_groupinfo_api(struct torture_context *torture)
                ret = false;
        }
 
-       talloc_free(ctx);
-
 done:
+       talloc_free(ctx);
        talloc_free(mem_ctx);
        return ret;
 }
index 9837a88e36d3ae07c123c8855ace2b1c5f8ef623..84a642a6225671c129fb8ed6e9fd29d4c57d8a3f 100644 (file)
@@ -54,14 +54,15 @@ bool torture_createuser(struct torture_context *torture)
 {
        NTSTATUS status;
        TALLOC_CTX *mem_ctx;
-       struct libnet_context *ctx;
+       struct libnet_context *ctx = NULL;
        struct libnet_CreateUser req;
        bool ret = true;
 
        mem_ctx = talloc_init("test_createuser");
 
-       ctx = libnet_context_init(torture->ev, torture->lp_ctx);
-       ctx->cred = cmdline_credentials;
+       if (!test_libnet_context_init(torture, true, &ctx)) {
+               return false;
+       }
 
        req.in.user_name = TEST_USERNAME;
        req.in.domain_name = lp_workgroup(torture->lp_ctx);
@@ -102,15 +103,12 @@ bool torture_deleteuser(struct torture_context *torture)
        struct policy_handle h;
        struct lsa_String domain_name;
        const char *name = TEST_USERNAME;
-       struct libnet_context *ctx;
+       struct libnet_context *ctx = NULL;
        struct libnet_DeleteUser req;
        bool ret = true;
 
        prep_mem_ctx = talloc_init("prepare test_deleteuser");
 
-       ctx = libnet_context_init(torture->ev, torture->lp_ctx);
-       ctx->cred = cmdline_credentials;
-
        req.in.user_name = TEST_USERNAME;
        req.in.domain_name = lp_workgroup(torture->lp_ctx);
 
@@ -135,6 +133,10 @@ bool torture_deleteuser(struct torture_context *torture)
 
        mem_ctx = talloc_init("test_deleteuser");
 
+       if (!test_libnet_context_init(torture, true, &ctx)) {
+               return false;
+       }
+
        status = libnet_DeleteUser(ctx, mem_ctx, &req);
        if (!NT_STATUS_IS_OK(status)) {
                torture_comment(torture, "libnet_DeleteUser call failed: %s\n", nt_errstr(status));
@@ -320,7 +322,7 @@ bool torture_modifyuser(struct torture_context *torture)
        struct policy_handle h;
        struct lsa_String domain_name;
        char *name;
-       struct libnet_context *ctx;
+       struct libnet_context *ctx = NULL;
        struct libnet_ModifyUser req;
        struct libnet_UserInfo user_req;
        int fld;
@@ -329,9 +331,6 @@ bool torture_modifyuser(struct torture_context *torture)
 
        prep_mem_ctx = talloc_init("prepare test_deleteuser");
 
-       ctx = libnet_context_init(torture->ev, torture->lp_ctx);
-       ctx->cred = cmdline_credentials;
-
        status = torture_rpc_connection(torture,
                                        &p,
                                        &ndr_table_samr);
@@ -356,7 +355,7 @@ bool torture_modifyuser(struct torture_context *torture)
 
        torture_comment(torture, "Testing change of all fields - each single one in turn\n");
 
-       if (!_libnet_context_init_pipes(torture, ctx)) {
+       if (!test_libnet_context_init(torture, true, &ctx)) {
                return false;
        }
 
@@ -439,7 +438,7 @@ bool torture_userinfo_api(struct torture_context *torture)
        bool ret = true;
        NTSTATUS status;
        TALLOC_CTX *mem_ctx = NULL, *prep_mem_ctx;
-       struct libnet_context *ctx;
+       struct libnet_context *ctx = NULL;
        struct dcerpc_pipe *p;
        struct policy_handle h;
        struct lsa_String domain_name;
@@ -448,9 +447,6 @@ bool torture_userinfo_api(struct torture_context *torture)
 
        prep_mem_ctx = talloc_init("prepare torture user info");
 
-       ctx = libnet_context_init(torture->ev, torture->lp_ctx);
-       ctx->cred = cmdline_credentials;
-
        status = torture_rpc_connection(torture,
                                        &p,
                                        &ndr_table_samr);
@@ -472,6 +468,10 @@ bool torture_userinfo_api(struct torture_context *torture)
 
        mem_ctx = talloc_init("torture user info");
 
+       if (!test_libnet_context_init(torture, true, &ctx)) {
+               return false;
+       }
+
        ZERO_STRUCT(req);
 
        req.in.domain_name = domain_name.string;
@@ -498,9 +498,8 @@ bool torture_userinfo_api(struct torture_context *torture)
                ret = false;
        }
 
-       talloc_free(ctx);
-
 done:
+       talloc_free(ctx);
        talloc_free(mem_ctx);
        return ret;
 }