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

📄 util_smb.c

📁 samba最新软件
💻 C
📖 第 1 页 / 共 2 页
字号:
		return NT_STATUS_OK;	}	printf("Expected value '%s' not '%*.*s' for ea %s\n",	       value, 	       (int)info.ea_list.out.eas[0].value.length,	       (int)info.ea_list.out.eas[0].value.length,	       info.ea_list.out.eas[0].value.data,	       eaname);	talloc_free(mem_ctx);	return NT_STATUS_EA_CORRUPT_ERROR;}_PUBLIC_ bool torture_open_connection_share(TALLOC_CTX *mem_ctx,				   struct smbcli_state **c, 				   struct torture_context *tctx,				   const char *hostname, 				   const char *sharename,				   struct event_context *ev){	NTSTATUS status;	struct smbcli_options options;	lp_smbcli_options(tctx->lp_ctx, &options);	options.use_oplocks = torture_setting_bool(tctx, "use_oplocks", true);	options.use_level2_oplocks = torture_setting_bool(tctx, "use_level2_oplocks", true);	status = smbcli_full_connection(mem_ctx, c, hostname, 					lp_smb_ports(tctx->lp_ctx),					sharename, NULL,					cmdline_credentials, 					lp_resolve_context(tctx->lp_ctx),					ev, &options);	if (!NT_STATUS_IS_OK(status)) {		printf("Failed to open connection - %s\n", nt_errstr(status));		return false;	}	return true;}_PUBLIC_ bool torture_get_conn_index(int conn_index,				     TALLOC_CTX *mem_ctx,				     struct torture_context *tctx,				     char **host, char **share){	char **unc_list = NULL;	int num_unc_names = 0;	const char *p;	(*host) = talloc_strdup(mem_ctx, torture_setting_string(tctx, "host", NULL));	(*share) = talloc_strdup(mem_ctx, torture_setting_string(tctx, "share", NULL));		p = torture_setting_string(tctx, "unclist", NULL);	if (!p) {		return true;	}	unc_list = file_lines_load(p, &num_unc_names, NULL);	if (!unc_list || num_unc_names <= 0) {		DEBUG(0,("Failed to load unc names list from '%s'\n", p));		return false;	}	if (!smbcli_parse_unc(unc_list[conn_index % num_unc_names],			      mem_ctx, host, share)) {		DEBUG(0, ("Failed to parse UNC name %s\n",			  unc_list[conn_index % num_unc_names]));		return false;	}	talloc_free(unc_list);	return true;}_PUBLIC_ bool torture_open_connection_ev(struct smbcli_state **c,					 int conn_index,					 struct torture_context *tctx,					 struct event_context *ev){	char *host, *share;	bool ret;	if (!torture_get_conn_index(conn_index, ev, tctx, &host, &share)) {		return false;	}	ret = torture_open_connection_share(NULL, c, tctx, host, share, ev);	talloc_free(host);	talloc_free(share);	return ret;}_PUBLIC_ bool torture_open_connection(struct smbcli_state **c, struct torture_context *tctx, int conn_index){	return torture_open_connection_ev(c, conn_index, tctx, tctx->ev);}_PUBLIC_ bool torture_close_connection(struct smbcli_state *c){	bool ret = true;	if (!c) return true;	if (NT_STATUS_IS_ERR(smbcli_tdis(c))) {		printf("tdis failed (%s)\n", smbcli_errstr(c->tree));		ret = false;	}	talloc_free(c);	return ret;}/* check if the server produced the expected error code */_PUBLIC_ bool check_error(const char *location, struct smbcli_state *c, 		 uint8_t eclass, uint32_t ecode, NTSTATUS nterr){	NTSTATUS status;		status = smbcli_nt_error(c->tree);	if (NT_STATUS_IS_DOS(status)) {		int class, num;		class = NT_STATUS_DOS_CLASS(status);		num = NT_STATUS_DOS_CODE(status);                if (eclass != class || ecode != num) {                        printf("unexpected error code %s\n", nt_errstr(status));                        printf(" expected %s or %s (at %s)\n", 			       nt_errstr(NT_STATUS_DOS(eclass, ecode)),                                nt_errstr(nterr), location);                        return false;                }        } else {                if (!NT_STATUS_EQUAL(nterr, status)) {                        printf("unexpected error code %s\n", nt_errstr(status));                        printf(" expected %s (at %s)\n", nt_errstr(nterr), location);                        return false;                }        }	return true;}static struct smbcli_state *current_cli;static int procnum; /* records process count number when forking */static void sigcont(int sig){}double torture_create_procs(struct torture_context *tctx, 							bool (*fn)(struct torture_context *, struct smbcli_state *, int), bool *result){	int i, status;	volatile pid_t *child_status;	volatile bool *child_status_out;	int synccount;	int tries = 8;	int torture_nprocs = torture_setting_int(tctx, "nprocs", 4);	double start_time_limit = 10 + (torture_nprocs * 1.5);	struct timeval tv;	*result = true;	synccount = 0;	signal(SIGCONT, sigcont);	child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*torture_nprocs);	if (!child_status) {		printf("Failed to setup shared memory\n");		return -1;	}	child_status_out = (volatile bool *)shm_setup(sizeof(bool)*torture_nprocs);	if (!child_status_out) {		printf("Failed to setup result status shared memory\n");		return -1;	}	for (i = 0; i < torture_nprocs; i++) {		child_status[i] = 0;		child_status_out[i] = true;	}	tv = timeval_current();	for (i=0;i<torture_nprocs;i++) {		procnum = i;		if (fork() == 0) {			char *myname;			pid_t mypid = getpid();			srandom(((int)mypid) ^ ((int)time(NULL)));			asprintf(&myname, "CLIENT%d", i);			lp_set_cmdline(tctx->lp_ctx, "netbios name", myname);			free(myname);			while (1) {				if (torture_open_connection(&current_cli, tctx, i)) {					break;				}				if (tries-- == 0) {					printf("pid %d failed to start\n", (int)getpid());					_exit(1);				}				msleep(100);				}			child_status[i] = getpid();			pause();			if (child_status[i]) {				printf("Child %d failed to start!\n", i);				child_status_out[i] = 1;				_exit(1);			}			child_status_out[i] = fn(tctx, current_cli, i);			_exit(0);		}	}	do {		synccount = 0;		for (i=0;i<torture_nprocs;i++) {			if (child_status[i]) synccount++;		}		if (synccount == torture_nprocs) break;		msleep(100);	} while (timeval_elapsed(&tv) < start_time_limit);	if (synccount != torture_nprocs) {		printf("FAILED TO START %d CLIENTS (started %d)\n", torture_nprocs, synccount);		*result = false;		return timeval_elapsed(&tv);	}	printf("Starting %d clients\n", torture_nprocs);	/* start the client load */	tv = timeval_current();	for (i=0;i<torture_nprocs;i++) {		child_status[i] = 0;	}	printf("%d clients started\n", torture_nprocs);	kill(0, SIGCONT);	for (i=0;i<torture_nprocs;i++) {		int ret;		while ((ret=waitpid(0, &status, 0)) == -1 && errno == EINTR) /* noop */ ;		if (ret == -1 || WEXITSTATUS(status) != 0) {			*result = false;		}	}	printf("\n");		for (i=0;i<torture_nprocs;i++) {		if (!child_status_out[i]) {			*result = false;		}	}	return timeval_elapsed(&tv);}static bool wrap_smb_multi_test(struct torture_context *torture,								struct torture_tcase *tcase,								struct torture_test *test){	bool (*fn)(struct torture_context *, struct smbcli_state *, int ) = test->fn;	bool result;	torture_create_procs(torture, fn, &result);	return result;}_PUBLIC_ struct torture_test *torture_suite_add_smb_multi_test(									struct torture_suite *suite,									const char *name,									bool (*run) (struct torture_context *,												 struct smbcli_state *,												int i)){	struct torture_test *test; 	struct torture_tcase *tcase;		tcase = torture_suite_add_tcase(suite, name);	test = talloc(tcase, struct torture_test);	test->name = talloc_strdup(test, name);	test->description = NULL;	test->run = wrap_smb_multi_test;	test->fn = run;	test->dangerous = false;	DLIST_ADD_END(tcase->tests, test, struct torture_test *);	return test;}static bool wrap_simple_2smb_test(struct torture_context *torture_ctx,									struct torture_tcase *tcase,									struct torture_test *test){	bool (*fn) (struct torture_context *, struct smbcli_state *,				struct smbcli_state *);	bool ret;	struct smbcli_state *cli1, *cli2;	if (!torture_open_connection(&cli1, torture_ctx, 0) || 		!torture_open_connection(&cli2, torture_ctx, 1))		return false;	fn = test->fn;	ret = fn(torture_ctx, cli1, cli2);	talloc_free(cli1);	talloc_free(cli2);	return ret;}_PUBLIC_ struct torture_test *torture_suite_add_2smb_test(									struct torture_suite *suite,									const char *name,									bool (*run) (struct torture_context *,												struct smbcli_state *,												struct smbcli_state *)){	struct torture_test *test; 	struct torture_tcase *tcase;		tcase = torture_suite_add_tcase(suite, name);	test = talloc(tcase, struct torture_test);	test->name = talloc_strdup(test, name);	test->description = NULL;	test->run = wrap_simple_2smb_test;	test->fn = run;	test->dangerous = false;	DLIST_ADD_END(tcase->tests, test, struct torture_test *);	return test;}static bool wrap_simple_1smb_test(struct torture_context *torture_ctx,									struct torture_tcase *tcase,									struct torture_test *test){	bool (*fn) (struct torture_context *, struct smbcli_state *);	bool ret;	struct smbcli_state *cli1;	if (!torture_open_connection(&cli1, torture_ctx, 0))		return false;	fn = test->fn;	ret = fn(torture_ctx, cli1);	talloc_free(cli1);	return ret;}_PUBLIC_ struct torture_test *torture_suite_add_1smb_test(				struct torture_suite *suite,				const char *name,				bool (*run) (struct torture_context *, struct smbcli_state *)){	struct torture_test *test; 	struct torture_tcase *tcase;		tcase = torture_suite_add_tcase(suite, name);	test = talloc(tcase, struct torture_test);	test->name = talloc_strdup(test, name);	test->description = NULL;	test->run = wrap_simple_1smb_test;	test->fn = run;	test->dangerous = false;	DLIST_ADD_END(tcase->tests, test, struct torture_test *);	return test;}NTSTATUS torture_second_tcon(TALLOC_CTX *mem_ctx,			     struct smbcli_session *session,			     const char *sharename,			     struct smbcli_tree **res){	union smb_tcon tcon;	struct smbcli_tree *result;	TALLOC_CTX *tmp_ctx;	NTSTATUS status;	if ((tmp_ctx = talloc_new(mem_ctx)) == NULL) {		return NT_STATUS_NO_MEMORY;	}	result = smbcli_tree_init(session, tmp_ctx, false);	if (result == NULL) {		talloc_free(tmp_ctx);		return NT_STATUS_NO_MEMORY;	}	tcon.generic.level = RAW_TCON_TCONX;	tcon.tconx.in.flags = 0;	/* Ignore share mode security here */	tcon.tconx.in.password = data_blob(NULL, 0);	tcon.tconx.in.path = sharename;	tcon.tconx.in.device = "?????";	status = smb_raw_tcon(result, tmp_ctx, &tcon);	if (!NT_STATUS_IS_OK(status)) {		talloc_free(tmp_ctx);		return status;	}	result->tid = tcon.tconx.out.tid;	*res = talloc_steal(mem_ctx, result);	talloc_free(tmp_ctx);	return NT_STATUS_OK;}

⌨️ 快捷键说明

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