s4: torture: Remove talloc_autofree_context() from locktest.
[garming/samba-autobuild/.git] / source4 / torture / locktest.c
index 819fbe072b950f2cc3a86bc606ffd54ce68a365d..704755464ed016fe15119eef7dd35190ef7f6ecb 100644 (file)
@@ -26,7 +26,6 @@
 #include "auth/gensec/gensec.h"
 #include "libcli/libcli.h"
 #include "param/param.h"
-#include "dynconfig/dynconfig.h"
 #include "libcli/resolve/resolve.h"
 
 static int numops = 1000;
@@ -34,9 +33,9 @@ static int showall;
 static int analyze;
 static int hide_unlock_fails;
 static int use_oplocks;
-static uint_t lock_range = 100;
-static uint_t lock_base = 0;
-static uint_t min_length = 0;
+static unsigned int lock_range = 100;
+static unsigned int lock_base = 0;
+static unsigned int min_length = 0;
 static int exact_error_codes;
 static int zero_zero;
 
@@ -107,7 +106,7 @@ static struct record *recorded;
 /***************************************************** 
 return a connection to a server
 *******************************************************/
-static struct smbcli_state *connect_one(struct event_context *ev,
+static struct smbcli_state *connect_one(struct tevent_context *ev,
                                        struct loadparm_context *lp_ctx,
                                        TALLOC_CTX *mem_ctx,
                                        char *share, int snum, int conn)
@@ -119,8 +118,8 @@ static struct smbcli_state *connect_one(struct event_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);
 
@@ -134,7 +133,7 @@ static struct smbcli_state *connect_one(struct event_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);
@@ -155,19 +154,20 @@ static struct smbcli_state *connect_one(struct event_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,
+                                               lpcfg_socket_options(lp_ctx),
                                                servers[snum], 
-                                               lp_resolve_context(lp_ctx),
+                                               lpcfg_resolve_context(lp_ctx),
                                                ev, &options, &session_options,
-                                               lp_iconv_convenience(lp_ctx));
+                                               lpcfg_gensec_settings(mem_ctx, lp_ctx));
                if (!NT_STATUS_IS_OK(status)) {
                        sleep(2);
                }
@@ -181,7 +181,7 @@ static struct smbcli_state *connect_one(struct event_context *ev,
 }
 
 
-static void reconnect(struct event_context *ev,
+static void reconnect(struct tevent_context *ev,
                      struct loadparm_context *lp_ctx,
                          TALLOC_CTX *mem_ctx,
                      struct smbcli_state *cli[NSERVERS][NCONNECTIONS], int fnum[NSERVERS][NCONNECTIONS][NFILES],
@@ -200,7 +200,7 @@ static void reconnect(struct event_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]));
@@ -215,13 +215,13 @@ static bool test_one(struct smbcli_state *cli[NSERVERS][NCONNECTIONS],
                     int fnum[NSERVERS][NCONNECTIONS][NFILES],
                     struct record *rec)
 {
-       uint_t conn = rec->conn;
-       uint_t f = rec->f;
+       unsigned int conn = rec->conn;
+       unsigned int f = rec->f;
        uint64_t start = rec->start;
        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]))) {
@@ -384,7 +384,7 @@ static int retest(struct smbcli_state *cli[NSERVERS][NCONNECTIONS],
                   int n)
 {
        int i;
-       printf("testing %u ...\n", n);
+       printf("Testing %u ...\n", n);
        for (i=0; i<n; i++) {
                if (i && i % 100 == 0) {
                        printf("%u\n", i);
@@ -403,9 +403,9 @@ static int retest(struct smbcli_state *cli[NSERVERS][NCONNECTIONS],
    we then do random locking ops in tamdem on the 4 fnums from each
    server and ensure that the results match
  */
-static int test_locks(struct event_context *ev,
+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];
@@ -425,7 +425,7 @@ static int test_locks(struct event_context *ev,
 #endif
                        recorded[n].conn = random() % NCONNECTIONS;
                        recorded[n].f = random() % NFILES;
-                       recorded[n].start = lock_base + ((uint_t)random() % (lock_range-1));
+                       recorded[n].start = lock_base + ((unsigned int)random() % (lock_range-1));
                        recorded[n].len =  min_length +
                                random() % (lock_range-(recorded[n].start-lock_base));
                        recorded[n].start *= RANGE_MULTIPLE;
@@ -547,13 +547,13 @@ 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;
        int seed, server;
        int username_count=0;
-       struct event_context *ev;
+       struct tevent_context *ev;
        struct loadparm_context *lp_ctx;
        poptContext pc;
        int argc_new, i;
@@ -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;
 }