diff options
Diffstat (limited to 'source4/torture/basic/mangle_test.c')
-rw-r--r-- | source4/torture/basic/mangle_test.c | 55 |
1 files changed, 29 insertions, 26 deletions
diff --git a/source4/torture/basic/mangle_test.c b/source4/torture/basic/mangle_test.c index 665360fc64..58d7098972 100644 --- a/source4/torture/basic/mangle_test.c +++ b/source4/torture/basic/mangle_test.c @@ -25,7 +25,6 @@ #include "lib/util/util_tdb.h" #include "libcli/libcli.h" #include "torture/util.h" -#include "pstring.h" static TDB_CONTEXT *tdb; @@ -33,11 +32,12 @@ static TDB_CONTEXT *tdb; static uint_t total, collisions, failures; -static BOOL test_one(struct smbcli_state *cli, const char *name) +static bool test_one(struct torture_context *tctx ,struct smbcli_state *cli, + const char *name) { int fnum; const char *shortname; - fstring name2; + const char *name2; NTSTATUS status; TDB_DATA data; @@ -46,37 +46,37 @@ static BOOL test_one(struct smbcli_state *cli, const char *name) fnum = smbcli_open(cli->tree, name, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); if (fnum == -1) { printf("open of %s failed (%s)\n", name, smbcli_errstr(cli->tree)); - return False; + return false; } if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) { printf("close of %s failed (%s)\n", name, smbcli_errstr(cli->tree)); - return False; + return false; } /* get the short name */ status = smbcli_qpathinfo_alt_name(cli->tree, name, &shortname); if (!NT_STATUS_IS_OK(status)) { printf("query altname of %s failed (%s)\n", name, smbcli_errstr(cli->tree)); - return False; + return false; } - snprintf(name2, sizeof(name2), "\\mangle_test\\%s", shortname); + name2 = talloc_asprintf(tctx, "\\mangle_test\\%s", shortname); if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, name2))) { printf("unlink of %s (%s) failed (%s)\n", name2, name, smbcli_errstr(cli->tree)); - return False; + return false; } /* recreate by short name */ fnum = smbcli_open(cli->tree, name2, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); if (fnum == -1) { printf("open2 of %s failed (%s)\n", name2, smbcli_errstr(cli->tree)); - return False; + return false; } if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) { printf("close of %s failed (%s)\n", name, smbcli_errstr(cli->tree)); - return False; + return false; } /* and unlink by long name */ @@ -85,7 +85,7 @@ static BOOL test_one(struct smbcli_state *cli, const char *name) name, name2, smbcli_errstr(cli->tree)); failures++; smbcli_unlink(cli->tree, name2); - return True; + return true; } /* see if the short name is already in the tdb */ @@ -108,22 +108,25 @@ static BOOL test_one(struct smbcli_state *cli, const char *name) tdb_store_bystring(tdb, shortname, namedata, TDB_REPLACE); } - return True; + return true; } -static void gen_name(char *name) +static char *gen_name(TALLOC_CTX *mem_ctx) { const char *chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._-$~..."; uint_t max_idx = strlen(chars); uint_t len; int i; char *p; + char *name; - fstrcpy(name, "\\mangle_test\\"); - p = name + strlen(name); + name = talloc_strdup(mem_ctx, "\\mangle_test\\"); len = 1 + random() % NAME_LENGTH; + + name = talloc_realloc(mem_ctx, name, char, strlen(name) + len + 6); + p = name + strlen(name); for (i=0;i<len;i++) { p[i] = chars[random() % max_idx]; @@ -141,7 +144,7 @@ static void gen_name(char *name) } /* and a medium probability of a common lead string */ - if (random() % 10 == 0) { + if ((len > 5) && (random() % 10 == 0)) { strncpy(p, "ABCDE", 5); } @@ -152,11 +155,13 @@ static void gen_name(char *name) s[4] = 0; } } + + return name; } -BOOL torture_mangle(struct torture_context *torture, - struct smbcli_state *cli) +bool torture_mangle(struct torture_context *torture, + struct smbcli_state *cli) { extern int torture_numops; int i; @@ -165,21 +170,19 @@ BOOL torture_mangle(struct torture_context *torture, tdb = tdb_open(NULL, 100000, TDB_INTERNAL, 0, 0); if (!tdb) { printf("ERROR: Failed to open tdb\n"); - return False; + return false; } if (!torture_setup_dir(cli, "\\mangle_test")) { - return False; + return false; } for (i=0;i<torture_numops;i++) { - fstring name; - - ZERO_STRUCT(name); + char *name; - gen_name(name); + name = gen_name(torture); - if (!test_one(cli, name)) { + if (!test_one(torture, cli, name)) { break; } if (total && total % 100 == 0) { @@ -193,7 +196,7 @@ BOOL torture_mangle(struct torture_context *torture, smbcli_unlink(cli->tree, "\\mangle_test\\*"); if (NT_STATUS_IS_ERR(smbcli_rmdir(cli->tree, "\\mangle_test"))) { printf("ERROR: Failed to remove directory\n"); - return False; + return false; } printf("\nTotal collisions %u/%u - %.2f%% (%u failures)\n", |