diff options
Diffstat (limited to 'source4/torture/raw/search.c')
-rw-r--r-- | source4/torture/raw/search.c | 204 |
1 files changed, 77 insertions, 127 deletions
diff --git a/source4/torture/raw/search.c b/source4/torture/raw/search.c index 986da474d0..0242b9c545 100644 --- a/source4/torture/raw/search.c +++ b/source4/torture/raw/search.c @@ -30,13 +30,13 @@ /* callback function for single_search */ -static BOOL single_search_callback(void *private, const union smb_search_data *file) +static bool single_search_callback(void *private, const union smb_search_data *file) { - union smb_search_data *data = private; + union smb_search_data *data = (union smb_search_data *)private; *data = *file; - return True; + return true; } /* @@ -231,10 +231,10 @@ 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 torture_context *tctx, - struct smbcli_state *cli) +static bool test_one_file(struct torture_context *tctx, + struct smbcli_state *cli) { - BOOL ret = True; + bool ret = true; int fnum; const char *fname = "\\torture_search.txt"; const char *fname2 = "\\torture_search-NOTEXIST.txt"; @@ -243,12 +243,10 @@ static BOOL test_one_file(struct torture_context *tctx, union smb_fileinfo all_info, alt_info, name_info, internal_info; union smb_search_data *s; - printf("Testing one file searches\n"); - fnum = create_complex_file(cli, tctx, fname); if (fnum == -1) { printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); - ret = False; + ret = false; goto done; } @@ -257,7 +255,7 @@ static BOOL test_one_file(struct torture_context *tctx, NTSTATUS expected_status; uint32_t cap = cli->transport->negotiate.capabilities; - printf("testing %s\n", levels[i].name); + torture_comment(tctx, "testing %s\n", levels[i].name); levels[i].status = torture_single_search(cli, tctx, fname, levels[i].level, @@ -276,7 +274,7 @@ static BOOL test_one_file(struct torture_context *tctx, printf("search level %s(%d) failed - %s\n", levels[i].name, (int)levels[i].level, nt_errstr(levels[i].status)); - ret = False; + ret = false; continue; } @@ -297,7 +295,7 @@ static BOOL test_one_file(struct torture_context *tctx, levels[i].name, (int)levels[i].level, nt_errstr(expected_status), nt_errstr(status)); - ret = False; + ret = false; } } @@ -305,38 +303,22 @@ static BOOL test_one_file(struct torture_context *tctx, all_info.generic.level = RAW_FILEINFO_ALL_INFO; all_info.generic.in.file.path = fname; status = smb_raw_pathinfo(cli->tree, tctx, &all_info); - if (!NT_STATUS_IS_OK(status)) { - printf("RAW_FILEINFO_ALL_INFO failed - %s\n", nt_errstr(status)); - ret = False; - goto done; - } + torture_assert_ntstatus_ok(tctx, status, "RAW_FILEINFO_ALL_INFO failed"); alt_info.generic.level = RAW_FILEINFO_ALT_NAME_INFO; alt_info.generic.in.file.path = fname; status = smb_raw_pathinfo(cli->tree, tctx, &alt_info); - if (!NT_STATUS_IS_OK(status)) { - printf("RAW_FILEINFO_ALT_NAME_INFO failed - %s\n", nt_errstr(status)); - ret = False; - goto done; - } + torture_assert_ntstatus_ok(tctx, status, "RAW_FILEINFO_ALT_NAME_INFO failed"); internal_info.generic.level = RAW_FILEINFO_INTERNAL_INFORMATION; internal_info.generic.in.file.path = fname; status = smb_raw_pathinfo(cli->tree, tctx, &internal_info); - if (!NT_STATUS_IS_OK(status)) { - printf("RAW_FILEINFO_INTERNAL_INFORMATION failed - %s\n", nt_errstr(status)); - ret = False; - goto done; - } + torture_assert_ntstatus_ok(tctx, status, "RAW_FILEINFO_INTERNAL_INFORMATION failed"); name_info.generic.level = RAW_FILEINFO_NAME_INFO; name_info.generic.in.file.path = fname; status = smb_raw_pathinfo(cli->tree, tctx, &name_info); - if (!NT_STATUS_IS_OK(status)) { - printf("RAW_FILEINFO_NAME_INFO failed - %s\n", nt_errstr(status)); - ret = False; - goto done; - } + torture_assert_ntstatus_ok(tctx, status, "RAW_FILEINFO_NAME_INFO failed"); #define CHECK_VAL(name, sname1, field1, v, sname2, field2) do { \ s = find(name); \ @@ -346,7 +328,7 @@ static BOOL test_one_file(struct torture_context *tctx, __location__, \ #sname1, #field1, (int)s->sname1.field1, \ #sname2, #field2, (int)v.sname2.out.field2); \ - ret = False; \ + ret = false; \ } \ }} while (0) @@ -358,7 +340,7 @@ static BOOL test_one_file(struct torture_context *tctx, __location__, \ #sname1, #field1, timestring(tctx, s->sname1.field1), \ #sname2, #field2, nt_time_string(tctx, v.sname2.out.field2)); \ - ret = False; \ + ret = false; \ } \ }} while (0) @@ -370,7 +352,7 @@ static BOOL test_one_file(struct torture_context *tctx, __location__, \ #sname1, #field1, nt_time_string(tctx, s->sname1.field1), \ #sname2, #field2, nt_time_string(tctx, v.sname2.out.field2)); \ - ret = False; \ + ret = false; \ } \ }} while (0) @@ -382,7 +364,7 @@ static BOOL test_one_file(struct torture_context *tctx, __location__, \ #sname1, #field1, s->sname1.field1, \ #sname2, #field2, v.sname2.out.field2.s); \ - ret = False; \ + ret = false; \ } \ }} while (0) @@ -396,7 +378,7 @@ static BOOL test_one_file(struct torture_context *tctx, __location__, \ #sname1, #field1, s->sname1.field1.s, \ #sname2, #field2, v.sname2.out.field2.s); \ - ret = False; \ + ret = false; \ } \ }} while (0) @@ -410,7 +392,7 @@ static BOOL test_one_file(struct torture_context *tctx, __location__, \ #sname1, #field1, s->sname1.field1.s, \ fname); \ - ret = False; \ + ret = false; \ } \ }} while (0) @@ -423,7 +405,7 @@ static BOOL test_one_file(struct torture_context *tctx, __location__, \ #sname1, #field1, s->sname1.field1, \ fname); \ - ret = False; \ + ret = false; \ } \ }} while (0) @@ -527,9 +509,9 @@ struct multiple_result { /* callback function for multiple_search */ -static BOOL multiple_search_callback(void *private, const union smb_search_data *file) +static bool multiple_search_callback(void *private, const union smb_search_data *file) { - struct multiple_result *data = private; + struct multiple_result *data = (struct multiple_result *)private; data->count++; @@ -540,7 +522,7 @@ static BOOL multiple_search_callback(void *private, const union smb_search_data data->list[data->count-1] = *file; - return True; + return true; } enum continue_type {CONT_FLAGS, CONT_NAME, CONT_RESUME_KEY}; @@ -559,7 +541,7 @@ static NTSTATUS multiple_search(struct smbcli_state *cli, union smb_search_next io2; NTSTATUS status; const int per_search = 100; - struct multiple_result *result = data; + struct multiple_result *result = (struct multiple_result *)data; if (data_level == RAW_SEARCH_DATA_SEARCH) { io.search_first.level = RAW_SEARCH_SEARCH; @@ -640,28 +622,11 @@ static NTSTATUS multiple_search(struct smbcli_state *cli, return status; } -#define CHECK_STATUS(status, correct) do { \ - if (!NT_STATUS_EQUAL(status, 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_STATUS(status, correct) torture_assert_ntstatus_equal(tctx, status, correct, "incorrect status") -#define CHECK_VALUE(v, correct) do { \ - if ((v) != (correct)) { \ - printf("(%s) Incorrect value %s=%ld - should be %ld\n", \ - __location__, #v, (long)v, (long)correct); \ - ret = False; \ - goto done; \ - }} while (0) +#define CHECK_VALUE(v, correct) torture_assert_int_equal(tctx, (v), (correct), "incorrect value"); -#define CHECK_STRING(v, correct) do { \ - if (strcasecmp_m(v, correct) != 0) { \ - printf("(%s) Incorrect value %s='%s' - should be '%s'\n", \ - __location__, #v, v, correct); \ - ret = False; \ - }} while (0) +#define CHECK_STRING(v, correct) torture_assert_casestr_equal(tctx, v, correct, "incorrect value"); static enum smb_search_data_level compare_data_level; @@ -688,12 +653,12 @@ static int search_compare(union smb_search_data *d1, union smb_search_data *d2) basic testing of search calls using many files */ static bool test_many_files(struct torture_context *tctx, - struct smbcli_state *cli) + struct smbcli_state *cli) { const int num_files = 700; int i, fnum, t; char *fname; - BOOL ret = True; + bool ret = true; NTSTATUS status; struct multiple_result result; struct { @@ -727,19 +692,15 @@ static bool test_many_files(struct torture_context *tctx, }; if (!torture_setup_dir(cli, BASEDIR)) { - return False; + return false; } - printf("Testing with %d files\n", num_files); + torture_comment(tctx, "Testing with %d files\n", num_files); for (i=0;i<num_files;i++) { fname = talloc_asprintf(cli, 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; - } + torture_assert(tctx, fnum != -1, "Failed to create"); talloc_free(fname); smbcli_close(cli->tree, fnum); } @@ -749,20 +710,15 @@ static bool test_many_files(struct torture_context *tctx, ZERO_STRUCT(result); result.tctx = talloc_new(tctx); - printf("Continue %s via %s\n", search_types[t].name, search_types[t].cont_name); + torture_comment(tctx, + "Continue %s via %s\n", search_types[t].name, search_types[t].cont_name); status = multiple_search(cli, tctx, BASEDIR "\\*.*", search_types[t].data_level, search_types[t].cont_type, &result); - if (!NT_STATUS_IS_OK(status)) { - printf("search type %s failed - %s\n", - search_types[t].name, - nt_errstr(status)); - ret = False; - continue; - } + torture_assert_ntstatus_ok(tctx, status, "search failed"); CHECK_VALUE(result.count, num_files); compare_data_level = search_types[t].data_level; @@ -780,17 +736,12 @@ static bool test_many_files(struct torture_context *tctx, } s = extract_name(&result.list[i], level, compare_data_level); fname = talloc_asprintf(cli, "t%03d-%d.txt", i, i); - if (strcmp(fname, s)) { - printf("Incorrect name %s at entry %d\n", s, i); - ret = False; - break; - } + torture_assert_str_equal(tctx, fname, s, "Incorrect name"); talloc_free(fname); } talloc_free(result.tctx); } -done: smb_raw_exit(cli->session); smbcli_deltree(cli->tree, BASEDIR); @@ -800,7 +751,7 @@ done: /* check a individual file result */ -static BOOL check_result(struct multiple_result *result, const char *name, BOOL exist, uint32_t attrib) +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++) { @@ -810,24 +761,24 @@ static BOOL check_result(struct multiple_result *result, const char *name, BOOL if (exist) { printf("failed: '%s' should exist with attribute %s\n", name, attrib_string(result->list, attrib)); - return False; + return false; } - return True; + 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; + 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 false; } - return True; + return true; } /* @@ -839,7 +790,7 @@ static bool test_modify_search(struct torture_context *tctx, const int num_files = 20; int i, fnum; char *fname; - BOOL ret = True; + bool ret = true; NTSTATUS status; struct multiple_result result; union smb_search_first io; @@ -847,7 +798,7 @@ static bool test_modify_search(struct torture_context *tctx, union smb_setfileinfo sfinfo; if (!torture_setup_dir(cli, BASEDIR)) { - return False; + return false; } printf("Creating %d files\n", num_files); @@ -857,7 +808,7 @@ static bool test_modify_search(struct torture_context *tctx, 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; + ret = false; goto done; } talloc_free(fname); @@ -925,16 +876,16 @@ static bool test_modify_search(struct torture_context *tctx, CHECK_STATUS(status, NT_STATUS_OK); CHECK_VALUE(result.count, 20); - 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); + 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++) { @@ -961,12 +912,12 @@ static bool test_sorted(struct torture_context *tctx, struct smbcli_state *cli) const int num_files = 700; int i, fnum; char *fname; - BOOL ret = True; + bool ret = true; NTSTATUS status; struct multiple_result result; if (!torture_setup_dir(cli, BASEDIR)) { - return False; + return false; } printf("Creating %d files\n", num_files); @@ -976,7 +927,7 @@ static bool test_sorted(struct torture_context *tctx, struct smbcli_state *cli) 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; + ret = false; goto done; } talloc_free(fname); @@ -1025,12 +976,12 @@ static bool test_many_dirs(struct torture_context *tctx, const int num_dirs = 20; int i, fnum, n; char *fname, *dname; - BOOL ret = True; + bool ret = true; NTSTATUS status; union smb_search_data *file, *file2, *file3; if (!torture_setup_dir(cli, BASEDIR)) { - return False; + return false; } printf("Creating %d dirs\n", num_dirs); @@ -1041,7 +992,7 @@ static bool test_many_dirs(struct torture_context *tctx, if (!NT_STATUS_IS_OK(status)) { printf("(%s) Failed to create %s - %s\n", __location__, dname, nt_errstr(status)); - ret = False; + ret = false; goto done; } @@ -1051,7 +1002,7 @@ static bool test_many_dirs(struct torture_context *tctx, if (fnum == -1) { printf("(%s) Failed to create %s - %s\n", __location__, fname, smbcli_errstr(cli->tree)); - ret = False; + ret = false; goto done; } talloc_free(fname); @@ -1083,14 +1034,14 @@ static bool test_many_dirs(struct torture_context *tctx, 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; + 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; + ret = false; goto done; } @@ -1116,14 +1067,14 @@ static bool test_many_dirs(struct torture_context *tctx, 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; + 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; + ret = false; goto done; } @@ -1149,7 +1100,7 @@ static bool test_many_dirs(struct torture_context *tctx, 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; + ret = false; goto done; } CHECK_STATUS(status, NT_STATUS_OK); @@ -1157,14 +1108,14 @@ static bool test_many_dirs(struct torture_context *tctx, 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; + 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; + ret = false; goto done; } @@ -1191,14 +1142,14 @@ static bool test_os2_delete(struct torture_context *tctx, int total_deleted = 0; int i, fnum; char *fname; - BOOL ret = True; + 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; + return false; } printf("Testing OS/2 style delete on %d files\n", num_files); @@ -1208,7 +1159,7 @@ static bool test_os2_delete(struct torture_context *tctx, 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; + ret = false; goto done; } talloc_free(fname); @@ -1276,7 +1227,7 @@ static bool test_os2_delete(struct torture_context *tctx, if (total_deleted != num_files) { printf("error: deleted %d - expected to delete %d\n", total_deleted, num_files); - ret = False; + ret = false; } done: @@ -1299,7 +1250,7 @@ static bool test_ea_list(struct torture_context *tctx, struct smbcli_state *cli) { int fnum; - BOOL ret = True; + bool ret = true; NTSTATUS status; union smb_search_first io; union smb_search_next nxt; @@ -1307,7 +1258,7 @@ static bool test_ea_list(struct torture_context *tctx, union smb_setfileinfo setfile; if (!torture_setup_dir(cli, BASEDIR)) { - return False; + return false; } printf("Testing RAW_SEARCH_EA_LIST level\n"); @@ -1402,7 +1353,6 @@ static bool test_ea_list(struct torture_context *tctx, CHECK_STRING(result.list[2].ea_list.eas.eas[1].name.s, "THIRD EA"); CHECK_VALUE(result.list[2].ea_list.eas.eas[1].value.length, 0); -done: smb_raw_exit(cli->session); smbcli_deltree(cli->tree, BASEDIR); @@ -1418,7 +1368,7 @@ struct torture_suite *torture_raw_search(TALLOC_CTX *mem_ctx) { struct torture_suite *suite = torture_suite_create(mem_ctx, "SEARCH"); - torture_suite_add_1smb_test(suite, "one file", test_one_file); + torture_suite_add_1smb_test(suite, "one file search", test_one_file); torture_suite_add_1smb_test(suite, "many files", test_many_files); torture_suite_add_1smb_test(suite, "sorted", test_sorted); torture_suite_add_1smb_test(suite, "modify search", test_modify_search); |