From d48dc5b2e6e45b5a0daa96b32f0b45cdf35a80e5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 15 Feb 2008 15:26:20 +1100 Subject: fixed masktest to use popt, and fixed the incorrect pstring conversion (This used to be commit c37133fd95e6d02a0cdf0f7b5408211740d8046c) --- source4/torture/masktest.c | 157 ++++++++++++++++++--------------------------- 1 file changed, 63 insertions(+), 94 deletions(-) (limited to 'source4/torture/masktest.c') diff --git a/source4/torture/masktest.c b/source4/torture/masktest.c index 855da54340..ac7029aa50 100644 --- a/source4/torture/masktest.c +++ b/source4/torture/masktest.c @@ -18,6 +18,7 @@ */ #include "includes.h" +#include "lib/cmdline/popt_common.h" #include "system/filesys.h" #include "system/dir.h" #include "libcli/libcli.h" @@ -30,12 +31,10 @@ #include "dynconfig.h" #include "libcli/resolve/resolve.h" -static struct cli_credentials *credentials; static bool showall = false; static bool old_list = false; static const char *maskchars = "<>\"?*abc."; static const char *filechars = "abcdefghijklm."; -static int verbose; static int die_on_error; static int NumLoops = 0; static int max_length = 20; @@ -87,13 +86,13 @@ static struct smbcli_state *connect_one(struct resolve_context *resolve_ctx, *share = 0; share++; - cli_credentials_set_workstation(credentials, "masktest", CRED_SPECIFIED); + cli_credentials_set_workstation(cmdline_credentials, "masktest", CRED_SPECIFIED); status = smbcli_full_connection(NULL, &c, server, ports, share, NULL, - credentials, resolve_ctx, NULL, + cmdline_credentials, resolve_ctx, NULL, options); if (!NT_STATUS_IS_OK(status)) { @@ -112,7 +111,7 @@ static bool f_info_hit; static void listfn(struct clilist_file_info *f, const char *s, void *state) { - struct masktest_state *m = talloc_get_type(state,struct masktest_state); + struct masktest_state *m = (struct masktest_state *)state; if (ISDOT(f->name)) { resultp[0] = '+'; @@ -128,7 +127,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, fstring short_name) { const char *mask; struct masktest_state state; @@ -151,12 +150,12 @@ static void get_real_name(TALLOC_CTX *mem_ctx, struct smbcli_state *cli, if (f_info_hit) { fstrcpy(short_name, last_hit.short_name); strlower(short_name); - long_name = talloc_strdup(mem_ctx, last_hit.long_name); - strlower(long_name); + *long_name = talloc_strdup(mem_ctx, last_hit.long_name); + strlower(*long_name); } if (*short_name == '\0') { - fstrcpy(short_name, long_name); + fstrcpy(short_name, *long_name); } } @@ -168,7 +167,7 @@ static void testpair(TALLOC_CTX *mem_ctx, struct smbcli_state *cli, char *mask, char *res2; static int count; fstring short_name; - char *long_name; + char *long_name = NULL; struct masktest_state state; count++; @@ -186,7 +185,7 @@ static void testpair(TALLOC_CTX *mem_ctx, struct smbcli_state *cli, char *mask, resultp = res1; fstrcpy(short_name, ""); - get_real_name(mem_ctx, cli, long_name, short_name); + get_real_name(mem_ctx, cli, &long_name, short_name); fstrcpy(res1, "---"); smbcli_list_new(cli->tree, mask, FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY, @@ -241,6 +240,8 @@ static void test_mask(int argc, char *argv[], l2 = 1 + random() % max_length; mask = talloc_strdup(mem_ctx, "\\masktest\\"); file = talloc_strdup(mem_ctx, "\\masktest\\"); + mask = talloc_realloc_size(mem_ctx, mask, strlen(mask)+l1+1); + file = talloc_realloc_size(mem_ctx, file, strlen(file)+l2+1); l = strlen(mask); for (i=0;i"); - share = argv[1]; - - all_string_sub(share,"/","\\",0); + while((opt = poptGetNextOpt(pc)) != -1) { + switch (opt) { + case OPT_UNCLIST: + lp_set_cmdline(cmdline_lp_ctx, "torture:unclist", poptGetOptArg(pc)); + break; + } + } - setup_logging(argv[0], DEBUG_STDOUT); + argv_new = discard_const_p(char *, poptGetArgs(pc)); + argc_new = argc; + for (i=0; i= 2)) { + usage(pc); + exit(1); + } - global_loadparm = lp_ctx = loadparm_init(talloc_autofree_context()); - lp_load(lp_ctx, dyn_CONFIGFILE); + setup_logging("masktest", DEBUG_STDOUT); - credentials = cli_credentials_init(talloc_autofree_context()); - cli_credentials_guess(credentials, lp_ctx); + share = argv_new[1]; - seed = time(NULL); + all_string_sub(share,"/","\\",0); - while ((opt = getopt(argc, argv, "n:d:U:s:hm:f:aoW:M:vEl:")) != EOF) { - switch (opt) { - case 'n': - NumLoops = atoi(optarg); - break; - case 'd': - DEBUGLEVEL = atoi(optarg); - break; - case 'E': - die_on_error = 1; - break; - case 'v': - verbose++; - break; - case 'M': - lp_set_cmdline(lp_ctx, "max protocol", optarg); - break; - case 'U': - cli_credentials_parse_string(credentials, optarg, CRED_SPECIFIED); - break; - case 's': - seed = atoi(optarg); - break; - case 'h': - usage(); - exit(1); - case 'm': - maskchars = optarg; - break; - case 'l': - max_length = atoi(optarg); - break; - case 'f': - filechars = optarg; - break; - case 'a': - showall = 1; - break; - case 'o': - old_list = true; - break; - default: - printf("Unknown option %c (%d)\n", (char)opt, opt); - exit(1); - } - } + lp_ctx = cmdline_lp_ctx; gensec_init(lp_ctx); - argc -= optind; - argv += optind; - lp_smbcli_options(lp_ctx, &options); cli = connect_one(lp_resolve_context(lp_ctx), share, @@ -398,7 +367,7 @@ static void usage(void) DEBUG(0,("seed=%d format --- --- (server, correct)\n", seed)); srandom(seed); - test_mask(argc, argv, cli); + test_mask(argc_new-1, argv_new+1, cli); return(0); } -- cgit