summaryrefslogtreecommitdiff
path: root/source4/torture/raw/search.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-10-27 01:11:44 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:04:48 -0500
commitb9ddb09f03332a9c4442e61bb5c73f7bde04d1d6 (patch)
treeb5d0875e981f6dec57cc06ce98ce3a1428817e86 /source4/torture/raw/search.c
parent05ad898f68a2df1b102af95fdba0704479bde073 (diff)
downloadsamba-b9ddb09f03332a9c4442e61bb5c73f7bde04d1d6.tar.gz
samba-b9ddb09f03332a9c4442e61bb5c73f7bde04d1d6.tar.bz2
samba-b9ddb09f03332a9c4442e61bb5c73f7bde04d1d6.zip
r3276: - allow for more than 256 open old style searches (limit currently set at an arbitrary 5000)
- auto-cleanup old searches that the client forgot to close (common with old searches) - expanded the RAW-SEARCH test to test more than 256 old searches, and old search rewind (w2k3 fails this - it appears to not support rewind on old style searches) (This used to be commit bc83d823b2140a10007490bf0101843a886f99a6)
Diffstat (limited to 'source4/torture/raw/search.c')
-rw-r--r--source4/torture/raw/search.c180
1 files changed, 166 insertions, 14 deletions
diff --git a/source4/torture/raw/search.c b/source4/torture/raw/search.c
index c8f21de8d8..04c1f8db57 100644
--- a/source4/torture/raw/search.c
+++ b/source4/torture/raw/search.c
@@ -913,37 +913,189 @@ done:
}
+
/*
- basic testing of all RAW_SEARCH_* calls using a single file
+ basic testing of many old style search calls using separate dirs
*/
-BOOL torture_raw_search(int dummy)
+static BOOL test_many_dirs(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
{
- struct smbcli_state *cli;
+ const int num_dirs = 300;
+ int i, fnum, n;
+ char *fname, *dname;
BOOL ret = True;
- TALLOC_CTX *mem_ctx;
+ NTSTATUS status;
+ union smb_search_data *file, *file2, *file3;
- if (!torture_open_connection(&cli)) {
+ if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
+ NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
+ printf("Failed to create " BASEDIR " - %s\n", smbcli_errstr(cli->tree));
return False;
}
- mem_ctx = talloc_init("torture_search");
+ printf("Creating %d dirs\n", num_dirs);
- if (!test_one_file(cli, mem_ctx)) {
- ret = False;
+ for (i=0;i<num_dirs;i++) {
+ asprintf(&dname, BASEDIR "\\d%d", i);
+ status = smbcli_mkdir(cli->tree, dname);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("(%s) Failed to create %s - %s\n",
+ __location__, dname, nt_errstr(status));
+ ret = False;
+ goto done;
+ }
+
+ for (n=0;n<3;n++) {
+ asprintf(&fname, BASEDIR "\\d%d\\f%d-%d.txt", i, i, n);
+ fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
+ if (fnum == -1) {
+ printf("(%s) Failed to create %s - %s\n",
+ __location__, fname, smbcli_errstr(cli->tree));
+ ret = False;
+ goto done;
+ }
+ free(fname);
+ }
+
+ free(dname);
+ smbcli_close(cli->tree, fnum);
}
- if (!test_many_files(cli, mem_ctx)) {
- ret = False;
+ file = talloc_zero_array_p(mem_ctx, union smb_search_data, num_dirs);
+ file2 = talloc_zero_array_p(mem_ctx, union smb_search_data, num_dirs);
+ file3 = talloc_zero_array_p(mem_ctx, union smb_search_data, num_dirs);
+
+ printf("Search first on %d dirs\n", num_dirs);
+
+ for (i=0;i<num_dirs;i++) {
+ union smb_search_first io;
+ io.generic.level = RAW_SEARCH_SEARCH;
+ io.search_first.in.max_count = 1;
+ io.search_first.in.search_attrib = 0;
+ io.search_first.in.pattern = talloc_asprintf(mem_ctx, BASEDIR "\\d%d\\*.txt", i);
+ fname = talloc_asprintf(mem_ctx, "f%d-", i);
+
+ io.search_first.out.count = 0;
+
+ status = smb_raw_search_first(cli->tree, mem_ctx,
+ &io, (void *)&file[i], single_search_callback);
+ if (io.search_first.out.count != 1) {
+ printf("(%s) search first gave %d entries for dir %d - %s\n",
+ __location__, io.search_first.out.count, i, nt_errstr(status));
+ ret = False;
+ goto done;
+ }
+ CHECK_STATUS(status, NT_STATUS_OK);
+ if (strncasecmp(file[i].search.name, fname, strlen(fname)) != 0) {
+ printf("(%s) incorrect name '%s' expected '%s'[12].txt\n",
+ __location__, file[i].search.name, fname);
+ ret = False;
+ goto done;
+ }
+
+ talloc_free(fname);
}
- if (!test_sorted(cli, mem_ctx)) {
- ret = False;
+ printf("Search next on %d dirs\n", num_dirs);
+
+ for (i=0;i<num_dirs;i++) {
+ union smb_search_next io2;
+
+ io2.generic.level = RAW_SEARCH_SEARCH;
+ io2.search_next.in.max_count = 1;
+ io2.search_next.in.search_attrib = 0;
+ io2.search_next.in.id = file[i].search.id;
+ fname = talloc_asprintf(mem_ctx, "f%d-", i);
+
+ io2.search_next.out.count = 0;
+
+ status = smb_raw_search_next(cli->tree, mem_ctx,
+ &io2, (void *)&file2[i], single_search_callback);
+ if (io2.search_next.out.count != 1) {
+ printf("(%s) search next gave %d entries for dir %d - %s\n",
+ __location__, io2.search_next.out.count, i, nt_errstr(status));
+ ret = False;
+ goto done;
+ }
+ CHECK_STATUS(status, NT_STATUS_OK);
+ if (strncasecmp(file2[i].search.name, fname, strlen(fname)) != 0) {
+ printf("(%s) incorrect name '%s' expected '%s'[12].txt\n",
+ __location__, file2[i].search.name, fname);
+ ret = False;
+ goto done;
+ }
+
+ talloc_free(fname);
}
- if (!test_modify_search(cli, mem_ctx)) {
- ret = False;
+
+ printf("Search next (rewind) on %d dirs\n", num_dirs);
+
+ for (i=0;i<num_dirs;i++) {
+ union smb_search_next io2;
+
+ io2.generic.level = RAW_SEARCH_SEARCH;
+ io2.search_next.in.max_count = 1;
+ io2.search_next.in.search_attrib = 0;
+ io2.search_next.in.id = file[i].search.id;
+ fname = talloc_asprintf(mem_ctx, "f%d-", i);
+ io2.search_next.out.count = 0;
+
+ status = smb_raw_search_next(cli->tree, mem_ctx,
+ &io2, (void *)&file3[i], single_search_callback);
+ if (io2.search_next.out.count != 1) {
+ printf("(%s) search next gave %d entries for dir %d - %s\n",
+ __location__, io2.search_next.out.count, i, nt_errstr(status));
+ ret = False;
+ goto done;
+ }
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ if (strncasecmp(file3[i].search.name, file2[i].search.name, 3) != 0) {
+ printf("(%s) incorrect name '%s' on rewind at dir %d\n",
+ __location__, file2[i].search.name, i);
+ ret = False;
+ goto done;
+ }
+
+ if (strcmp(file3[i].search.name, file2[i].search.name) != 0) {
+ printf("(%s) server did not rewind - got '%s' expected '%s'\n",
+ __location__, file3[i].search.name, file2[i].search.name);
+ ret = False;
+ goto done;
+ }
+
+ talloc_free(fname);
+ }
+
+
+done:
+ smb_raw_exit(cli->session);
+ smbcli_deltree(cli->tree, BASEDIR);
+
+ return ret;
+}
+
+/*
+ basic testing of all RAW_SEARCH_* calls using a single file
+*/
+BOOL torture_raw_search(int dummy)
+{
+ struct smbcli_state *cli;
+ BOOL ret = True;
+ TALLOC_CTX *mem_ctx;
+
+ if (!torture_open_connection(&cli)) {
+ return False;
}
+ mem_ctx = talloc_init("torture_search");
+
+ ret &= test_one_file(cli, mem_ctx);
+ ret &= test_many_files(cli, mem_ctx);
+ ret &= test_sorted(cli, mem_ctx);
+ ret &= test_modify_search(cli, mem_ctx);
+ ret &= test_many_dirs(cli, mem_ctx);
+
torture_close_connection(cli);
talloc_destroy(mem_ctx);