s4:torture/smb2: replace torture:cn_max_buffer_size option with the negotiated max...
[samba.git] / source4 / torture / smbtorture.c
index 1a1fa348b7ae9112dc8b312d16304873c62aa656..018f39f00d9ee42e6000ce6cf09f9f71cd76b30a 100644 (file)
@@ -34,7 +34,7 @@
 #include "param/param.h"
 #include "lib/util/samba_modules.h"
 
-#if HAVE_READLINE_HISTORY_H
+#ifdef HAVE_READLINE_HISTORY_H
 #include <readline/history.h>
 #endif
 
@@ -150,7 +150,9 @@ bool torture_run_named_tests(struct torture_context *torture, const char *name,
        return ret;
 }
 
-bool torture_parse_target(struct loadparm_context *lp_ctx, const char *target)
+bool torture_parse_target(TALLOC_CTX *ctx,
+                               struct loadparm_context *lp_ctx,
+                               const char *target)
 {
        char *host = NULL, *share = NULL;
        struct dcerpc_binding *binding_struct;
@@ -158,12 +160,20 @@ bool torture_parse_target(struct loadparm_context *lp_ctx, const char *target)
 
        /* see if its a RPC transport specifier */
        if (!smbcli_parse_unc(target, NULL, &host, &share)) {
-               status = dcerpc_parse_binding(talloc_autofree_context(), target, &binding_struct);
+               const char *h;
+
+               status = dcerpc_parse_binding(ctx, target, &binding_struct);
                if (NT_STATUS_IS_ERR(status)) {
                        d_printf("Invalid option: %s is not a valid torture target (share or binding string)\n\n", target);
                        return false;
                }
-               lpcfg_set_cmdline(lp_ctx, "torture:host", binding_struct->host);
+
+               h = dcerpc_binding_get_string_option(binding_struct, "host");
+               host = discard_const_p(char, h);
+               if (host != NULL) {
+                       lpcfg_set_cmdline(lp_ctx, "torture:host", host);
+               }
+
                if (lpcfg_parm_string(lp_ctx, NULL, "torture", "share") == NULL)
                        lpcfg_set_cmdline(lp_ctx, "torture:share", "IPC$");
                lpcfg_set_cmdline(lp_ctx, "torture:binding", target);
@@ -353,7 +363,7 @@ _NORETURN_ static void max_runtime_handler(int sig)
 /****************************************************************************
   main program
 ****************************************************************************/
-int main(int argc,char *argv[])
+int main(int argc, const char *argv[])
 {
        int opt, i;
        bool correct = true;
@@ -373,12 +383,13 @@ int main(int argc,char *argv[])
        const char *extra_module = NULL;
        static int list_tests = 0, list_testsuites = 0;
        int num_extra_users = 0;
-       char **restricted = NULL;
+       const char **restricted = NULL;
        int num_restricted = -1;
        const char *load_list = NULL;
        enum {OPT_LOADFILE=1000,OPT_UNCLIST,OPT_TIMELIMIT,OPT_DNS, OPT_LIST,
              OPT_DANGEROUS,OPT_SMB_PORTS,OPT_ASYNC,OPT_NUMPROGS,
              OPT_EXTRA_USER,};
+       TALLOC_CTX *mem_ctx = NULL;
 
        struct poptOption long_options[] = {
                POPT_AUTOHELP
@@ -420,12 +431,18 @@ int main(int argc,char *argv[])
 
        setlinebuf(stdout);
 
+       mem_ctx = talloc_named_const(NULL, 0, "torture_ctx");
+       if (mem_ctx == NULL) {
+               printf("Unable to allocate torture_ctx\n");
+               exit(1);
+       }
+
        printf("smbtorture %s\n", samba_version_string());
 
        /* we are never interested in SIGPIPE */
        BlockSignals(true, SIGPIPE);
 
-       pc = poptGetContext("smbtorture", argc, (const char **) argv, long_options, 
+       pc = poptGetContext("smbtorture", argc, argv, long_options,
                            POPT_CONTEXT_KEEP_FIRST);
 
        poptSetOtherOptionHelp(pc, "<binding>|<unc> TEST1 TEST2 ...");
@@ -458,9 +475,15 @@ int main(int argc,char *argv[])
                        break;
                case OPT_EXTRA_USER:
                        {
-                               char *option = talloc_asprintf(NULL, "torture:extra_user%u",
-                                                              ++num_extra_users);
+                               char *option = talloc_asprintf(mem_ctx,
+                                               "torture:extra_user%u",
+                                               ++num_extra_users);
                                const char *value = poptGetOptArg(pc);
+                               if (option == NULL) {
+                                       printf("talloc fail\n");
+                                       talloc_free(mem_ctx);
+                                       exit(1);
+                               }
                                lpcfg_set_cmdline(cmdline_lp_ctx, option, value);
                                talloc_free(option);
                        }
@@ -468,16 +491,19 @@ int main(int argc,char *argv[])
                default:
                        if (opt < 0) {
                                printf("bad command line option %d\n", opt);
+                               talloc_free(mem_ctx);
                                exit(1);
                        }
                }
        }
 
        if (load_list != NULL) {
-               restricted = file_lines_load(load_list, &num_restricted, 0,
-                                                                        talloc_autofree_context());
+               char **r;
+               r = file_lines_load(load_list, &num_restricted, 0, mem_ctx);
+               restricted = discard_const_p(const char *, r);
                if (restricted == NULL) {
                        printf("Unable to read load list file '%s'\n", load_list);
+                       talloc_free(mem_ctx);
                        exit(1);
                }
        }
@@ -498,10 +524,10 @@ int main(int argc,char *argv[])
                lpcfg_set_cmdline(cmdline_lp_ctx, "torture:w2k8", "true");
                lpcfg_set_cmdline(cmdline_lp_ctx,
                    "torture:invalid_lock_range_support", "false");
+       } else if (strcmp(target, "w2k12") == 0) {
+               lpcfg_set_cmdline(cmdline_lp_ctx, "torture:w2k12", "true");
        } else if (strcmp(target, "win7") == 0) {
                lpcfg_set_cmdline(cmdline_lp_ctx, "torture:win7", "true");
-               lpcfg_set_cmdline(cmdline_lp_ctx, "torture:cn_max_buffer_size",
-                   "0x00010000");
                lpcfg_set_cmdline(cmdline_lp_ctx, "torture:resume_key_support", "false");
                lpcfg_set_cmdline(cmdline_lp_ctx, "torture:rewind_support", "false");
 
@@ -549,18 +575,20 @@ int main(int argc,char *argv[])
                if (fn == NULL) 
                        d_printf("Unable to load module from %s\n", poptGetOptArg(pc));
                else {
-                       status = fn();
+                       status = fn(mem_ctx);
                        if (NT_STATUS_IS_ERR(status)) {
                                d_printf("Error initializing module %s: %s\n", 
                                        poptGetOptArg(pc), nt_errstr(status));
                        }
                }
        } else { 
-               torture_init();
+               torture_init(mem_ctx);
        }
 
        if (list_testsuites) {
                print_testsuite_list();
+               talloc_free(mem_ctx);
+               popt_free_cmdline_credentials();
                return 0;
        }
 
@@ -582,6 +610,8 @@ int main(int argc,char *argv[])
                                print_test_list(torture_root, NULL, argv_new[i]);
                        }
                }
+               talloc_free(mem_ctx);
+               popt_free_cmdline_credentials();
                return 0;
        }
 
@@ -597,16 +627,18 @@ int main(int argc,char *argv[])
                ui_ops = &torture_subunit_ui_ops;
        } else {
                printf("Unknown output format '%s'\n", ui_ops_name);
+               talloc_free(mem_ctx);
                exit(1);
        }
 
-       results = torture_results_init(talloc_autofree_context(), ui_ops);
+       results = torture_results_init(mem_ctx, ui_ops);
 
-       torture = torture_context_init(s4_event_context_init(talloc_autofree_context()),
+       torture = torture_context_init(s4_event_context_init(mem_ctx),
                                       results);
        if (basedir != NULL) {
                if (basedir[0] != '/') {
                        fprintf(stderr, "Please specify an absolute path to --basedir\n");
+                       talloc_free(mem_ctx);
                        return 1;
                }
                outputdir = talloc_asprintf(torture, "%s/smbtortureXXXXXX", basedir);
@@ -614,17 +646,21 @@ int main(int argc,char *argv[])
                char *pwd = talloc_size(torture, PATH_MAX);
                if (!getcwd(pwd, PATH_MAX)) {
                        fprintf(stderr, "Unable to determine current working directory\n");
+                       talloc_free(mem_ctx);
                        return 1;
                }
                outputdir = talloc_asprintf(torture, "%s/smbtortureXXXXXX", pwd);
        }
        if (!outputdir) {
                fprintf(stderr, "Could not allocate per-run output dir\n");
+               talloc_free(mem_ctx);
                return 1;
        }
        torture->outputdir = mkdtemp(outputdir);
        if (!torture->outputdir) {
                perror("Failed to make temp output dir");
+               talloc_free(mem_ctx);
+               return 1;
        }
 
        torture->lp_ctx = cmdline_lp_ctx;
@@ -645,8 +681,9 @@ int main(int argc,char *argv[])
                        printf("You must specify a test to run, or 'ALL'\n");
                        usage(pc);
                        torture->results->returncode = 1;
-               } else if (!torture_parse_target(cmdline_lp_ctx, argv_new[1])) {
-               /* Take the target name or binding. */
+               } else if (!torture_parse_target(torture,
+                                       cmdline_lp_ctx, argv_new[1])) {
+                       /* Take the target name or binding. */
                        usage(pc);
                        torture->results->returncode = 1;
                } else {
@@ -663,8 +700,11 @@ int main(int argc,char *argv[])
        torture_deltree_outputdir(torture);
 
        if (torture->results->returncode && correct) {
+               talloc_free(mem_ctx);
+               popt_free_cmdline_credentials();
                return(0);
        } else {
+               talloc_free(mem_ctx);
                return(1);
        }
 }