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

📄 base.c

📁 samba最新软件
💻 C
📖 第 1 页 / 共 4 页
字号:
		torture_comment(tctx, "server fails write with wrong TID : %s\n", smbcli_errstr(cli->tree));	}	/* try a write with an invalid tid */	cli->tree->tid = cnum3;	if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {		torture_comment(tctx, "* server allows write with invalid TID\n");		ret = false;	} else {		torture_comment(tctx, "server fails write with invalid TID : %s\n", smbcli_errstr(cli->tree));	}	/* try a write with an invalid vuid */	cli->session->vuid = vuid2;	cli->tree->tid = cnum1;	if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {		torture_comment(tctx, "* server allows write with invalid VUID\n");		ret = false;	} else {		torture_comment(tctx, "server fails write with invalid VUID : %s\n", smbcli_errstr(cli->tree));	}	cli->session->vuid = vuid1;	cli->tree->tid = cnum1;	if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum1))) {		torture_comment(tctx, "close failed (%s)\n", smbcli_errstr(cli->tree));		return false;	}	cli->tree->tid = cnum2;	if (NT_STATUS_IS_ERR(smbcli_tdis(cli))) {		torture_comment(tctx, "secondary tdis failed (%s)\n", smbcli_errstr(cli->tree));		return false;	}	cli->tree = tree1;  /* restore initial tree */	cli->tree->tid = cnum1;	smbcli_unlink(tree1, fname);	return ret;}/** checks for correct tconX support */static bool run_tcon_devtype_test(struct torture_context *tctx, 								  struct smbcli_state *cli1){	const char *share = torture_setting_string(tctx, "share", NULL);	if (!tcon_devtest(tctx, cli1, "IPC$", "A:", NT_STATUS_BAD_DEVICE_TYPE))		return false;	if (!tcon_devtest(tctx, cli1, "IPC$", "?????", NT_STATUS_OK))		return false;	if (!tcon_devtest(tctx, cli1, "IPC$", "LPT:", NT_STATUS_BAD_DEVICE_TYPE))		return false;	if (!tcon_devtest(tctx, cli1, "IPC$", "IPC", NT_STATUS_OK))		return false;				if (!tcon_devtest(tctx, cli1, "IPC$", "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))		return false;	if (!tcon_devtest(tctx, cli1, share, "A:", NT_STATUS_OK))		return false;	if (!tcon_devtest(tctx, cli1, share, "?????", NT_STATUS_OK))		return false;	if (!tcon_devtest(tctx, cli1, share, "LPT:", NT_STATUS_BAD_DEVICE_TYPE))		return false;	if (!tcon_devtest(tctx, cli1, share, "IPC", NT_STATUS_BAD_DEVICE_TYPE))		return false;				if (!tcon_devtest(tctx, cli1, share, "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))		return false;	return true;}static bool rw_torture2(struct torture_context *tctx,						struct smbcli_state *c1, struct smbcli_state *c2){	const char *lockfname = "\\torture2.lck";	int fnum1;	int fnum2;	int i;	uint8_t buf[131072];	uint8_t buf_rd[131072];	bool correct = true;	ssize_t bytes_read, bytes_written;	torture_assert(tctx, smbcli_deltree(c1->tree, lockfname) != -1,				   talloc_asprintf(tctx, 		"unlink failed (%s)", smbcli_errstr(c1->tree)));	fnum1 = smbcli_open(c1->tree, lockfname, O_RDWR | O_CREAT | O_EXCL, 			 DENY_NONE);	torture_assert(tctx, fnum1 != -1, 				   talloc_asprintf(tctx, 		"first open read/write of %s failed (%s)",				lockfname, smbcli_errstr(c1->tree)));	fnum2 = smbcli_open(c2->tree, lockfname, O_RDONLY, 			 DENY_NONE);	torture_assert(tctx, fnum2 != -1, 				   talloc_asprintf(tctx, 		"second open read-only of %s failed (%s)",				lockfname, smbcli_errstr(c2->tree)));	torture_comment(tctx, "Checking data integrity over %d ops\n", 					torture_numops);	for (i=0;i<torture_numops;i++)	{		size_t buf_size = ((uint_t)random()%(sizeof(buf)-1))+ 1;		if (i % 10 == 0) {			if (torture_setting_bool(tctx, "progress", true)) {				torture_comment(tctx, "%d\r", i); fflush(stdout);			}		}		generate_random_buffer(buf, buf_size);		if ((bytes_written = smbcli_write(c1->tree, fnum1, 0, buf, 0, buf_size)) != buf_size) {			torture_comment(tctx, "write failed (%s)\n", smbcli_errstr(c1->tree));			torture_comment(tctx, "wrote %d, expected %d\n", (int)bytes_written, (int)buf_size); 			correct = false;			break;		}		if ((bytes_read = smbcli_read(c2->tree, fnum2, buf_rd, 0, buf_size)) != buf_size) {			torture_comment(tctx, "read failed (%s)\n", smbcli_errstr(c2->tree));			torture_comment(tctx, "read %d, expected %d\n", (int)bytes_read, (int)buf_size); 			correct = false;			break;		}		torture_assert_mem_equal(tctx, buf_rd, buf, buf_size, 			"read/write compare failed\n");	}	torture_assert_ntstatus_ok(tctx, smbcli_close(c2->tree, fnum2), 		talloc_asprintf(tctx, "close failed (%s)", smbcli_errstr(c2->tree)));	torture_assert_ntstatus_ok(tctx, smbcli_close(c1->tree, fnum1),		talloc_asprintf(tctx, "close failed (%s)", smbcli_errstr(c1->tree)));	torture_assert_ntstatus_ok(tctx, smbcli_unlink(c1->tree, lockfname),		talloc_asprintf(tctx, "unlink failed (%s)", smbcli_errstr(c1->tree)));	torture_comment(tctx, "\n");	return correct;}static bool run_readwritetest(struct torture_context *tctx,							  struct smbcli_state *cli1,							  struct smbcli_state *cli2){	torture_comment(tctx, "Running readwritetest v1\n");	if (!rw_torture2(tctx, cli1, cli2)) 		return false;	torture_comment(tctx, "Running readwritetest v2\n");	if (!rw_torture2(tctx, cli1, cli1))		return false;	return true;}/*test the timing of deferred open requests*/static bool run_deferopen(struct torture_context *tctx, struct smbcli_state *cli, int dummy){	const char *fname = "\\defer_open_test.dat";	int retries=4;	int i = 0;	bool correct = true;	int nsec;	int msec;	double sec;	nsec = torture_setting_int(tctx, "sharedelay", 1000000);	msec = nsec / 1000;	sec = ((double)nsec) / ((double) 1000000);	if (retries <= 0) {		torture_comment(tctx, "failed to connect\n");		return false;	}	torture_comment(tctx, "Testing deferred open requests.\n");	while (i < 4) {		int fnum = -1;		do {			struct timeval tv;			tv = timeval_current();			fnum = smbcli_nt_create_full(cli->tree, fname, 0, 						     SEC_RIGHTS_FILE_ALL,						     FILE_ATTRIBUTE_NORMAL, 						     NTCREATEX_SHARE_ACCESS_NONE,						     NTCREATEX_DISP_OPEN_IF, 0, 0);			if (fnum != -1) {				break;			}			if (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)) {				double e = timeval_elapsed(&tv);				if (e < (0.5 * sec) || e > ((1.5 * sec) + 1)) {					torture_comment(tctx,"Timing incorrect %.2f violation 1 sec == %.2f\n",						e, sec);					return false;				}			}		} while (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION));		if (fnum == -1) {			torture_comment(tctx,"Failed to open %s, error=%s\n", fname, smbcli_errstr(cli->tree));			return false;		}		torture_comment(tctx, "pid %u open %d\n", (unsigned)getpid(), i);		msleep(10 * msec);		i++;		if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) {			torture_comment(tctx,"Failed to close %s, error=%s\n", fname, smbcli_errstr(cli->tree));			return false;		}		msleep(2 * msec);	}	if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {		/* All until the last unlink will fail with sharing violation. */		if (!NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)) {			torture_comment(tctx, "unlink of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));			correct = false;		}	}	torture_comment(tctx, "deferred test finished\n");	return correct;}/**  Try with a wrong vuid and check error message. */static bool run_vuidtest(struct torture_context *tctx, 						 struct smbcli_state *cli){	const char *fname = "\\vuid.tst";	int fnum;	size_t size;	time_t c_time, a_time, m_time;	uint16_t orig_vuid;	NTSTATUS result;	smbcli_unlink(cli->tree, fname);	fnum = smbcli_open(cli->tree, fname, 			O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);	orig_vuid = cli->session->vuid;	cli->session->vuid += 1234;	torture_comment(tctx, "Testing qfileinfo with wrong vuid\n");		if (NT_STATUS_IS_OK(result = smbcli_qfileinfo(cli->tree, fnum, NULL,						   &size, &c_time, &a_time,						   &m_time, NULL, NULL))) {		torture_fail(tctx, "qfileinfo passed with wrong vuid");	}	if (!NT_STATUS_EQUAL(cli->transport->error.e.nt_status, 			     NT_STATUS_DOS(ERRSRV, ERRbaduid)) &&	    !NT_STATUS_EQUAL(cli->transport->error.e.nt_status, 			     NT_STATUS_INVALID_HANDLE)) {		torture_fail(tctx, talloc_asprintf(tctx, 				"qfileinfo should have returned DOS error "		       "ERRSRV:ERRbaduid\n  but returned %s",		       smbcli_errstr(cli->tree)));	}	cli->session->vuid -= 1234;	torture_assert_ntstatus_ok(tctx, smbcli_close(cli->tree, fnum),		talloc_asprintf(tctx, "close failed (%s)", smbcli_errstr(cli->tree)));	smbcli_unlink(cli->tree, fname);	return true;}/*  Test open mode returns on read-only files. */ static bool run_opentest(struct torture_context *tctx, struct smbcli_state *cli1, 						  struct smbcli_state *cli2){	const char *fname = "\\readonly.file";	char *control_char_fname;	int fnum1, fnum2;	uint8_t buf[20];	size_t fsize;	bool correct = true;	char *tmp_path;	int failures = 0;	int i;	asprintf(&control_char_fname, "\\readonly.afile");	for (i = 1; i <= 0x1f; i++) {		control_char_fname[10] = i;		fnum1 = smbcli_nt_create_full(cli1->tree, control_char_fname, 0, SEC_FILE_WRITE_DATA, FILE_ATTRIBUTE_NORMAL,				   NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);		        	if (!check_error(__location__, cli1, ERRDOS, ERRinvalidname, 				NT_STATUS_OBJECT_NAME_INVALID)) {			torture_comment(tctx, "Error code should be NT_STATUS_OBJECT_NAME_INVALID, was %s for file with %d char\n",					smbcli_errstr(cli1->tree), i);			failures++;		}		if (fnum1 != -1) {			smbcli_close(cli1->tree, fnum1);		}		smbcli_setatr(cli1->tree, control_char_fname, 0, 0);		smbcli_unlink(cli1->tree, control_char_fname);	}	free(control_char_fname);	if (!failures)		torture_comment(tctx, "Create file with control char names passed.\n");	smbcli_setatr(cli1->tree, fname, 0, 0);	smbcli_unlink(cli1->tree, fname);		fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);	if (fnum1 == -1) {		torture_comment(tctx, "open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));		return false;	}	if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {		torture_comment(tctx, "close2 failed (%s)\n", smbcli_errstr(cli1->tree));		return false;	}		if (NT_STATUS_IS_ERR(smbcli_setatr(cli1->tree, fname, FILE_ATTRIBUTE_READONLY, 0))) {		torture_comment(tctx, "smbcli_setatr failed (%s)\n", smbcli_errstr(cli1->tree));		CHECK_MAX_FAILURES(error_test1);		return false;	}		fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_WRITE);	if (fnum1 == -1) {		torture_comment(tctx, "open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));		CHECK_MAX_FAILURES(error_test1);		return false;	}		/* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */	fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_ALL);	        if (check_error(__location__, cli1, ERRDOS, ERRnoaccess, 			NT_STATUS_ACCESS_DENIED)) {		torture_comment(tctx, "correct error code ERRDOS/ERRnoaccess returned\n");	}		torture_comment(tctx, "finished open test 1\n");error_test1:	smbcli_close(cli1->tree, fnum1);		/* Now try not readonly and ensure ERRbadshare is returned. */		smbcli_setatr(cli1->tree, fname, 0, 0);		fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_WRITE);	if (fnum1 == -1) {		torture_comment(tctx, "open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));		return false;	}		/* This will fail - but the error should be ERRshare. */	fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_ALL);		if (check_error(__location__, cli1, ERRDOS, ERRbadshare, 			NT_STATUS_SHARING_VIOLATION)) {		torture_comment(tctx, "correct error code ERRDOS/ERRbadshare returned\n");	}		if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {		torture_comment(tctx, "close2 failed (%s)\n", smbcli_errstr(cli1->tree));		return false;	}		smbcli_unlink(cli1->tree, fname);		torture_comment(tctx, "finished open test 2\n");		/* Test truncate open disposition on file opened for read. */		fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);	if (fnum1 == -1) {		torture_comment(tctx, "(3) open (1) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));		return false;	}		/* write 20 bytes. */		memset(buf, '\0', 20);	if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, 20) != 20) {		torture_comment(tctx, "write failed (%s)\n", smbcli_errstr(cli1->tree));		correct = false;	}	if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {		torture_comment(tctx, "(3) close1 failed (%s)\n", smbcli_errstr(cli1->tree));		return false;	}		/* Ensure size == 20. */	if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {		torture_comment(tctx, "(3) getatr failed (%s)\n", smbcli_errstr(cli1->tree));		CHECK_MAX_FAILURES(error_test3);		return false;	}		if (fsize != 20) {		torture_comment(tctx, "(3) file size != 20\n");		CHECK_MAX_FAILURES(error_test3);

⌨️ 快捷键说明

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