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

📄 torture.c

📁 samba-3.0.22.tar.gz 编译smb服务器的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
			printf("tconx to share %s with type %s "			       "should have failed but succeeded\n",			       myshare, devtype);			ret = False;		} else {			if (NT_STATUS_EQUAL(cli_nt_error(cli),					    expected_error)) {				ret = True;			} else {				printf("Returned unexpected error\n");				ret = False;			}		}	}	return ret;}/* checks for correct tconX support */static BOOL run_tcon_devtype_test(int dummy){	static struct cli_state *cli1 = NULL;	BOOL retry;	int flags = 0;	NTSTATUS status;	BOOL ret = True;	status = cli_full_connection(&cli1, myname,				     host, NULL, port_to_use,				     NULL, NULL,				     username, workgroup,				     password, flags, Undefined, &retry);	if (!NT_STATUS_IS_OK(status)) {		printf("could not open connection\n");		return False;	}	if (!tcon_devtest(cli1, "IPC$", "A:", NULL, NT_STATUS_BAD_DEVICE_TYPE))		ret = False;	if (!tcon_devtest(cli1, "IPC$", "?????", "IPC", NT_STATUS_OK))		ret = False;	if (!tcon_devtest(cli1, "IPC$", "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))		ret = False;	if (!tcon_devtest(cli1, "IPC$", "IPC", "IPC", NT_STATUS_OK))		ret = False;				if (!tcon_devtest(cli1, "IPC$", "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))		ret = False;	if (!tcon_devtest(cli1, share, "A:", "A:", NT_STATUS_OK))		ret = False;	if (!tcon_devtest(cli1, share, "?????", "A:", NT_STATUS_OK))		ret = False;	if (!tcon_devtest(cli1, share, "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))		ret = False;	if (!tcon_devtest(cli1, share, "IPC", NULL, NT_STATUS_BAD_DEVICE_TYPE))		ret = False;				if (!tcon_devtest(cli1, share, "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))		ret = False;	cli_shutdown(cli1);	if (ret)		printf("Passed tcondevtest\n");	return ret;}/*  This test checks that   1) the server supports multiple locking contexts on the one SMB  connection, distinguished by PID.    2) the server correctly fails overlapping locks made by the same PID (this     goes against POSIX behaviour, which is why it is tricky to implement)  3) the server denies unlock requests by an incorrect client PID*/static BOOL run_locktest2(int dummy){	static struct cli_state *cli;	const char *fname = "\\lockt2.lck";	int fnum1, fnum2, fnum3;	BOOL correct = True;	if (!torture_open_connection(&cli)) {		return False;	}	cli_sockopt(cli, sockops);	printf("starting locktest2\n");	cli_unlink(cli, fname);	cli_setpid(cli, 1);	fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);	if (fnum1 == -1) {		printf("open of %s failed (%s)\n", fname, cli_errstr(cli));		return False;	}	fnum2 = cli_open(cli, fname, O_RDWR, DENY_NONE);	if (fnum2 == -1) {		printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli));		return False;	}	cli_setpid(cli, 2);	fnum3 = cli_open(cli, fname, O_RDWR, DENY_NONE);	if (fnum3 == -1) {		printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli));		return False;	}	cli_setpid(cli, 1);	if (!cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {		printf("lock1 failed (%s)\n", cli_errstr(cli));		return False;	}	if (cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {		printf("WRITE lock1 succeeded! This is a locking bug\n");		correct = False;	} else {		if (!check_error(__LINE__, cli, ERRDOS, ERRlock, 				 NT_STATUS_LOCK_NOT_GRANTED)) return False;	}	if (cli_lock(cli, fnum2, 0, 4, 0, WRITE_LOCK)) {		printf("WRITE lock2 succeeded! This is a locking bug\n");		correct = False;	} else {		if (!check_error(__LINE__, cli, ERRDOS, ERRlock, 				 NT_STATUS_LOCK_NOT_GRANTED)) return False;	}	if (cli_lock(cli, fnum2, 0, 4, 0, READ_LOCK)) {		printf("READ lock2 succeeded! This is a locking bug\n");		correct = False;	} else {		if (!check_error(__LINE__, cli, ERRDOS, ERRlock, 				 NT_STATUS_FILE_LOCK_CONFLICT)) return False;	}	if (!cli_lock(cli, fnum1, 100, 4, 0, WRITE_LOCK)) {		printf("lock at 100 failed (%s)\n", cli_errstr(cli));	}	cli_setpid(cli, 2);	if (cli_unlock(cli, fnum1, 100, 4)) {		printf("unlock at 100 succeeded! This is a locking bug\n");		correct = False;	}	if (cli_unlock(cli, fnum1, 0, 4)) {		printf("unlock1 succeeded! This is a locking bug\n");		correct = False;	} else {		if (!check_error(__LINE__, cli, 				 ERRDOS, ERRlock, 				 NT_STATUS_RANGE_NOT_LOCKED)) return False;	}	if (cli_unlock(cli, fnum1, 0, 8)) {		printf("unlock2 succeeded! This is a locking bug\n");		correct = False;	} else {		if (!check_error(__LINE__, cli, 				 ERRDOS, ERRlock, 				 NT_STATUS_RANGE_NOT_LOCKED)) return False;	}	if (cli_lock(cli, fnum3, 0, 4, 0, WRITE_LOCK)) {		printf("lock3 succeeded! This is a locking bug\n");		correct = False;	} else {		if (!check_error(__LINE__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;	}	cli_setpid(cli, 1);	if (!cli_close(cli, fnum1)) {		printf("close1 failed (%s)\n", cli_errstr(cli));		return False;	}	if (!cli_close(cli, fnum2)) {		printf("close2 failed (%s)\n", cli_errstr(cli));		return False;	}	if (!cli_close(cli, fnum3)) {		printf("close3 failed (%s)\n", cli_errstr(cli));		return False;	}	if (!torture_close_connection(cli)) {		correct = False;	}	printf("locktest2 finished\n");	return correct;}/*  This test checks that   1) the server supports the full offset range in lock requests*/static BOOL run_locktest3(int dummy){	static struct cli_state *cli1, *cli2;	const char *fname = "\\lockt3.lck";	int fnum1, fnum2, i;	uint32 offset;	BOOL correct = True;#define NEXT_OFFSET offset += (~(uint32)0) / torture_numops	if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {		return False;	}	cli_sockopt(cli1, sockops);	cli_sockopt(cli2, sockops);	printf("starting locktest3\n");	cli_unlink(cli1, fname);	fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);	if (fnum1 == -1) {		printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));		return False;	}	fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);	if (fnum2 == -1) {		printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli2));		return False;	}	for (offset=i=0;i<torture_numops;i++) {		NEXT_OFFSET;		if (!cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {			printf("lock1 %d failed (%s)\n", 			       i,			       cli_errstr(cli1));			return False;		}		if (!cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {			printf("lock2 %d failed (%s)\n", 			       i,			       cli_errstr(cli1));			return False;		}	}	for (offset=i=0;i<torture_numops;i++) {		NEXT_OFFSET;		if (cli_lock(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {			printf("error: lock1 %d succeeded!\n", i);			return False;		}		if (cli_lock(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {			printf("error: lock2 %d succeeded!\n", i);			return False;		}		if (cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {			printf("error: lock3 %d succeeded!\n", i);			return False;		}		if (cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {			printf("error: lock4 %d succeeded!\n", i);			return False;		}	}	for (offset=i=0;i<torture_numops;i++) {		NEXT_OFFSET;		if (!cli_unlock(cli1, fnum1, offset-1, 1)) {			printf("unlock1 %d failed (%s)\n", 			       i,			       cli_errstr(cli1));			return False;		}		if (!cli_unlock(cli2, fnum2, offset-2, 1)) {			printf("unlock2 %d failed (%s)\n", 			       i,			       cli_errstr(cli1));			return False;		}	}	if (!cli_close(cli1, fnum1)) {		printf("close1 failed (%s)\n", cli_errstr(cli1));		return False;	}	if (!cli_close(cli2, fnum2)) {		printf("close2 failed (%s)\n", cli_errstr(cli2));		return False;	}	if (!cli_unlink(cli1, fname)) {		printf("unlink failed (%s)\n", cli_errstr(cli1));		return False;	}	if (!torture_close_connection(cli1)) {		correct = False;	}		if (!torture_close_connection(cli2)) {		correct = False;	}	printf("finished locktest3\n");	return correct;}#define EXPECTED(ret, v) if ((ret) != (v)) { \        printf("** "); correct = False; \        }/*  looks at overlapping locks*/static BOOL run_locktest4(int dummy){	static struct cli_state *cli1, *cli2;	const char *fname = "\\lockt4.lck";	int fnum1, fnum2, f;	BOOL ret;	char buf[1000];	BOOL correct = True;	if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {		return False;	}	cli_sockopt(cli1, sockops);	cli_sockopt(cli2, sockops);	printf("starting locktest4\n");	cli_unlink(cli1, fname);	fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);	fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);	memset(buf, 0, sizeof(buf));	if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {		printf("Failed to create file\n");		correct = False;		goto fail;	}	ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&	      cli_lock(cli1, fnum1, 2, 4, 0, WRITE_LOCK);	EXPECTED(ret, False);	printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");	    	ret = cli_lock(cli1, fnum1, 10, 4, 0, READ_LOCK) &&	      cli_lock(cli1, fnum1, 12, 4, 0, READ_LOCK);	EXPECTED(ret, True);	printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");	ret = cli_lock(cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&	      cli_lock(cli2, fnum2, 22, 4, 0, WRITE_LOCK);	EXPECTED(ret, False);	printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");	    	ret = cli_lock(cli1, fnum1, 30, 4, 0, READ_LOCK) &&	      cli_lock(cli2, fnum2, 32, 4, 0, READ_LOCK);	EXPECTED(ret, True);	printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");		ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&	      (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 42, 4, 0, WRITE_LOCK));	EXPECTED(ret, False);	printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");	    	ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 50, 4, 0, READ_LOCK)) &&	      (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 52, 4, 0, READ_LOCK));	EXPECTED(ret, True);	printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");	ret = cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK) &&	      cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK);	EXPECTED(ret, True);	printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");	ret = cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&	      cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK);	EXPECTED(ret, False);	printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");	ret = cli_lock(cli1, fnum1, 80, 4, 0, READ_LOCK) &&	      cli_lock(cli1, fnum1, 80, 4, 0, WRITE_LOCK);	EXPECTED(ret, False);	printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");	ret = cli_lock(cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&	      cli_lock(cli1, fnum1, 90, 4, 0, READ_LOCK);	EXPECTED(ret, True);	printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");	ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&	      (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 100, 4, 0, READ_LOCK));	EXPECTED(ret, False);	printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");	ret = cli_lock(cli1, fnum1, 110, 4, 0, READ_LOCK) &&	      cli_lock(cli1, fnum1, 112, 4, 0, READ_LOCK) &&	      cli_unlock(cli1, fnum1, 110, 6);	EXPECTED(ret, False);	printf("the same process %s coalesce read locks\n", ret?"can":"cannot");	ret = cli_lock(cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&	      (cli_read(cli2, fnum2, buf, 120, 4) == 4);	EXPECTED(ret, False);	printf("this server %s strict write locking\n", ret?"doesn't do":"does");	ret = cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK) &&	      (cli_write(cli2, fnum2, 0, buf, 130, 4) == 4);	EXPECTED(ret, False);	printf("this server %s strict read locking\n", ret?"doesn't do":"does");	ret = cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&	      cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&	      cli_unlock(cli1, fnum1, 140, 4) &&	      cli_unlock(cli1, fnum1, 140, 4);	EXPECTED(ret, True);	printf("this server %s do recursive read locking\n", ret?"does":"doesn't");	ret = cli_lock(cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&	      cli_lock(cli1, fnum1, 150, 4, 0, READ_LOCK) &&	      cli_unlock(cli1, fnum1, 150, 4) &&	      (cli_read(cli2, fnum2, buf, 150, 4) == 4) &&	      !(cli_write(cli2, fnum2, 0, buf, 150, 4) == 4) &&	      cli_unlock(cli1, fnum1, 150, 4);	EXPECTED(ret, True);	printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");	ret = cli_lock(cli1, fnum1, 160, 4, 0, READ_LOCK) &&	      cli_unlock(cli1, fnum1, 160, 4) &&	      (cli_write(cli2, fnum2, 0, buf, 160, 4) == 4) &&			      (cli_read(cli2, fnum2, buf, 160, 4) == 4);			EXPECTED(ret, True);	printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");	ret = cli_lock(cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&	      cli_unlock(cli1, fnum1, 170, 4) &&	      (cli_write(cli2, fnum2, 0, buf, 170, 4) == 4) &&			      (cli_read(cli2, fnum2, buf, 170, 4) == 4);			EXPECTED(ret, True);	printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");	ret = cli_lock(cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&	      cli_lock(cli1, fnum1, 190, 4, 0, READ_LOCK) &&	      cli_unlock(cli1, fnum1, 190, 4) &&	      !(cli_write(cli2, fnum2, 0, buf, 190, 4) == 4) &&			      (cli_read(cli2, fnum2, buf, 190, 4) == 4);			EXPECTED(ret, True);	printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");	cli_close(cli1, fnum1);	cli_close(cli2, fnum2);	fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);	f = cli_open(cli1, fname, O_RDWR, DENY_NONE);	ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&	      cli_lock(cli1, f, 0, 1, 0, READ_LOCK) &&	      cli_close(cli1, fnum1) &&	      ((fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE)) != -1) &&	      cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);        cli_close(cli1, f);	cli_close(cli1, fnum1);	EXPECTED(ret, True);	printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't"); fail:	cli_close(cli1, fnum1);	cli_close(cli2, fnum2);	cli_unlink(cli1, fname);	torture_close_connection(cli1);	torture_close_connection(cli2);	printf("finished locktest4\n");	return correct;}/*  looks at lock upgrade/downgrade.*/static BOOL run_locktest5(int dummy){	static struct cli_state *cli1, *cli2;	const char *fname = "\\lockt5.lck";	int fnum1, fnum2, fnum3;	BOOL ret;	char buf[1000];	BOOL correct = True;	if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {		return False;	}	cli_sockopt(cli1, sockops);	cli_sockopt(cli2, sockops);	printf("starting locktest5\n");	cli_unlink(cli1, fname);	fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);	fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);	fnum3 = cli_open(cli1, fname, O_RDWR, DENY_NONE);	memset(buf, 0, sizeof(buf));	if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {		printf("Failed to create file\n");		correct = False;		goto fail;

⌨️ 快捷键说明

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