s4-loadparm: 2nd half of lp_ to lpcfg_ conversion
[gd/samba-autobuild/.git] / source4 / torture / masktest.c
index a739a1e1b5b6baa66ba3196e87ab6d15d6f406dc..9c66291087fb6d3f1f7e7366eb5bdcb6a719c4dc 100644 (file)
 #include "system/filesys.h"
 #include "system/dir.h"
 #include "libcli/libcli.h"
-#include "libcli/raw/libcliraw.h"
 #include "system/time.h"
-#include "pstring.h"
 #include "auth/credentials/credentials.h"
 #include "auth/gensec/gensec.h"
 #include "param/param.h"
-#include "dynconfig/dynconfig.h"
 #include "libcli/resolve/resolve.h"
 #include "lib/events/events.h"
 
@@ -55,10 +52,10 @@ static bool reg_match_one(struct smbcli_state *cli, const char *pattern, const c
        return ms_fnmatch(pattern, file, cli->transport->negotiate.protocol)==0;
 }
 
-static char *reg_test(struct smbcli_state *cli, char *pattern, char *long_name, char *short_name)
+static char *reg_test(struct smbcli_state *cli, TALLOC_CTX *mem_ctx, const char *pattern, const char *long_name, const char *short_name)
 {
-       static fstring ret;
-       fstrcpy(ret, "---");
+       char *ret;
+       ret = talloc_strdup(mem_ctx, "---");
 
        pattern = 1+strrchr_m(pattern,'\\');
 
@@ -74,16 +71,19 @@ static char *reg_test(struct smbcli_state *cli, char *pattern, char *long_name,
 return a connection to a server
 *******************************************************/
 static struct smbcli_state *connect_one(struct resolve_context *resolve_ctx, 
-                                       struct event_context *ev,
+                                       struct tevent_context *ev,
+                                       TALLOC_CTX *mem_ctx,
                                        char *share, const char **ports,
+                                       const char *socket_options,
                                        struct smbcli_options *options,
-                                       struct smbcli_session_options *session_options)
+                                       struct smbcli_session_options *session_options,
+                                       struct gensec_settings *gensec_settings)
 {
        struct smbcli_state *c;
-       fstring server;
+       char *server;
        NTSTATUS status;
 
-       fstrcpy(server,share+2);
+       server = talloc_strdup(mem_ctx, share+2);
        share = strchr_m(server,'\\');
        if (!share) return NULL;
        *share = 0;
@@ -95,8 +95,10 @@ static struct smbcli_state *connect_one(struct resolve_context *resolve_ctx,
                                        server, 
                                        ports,
                                        share, NULL,
+                                       socket_options,
                                        cmdline_credentials, resolve_ctx, ev,
-                                       options, session_options);
+                                       options, session_options,
+                                       gensec_settings);
 
        if (!NT_STATUS_IS_OK(status)) {
                return NULL;
@@ -130,7 +132,7 @@ static void listfn(struct clilist_file_info *f, const char *s, void *state)
 }
 
 static void get_real_name(TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
-                         char **long_name, fstring short_name)
+                         char **long_name, char **short_name)
 {
        const char *mask;
        struct masktest_state state;
@@ -151,14 +153,14 @@ static void get_real_name(TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
                        listfn, &state);
 
        if (f_info_hit) {
-               fstrcpy(short_name, last_hit.short_name);
-               strlower(short_name);
+               *short_name = talloc_strdup(mem_ctx, last_hit.short_name);
+               strlower(*short_name);
                *long_name = talloc_strdup(mem_ctx, last_hit.long_name);
                strlower(*long_name);
        }
 
        if (*short_name == '\0') {
-               fstrcpy(short_name, *long_name);
+               *short_name = talloc_strdup(mem_ctx, *long_name);
        }
 }
 
@@ -166,16 +168,16 @@ static void testpair(TALLOC_CTX *mem_ctx, struct smbcli_state *cli, char *mask,
                char *file)
 {
        int fnum;
-       fstring res1;
+       char res1[256];
        char *res2;
        static int count;
-       fstring short_name;
+       char *short_name = NULL;
        char *long_name = NULL;
        struct masktest_state state;
 
        count++;
 
-       fstrcpy(res1, "---");
+       safe_strcpy(res1, "---", sizeof(res1));
 
        state.mem_ctx = mem_ctx;
 
@@ -187,15 +189,15 @@ static void testpair(TALLOC_CTX *mem_ctx, struct smbcli_state *cli, char *mask,
        smbcli_close(cli->tree, fnum);
 
        resultp = res1;
-       fstrcpy(short_name, "");
-       get_real_name(mem_ctx, cli, &long_name, short_name);
-       fstrcpy(res1, "---");
+       short_name = talloc_strdup(mem_ctx, "");
+       get_real_name(mem_ctx, cli, &long_name, &short_name);
+       safe_strcpy(res1, "---", sizeof(res1));
        smbcli_list_new(cli->tree, mask,
                        FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY,
                        RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO,
                        listfn, &state);
 
-       res2 = reg_test(cli, mask, long_name, short_name);
+       res2 = reg_test(cli, mem_ctx, mask, long_name, short_name);
 
        if (showall || strcmp(res1, res2)) {
                d_printf("%s %s %d mask=[%s] file=[%s] rfile=[%s/%s]\n",
@@ -211,16 +213,14 @@ static void testpair(TALLOC_CTX *mem_ctx, struct smbcli_state *cli, char *mask,
 }
 
 static void test_mask(int argc, char *argv[],
+                                         TALLOC_CTX *mem_ctx,
                      struct smbcli_state *cli)
 {
-       TALLOC_CTX *mem_ctx;
        char *mask, *file;
        int l1, l2, i, l;
        int mc_len = strlen(maskchars);
        int fc_len = strlen(filechars);
 
-       mem_ctx = talloc_init("test_mask");
-
        smbcli_mkdir(cli->tree, "\\masktest");
 
        smbcli_unlink(cli->tree, "\\masktest\\*");
@@ -294,13 +294,14 @@ static void usage(poptContext pc)
        struct smbcli_state *cli;       
        int opt;
        int seed;
-       struct event_context *ev;
+       struct tevent_context *ev;
        struct loadparm_context *lp_ctx;
        struct smbcli_options options;
        struct smbcli_session_options session_options;
        poptContext pc;
        int argc_new, i;
        char **argv_new;
+       TALLOC_CTX *mem_ctx;
        enum {OPT_UNCLIST=1000};
        struct poptOption long_options[] = {
                POPT_AUTOHELP
@@ -330,7 +331,7 @@ static void usage(poptContext pc)
        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;
                }
        }
@@ -357,15 +358,19 @@ static void usage(poptContext pc)
 
        lp_ctx = cmdline_lp_ctx;
 
-       ev = s4_event_context_init(talloc_autofree_context());
+       mem_ctx = talloc_autofree_context();
+
+       ev = s4_event_context_init(mem_ctx);
 
        gensec_init(lp_ctx);
 
-       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);
 
-       cli = connect_one(lp_resolve_context(lp_ctx), ev, share, 
-                         lp_smb_ports(lp_ctx), &options, &session_options);
+       cli = connect_one(lpcfg_resolve_context(lp_ctx), ev, mem_ctx, share,
+                         lpcfg_smb_ports(lp_ctx), lpcfg_socket_options(lp_ctx),
+                         &options, &session_options,
+                         lpcfg_gensec_settings(mem_ctx, lp_ctx));
        if (!cli) {
                DEBUG(0,("Failed to connect to %s\n", share));
                exit(1);
@@ -375,7 +380,7 @@ static void usage(poptContext pc)
        DEBUG(0,("seed=%d     format --- --- (server, correct)\n", seed));
        srandom(seed);
 
-       test_mask(argc_new-1, argv_new+1, cli);
+       test_mask(argc_new-1, argv_new+1, mem_ctx, cli);
 
        return(0);
 }