⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 search.c

📁 samba最新软件
💻 C
📖 第 1 页 / 共 4 页
字号:
	}	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);		torture_assert(tctx, fnum != -1, "Failed to create");		talloc_free(fname);		smbcli_close(cli->tree, fnum);	}	for (t=0;t<ARRAY_SIZE(search_types);t++) {		ZERO_STRUCT(result);		if ((search_types[t].cont_type == CONT_RESUME_KEY) &&		    (search_types[t].data_level != RAW_SEARCH_DATA_SEARCH) &&		    torture_setting_bool(tctx, "samba3", false)) {			torture_comment(tctx,					"SKIP: Continue %s via %s\n",					search_types[t].name, search_types[t].cont_name);			continue;		}		result.tctx = talloc_new(tctx);			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);			torture_assert_ntstatus_ok(tctx, status, "search failed");		CHECK_VALUE(result.count, num_files);		compare_data_level = search_types[t].data_level;		qsort(result.list, result.count, sizeof(result.list[0]), 		      QSORT_CAST  search_compare);		for (i=0;i<result.count;i++) {			const char *s;			enum smb_search_level level;			if (compare_data_level == RAW_SEARCH_DATA_SEARCH) {				level = RAW_SEARCH_SEARCH;			} else {				level = RAW_SEARCH_TRANS2;			}			s = extract_name(&result.list[i], level, compare_data_level);			fname = talloc_asprintf(cli, "t%03d-%d.txt", i, i);			torture_assert_str_equal(tctx, fname, s, "Incorrect name");			talloc_free(fname);		}		talloc_free(result.tctx);	}	smb_raw_exit(cli->session);	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;}/*    test what happens when the directory is modified during a search*/static bool test_modify_search(struct torture_context *tctx, 							   struct smbcli_state *cli){	const int num_files = 20;	int i, fnum;	char *fname;	bool ret = true;	NTSTATUS status;	struct multiple_result result;	union smb_search_first io;	union smb_search_next io2;	union smb_setfileinfo sfinfo;	if (!torture_setup_dir(cli, BASEDIR)) {		return false;	}	printf("Creating %d files\n", num_files);	for (i=num_files-1;i>=0;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;		}		talloc_free(fname);		smbcli_close(cli->tree, fnum);	}	printf("pulling the first file\n");	ZERO_STRUCT(result);	result.tctx = talloc_new(tctx);	io.t2ffirst.level = RAW_SEARCH_TRANS2;	io.t2ffirst.data_level = RAW_SEARCH_DATA_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, tctx,				      &io, &result, multiple_search_callback);	CHECK_STATUS(status, NT_STATUS_OK);	CHECK_VALUE(result.count, 1);		printf("pulling the second file\n");	io2.t2fnext.level = RAW_SEARCH_TRANS2;	io2.t2fnext.data_level = RAW_SEARCH_DATA_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;	io2.t2fnext.in.last_name = result.list[result.count-1].both_directory_info.name.s;	status = smb_raw_search_next(cli->tree, tctx,				     &io2, &result, multiple_search_callback);	CHECK_STATUS(status, NT_STATUS_OK);	CHECK_VALUE(result.count, 2);	result.count = 0;	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, tctx, 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.in.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.t2fnext.level = RAW_SEARCH_TRANS2;	io2.t2fnext.data_level = RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO;	io2.t2fnext.in.handle = io.t2ffirst.out.handle;	io2.t2fnext.in.max_count = num_files + 3;	io2.t2fnext.in.resume_key = 0;	io2.t2fnext.in.flags = 0;	io2.t2fnext.in.last_name = ".";	status = smb_raw_search_next(cli->tree, tctx,				     &io2, &result, multiple_search_callback);	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);	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(tctx, 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 torture_context *tctx, struct smbcli_state *cli){	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++) {		fname = talloc_asprintf(cli, BASEDIR "\\%s.txt", generate_random_str_list(tctx, 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;		}		talloc_free(fname);		smbcli_close(cli->tree, fnum);	}	ZERO_STRUCT(result);	result.tctx = tctx;		status = multiple_search(cli, tctx, BASEDIR "\\*.*", 				 RAW_SEARCH_DATA_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_m(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 torture_context *tctx, 						   struct smbcli_state *cli){	const int num_dirs = 20;	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++) {		dname = talloc_asprintf(cli, 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++) {			fname = talloc_asprintf(cli, 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;			}			talloc_free(fname);			smbcli_close(cli->tree, fnum);		}		talloc_free(dname);	}	file  = talloc_zero_array(tctx, union smb_search_data, num_dirs);	file2 = talloc_zero_array(tctx, union smb_search_data, num_dirs);	file3 = talloc_zero_array(tctx, 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.search_first.level = RAW_SEARCH_SEARCH;		io.search_first.data_level = RAW_SEARCH_DATA_SEARCH;		io.search_first.in.max_count = 1;		io.search_first.in.search_attrib = 0;		io.search_first.in.pattern = talloc_asprintf(tctx, BASEDIR "\\d%d\\*.txt", i);		fname = talloc_asprintf(tctx, "f%d-", i);		io.search_first.out.count = 0;		status = smb_raw_search_first(cli->tree, tctx,					      &io, (void *)&file[i], single_search_callback);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -