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

📄 notify.c

📁 samba最新软件
💻 C
📖 第 1 页 / 共 3 页
字号:
	printf("TESTING CHANGE NOTIFY WITH MASK CHANGE\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. Setup both with and without recursion */	notify.nttrans.level = RAW_NOTIFY_NTTRANS;	notify.nttrans.in.buffer_size = 1000;	notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_ATTRIBUTES;	notify.nttrans.in.file.fnum = fnum;	notify.nttrans.in.recursive = true;	req1 = smb_raw_changenotify_send(cli->tree, &notify);	notify.nttrans.in.recursive = false;	req2 = smb_raw_changenotify_send(cli->tree, &notify);	/* cancel initial requests so the buffer is setup */	smb_raw_ntcancel(req1);	status = smb_raw_changenotify_recv(req1, mem_ctx, &notify);	CHECK_STATUS(status, NT_STATUS_CANCELLED);	smb_raw_ntcancel(req2);	status = smb_raw_changenotify_recv(req2, mem_ctx, &notify);	CHECK_STATUS(status, NT_STATUS_CANCELLED);	notify.nttrans.in.recursive = true;	req1 = smb_raw_changenotify_send(cli->tree, &notify);	/* Set to hidden then back again. */	smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));	smbcli_setatr(cli->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_HIDDEN, 0);	smbcli_unlink(cli->tree, BASEDIR "\\tname1");	status = smb_raw_changenotify_recv(req1, mem_ctx, &notify);	CHECK_STATUS(status, NT_STATUS_OK);	CHECK_VAL(notify.nttrans.out.num_changes, 1);	CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_MODIFIED);	CHECK_WSTR(notify.nttrans.out.changes[0].name, "tname1", STR_UNICODE);	/* Now try and change the mask to include other events.	 * This should not work - once the mask is set on a directory	 * fnum it seems to be fixed until the fnum is closed. */	notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_CREATION;	notify.nttrans.in.recursive = true;	req1 = smb_raw_changenotify_send(cli->tree, &notify);	notify.nttrans.in.recursive = false;	req2 = smb_raw_changenotify_send(cli->tree, &notify);	smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");	smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name\\subname1");	smbcli_close(cli->tree, 		     smbcli_open(cli->tree, BASEDIR "\\subdir-name\\subname2", O_CREAT, 0));	smbcli_rename(cli->tree, BASEDIR "\\subdir-name\\subname1", BASEDIR "\\subdir-name\\subname1-r");	smbcli_rename(cli->tree, BASEDIR "\\subdir-name\\subname2", BASEDIR "\\subname2-r");	smbcli_rename(cli->tree, BASEDIR "\\subname2-r", BASEDIR "\\subname3-r");	smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name\\subname1-r");	smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");	smbcli_unlink(cli->tree, BASEDIR "\\subname3-r");	status = smb_raw_changenotify_recv(req1, mem_ctx, &notify);	CHECK_STATUS(status, NT_STATUS_OK);	CHECK_VAL(notify.nttrans.out.num_changes, 1);	CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_MODIFIED);	CHECK_WSTR(notify.nttrans.out.changes[0].name, "subname2-r", STR_UNICODE);	status = smb_raw_changenotify_recv(req2, mem_ctx, &notify);	CHECK_STATUS(status, NT_STATUS_OK);	CHECK_VAL(notify.nttrans.out.num_changes, 1);	CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_MODIFIED);	CHECK_WSTR(notify.nttrans.out.changes[0].name, "subname3-r", STR_UNICODE);	if (!ret) {		goto done;	}done:	smb_raw_exit(cli->session);	return ret;}/*    testing of mask bits for change notify*/static bool test_notify_mask(struct smbcli_state *cli, struct torture_context *tctx){	bool ret = true;	NTSTATUS status;	union smb_notify notify;	union smb_open io;	int fnum, fnum2;	uint32_t mask;	int i;	char c = 1;	struct timeval tv;	NTTIME t;	printf("TESTING CHANGE NOTIFY COMPLETION FILTERS\n");	tv = timeval_current_ofs(1000, 0);	t = timeval_to_nttime(&tv);			/*	  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;	notify.nttrans.level = RAW_NOTIFY_NTTRANS;	notify.nttrans.in.buffer_size = 1000;	notify.nttrans.in.recursive = true;#define NOTIFY_MASK_TEST(setup, op, cleanup, Action, expected, nchanges) \	do { for (mask=i=0;i<32;i++) { \		struct smbcli_request *req; \		status = smb_raw_open(cli->tree, tctx, &io); \		CHECK_STATUS(status, NT_STATUS_OK); \		fnum = io.ntcreatex.out.file.fnum; \		setup \		notify.nttrans.in.file.fnum = fnum;	\		notify.nttrans.in.completion_filter = (1<<i); \		req = smb_raw_changenotify_send(cli->tree, &notify); \		op \		msleep(200); smb_raw_ntcancel(req); \		status = smb_raw_changenotify_recv(req, tctx, &notify); \		cleanup \		smbcli_close(cli->tree, fnum); \		if (NT_STATUS_EQUAL(status, NT_STATUS_CANCELLED)) continue; \		CHECK_STATUS(status, NT_STATUS_OK); \		/* special case to cope with file rename behaviour */ \		if (nchanges == 2 && notify.nttrans.out.num_changes == 1 && \		    notify.nttrans.out.changes[0].action == NOTIFY_ACTION_MODIFIED && \		    ((expected) & FILE_NOTIFY_CHANGE_ATTRIBUTES) && \		    Action == NOTIFY_ACTION_OLD_NAME) { \			printf("(rename file special handling OK)\n"); \		} else if (nchanges != notify.nttrans.out.num_changes) { \			printf("ERROR: nchanges=%d expected=%d action=%d filter=0x%08x\n", \			       notify.nttrans.out.num_changes, \			       nchanges, \			       notify.nttrans.out.changes[0].action, \			       notify.nttrans.in.completion_filter); \			ret = false; \		} else if (notify.nttrans.out.changes[0].action != Action) { \			printf("ERROR: nchanges=%d action=%d expectedAction=%d filter=0x%08x\n", \			       notify.nttrans.out.num_changes, \			       notify.nttrans.out.changes[0].action, \			       Action, \			       notify.nttrans.in.completion_filter); \			ret = false; \		} else if (strcmp(notify.nttrans.out.changes[0].name.s, "tname1") != 0) { \			printf("ERROR: nchanges=%d action=%d filter=0x%08x name=%s\n", \			       notify.nttrans.out.num_changes, \			       notify.nttrans.out.changes[0].action, \			       notify.nttrans.in.completion_filter, \			       notify.nttrans.out.changes[0].name.s);	\			ret = false; \		} \		mask |= (1<<i); \	} \	if ((expected) != mask) { \		if (((expected) & ~mask) != 0) { \			printf("ERROR: trigger on too few bits. mask=0x%08x expected=0x%08x\n", \			       mask, expected); \			ret = false; \		} else { \			printf("WARNING: trigger on too many bits. mask=0x%08x expected=0x%08x\n", \			       mask, expected); \		} \	} \	} while (0)	printf("testing mkdir\n");	NOTIFY_MASK_TEST(;,			 smbcli_mkdir(cli->tree, BASEDIR "\\tname1");,			 smbcli_rmdir(cli->tree, BASEDIR "\\tname1");,			 NOTIFY_ACTION_ADDED,			 FILE_NOTIFY_CHANGE_DIR_NAME, 1);	printf("testing create file\n");	NOTIFY_MASK_TEST(;,			 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,			 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,			 NOTIFY_ACTION_ADDED,			 FILE_NOTIFY_CHANGE_FILE_NAME, 1);	printf("testing unlink\n");	NOTIFY_MASK_TEST(			 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,			 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,			 ;,			 NOTIFY_ACTION_REMOVED,			 FILE_NOTIFY_CHANGE_FILE_NAME, 1);	printf("testing rmdir\n");	NOTIFY_MASK_TEST(			 smbcli_mkdir(cli->tree, BASEDIR "\\tname1");,			 smbcli_rmdir(cli->tree, BASEDIR "\\tname1");,			 ;,			 NOTIFY_ACTION_REMOVED,			 FILE_NOTIFY_CHANGE_DIR_NAME, 1);	printf("testing rename file\n");	NOTIFY_MASK_TEST(			 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,			 smbcli_rename(cli->tree, BASEDIR "\\tname1", BASEDIR "\\tname2");,			 smbcli_unlink(cli->tree, BASEDIR "\\tname2");,			 NOTIFY_ACTION_OLD_NAME,			 FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_ATTRIBUTES|FILE_NOTIFY_CHANGE_CREATION, 2);	printf("testing rename dir\n");	NOTIFY_MASK_TEST(		smbcli_mkdir(cli->tree, BASEDIR "\\tname1");,		smbcli_rename(cli->tree, BASEDIR "\\tname1", BASEDIR "\\tname2");,		smbcli_rmdir(cli->tree, BASEDIR "\\tname2");,		NOTIFY_ACTION_OLD_NAME,		FILE_NOTIFY_CHANGE_DIR_NAME, 2);	printf("testing set path attribute\n");	NOTIFY_MASK_TEST(		smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,		smbcli_setatr(cli->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_HIDDEN, 0);,		smbcli_unlink(cli->tree, BASEDIR "\\tname1");,		NOTIFY_ACTION_MODIFIED,		FILE_NOTIFY_CHANGE_ATTRIBUTES, 1);	printf("testing set path write time\n");	NOTIFY_MASK_TEST(		smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,		smbcli_setatr(cli->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_NORMAL, 1000);,		smbcli_unlink(cli->tree, BASEDIR "\\tname1");,		NOTIFY_ACTION_MODIFIED,		FILE_NOTIFY_CHANGE_LAST_WRITE, 1);	printf("testing set file attribute\n");	NOTIFY_MASK_TEST(		fnum2 = create_complex_file(cli, tctx, BASEDIR "\\tname1");,		smbcli_fsetatr(cli->tree, fnum2, FILE_ATTRIBUTE_HIDDEN, 0, 0, 0, 0);,		(smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,		NOTIFY_ACTION_MODIFIED,		FILE_NOTIFY_CHANGE_ATTRIBUTES, 1);	if (torture_setting_bool(tctx, "samba3", false)) {		printf("Samba3 does not yet support create times "		       "everywhere\n");	}	else {		printf("testing set file create time\n");		NOTIFY_MASK_TEST(			fnum2 = create_complex_file(cli, tctx,						    BASEDIR "\\tname1");,			smbcli_fsetatr(cli->tree, fnum2, 0, t, 0, 0, 0);,			(smbcli_close(cli->tree, fnum2),			 smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,			NOTIFY_ACTION_MODIFIED,			FILE_NOTIFY_CHANGE_CREATION, 1);	}	printf("testing set file access time\n");	NOTIFY_MASK_TEST(		fnum2 = create_complex_file(cli, tctx, BASEDIR "\\tname1");,		smbcli_fsetatr(cli->tree, fnum2, 0, 0, t, 0, 0);,		(smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,		NOTIFY_ACTION_MODIFIED,		FILE_NOTIFY_CHANGE_LAST_ACCESS, 1);	printf("testing set file write time\n");	NOTIFY_MASK_TEST(		fnum2 = create_complex_file(cli, tctx, BASEDIR "\\tname1");,		smbcli_fsetatr(cli->tree, fnum2, 0, 0, 0, t, 0);,		(smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,		NOTIFY_ACTION_MODIFIED,		FILE_NOTIFY_CHANGE_LAST_WRITE, 1);	printf("testing set file change time\n");	NOTIFY_MASK_TEST(		fnum2 = create_complex_file(cli, tctx, BASEDIR "\\tname1");,		smbcli_fsetatr(cli->tree, fnum2, 0, 0, 0, 0, t);,		(smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,		NOTIFY_ACTION_MODIFIED,		0, 1);	printf("testing write\n");	NOTIFY_MASK_TEST(		fnum2 = create_complex_file(cli, tctx, BASEDIR "\\tname1");,		smbcli_write(cli->tree, fnum2, 1, &c, 10000, 1);,		(smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,		NOTIFY_ACTION_MODIFIED,		0, 1);	printf("testing truncate\n");	NOTIFY_MASK_TEST(		fnum2 = create_complex_file(cli, tctx, BASEDIR "\\tname1");,		smbcli_ftruncate(cli->tree, fnum2, 10000);,		(smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,		NOTIFY_ACTION_MODIFIED,		FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_ATTRIBUTES, 1);done:	smb_raw_exit(cli->session);	return ret;}/*  basic testing of change notify on files*/static bool test_notify_file(struct smbcli_state *cli, TALLOC_CTX *mem_ctx){	NTSTATUS status;	bool ret = true;	union smb_open io;	union smb_close cl;	union smb_notify notify;	struct smbcli_request *req;	int fnum;	const char *fname = BASEDIR "\\file.txt";	printf("TESTING CHANGE NOTIFY ON FILES\n");	io.generic.level = RAW_OPEN_NTCREATEX;	io.ntcreatex.in.root_fid = 0;	io.ntcreatex.in.flags = 0;	io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;	io.ntcreatex.in.create_options = 0;	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_CREATE;	io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;	io.ntcreatex.in.security_flags = 0;	io.ntcreatex.in.fname = fname;	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.file.fnum = fnum;	notify.nttrans.in.buffer_size = 1000;	notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_STREAM_NAME;	notify.nttrans.in.recursive = false;	printf("testing if notifies on file handles are invalid (should be)\n");	req = smb_raw_changenotify_send(cli->tree, &notify);	status = smb_raw_changenotify_recv(req, mem_ctx, &notify);	CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);	cl.close.level = RAW_CLOSE_CLOSE;	cl.close.in.file.fnum = fnum;	cl.close.in.write_time = 0;	status = smb_raw_close(cli->tree, &cl);	CHECK_STATUS(status, NT_STATUS_OK);	status = smbcli_unlink(cli->tree, fname);	CHECK_STATUS(status, NT_STATUS_OK);done:	smb_raw_exit(cli->session);	return ret;}/*  basic testing of change notifies followed by a tdis*/static bool test_notify_tdis(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 TDIS\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,

⌨️ 快捷键说明

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