示例#1
0
文件: tfs.c 项目: Nils-TUD/Escape
static void test_perms(void) {
	size_t i;
	struct stat info;
	struct {
		const char *dir;
		const char *file;
	} paths[] = {
		{"/newfile","/newfile/test"},
		{"/sys/newfile","/sys/newfile/test"}
	};
	test_caseStart("Testing permissions");

	for(i = 0; i < ARRAY_SIZE(paths); i++) {
		/* create new file */
		fs_createFile(paths[i].dir,"foobar");
		test_assertInt(chmod(paths[i].dir,0600),0);
		test_assertInt(chown(paths[i].dir,1,1),0);

		/* I'm the owner */
		RUN_IN_CHILD(
			test_assertInt(setgid(1),0);
			test_assertInt(setuid(1),0);

			test_assertCan(paths[i].dir,O_READ);
			test_assertCan(paths[i].dir,O_WRITE);
		);

		/* I'm NOT the owner */
		RUN_IN_CHILD(
			test_assertInt(setgid(1),0);
			test_assertInt(setuid(2),0);

			test_assertCanNot(paths[i].dir,O_READ,-EACCES);
			test_assertCanNot(paths[i].dir,O_WRITE,-EACCES);
		);
示例#2
0
文件: tfs.c 项目: jarn0x/Escape
static void test_rename(void) {
	test_caseStart("Testing rename()");

	fs_createFile("/newfile","test!");
	test_assertCan("/newfile",O_READ);
	test_assertInt(rename("/newfile","/newerfile"),0);
	test_assertCanNot("/newfile",O_READ,-ENOENT);
	test_assertInt(unlink("/newerfile"),0);
	test_assertCanNot("/newerfile",O_READ,-ENOENT);

	test_caseSucceeded();
}
示例#3
0
文件: tfs.c 项目: jarn0x/Escape
static void test_perms(void) {
	size_t i;
	struct stat info;
	struct {
		const char *dir;
		const char *file;
	} paths[] = {
		{"/newfile","/newfile/test"},
		{"/sys/newfile","/sys/newfile/test"}
	};
	test_caseStart("Testing permissions");

	for(i = 0; i < ARRAY_SIZE(paths); i++) {
		/* create new file */
		fs_createFile(paths[i].dir,"foobar");
		test_assertInt(chmod(paths[i].dir,0600),0);
		test_assertInt(chown(paths[i].dir,1,1),0);

		/* I'm the owner */
		test_assertInt(setegid(1),0);
		test_assertInt(seteuid(1),0);

		test_assertCan(paths[i].dir,O_READ);
		test_assertCan(paths[i].dir,O_WRITE);

		/* I'm NOT the owner */
		test_assertInt(seteuid(0),0);
		test_assertInt(seteuid(2),0);

		test_assertCanNot(paths[i].dir,O_READ,-EACCES);
		test_assertCanNot(paths[i].dir,O_WRITE,-EACCES);

		/* give group read-perm */
		test_assertInt(seteuid(0),0);
		test_assertInt(chmod(paths[i].dir,0640),0);
		test_assertInt(seteuid(2),0);

		test_assertCan(paths[i].dir,O_READ);
		test_assertCanNot(paths[i].dir,O_WRITE,-EACCES);

		/* neither owner nor group */
		test_assertInt(seteuid(0),0);
		test_assertInt(setegid(0),0);
		test_assertInt(setegid(2),0);
		test_assertInt(seteuid(2),0);

		test_assertCanNot(paths[i].dir,O_READ,-EACCES);
		test_assertCanNot(paths[i].dir,O_WRITE,-EACCES);

		/* give others read+write perm */
		test_assertInt(seteuid(0),0);
		test_assertInt(chmod(paths[i].dir,0646),0);
		test_assertInt(seteuid(2),0);

		test_assertCan(paths[i].dir,O_READ);
		test_assertCan(paths[i].dir,O_WRITE);

		/* delete it */
		test_assertInt(seteuid(0),0);
		test_assertInt(unlink(paths[i].dir),0);


		/* create new folder */
		test_assertInt(mkdir(paths[i].dir,DIR_DEF_MODE),0);
		test_assertInt(chmod(paths[i].dir,0700),0);
		test_assertInt(chown(paths[i].dir,1,1),0);

		/* I'm the owner */
		test_assertInt(setegid(1),0);
		test_assertInt(seteuid(1),0);

		test_assertCan(paths[i].dir,O_READ);
		test_assertCan(paths[i].dir,O_WRITE);
		fs_createFile(paths[i].file,"foo");
		test_assertInt(stat(paths[i].file,&info),0);

		/* I'm NOT the owner */
		test_assertInt(seteuid(0),0);
		test_assertInt(seteuid(2),0);

		test_assertCanNot(paths[i].dir,O_READ,-EACCES);
		test_assertCanNot(paths[i].dir,O_WRITE,-EACCES);
		test_assertInt(stat(paths[i].file,&info),-EACCES);

		/* give group read-perm */
		test_assertInt(seteuid(0),0);
		test_assertInt(chmod(paths[i].dir,0740),0);
		test_assertInt(seteuid(2),0);

		test_assertCan(paths[i].dir,O_READ);
		test_assertCanNot(paths[i].dir,O_WRITE,-EACCES);
		test_assertInt(stat(paths[i].file,&info),-EACCES);

		/* neither owner nor group */
		test_assertInt(seteuid(0),0);
		test_assertInt(setegid(0),0);
		test_assertInt(setegid(2),0);
		test_assertInt(seteuid(2),0);

		test_assertCanNot(paths[i].dir,O_READ,-EACCES);
		test_assertCanNot(paths[i].dir,O_WRITE,-EACCES);
		test_assertInt(stat(paths[i].file,&info),-EACCES);

		/* give others read+write perm */
		test_assertInt(seteuid(0),0);
		test_assertInt(chmod(paths[i].dir,0747),0);
		test_assertInt(seteuid(2),0);

		test_assertCan(paths[i].dir,O_READ);
		test_assertCan(paths[i].dir,O_WRITE);
		test_assertInt(stat(paths[i].file,&info),0);

		/* delete it */
		test_assertInt(seteuid(0),0);
		test_assertInt(unlink(paths[i].file),0);
		test_assertInt(rmdir(paths[i].dir),0);
	}

	test_caseSucceeded();
}