r4164: added a test that simulates a OS/2 file delete. This includes seek by
[sfrench/samba-autobuild/.git] / source4 / torture / raw / search.c
index 698f405fb4b45855b120b6f2b1ca0f14c2b3615f..f159c4e15455d1402666442a54500a8f12d12627 100644 (file)
@@ -19,6 +19,7 @@
 */
 
 #include "includes.h"
+#include "libcli/raw/libcliraw.h"
 
 
 #define BASEDIR "\\testsearch"
@@ -38,17 +39,20 @@ static BOOL single_search_callback(void *private, union smb_search_data *file)
 /*
   do a single file (non-wildcard) search 
 */
-static NTSTATUS single_search(struct cli_state *cli, 
+static NTSTATUS single_search(struct smbcli_state *cli, 
                              TALLOC_CTX *mem_ctx,
                              const char *pattern,
                              enum smb_search_level level,
                              union smb_search_data *data)
 {
        union smb_search_first io;
+       union smb_search_close c;
        NTSTATUS status;
 
        io.generic.level = level;
-       if (level == RAW_SEARCH_SEARCH) {
+       if (level == RAW_SEARCH_SEARCH ||
+           level == RAW_SEARCH_FFIRST ||
+           level == RAW_SEARCH_FUNIQUE) {
                io.search_first.in.max_count = 1;
                io.search_first.in.search_attrib = 0;
                io.search_first.in.pattern = pattern;
@@ -62,6 +66,14 @@ static NTSTATUS single_search(struct cli_state *cli,
 
        status = smb_raw_search_first(cli->tree, mem_ctx,
                                      &io, (void *)data, single_search_callback);
+
+       if (NT_STATUS_IS_OK(status) && level == RAW_SEARCH_FFIRST) {
+               c.fclose.level = RAW_FINDCLOSE_FCLOSE;
+               c.fclose.in.max_count = 1;
+               c.fclose.in.search_attrib = 0;
+               c.fclose.in.id = data->search.id;
+               status = smb_raw_search_close(cli->tree, &c);
+       }
        
        return status;
 }
@@ -74,6 +86,8 @@ static struct {
        NTSTATUS status;
        union smb_search_data data;
 } levels[] = {
+       {"FFIRST",                 RAW_SEARCH_FFIRST, },
+       {"FUNIQUE",                RAW_SEARCH_FUNIQUE, },
        {"SEARCH",                 RAW_SEARCH_SEARCH, },
        {"STANDARD",               RAW_SEARCH_STANDARD, },
        {"EA_SIZE",                RAW_SEARCH_EA_SIZE, },
@@ -102,11 +116,12 @@ static union smb_search_data *find(const char *name)
 /* 
    basic testing of all RAW_SEARCH_* calls using a single file
 */
-static BOOL test_one_file(struct cli_state *cli, TALLOC_CTX *mem_ctx)
+static BOOL test_one_file(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 {
        BOOL ret = True;
        int fnum;
        const char *fname = "\\torture_search.txt";
+       const char *fname2 = "\\torture_search-NOTEXIST.txt";
        NTSTATUS status;
        int i;
        union smb_fileinfo all_info, alt_info, name_info, internal_info;
@@ -116,13 +131,14 @@ static BOOL test_one_file(struct cli_state *cli, TALLOC_CTX *mem_ctx)
 
        fnum = create_complex_file(cli, mem_ctx, fname);
        if (fnum == -1) {
-               printf("ERROR: open of %s failed (%s)\n", fname, cli_errstr(cli->tree));
+               printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
                ret = False;
                goto done;
        }
 
        /* call all the levels */
        for (i=0;i<ARRAY_SIZE(levels);i++) {
+               NTSTATUS expected_status;
                uint32_t cap = cli->transport->negotiate.capabilities;
 
                printf("testing %s\n", levels[i].name);
@@ -142,6 +158,24 @@ static BOOL test_one_file(struct cli_state *cli, TALLOC_CTX *mem_ctx)
                               levels[i].name, (int)levels[i].level, 
                               nt_errstr(levels[i].status));
                        ret = False;
+                       continue;
+               }
+
+               status = single_search(cli, mem_ctx, fname2, 
+                                      levels[i].level, &levels[i].data);
+               
+               expected_status = NT_STATUS_NO_SUCH_FILE;
+               if (levels[i].level == RAW_SEARCH_SEARCH ||
+                   levels[i].level == RAW_SEARCH_FFIRST ||
+                   levels[i].level == RAW_SEARCH_FUNIQUE) {
+                       expected_status = STATUS_NO_MORE_FILES;
+               }
+               if (!NT_STATUS_EQUAL(status, expected_status)) {
+                       printf("search level %s(%d) should fail with %s - %s\n",
+                              levels[i].name, (int)levels[i].level, 
+                              nt_errstr(expected_status),
+                              nt_errstr(status));
+                       ret = False;
                }
        }
 
@@ -185,9 +219,9 @@ static BOOL test_one_file(struct cli_state *cli, TALLOC_CTX *mem_ctx)
 #define CHECK_VAL(name, sname1, field1, v, sname2, field2) do { \
        s = find(name); \
        if (s) { \
-               if (s->sname1.field1 != v.sname2.out.field2) { \
-                       printf("(%d) %s/%s [%d] != %s/%s [%d]\n", \
-                              __LINE__, \
+               if ((s->sname1.field1) != (v.sname2.out.field2)) { \
+                       printf("(%s) %s/%s [0x%x] != %s/%s [0x%x]\n", \
+                              __location__, \
                                #sname1, #field1, (int)s->sname1.field1, \
                                #sname2, #field2, (int)v.sname2.out.field2); \
                        ret = False; \
@@ -198,8 +232,8 @@ static BOOL test_one_file(struct cli_state *cli, TALLOC_CTX *mem_ctx)
        s = find(name); \
        if (s) { \
                if (s->sname1.field1 != (~1 & nt_time_to_unix(v.sname2.out.field2))) { \
-                       printf("(%d) %s/%s [%s] != %s/%s [%s]\n", \
-                              __LINE__, \
+                       printf("(%s) %s/%s [%s] != %s/%s [%s]\n", \
+                              __location__, \
                                #sname1, #field1, timestring(mem_ctx, s->sname1.field1), \
                                #sname2, #field2, nt_time_string(mem_ctx, v.sname2.out.field2)); \
                        ret = False; \
@@ -210,8 +244,8 @@ static BOOL test_one_file(struct cli_state *cli, TALLOC_CTX *mem_ctx)
        s = find(name); \
        if (s) { \
                if (s->sname1.field1 != v.sname2.out.field2) { \
-                       printf("(%d) %s/%s [%s] != %s/%s [%s]\n", \
-                              __LINE__, \
+                       printf("(%s) %s/%s [%s] != %s/%s [%s]\n", \
+                              __location__, \
                                #sname1, #field1, nt_time_string(mem_ctx, s->sname1.field1), \
                                #sname2, #field2, nt_time_string(mem_ctx, v.sname2.out.field2)); \
                        ret = False; \
@@ -222,8 +256,8 @@ static BOOL test_one_file(struct cli_state *cli, TALLOC_CTX *mem_ctx)
        s = find(name); \
        if (s) { \
                if (!s->sname1.field1 || strcmp(s->sname1.field1, v.sname2.out.field2.s)) { \
-                       printf("(%d) %s/%s [%s] != %s/%s [%s]\n", \
-                              __LINE__, \
+                       printf("(%s) %s/%s [%s] != %s/%s [%s]\n", \
+                              __location__, \
                                #sname1, #field1, s->sname1.field1, \
                                #sname2, #field2, v.sname2.out.field2.s); \
                        ret = False; \
@@ -235,9 +269,9 @@ static BOOL test_one_file(struct cli_state *cli, TALLOC_CTX *mem_ctx)
        if (s) { \
                if (!s->sname1.field1.s || \
                    strcmp(s->sname1.field1.s, v.sname2.out.field2.s) || \
-                   wire_bad_flags(&s->sname1.field1, flags)) { \
-                       printf("(%d) %s/%s [%s] != %s/%s [%s]\n", \
-                              __LINE__, \
+                   wire_bad_flags(&s->sname1.field1, flags, cli)) { \
+                       printf("(%s) %s/%s [%s] != %s/%s [%s]\n", \
+                              __location__, \
                                #sname1, #field1, s->sname1.field1.s, \
                                #sname2, #field2, v.sname2.out.field2.s); \
                        ret = False; \
@@ -249,9 +283,9 @@ static BOOL test_one_file(struct cli_state *cli, TALLOC_CTX *mem_ctx)
        if (s) { \
                if (!s->sname1.field1.s || \
                    strcmp(s->sname1.field1.s, fname) || \
-                   wire_bad_flags(&s->sname1.field1, flags)) { \
-                       printf("(%d) %s/%s [%s] != %s\n", \
-                              __LINE__, \
+                   wire_bad_flags(&s->sname1.field1, flags, cli)) { \
+                       printf("(%s) %s/%s [%s] != %s\n", \
+                              __location__, \
                                #sname1, #field1, s->sname1.field1.s, \
                                fname); \
                        ret = False; \
@@ -263,8 +297,8 @@ static BOOL test_one_file(struct cli_state *cli, TALLOC_CTX *mem_ctx)
        if (s) { \
                if (!s->sname1.field1 || \
                    strcmp(s->sname1.field1, fname)) { \
-                       printf("(%d) %s/%s [%s] != %s\n", \
-                              __LINE__, \
+                       printf("(%s) %s/%s [%s] != %s\n", \
+                              __location__, \
                                #sname1, #field1, s->sname1.field1, \
                                fname); \
                        ret = False; \
@@ -272,9 +306,9 @@ static BOOL test_one_file(struct cli_state *cli, TALLOC_CTX *mem_ctx)
        }} while (0)
        
        /* check that all the results are as expected */
-       CHECK_VAL("SEARCH",              search,              attrib, all_info, all_info, attrib);
-       CHECK_VAL("STANDARD",            standard,            attrib, all_info, all_info, attrib);
-       CHECK_VAL("EA_SIZE",             ea_size,             attrib, all_info, all_info, attrib);
+       CHECK_VAL("SEARCH",              search,              attrib, all_info, all_info, attrib&0xFFF);
+       CHECK_VAL("STANDARD",            standard,            attrib, all_info, all_info, attrib&0xFFF);
+       CHECK_VAL("EA_SIZE",             ea_size,             attrib, all_info, all_info, attrib&0xFFF);
        CHECK_VAL("DIRECTORY_INFO",      directory_info,      attrib, all_info, all_info, attrib);
        CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, attrib, all_info, all_info, attrib);
        CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, attrib, all_info, all_info, attrib);
@@ -356,7 +390,7 @@ static BOOL test_one_file(struct cli_state *cli, TALLOC_CTX *mem_ctx)
 
 done:
        smb_raw_exit(cli->session);
-       cli_unlink(cli->tree, fname);
+       smbcli_unlink(cli->tree, fname);
 
        return ret;
 }
@@ -377,9 +411,10 @@ static BOOL multiple_search_callback(void *private, union smb_search_data *file)
 
 
        data->count++;
-       data->list = talloc_realloc(data->mem_ctx, 
-                                   data->list, 
-                                   data->count * (sizeof(data->list[0])));
+       data->list = talloc_realloc_p(data->mem_ctx,
+                                     data->list, 
+                                     union smb_search_data,
+                                     data->count);
 
        data->list[data->count-1] = *file;
 
@@ -391,7 +426,7 @@ enum continue_type {CONT_FLAGS, CONT_NAME, CONT_RESUME_KEY};
 /*
   do a single file (non-wildcard) search 
 */
-static NTSTATUS multiple_search(struct cli_state *cli, 
+static NTSTATUS multiple_search(struct smbcli_state *cli, 
                                TALLOC_CTX *mem_ctx,
                                const char *pattern,
                                enum smb_search_level level,
@@ -412,11 +447,11 @@ static NTSTATUS multiple_search(struct cli_state *cli,
        } else {
                io.t2ffirst.in.search_attrib = 0;
                io.t2ffirst.in.max_count = per_search;
-               io.t2ffirst.in.flags = 0;
+               io.t2ffirst.in.flags = FLAG_TRANS2_FIND_CLOSE_IF_END;
                io.t2ffirst.in.storage_type = 0;
                io.t2ffirst.in.pattern = pattern;
                if (cont_type == CONT_RESUME_KEY) {
-                       io.t2ffirst.in.flags = FLAG_TRANS2_FIND_REQUIRE_RESUME | 
+                       io.t2ffirst.in.flags |= FLAG_TRANS2_FIND_REQUIRE_RESUME | 
                                FLAG_TRANS2_FIND_BACKUP_INTENT;
                }
        }
@@ -430,12 +465,12 @@ static NTSTATUS multiple_search(struct cli_state *cli,
                if (level == RAW_SEARCH_SEARCH) {
                        io2.search_next.in.max_count = per_search;
                        io2.search_next.in.search_attrib = 0;
-                       io2.search_next.in.search_id = result->list[result->count-1].search.search_id;
+                       io2.search_next.in.id = result->list[result->count-1].search.id;
                } else {
                        io2.t2fnext.in.handle = io.t2ffirst.out.handle;
                        io2.t2fnext.in.max_count = per_search;
                        io2.t2fnext.in.resume_key = 0;
-                       io2.t2fnext.in.flags = 0;
+                       io2.t2fnext.in.flags = FLAG_TRANS2_FIND_CLOSE_IF_END;
                        io2.t2fnext.in.last_name = "";
                        switch (cont_type) {
                        case CONT_RESUME_KEY:
@@ -452,7 +487,11 @@ static NTSTATUS multiple_search(struct cli_state *cli,
                                        io2.t2fnext.in.resume_key = 
                                                result->list[result->count-1].both_directory_info.file_index;
                                }
-                               io2.t2fnext.in.flags = FLAG_TRANS2_FIND_REQUIRE_RESUME |
+                               if (io2.t2fnext.in.resume_key == 0) {
+                                       printf("Server does not support resume by key\n");
+                                       return NT_STATUS_NOT_SUPPORTED;
+                               }
+                               io2.t2fnext.in.flags |= FLAG_TRANS2_FIND_REQUIRE_RESUME |
                                        FLAG_TRANS2_FIND_BACKUP_INTENT;
                                break;
                        case CONT_NAME:
@@ -471,7 +510,7 @@ static NTSTATUS multiple_search(struct cli_state *cli,
                                }
                                break;
                        case CONT_FLAGS:
-                               io2.t2fnext.in.flags = FLAG_TRANS2_FIND_CONTINUE;
+                               io2.t2fnext.in.flags |= FLAG_TRANS2_FIND_CONTINUE;
                                break;
                        }
                }
@@ -496,50 +535,50 @@ static NTSTATUS multiple_search(struct cli_state *cli,
 
 #define CHECK_STATUS(status, correct) do { \
        if (!NT_STATUS_EQUAL(status, correct)) { \
-               printf("(%d) Incorrect status %s - should be %s\n", \
-                      __LINE__, nt_errstr(status), nt_errstr(correct)); \
+               printf("(%s) Incorrect status %s - should be %s\n", \
+                      __location__, nt_errstr(status), nt_errstr(correct)); \
                ret = False; \
                goto done; \
        }} while (0)
 
 #define CHECK_VALUE(v, correct) do { \
        if ((v) != (correct)) { \
-               printf("(%d) Incorrect value %s=%d - should be %d\n", \
-                      __LINE__, #v, v, correct); \
+               printf("(%s) Incorrect value %s=%d - should be %d\n", \
+                      __location__, #v, v, correct); \
                ret = False; \
        }} while (0)
 
 
 static int search_both_compare(union smb_search_data *d1, union smb_search_data *d2)
 {
-       return strcmp(d1->both_directory_info.name.s, d2->both_directory_info.name.s);
+       return strcmp_safe(d1->both_directory_info.name.s, d2->both_directory_info.name.s);
 }
 
 static int search_standard_compare(union smb_search_data *d1, union smb_search_data *d2)
 {
-       return strcmp(d1->standard.name.s, d2->standard.name.s);
+       return strcmp_safe(d1->standard.name.s, d2->standard.name.s);
 }
 
 static int search_ea_size_compare(union smb_search_data *d1, union smb_search_data *d2)
 {
-       return strcmp(d1->ea_size.name.s, d2->ea_size.name.s);
+       return strcmp_safe(d1->ea_size.name.s, d2->ea_size.name.s);
 }
 
 static int search_directory_info_compare(union smb_search_data *d1, union smb_search_data *d2)
 {
-       return strcmp(d1->directory_info.name.s, d2->directory_info.name.s);
+       return strcmp_safe(d1->directory_info.name.s, d2->directory_info.name.s);
 }
 
 static int search_old_compare(union smb_search_data *d1, union smb_search_data *d2)
 {
-       return strcmp(d1->search.name, d2->search.name);
+       return strcmp_safe(d1->search.name, d2->search.name);
 }
 
 
 /* 
    basic testing of search calls using many files
 */
-static BOOL test_many_files(struct cli_state *cli, TALLOC_CTX *mem_ctx)
+static BOOL test_many_files(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 {
        const int num_files = 700;
        int i, fnum, t;
@@ -553,6 +592,7 @@ static BOOL test_many_files(struct cli_state *cli, TALLOC_CTX *mem_ctx)
                enum smb_search_level level;
                enum continue_type cont_type;
        } search_types[] = {
+               {"SEARCH",              "ID",    RAW_SEARCH_SEARCH,              CONT_RESUME_KEY},
                {"BOTH_DIRECTORY_INFO", "NAME",  RAW_SEARCH_BOTH_DIRECTORY_INFO, CONT_NAME},
                {"BOTH_DIRECTORY_INFO", "FLAGS", RAW_SEARCH_BOTH_DIRECTORY_INFO, CONT_FLAGS},
                {"BOTH_DIRECTORY_INFO", "KEY",   RAW_SEARCH_BOTH_DIRECTORY_INFO, CONT_RESUME_KEY},
@@ -564,13 +604,10 @@ static BOOL test_many_files(struct cli_state *cli, TALLOC_CTX *mem_ctx)
                {"EA_SIZE",             "NAME",  RAW_SEARCH_EA_SIZE,             CONT_NAME},
                {"DIRECTORY_INFO",      "FLAGS", RAW_SEARCH_DIRECTORY_INFO,      CONT_FLAGS},
                {"DIRECTORY_INFO",      "KEY",   RAW_SEARCH_DIRECTORY_INFO,      CONT_RESUME_KEY},
-               {"DIRECTORY_INFO",      "NAME",  RAW_SEARCH_DIRECTORY_INFO,      CONT_NAME},
-               {"SEARCH",              "ID",    RAW_SEARCH_SEARCH,              CONT_RESUME_KEY}
+               {"DIRECTORY_INFO",      "NAME",  RAW_SEARCH_DIRECTORY_INFO,      CONT_NAME}
        };
 
-       if (cli_deltree(cli->tree, BASEDIR) == -1 || 
-           NT_STATUS_IS_ERR(cli_mkdir(cli->tree, BASEDIR))) {
-               printf("Failed to create " BASEDIR " - %s\n", cli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
@@ -578,20 +615,20 @@ static BOOL test_many_files(struct cli_state *cli, TALLOC_CTX *mem_ctx)
 
        for (i=0;i<num_files;i++) {
                asprintf(&fname, BASEDIR "\\t%03d-%d.txt", i, i);
-               fnum = cli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
+               fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
                if (fnum == -1) {
-                       printf("Failed to create %s - %s\n", fname, cli_errstr(cli->tree));
+                       printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
                        ret = False;
                        goto done;
                }
                free(fname);
-               cli_close(cli->tree, fnum);
+               smbcli_close(cli->tree, fnum);
        }
 
 
        for (t=0;t<ARRAY_SIZE(search_types);t++) {
                ZERO_STRUCT(result);
-               result.mem_ctx = mem_ctx;
+               result.mem_ctx = talloc(mem_ctx, 0);
        
                printf("Continue %s via %s\n", search_types[t].name, search_types[t].cont_name);
 
@@ -600,7 +637,11 @@ static BOOL test_many_files(struct cli_state *cli, TALLOC_CTX *mem_ctx)
                                         search_types[t].cont_type,
                                         &result);
        
-               CHECK_STATUS(status, NT_STATUS_OK);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("search failed - %s\n", nt_errstr(status));
+                       ret = False;
+                       continue;
+               }
                CHECK_VALUE(result.count, num_files);
 
                if (search_types[t].level == RAW_SEARCH_BOTH_DIRECTORY_INFO) {
@@ -620,7 +661,7 @@ static BOOL test_many_files(struct cli_state *cli, TALLOC_CTX *mem_ctx)
                              QSORT_CAST search_old_compare);
                }
 
-               for (i=0;i<num_files;i++) {
+               for (i=0;i<result.count;i++) {
                        const char *s;
                        if (search_types[t].level == RAW_SEARCH_BOTH_DIRECTORY_INFO) {
                                s = result.list[i].both_directory_info.name.s;
@@ -641,39 +682,518 @@ static BOOL test_many_files(struct cli_state *cli, TALLOC_CTX *mem_ctx)
                        }
                        free(fname);
                }
+               talloc_free(result.mem_ctx);
        }
 
 done:
        smb_raw_exit(cli->session);
-       cli_deltree(cli->tree, BASEDIR);
+       smbcli_deltree(cli->tree, BASEDIR);
 
        return ret;
 }
 
+/*
+  check a individual file result
+*/
+static BOOL check_result(struct multiple_result *result, const char *name, BOOL exist, uint32_t attrib)
+{
+       int i;
+       for (i=0;i<result->count;i++) {
+               if (strcmp(name, result->list[i].both_directory_info.name.s) == 0) break;
+       }
+       if (i == result->count) {
+               if (exist) {
+                       printf("failed: '%s' should exist with attribute %s\n", 
+                              name, attrib_string(result->list, attrib));
+                       return False;
+               }
+               return True;
+       }
+
+       if (!exist) {
+               printf("failed: '%s' should NOT exist (has attribute %s)\n", 
+                      name, attrib_string(result->list, result->list[i].both_directory_info.attrib));
+               return False;
+       }
+
+       if ((result->list[i].both_directory_info.attrib&0xFFF) != attrib) {
+               printf("failed: '%s' should have attribute 0x%x (has 0x%x)\n",
+                      name, 
+                      attrib, result->list[i].both_directory_info.attrib);
+               return False;
+       }
+       return True;
+}
 
 /* 
-   basic testing of all RAW_SEARCH_* calls using a single file
+   test what happens when the directory is modified during a search
 */
-BOOL torture_raw_search(int dummy)
+static BOOL test_modify_search(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 {
-       struct cli_state *cli;
+       const int num_files = 20;
+       int i, fnum;
+       char *fname;
        BOOL ret = True;
-       TALLOC_CTX *mem_ctx;
+       NTSTATUS status;
+       struct multiple_result result;
+       union smb_search_first io;
+       union smb_search_next io2;
+       union smb_setfileinfo sfinfo;
 
-       if (!torture_open_connection(&cli)) {
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
-       mem_ctx = talloc_init("torture_search");
+       printf("Creating %d files\n", num_files);
 
-       if (!test_one_file(cli, mem_ctx)) {
-               ret = False;
+       for (i=num_files-1;i>=0;i--) {
+               asprintf(&fname, BASEDIR "\\t%03d-%d.txt", i, i);
+               fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
+               if (fnum == -1) {
+                       printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
+                       ret = False;
+                       goto done;
+               }
+               free(fname);
+               smbcli_close(cli->tree, fnum);
+       }
+
+       printf("pulling the first file\n");
+       ZERO_STRUCT(result);
+       result.mem_ctx = talloc(mem_ctx, 0);
+
+       io.generic.level = RAW_SEARCH_BOTH_DIRECTORY_INFO;
+       io.t2ffirst.in.search_attrib = 0;
+       io.t2ffirst.in.max_count = 0;
+       io.t2ffirst.in.flags = 0;
+       io.t2ffirst.in.storage_type = 0;
+       io.t2ffirst.in.pattern = BASEDIR "\\*.*";
+
+       status = smb_raw_search_first(cli->tree, mem_ctx,
+                                     &io, &result, multiple_search_callback);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       CHECK_VALUE(result.count, 1);
+       
+       printf("pulling the second file\n");
+       io2.generic.level = RAW_SEARCH_BOTH_DIRECTORY_INFO;
+       io2.t2fnext.in.handle = io.t2ffirst.out.handle;
+       io2.t2fnext.in.max_count = 1;
+       io2.t2fnext.in.resume_key = 0;
+       io2.t2fnext.in.flags = 0;
+       if (result.count == 0) {
+               io2.t2fnext.in.last_name = "";
+       } else {
+               io2.t2fnext.in.last_name = result.list[result.count-1].both_directory_info.name.s;
+       }
+
+       status = smb_raw_search_next(cli->tree, mem_ctx,
+                                    &io2, &result, multiple_search_callback);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       CHECK_VALUE(result.count, 2);
+
+       printf("Changing attributes and deleting\n");
+       smbcli_open(cli->tree, BASEDIR "\\T003-03.txt.2", O_CREAT|O_RDWR, DENY_NONE);
+       smbcli_open(cli->tree, BASEDIR "\\T013-13.txt.2", O_CREAT|O_RDWR, DENY_NONE);
+       fnum = create_complex_file(cli, mem_ctx, BASEDIR "\\T013-13.txt.3");
+       smbcli_unlink(cli->tree, BASEDIR "\\T014-14.txt");
+       torture_set_file_attribute(cli->tree, BASEDIR "\\T015-15.txt", FILE_ATTRIBUTE_HIDDEN);
+       torture_set_file_attribute(cli->tree, BASEDIR "\\T016-16.txt", FILE_ATTRIBUTE_NORMAL);
+       torture_set_file_attribute(cli->tree, BASEDIR "\\T017-17.txt", FILE_ATTRIBUTE_SYSTEM);  
+       torture_set_file_attribute(cli->tree, BASEDIR "\\T018-18.txt", 0);      
+       sfinfo.generic.level = RAW_SFILEINFO_DISPOSITION_INFORMATION;
+       sfinfo.generic.file.fnum = fnum;
+       sfinfo.disposition_info.in.delete_on_close = 1;
+       status = smb_raw_setfileinfo(cli->tree, &sfinfo);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       io2.generic.level = RAW_SEARCH_BOTH_DIRECTORY_INFO;
+       io2.t2fnext.in.handle = io.t2ffirst.out.handle;
+       io2.t2fnext.in.max_count = num_files - 1;
+       io2.t2fnext.in.resume_key = 0;
+       io2.t2fnext.in.flags = 0;
+       io2.t2fnext.in.last_name = result.list[result.count-2].both_directory_info.name.s;
+
+       status = smb_raw_search_next(cli->tree, mem_ctx,
+                                    &io2, &result, multiple_search_callback);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       CHECK_VALUE(result.count, 21);
+
+       ret &= check_result(&result, "t009-9.txt", True, FILE_ATTRIBUTE_ARCHIVE);
+       ret &= check_result(&result, "t014-14.txt", False, 0);
+       ret &= check_result(&result, "t015-15.txt", False, 0);
+       ret &= check_result(&result, "t016-16.txt", True, FILE_ATTRIBUTE_NORMAL);
+       ret &= check_result(&result, "t017-17.txt", False, 0);
+       ret &= check_result(&result, "t018-18.txt", True, FILE_ATTRIBUTE_ARCHIVE);
+       ret &= check_result(&result, "t019-19.txt", True, FILE_ATTRIBUTE_ARCHIVE);
+       ret &= check_result(&result, "T013-13.txt.2", True, FILE_ATTRIBUTE_ARCHIVE);
+       ret &= check_result(&result, "T003-3.txt.2", False, 0);
+       ret &= check_result(&result, "T013-13.txt.3", True, FILE_ATTRIBUTE_ARCHIVE);
+
+       if (!ret) {
+               for (i=0;i<result.count;i++) {
+                       printf("%s %s (0x%x)\n", 
+                              result.list[i].both_directory_info.name.s, 
+                              attrib_string(mem_ctx, result.list[i].both_directory_info.attrib),
+                              result.list[i].both_directory_info.attrib);
+               }
+       }
+
+done:
+       smb_raw_exit(cli->session);
+       smbcli_deltree(cli->tree, BASEDIR);
+
+       return ret;
+}
+
+
+/* 
+   testing if directories always come back sorted
+*/
+static BOOL test_sorted(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+{
+       const int num_files = 700;
+       int i, fnum;
+       char *fname;
+       BOOL ret = True;
+       NTSTATUS status;
+       struct multiple_result result;
+
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return False;
+       }
+
+       printf("Creating %d files\n", num_files);
+
+       for (i=0;i<num_files;i++) {
+               asprintf(&fname, BASEDIR "\\%s.txt", generate_random_str_list(mem_ctx, 10, "abcdefgh"));
+               fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
+               if (fnum == -1) {
+                       printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
+                       ret = False;
+                       goto done;
+               }
+               free(fname);
+               smbcli_close(cli->tree, fnum);
+       }
+
+
+       ZERO_STRUCT(result);
+       result.mem_ctx = mem_ctx;
+       
+       status = multiple_search(cli, mem_ctx, BASEDIR "\\*.*", 
+                                RAW_SEARCH_BOTH_DIRECTORY_INFO,
+                                CONT_NAME, &result);   
+       CHECK_STATUS(status, NT_STATUS_OK);
+       CHECK_VALUE(result.count, num_files);
+
+       for (i=0;i<num_files-1;i++) {
+               const char *name1, *name2;
+               name1 = result.list[i].both_directory_info.name.s;
+               name2 = result.list[i+1].both_directory_info.name.s;
+               if (StrCaseCmp(name1, name2) > 0) {
+                       printf("non-alphabetical order at entry %d  '%s' '%s'\n", 
+                              i, name1, name2);
+                       printf("Server does not produce sorted directory listings (not an error)\n");
+                       goto done;
+               }
+       }
+
+       talloc_free(result.list);
+
+done:
+       smb_raw_exit(cli->session);
+       smbcli_deltree(cli->tree, BASEDIR);
+
+       return ret;
+}
+
+
+
+/* 
+   basic testing of many old style search calls using separate dirs
+*/
+static BOOL test_many_dirs(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+{
+       const int num_dirs = 300;
+       int i, fnum, n;
+       char *fname, *dname;
+       BOOL ret = True;
+       NTSTATUS status;
+       union smb_search_data *file, *file2, *file3;
+
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return False;
+       }
+
+       printf("Creating %d dirs\n", num_dirs);
+
+       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);
+       }
+
+       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);
+       }
+
+       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);
+       }
+
+
+       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;
+}
+
+
+/* 
+   testing of OS/2 style delete
+*/
+static BOOL test_os2_delete(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+{
+       const int num_files = 700;
+       const int delete_count = 4;
+       int total_deleted = 0;
+       int i, fnum;
+       char *fname;
+       BOOL ret = True;
+       NTSTATUS status;
+       union smb_search_first io;
+       union smb_search_next io2;
+       struct multiple_result result;
+
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return False;
+       }
+
+       printf("Testing OS/2 style delete on %d files\n", num_files);
+
+       for (i=0;i<num_files;i++) {
+               asprintf(&fname, BASEDIR "\\file%u.txt", i);
+               fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
+               if (fnum == -1) {
+                       printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
+                       ret = False;
+                       goto done;
+               }
+               free(fname);
+               smbcli_close(cli->tree, fnum);
+       }
+
+
+       ZERO_STRUCT(result);
+       result.mem_ctx = mem_ctx;
+
+       io.t2ffirst.level = RAW_SEARCH_EA_SIZE;
+       io.t2ffirst.in.search_attrib = 0;
+       io.t2ffirst.in.max_count = 100;
+       io.t2ffirst.in.flags = FLAG_TRANS2_FIND_REQUIRE_RESUME;
+       io.t2ffirst.in.storage_type = 0;
+       io.t2ffirst.in.pattern = BASEDIR "\\*";
+
+       status = smb_raw_search_first(cli->tree, mem_ctx,
+                                     &io, &result, multiple_search_callback);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       for (i=0;i<MIN(result.count, delete_count);i++) {
+               asprintf(&fname, BASEDIR "\\%s", result.list[i].ea_size.name.s);
+               status = smbcli_unlink(cli->tree, fname);
+               CHECK_STATUS(status, NT_STATUS_OK);
+               total_deleted++;
        }
 
-       if (!test_many_files(cli, mem_ctx)) {
+       io2.t2fnext.level = RAW_SEARCH_EA_SIZE;
+       io2.t2fnext.in.handle = io.t2ffirst.out.handle;
+       io2.t2fnext.in.max_count = 100;
+       io2.t2fnext.in.resume_key = result.list[i-1].ea_size.resume_key;
+       io2.t2fnext.in.flags = FLAG_TRANS2_FIND_REQUIRE_RESUME;
+       io2.t2fnext.in.last_name = result.list[i-1].ea_size.name.s;
+
+       do {
+               ZERO_STRUCT(result);
+               result.mem_ctx = mem_ctx;
+
+               status = smb_raw_search_next(cli->tree, mem_ctx,
+                                            &io2, &result, multiple_search_callback);
+               if (!NT_STATUS_IS_OK(status)) {
+                       break;
+               }
+
+               for (i=0;i<MIN(result.count, delete_count);i++) {
+                       asprintf(&fname, BASEDIR "\\%s", result.list[i].ea_size.name.s);
+                       status = smbcli_unlink(cli->tree, fname);
+                       CHECK_STATUS(status, NT_STATUS_OK);
+                       total_deleted++;
+               }
+
+               if (i>0) {
+                       io2.t2fnext.in.resume_key = 0;
+                       io2.t2fnext.in.last_name = result.list[i-1].ea_size.name.s;
+               }
+       } while (NT_STATUS_IS_OK(status) && result.count != 0);
+
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       if (total_deleted != num_files) {
+               printf("error: deleted %d - expected to delete %d\n", 
+                      total_deleted, num_files);
                ret = False;
        }
 
+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(void)
+{
+       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);
+       ret &= test_os2_delete(cli, mem_ctx);
+
        torture_close_connection(cli);
        talloc_destroy(mem_ctx);