s4: torture: Remove talloc_autofree_context() from locktest.
[garming/samba-autobuild/.git] / source4 / torture / locktest.c
index a09b54cfd625cdb0b2555295fb8971fddf9f007c..704755464ed016fe15119eef7dd35190ef7f6ecb 100644 (file)
@@ -118,8 +118,8 @@ static struct smbcli_state *connect_one(struct tevent_context *ev,
        struct smbcli_options options;
        struct smbcli_session_options session_options;
 
-       lp_smbcli_options(lp_ctx, &options);
-       lp_smbcli_session_options(lp_ctx, &session_options);
+       lpcfg_smbcli_options(lp_ctx, &options);
+       lpcfg_smbcli_session_options(lp_ctx, &session_options);
 
        printf("connect_one(%s, %d, %d)\n", share, snum, conn);
 
@@ -133,7 +133,7 @@ static struct smbcli_state *connect_one(struct tevent_context *ev,
                char **unc_list = NULL;
                int num_unc_names;
                const char *p;
-               p = lp_parm_string(lp_ctx, NULL, "torture", "unclist");
+               p = lpcfg_parm_string(lp_ctx, NULL, "torture", "unclist");
                if (p) {
                        char *h, *s;
                        unc_list = file_lines_load(p, &num_unc_names, 0, NULL);
@@ -154,20 +154,20 @@ static struct smbcli_state *connect_one(struct tevent_context *ev,
        }
 
 
-       myname = talloc_asprintf(mem_ctx, "lock-%u-%u", getpid(), snum);
+       myname = talloc_asprintf(mem_ctx, "lock-%d-%d", (int) getpid(), snum);
        cli_credentials_set_workstation(servers[snum], myname, CRED_SPECIFIED);
 
        do {
                printf("\\\\%s\\%s\n", server, share);
                status = smbcli_full_connection(NULL, &c, 
                                                server, 
-                                               lp_smb_ports(lp_ctx),
+                                               lpcfg_smb_ports(lp_ctx),
                                                share, NULL,
-                                               lp_socket_options(lp_ctx),
+                                               lpcfg_socket_options(lp_ctx),
                                                servers[snum], 
-                                               lp_resolve_context(lp_ctx),
+                                               lpcfg_resolve_context(lp_ctx),
                                                ev, &options, &session_options,
-                                               lp_gensec_settings(mem_ctx, lp_ctx));
+                                               lpcfg_gensec_settings(mem_ctx, lp_ctx));
                if (!NT_STATUS_IS_OK(status)) {
                        sleep(2);
                }
@@ -200,7 +200,7 @@ static void reconnect(struct tevent_context *ev,
                        }
                        talloc_free(cli[server][conn]);
                }
-               cli[server][conn] = connect_one(ev, lp_ctx, mem_ctx, share[server], 
+               cli[server][conn] = connect_one(ev, lp_ctx, mem_ctx, share[server],
                                                server, conn);
                if (!cli[server][conn]) {
                        DEBUG(0,("Failed to connect to %s\n", share[server]));
@@ -221,7 +221,7 @@ static bool test_one(struct smbcli_state *cli[NSERVERS][NCONNECTIONS],
        uint64_t len = rec->len;
        enum brl_type op = rec->lock_type;
        int server;
-       bool ret[NSERVERS];
+       /* bool ret[NSERVERS]; */
        NTSTATUS status[NSERVERS];
 
        switch (rec->lock_op) {
@@ -233,7 +233,7 @@ static bool test_one(struct smbcli_state *cli[NSERVERS][NCONNECTIONS],
                        int fn=fnum[server][conn][f];
 
                        if (!(tree->session->transport->negotiate.capabilities & CAP_LARGE_FILES)) {
-                               res=smbcli_lock(tree, fn, start, len, LOCK_TIMEOUT, rec->lock_op);
+                               res=smbcli_lock(tree, fn, start, len, LOCK_TIMEOUT, (enum brl_type) rec->lock_op);
                        } else {
                                union smb_lock parms;
                                int ltype;
@@ -242,7 +242,7 @@ static bool test_one(struct smbcli_state *cli[NSERVERS][NCONNECTIONS],
                                parms.lockx.level = RAW_LOCK_LOCKX;
                                parms.lockx.in.file.fnum = fn;
        
-                               ltype = (rec->lock_op == READ_LOCK? 1 : 0);
+                               ltype = (rec->lock_type == READ_LOCK? 1 : 0);
                                ltype |= LOCKING_ANDX_LARGE_FILES;
                                parms.lockx.in.mode = ltype;
                                parms.lockx.in.timeout = LOCK_TIMEOUT;
@@ -256,8 +256,8 @@ static bool test_one(struct smbcli_state *cli[NSERVERS][NCONNECTIONS],
                                res = smb_raw_lock(tree, &parms);
                        }
 
-                       ret[server] = NT_STATUS_IS_OK(res); 
-                       status[server] = smbcli_nt_error(cli[server][conn]->tree);
+                       /* ret[server] = NT_STATUS_IS_OK(res); */
+                       status[server] = res;
                        if (!exact_error_codes && 
                            NT_STATUS_EQUAL(status[server], 
                                            NT_STATUS_FILE_LOCK_CONFLICT)) {
@@ -302,8 +302,8 @@ static bool test_one(struct smbcli_state *cli[NSERVERS][NCONNECTIONS],
                                res = smb_raw_lock(tree, &parms);
                        }
 
-                       ret[server] = NT_STATUS_IS_OK(res);
-                       status[server] = smbcli_nt_error(cli[server][conn]->tree);
+                       /* ret[server] = NT_STATUS_IS_OK(res); */
+                       status[server] = res;
                }
                if (showall || 
                    (!hide_unlock_fails && !NT_STATUS_EQUAL(status[0],status[1]))) {
@@ -405,7 +405,7 @@ static int retest(struct smbcli_state *cli[NSERVERS][NCONNECTIONS],
  */
 static int test_locks(struct tevent_context *ev,
                      struct loadparm_context *lp_ctx,
-                         TALLOC_CTX *mem_ctx,
+                     TALLOC_CTX *mem_ctx,
                      char *share[NSERVERS])
 {
        struct smbcli_state *cli[NSERVERS][NCONNECTIONS];
@@ -547,7 +547,7 @@ static void usage(poptContext pc)
 /****************************************************************************
   main program
 ****************************************************************************/
- int main(int argc,char *argv[])
+int main(int argc, const char *argv[])
 {
        char *share[NSERVERS];
        int opt;
@@ -580,29 +580,38 @@ static void usage(poptContext pc)
                POPT_COMMON_VERSION
                { NULL }
        };
+       TALLOC_CTX *mem_ctx = NULL;
+       int ret = -1;
 
        setlinebuf(stdout);
        seed = time(NULL);
 
-       pc = poptGetContext("locktest", argc, (const char **) argv, long_options, 
+       mem_ctx = talloc_named_const(NULL, 0, "locktest_ctx");
+       if (mem_ctx == NULL) {
+               printf("Unable to allocate locktest_ctx\n");
+               exit(1);
+       }
+
+       pc = poptGetContext("locktest", argc, argv, long_options,
                            POPT_CONTEXT_KEEP_FIRST);
 
        poptSetOtherOptionHelp(pc, "<unc1> <unc2>");
 
        lp_ctx = cmdline_lp_ctx;
-       servers[0] = cli_credentials_init(talloc_autofree_context());
-       servers[1] = cli_credentials_init(talloc_autofree_context());
+       servers[0] = cli_credentials_init(mem_ctx);
+       servers[1] = cli_credentials_init(mem_ctx);
        cli_credentials_guess(servers[0], lp_ctx);
        cli_credentials_guess(servers[1], lp_ctx);
 
        while((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_UNCLIST:
-                       lp_set_cmdline(cmdline_lp_ctx, "torture:unclist", poptGetOptArg(pc));
+                       lpcfg_set_cmdline(cmdline_lp_ctx, "torture:unclist", poptGetOptArg(pc));
                        break;
                case 'U':
                        if (username_count == 2) {
                                usage(pc);
+                               talloc_free(mem_ctx);
                                exit(1);
                        }
                        cli_credentials_parse_string(servers[username_count], poptGetOptArg(pc), CRED_SPECIFIED);
@@ -642,14 +651,16 @@ static void usage(poptContext pc)
                servers[1] = servers[0];
        }
 
-       ev = s4_event_context_init(talloc_autofree_context());
+       ev = s4_event_context_init(mem_ctx);
 
-       gensec_init(lp_ctx);
+       gensec_init();
 
        DEBUG(0,("seed=%u base=%d range=%d min_length=%d\n", 
                 seed, lock_base, lock_range, min_length));
        srandom(seed);
 
-       return test_locks(ev, lp_ctx, NULL, share);
+       ret = test_locks(ev, lp_ctx, NULL, share);
+       talloc_free(mem_ctx);
+       return ret;
 }