From 47dfe299c8a5a64ade88d15ecf71f99800ea40cd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 26 Mar 2004 02:39:48 +0000 Subject: - moved some of the base tests into torture/basic/ - added a CHARSET set of tests, which determines how the server deals with some specific charset issues related to UTF-16 support. Interestingly, Samba3 already passes all but one of these tests, because our incorrect UCS-2 and UTF-8 implementations where we don't check the validity of characters actually matches what Windows does! This means that adding UTF-16 support to Samba is going to be _much_ easier than we expected. (This used to be commit c8497a42364d186f08102224d5062d176ee81f5b) --- source4/torture/basic/mangle_test.c | 205 ++++++++++++++++++++++++++++++++++++ 1 file changed, 205 insertions(+) create mode 100644 source4/torture/basic/mangle_test.c (limited to 'source4/torture/basic/mangle_test.c') diff --git a/source4/torture/basic/mangle_test.c b/source4/torture/basic/mangle_test.c new file mode 100644 index 0000000000..94dac45b9d --- /dev/null +++ b/source4/torture/basic/mangle_test.c @@ -0,0 +1,205 @@ +/* + Unix SMB/CIFS implementation. + SMB torture tester - mangling test + Copyright (C) Andrew Tridgell 2002 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +static TDB_CONTEXT *tdb; + +#define NAME_LENGTH 20 + +static unsigned total, collisions, failures; + +static BOOL test_one(struct cli_state *cli, const char *name) +{ + int fnum; + const char *shortname; + fstring name2; + NTSTATUS status; + TDB_DATA data; + + total++; + + fnum = cli_open(cli->tree, name, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum == -1) { + printf("open of %s failed (%s)\n", name, cli_errstr(cli->tree)); + return False; + } + + if (NT_STATUS_IS_ERR(cli_close(cli->tree, fnum))) { + printf("close of %s failed (%s)\n", name, cli_errstr(cli->tree)); + return False; + } + + /* get the short name */ + status = cli_qpathinfo_alt_name(cli->tree, name, &shortname); + if (!NT_STATUS_IS_OK(status)) { + printf("query altname of %s failed (%s)\n", name, cli_errstr(cli->tree)); + return False; + } + + snprintf(name2, sizeof(name2), "\\mangle_test\\%s", shortname); + if (NT_STATUS_IS_ERR(cli_unlink(cli->tree, name2))) { + printf("unlink of %s (%s) failed (%s)\n", + name2, name, cli_errstr(cli->tree)); + return False; + } + + /* recreate by short name */ + fnum = cli_open(cli->tree, name2, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum == -1) { + printf("open2 of %s failed (%s)\n", name2, cli_errstr(cli->tree)); + return False; + } + if (NT_STATUS_IS_ERR(cli_close(cli->tree, fnum))) { + printf("close of %s failed (%s)\n", name, cli_errstr(cli->tree)); + return False; + } + + /* and unlink by long name */ + if (NT_STATUS_IS_ERR(cli_unlink(cli->tree, name))) { + printf("unlink2 of %s (%s) failed (%s)\n", + name, name2, cli_errstr(cli->tree)); + failures++; + cli_unlink(cli->tree, name2); + return True; + } + + /* see if the short name is already in the tdb */ + data = tdb_fetch_bystring(tdb, shortname); + if (data.dptr) { + /* maybe its a duplicate long name? */ + if (strcasecmp(name, data.dptr) != 0) { + /* we have a collision */ + collisions++; + printf("Collision between %s and %s -> %s " + " (coll/tot: %u/%u)\n", + name, data.dptr, shortname, collisions, total); + } + free(data.dptr); + } else { + TDB_DATA namedata; + /* store it for later */ + namedata.dptr = name; + namedata.dsize = strlen(name)+1; + tdb_store_bystring(tdb, shortname, namedata, TDB_REPLACE); + } + + return True; +} + + +static void gen_name(char *name) +{ + const char *chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._-$~..."; + unsigned max_idx = strlen(chars); + unsigned len; + int i; + char *p; + + fstrcpy(name, "\\mangle_test\\"); + p = name + strlen(name); + + len = 1 + random() % NAME_LENGTH; + + for (i=0;itree, "\\mangle_test\\*"); + cli_rmdir(cli->tree, "\\mangle_test"); + + if (NT_STATUS_IS_ERR(cli_mkdir(cli->tree, "\\mangle_test"))) { + printf("ERROR: Failed to make directory\n"); + return False; + } + + for (i=0;itree, "\\mangle_test\\*"); + if (NT_STATUS_IS_ERR(cli_rmdir(cli->tree, "\\mangle_test"))) { + printf("ERROR: Failed to remove directory\n"); + return False; + } + + printf("\nTotal collisions %u/%u - %.2f%% (%u failures)\n", + collisions, total, (100.0*collisions) / total, failures); + + torture_close_connection(cli); + + printf("mangle test finished\n"); + return (failures == 0); +} -- cgit