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

📄 notify.c

📁 samba最新软件
💻 C
📖 第 1 页 / 共 3 页
字号:
	   on file or directory name changes */	notify.nttrans.level = RAW_NOTIFY_NTTRANS;	notify.nttrans.in.buffer_size = 1000;	notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;	notify.nttrans.in.file.fnum = fnum;	notify.nttrans.in.recursive = true;	req = smb_raw_changenotify_send(cli->tree, &notify);	status = smbcli_tdis(cli);	CHECK_STATUS(status, NT_STATUS_OK);	cli->tree = NULL;	status = smb_raw_changenotify_recv(req, tctx, &notify);	CHECK_STATUS(status, NT_STATUS_OK);	CHECK_VAL(notify.nttrans.out.num_changes, 0);done:	torture_close_connection(cli);	return ret;}/*  basic testing of change notifies followed by a exit*/static bool test_notify_exit(struct torture_context *tctx){	bool ret = true;	NTSTATUS status;	union smb_notify notify;	union smb_open io;	int fnum;	struct smbcli_request *req;	struct smbcli_state *cli = NULL;	printf("TESTING CHANGE NOTIFY FOLLOWED BY EXIT\n");	if (!torture_open_connection(&cli, tctx, 0)) {		return false;	}	/*	  get a handle on the directory	*/	io.generic.level = RAW_OPEN_NTCREATEX;	io.ntcreatex.in.root_fid = 0;	io.ntcreatex.in.flags = 0;	io.ntcreatex.in.access_mask = SEC_FILE_ALL;	io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;	io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;	io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;	io.ntcreatex.in.alloc_size = 0;	io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;	io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;	io.ntcreatex.in.security_flags = 0;	io.ntcreatex.in.fname = BASEDIR;	status = smb_raw_open(cli->tree, tctx, &io);	CHECK_STATUS(status, NT_STATUS_OK);	fnum = io.ntcreatex.out.file.fnum;	/* ask for a change notify,	   on file or directory name changes */	notify.nttrans.level = RAW_NOTIFY_NTTRANS;	notify.nttrans.in.buffer_size = 1000;	notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;	notify.nttrans.in.file.fnum = fnum;	notify.nttrans.in.recursive = true;	req = smb_raw_changenotify_send(cli->tree, &notify);	status = smb_raw_exit(cli->session);	CHECK_STATUS(status, NT_STATUS_OK);	status = smb_raw_changenotify_recv(req, tctx, &notify);	CHECK_STATUS(status, NT_STATUS_OK);	CHECK_VAL(notify.nttrans.out.num_changes, 0);done:	torture_close_connection(cli);	return ret;}/*  basic testing of change notifies followed by a ulogoff*/static bool test_notify_ulogoff(struct torture_context *tctx){	bool ret = true;	NTSTATUS status;	union smb_notify notify;	union smb_open io;	int fnum;	struct smbcli_request *req;	struct smbcli_state *cli = NULL;	printf("TESTING CHANGE NOTIFY FOLLOWED BY ULOGOFF\n");	if (!torture_open_connection(&cli, tctx, 0)) {		return false;	}	/*	  get a handle on the directory	*/	io.generic.level = RAW_OPEN_NTCREATEX;	io.ntcreatex.in.root_fid = 0;	io.ntcreatex.in.flags = 0;	io.ntcreatex.in.access_mask = SEC_FILE_ALL;	io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;	io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;	io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;	io.ntcreatex.in.alloc_size = 0;	io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;	io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;	io.ntcreatex.in.security_flags = 0;	io.ntcreatex.in.fname = BASEDIR;	status = smb_raw_open(cli->tree, tctx, &io);	CHECK_STATUS(status, NT_STATUS_OK);	fnum = io.ntcreatex.out.file.fnum;	/* ask for a change notify,	   on file or directory name changes */	notify.nttrans.level = RAW_NOTIFY_NTTRANS;	notify.nttrans.in.buffer_size = 1000;	notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;	notify.nttrans.in.file.fnum = fnum;	notify.nttrans.in.recursive = true;	req = smb_raw_changenotify_send(cli->tree, &notify);	status = smb_raw_ulogoff(cli->session);	CHECK_STATUS(status, NT_STATUS_OK);	status = smb_raw_changenotify_recv(req, tctx, &notify);	CHECK_STATUS(status, NT_STATUS_OK);	CHECK_VAL(notify.nttrans.out.num_changes, 0);done:	torture_close_connection(cli);	return ret;}static void tcp_dis_handler(struct smbcli_transport *t, void *p){	struct smbcli_state *cli = (struct smbcli_state *)p;	smbcli_transport_dead(cli->transport, NT_STATUS_LOCAL_DISCONNECT);	cli->transport = NULL;	cli->tree = NULL;}/*  basic testing of change notifies followed by tcp disconnect*/static bool test_notify_tcp_dis(struct torture_context *tctx){	bool ret = true;	NTSTATUS status;	union smb_notify notify;	union smb_open io;	int fnum;	struct smbcli_request *req;	struct smbcli_state *cli = NULL;	printf("TESTING CHANGE NOTIFY FOLLOWED BY TCP DISCONNECT\n");	if (!torture_open_connection(&cli, tctx, 0)) {		return false;	}	/*	  get a handle on the directory	*/	io.generic.level = RAW_OPEN_NTCREATEX;	io.ntcreatex.in.root_fid = 0;	io.ntcreatex.in.flags = 0;	io.ntcreatex.in.access_mask = SEC_FILE_ALL;	io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;	io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;	io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;	io.ntcreatex.in.alloc_size = 0;	io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;	io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;	io.ntcreatex.in.security_flags = 0;	io.ntcreatex.in.fname = BASEDIR;	status = smb_raw_open(cli->tree, tctx, &io);	CHECK_STATUS(status, NT_STATUS_OK);	fnum = io.ntcreatex.out.file.fnum;	/* ask for a change notify,	   on file or directory name changes */	notify.nttrans.level = RAW_NOTIFY_NTTRANS;	notify.nttrans.in.buffer_size = 1000;	notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;	notify.nttrans.in.file.fnum = fnum;	notify.nttrans.in.recursive = true;	req = smb_raw_changenotify_send(cli->tree, &notify);	smbcli_transport_idle_handler(cli->transport, tcp_dis_handler, 250, cli);	status = smb_raw_changenotify_recv(req, tctx, &notify);	CHECK_STATUS(status, NT_STATUS_LOCAL_DISCONNECT);done:	torture_close_connection(cli);	return ret;}/*    test setting up two change notify requests on one handle*/static bool test_notify_double(struct smbcli_state *cli, TALLOC_CTX *mem_ctx){	bool ret = true;	NTSTATUS status;	union smb_notify notify;	union smb_open io;	int fnum;	struct smbcli_request *req1, *req2;	printf("TESTING CHANGE NOTIFY TWICE ON ONE DIRECTORY\n");			/*	  get a handle on the directory	*/	io.generic.level = RAW_OPEN_NTCREATEX;	io.ntcreatex.in.root_fid = 0;	io.ntcreatex.in.flags = 0;	io.ntcreatex.in.access_mask = SEC_FILE_ALL;	io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;	io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;	io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;	io.ntcreatex.in.alloc_size = 0;	io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;	io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;	io.ntcreatex.in.security_flags = 0;	io.ntcreatex.in.fname = BASEDIR;	status = smb_raw_open(cli->tree, mem_ctx, &io);	CHECK_STATUS(status, NT_STATUS_OK);	fnum = io.ntcreatex.out.file.fnum;	/* ask for a change notify,	   on file or directory name changes */	notify.nttrans.level = RAW_NOTIFY_NTTRANS;	notify.nttrans.in.buffer_size = 1000;	notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;	notify.nttrans.in.file.fnum = fnum;	notify.nttrans.in.recursive = true;	req1 = smb_raw_changenotify_send(cli->tree, &notify);	req2 = smb_raw_changenotify_send(cli->tree, &notify);	smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");	status = smb_raw_changenotify_recv(req1, mem_ctx, &notify);	CHECK_STATUS(status, NT_STATUS_OK);	CHECK_VAL(notify.nttrans.out.num_changes, 1);	CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);	smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name2");	status = smb_raw_changenotify_recv(req2, mem_ctx, &notify);	CHECK_STATUS(status, NT_STATUS_OK);	CHECK_VAL(notify.nttrans.out.num_changes, 1);	CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name2", STR_UNICODE);done:	smb_raw_exit(cli->session);	return ret;}/*    test multiple change notifies at different depths and with/without recursion*/static bool test_notify_tree(struct smbcli_state *cli, TALLOC_CTX *mem_ctx){	bool ret = true;	union smb_notify notify;	union smb_open io;	struct smbcli_request *req;	struct timeval tv;	struct {		const char *path;		bool recursive;		uint32_t filter;		int expected;		int fnum;		int counted;	} dirs[] = {		{BASEDIR "\\abc",               true, FILE_NOTIFY_CHANGE_NAME, 30 },		{BASEDIR "\\zqy",               true, FILE_NOTIFY_CHANGE_NAME, 8 },		{BASEDIR "\\atsy",              true, FILE_NOTIFY_CHANGE_NAME, 4 },		{BASEDIR "\\abc\\foo",          true,  FILE_NOTIFY_CHANGE_NAME, 2 },		{BASEDIR "\\abc\\blah",         true,  FILE_NOTIFY_CHANGE_NAME, 13 },		{BASEDIR "\\abc\\blah",         false, FILE_NOTIFY_CHANGE_NAME, 7 },		{BASEDIR "\\abc\\blah\\a",      true, FILE_NOTIFY_CHANGE_NAME, 2 },		{BASEDIR "\\abc\\blah\\b",      true, FILE_NOTIFY_CHANGE_NAME, 2 },		{BASEDIR "\\abc\\blah\\c",      true, FILE_NOTIFY_CHANGE_NAME, 2 },		{BASEDIR "\\abc\\fooblah",      true, FILE_NOTIFY_CHANGE_NAME, 2 },		{BASEDIR "\\zqy\\xx",           true, FILE_NOTIFY_CHANGE_NAME, 2 },		{BASEDIR "\\zqy\\yyy",          true, FILE_NOTIFY_CHANGE_NAME, 2 },		{BASEDIR "\\zqy\\..",           true, FILE_NOTIFY_CHANGE_NAME, 40 },		{BASEDIR,                       true, FILE_NOTIFY_CHANGE_NAME, 40 },		{BASEDIR,                       false,FILE_NOTIFY_CHANGE_NAME, 6 },		{BASEDIR "\\atsy",              false,FILE_NOTIFY_CHANGE_NAME, 4 },		{BASEDIR "\\abc",               true, FILE_NOTIFY_CHANGE_NAME, 24 },		{BASEDIR "\\abc",               false,FILE_NOTIFY_CHANGE_FILE_NAME, 0 },		{BASEDIR "\\abc",               true, FILE_NOTIFY_CHANGE_FILE_NAME, 0 },		{BASEDIR "\\abc",               true, FILE_NOTIFY_CHANGE_NAME, 24 },	};	int i;	NTSTATUS status;	bool all_done = false;	printf("TESTING CHANGE NOTIFY FOR DIFFERENT DEPTHS\n");	io.generic.level = RAW_OPEN_NTCREATEX;	io.ntcreatex.in.root_fid = 0;	io.ntcreatex.in.flags = 0;	io.ntcreatex.in.access_mask = SEC_FILE_ALL;	io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;	io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;	io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;	io.ntcreatex.in.alloc_size = 0;	io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;	io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;	io.ntcreatex.in.security_flags = 0;	notify.nttrans.level = RAW_NOTIFY_NTTRANS;	notify.nttrans.in.buffer_size = 20000;	/*	  setup the directory tree, and the notify buffer on each directory	*/	for (i=0;i<ARRAY_SIZE(dirs);i++) {		io.ntcreatex.in.fname = dirs[i].path;		status = smb_raw_open(cli->tree, mem_ctx, &io);		CHECK_STATUS(status, NT_STATUS_OK);		dirs[i].fnum = io.ntcreatex.out.file.fnum;		notify.nttrans.in.completion_filter = dirs[i].filter;		notify.nttrans.in.file.fnum = dirs[i].fnum;		notify.nttrans.in.recursive = dirs[i].recursive;		req = smb_raw_changenotify_send(cli->tree, &notify);		smb_raw_ntcancel(req);		status = smb_raw_changenotify_recv(req, mem_ctx, &notify);		CHECK_STATUS(status, NT_STATUS_CANCELLED);	}	/* trigger 2 events in each dir */	for (i=0;i<ARRAY_SIZE(dirs);i++) {		char *path = talloc_asprintf(mem_ctx, "%s\\test.dir", dirs[i].path);		smbcli_mkdir(cli->tree, path);		smbcli_rmdir(cli->tree, path);		talloc_free(path);	}	/* give a bit of time for the events to propogate */	tv = timeval_current();	do {		/* count events that have happened in each dir */		for (i=0;i<ARRAY_SIZE(dirs);i++) {			notify.nttrans.in.file.fnum = dirs[i].fnum;			req = smb_raw_changenotify_send(cli->tree, &notify);			smb_raw_ntcancel(req);			notify.nttrans.out.num_changes = 0;			status = smb_raw_changenotify_recv(req, mem_ctx, &notify);			dirs[i].counted += notify.nttrans.out.num_changes;		}				all_done = true;		for (i=0;i<ARRAY_SIZE(dirs);i++) {			if (dirs[i].counted != dirs[i].expected) {				all_done = false;			}		}	} while (!all_done && timeval_elapsed(&tv) < 20);	printf("took %.4f seconds to propogate all events\n", timeval_elapsed(&tv));	for (i=0;i<ARRAY_SIZE(dirs);i++) {		if (dirs[i].counted != dirs[i].expected) {			printf("ERROR: i=%d expected %d got %d for '%s'\n",			       i, dirs[i].expected, dirs[i].counted, dirs[i].path);			ret = false;		}	}	/*	  run from the back, closing and deleting	*/	for (i=ARRAY_SIZE(dirs)-1;i>=0;i--) {		smbcli_close(cli->tree, dirs[i].fnum);		smbcli_rmdir(cli->tree, dirs[i].path);	}done:	smb_raw_exit(cli->session);	return ret;}/*    basic testing of change notify*/bool torture_raw_notify(struct torture_context *torture, 			struct smbcli_state *cli, 			struct smbcli_state *cli2){	bool ret = true;			if (!torture_setup_dir(cli, BASEDIR)) {		return false;	}	ret &= test_notify_dir(cli, cli2, torture);	ret &= test_notify_mask(cli, torture);	ret &= test_notify_recursive(cli, torture);	ret &= test_notify_mask_change(cli, torture);	ret &= test_notify_file(cli, torture);	ret &= test_notify_tdis(torture);	ret &= test_notify_exit(torture);	ret &= test_notify_ulogoff(torture);	ret &= test_notify_tcp_dis(torture);	ret &= test_notify_double(cli, torture);	ret &= test_notify_tree(cli, torture);	smb_raw_exit(cli->session);	smbcli_deltree(cli->tree, BASEDIR);	return ret;}

⌨️ 快捷键说明

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