Beispiel #1
0
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);
		);
Beispiel #2
0
static void test_basics(void) {
	struct stat info1;
	struct stat info2;
	test_caseStart("Testing fs");

	test_assertInt(mkdir("/newdir",DIR_DEF_MODE),0);

	fs_createFile("/newdir/file1","foobar");
	fs_readFile("/newdir/file1","foobar");
	test_assertInt(link("/newdir/file1","/newdir/file2"),0);
	test_assertInt(stat("/newdir/file1",&info1),0);
	test_assertInt(stat("/newdir/file2",&info2),0);
	test_assertInt(memcmp(&info1,&info2,sizeof(struct stat)),0);
	test_assertUInt(info1.st_nlink,2);
	test_assertInt(unlink("/newdir/file1"),0);
	test_assertInt(rmdir("/newdir"),-ENOTEMPTY);
	test_assertInt(stat("/newdir/file1",&info1),-ENOENT);
	test_assertInt(stat("/newdir/file2",&info2),0);
	test_assertUInt(info2.st_nlink,1);
	test_assertInt(unlink("/newdir/file2"),0);

	test_assertInt(rmdir("/newdir"),0);
	int fd = open("/",O_RDONLY);
	test_assertTrue(fd >= 0);
	test_assertInt(syncfs(fd),0);
	close(fd);

	test_caseSucceeded();
}
Beispiel #3
0
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();
}
Beispiel #4
0
static void test_basics(void) {
	struct stat info1;
	struct stat info2;
	test_caseStart("Testing fs");

	test_assertInt(mkdir("/newdir",DIR_DEF_MODE),0);

	fs_createFile("/newdir/file1","foobar");
	fs_readFile("/newdir/file1","foobar");
	test_assertInt(link("/newdir/file1","/newdir/file2"),0);
	test_assertInt(stat("/newdir/file1",&info1),0);
	test_assertInt(stat("/newdir/file2",&info2),0);

	// compare elements individually, because the structs might contain uninitialized padding
	test_assertUInt(info1.st_atime,info2.st_atime);
	test_assertUInt(info1.st_mtime,info2.st_mtime);
	test_assertUInt(info1.st_ctime,info2.st_ctime);
	test_assertUInt(info1.st_blocks,info2.st_blocks);
	test_assertUInt(info1.st_blksize,info2.st_blksize);
	test_assertUInt(info1.st_dev,info2.st_dev);
	test_assertUInt(info1.st_uid,info2.st_uid);
	test_assertUInt(info1.st_gid,info2.st_gid);
	test_assertUInt(info1.st_ino,info2.st_ino);
	test_assertUInt(info1.st_nlink,info2.st_nlink);
	test_assertUInt(info1.st_mode,info2.st_mode);
	test_assertUInt(info1.st_size,info2.st_size);

	test_assertUInt(info1.st_nlink,2);
	test_assertInt(unlink("/newdir/file1"),0);
	test_assertInt(rmdir("/newdir"),-ENOTEMPTY);
	test_assertInt(stat("/newdir/file1",&info1),-ENOENT);
	test_assertInt(stat("/newdir/file2",&info2),0);
	test_assertUInt(info2.st_nlink,1);
	test_assertInt(unlink("/newdir/file2"),0);

	test_assertInt(rmdir("/newdir"),0);
	int fd = open("/",O_RDONLY);
	test_assertTrue(fd >= 0);
	test_assertInt(syncfs(fd),0);
	close(fd);

	test_caseSucceeded();
}
Beispiel #5
0
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();
}