Changeset View
Changeset View
Standalone View
Standalone View
tests/sys/fs/fusefs/default_permissions.cc
Show First 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
}; | }; | ||||
class Access: public DefaultPermissions {}; | class Access: public DefaultPermissions {}; | ||||
class Chown: public DefaultPermissions {}; | class Chown: public DefaultPermissions {}; | ||||
class Chgrp: public DefaultPermissions {}; | class Chgrp: public DefaultPermissions {}; | ||||
class CopyFileRange: public DefaultPermissions {}; | class CopyFileRange: public DefaultPermissions {}; | ||||
class Fspacectl: public DefaultPermissions {}; | |||||
class Lookup: public DefaultPermissions {}; | class Lookup: public DefaultPermissions {}; | ||||
class Open: public DefaultPermissions {}; | class Open: public DefaultPermissions {}; | ||||
class PosixFallocate: public DefaultPermissions {}; | class PosixFallocate: public DefaultPermissions {}; | ||||
class Setattr: public DefaultPermissions {}; | class Setattr: public DefaultPermissions {}; | ||||
class Unlink: public DefaultPermissions {}; | class Unlink: public DefaultPermissions {}; | ||||
class Utimensat: public DefaultPermissions {}; | class Utimensat: public DefaultPermissions {}; | ||||
class Write: public DefaultPermissions {}; | class Write: public DefaultPermissions {}; | ||||
▲ Show 20 Lines • Show All 658 Lines • ▼ Show 20 Lines | TEST_F(Listextattr, system) | ||||
expect_getattr(FUSE_ROOT_ID, S_IFDIR | 0777, UINT64_MAX, 1); | expect_getattr(FUSE_ROOT_ID, S_IFDIR | 0777, UINT64_MAX, 1); | ||||
/* Listing user extended attributes merely requires read access */ | /* Listing user extended attributes merely requires read access */ | ||||
expect_lookup(RELPATH, ino, S_IFREG | 0644, UINT64_MAX, geteuid()); | expect_lookup(RELPATH, ino, S_IFREG | 0644, UINT64_MAX, geteuid()); | ||||
ASSERT_EQ(-1, extattr_list_file(FULLPATH, ns, NULL, 0)); | ASSERT_EQ(-1, extattr_list_file(FULLPATH, ns, NULL, 0)); | ||||
ASSERT_EQ(EPERM, errno); | ASSERT_EQ(EPERM, errno); | ||||
} | } | ||||
/* A write by a non-owner should clear a file's SGID bit */ | |||||
TEST_F(Fspacectl, clear_sgid) | |||||
{ | |||||
const char FULLPATH[] = "mountpoint/file.txt"; | |||||
const char RELPATH[] = "file.txt"; | |||||
struct stat sb; | |||||
struct spacectl_range rqsr; | |||||
uint64_t ino = 42; | |||||
mode_t oldmode = 02777; | |||||
mode_t newmode = 0777; | |||||
off_t fsize = 16; | |||||
off_t off = 8; | |||||
off_t len = 8; | |||||
int fd; | |||||
expect_getattr(FUSE_ROOT_ID, S_IFDIR | 0755, UINT64_MAX, 1); | |||||
FuseTest::expect_lookup(RELPATH, ino, S_IFREG | oldmode, fsize, | |||||
1, UINT64_MAX, 0, 0); | |||||
expect_open(ino, 0, 1); | |||||
expect_fallocate(ino, off, len, | |||||
FUSE_FALLOC_FL_KEEP_SIZE | FUSE_FALLOC_FL_PUNCH_HOLE, 0); | |||||
expect_chmod(ino, newmode, fsize); | |||||
fd = open(FULLPATH, O_WRONLY); | |||||
ASSERT_LE(0, fd) << strerror(errno); | |||||
rqsr.r_len = len; | |||||
rqsr.r_offset = off; | |||||
EXPECT_EQ(0, fspacectl(fd, SPACECTL_DEALLOC, &rqsr, 0, NULL)); | |||||
ASSERT_EQ(0, fstat(fd, &sb)) << strerror(errno); | |||||
EXPECT_EQ(S_IFREG | newmode, sb.st_mode); | |||||
leak(fd); | |||||
} | |||||
/* A write by a non-owner should clear a file's SUID bit */ | |||||
TEST_F(Fspacectl, clear_suid) | |||||
{ | |||||
const char FULLPATH[] = "mountpoint/file.txt"; | |||||
const char RELPATH[] = "file.txt"; | |||||
struct stat sb; | |||||
struct spacectl_range rqsr; | |||||
uint64_t ino = 42; | |||||
mode_t oldmode = 04777; | |||||
mode_t newmode = 0777; | |||||
off_t fsize = 16; | |||||
off_t off = 8; | |||||
off_t len = 8; | |||||
int fd; | |||||
expect_getattr(FUSE_ROOT_ID, S_IFDIR | 0755, UINT64_MAX, 1); | |||||
FuseTest::expect_lookup(RELPATH, ino, S_IFREG | oldmode, fsize, | |||||
1, UINT64_MAX, 0, 0); | |||||
expect_open(ino, 0, 1); | |||||
expect_fallocate(ino, off, len, | |||||
FUSE_FALLOC_FL_KEEP_SIZE | FUSE_FALLOC_FL_PUNCH_HOLE, 0); | |||||
expect_chmod(ino, newmode, fsize); | |||||
fd = open(FULLPATH, O_WRONLY); | |||||
ASSERT_LE(0, fd) << strerror(errno); | |||||
rqsr.r_len = len; | |||||
rqsr.r_offset = off; | |||||
EXPECT_EQ(0, fspacectl(fd, SPACECTL_DEALLOC, &rqsr, 0, NULL)); | |||||
ASSERT_EQ(0, fstat(fd, &sb)) << strerror(errno); | |||||
EXPECT_EQ(S_IFREG | newmode, sb.st_mode); | |||||
leak(fd); | |||||
} | |||||
/* | |||||
* fspacectl() of a file without writable permissions should succeed as | |||||
* long as the file descriptor is writable. This is important when combined | |||||
* with O_CREAT | |||||
*/ | |||||
TEST_F(Fspacectl, posix_fallocate_of_newly_created_file) | |||||
{ | |||||
const char FULLPATH[] = "mountpoint/some_file.txt"; | |||||
const char RELPATH[] = "some_file.txt"; | |||||
struct spacectl_range rqsr; | |||||
const uint64_t ino = 42; | |||||
off_t off = 8; | |||||
off_t len = 8; | |||||
int fd; | |||||
expect_getattr(FUSE_ROOT_ID, S_IFDIR | 0777, UINT64_MAX, 1); | |||||
EXPECT_LOOKUP(FUSE_ROOT_ID, RELPATH) | |||||
.WillOnce(Invoke(ReturnErrno(ENOENT))); | |||||
expect_create(RELPATH, ino); | |||||
expect_fallocate(ino, off, len, | |||||
FUSE_FALLOC_FL_KEEP_SIZE | FUSE_FALLOC_FL_PUNCH_HOLE, 0); | |||||
fd = open(FULLPATH, O_CREAT | O_RDWR, 0); | |||||
ASSERT_LE(0, fd) << strerror(errno); | |||||
rqsr.r_len = len; | |||||
rqsr.r_offset = off; | |||||
EXPECT_EQ(0, fspacectl(fd, SPACECTL_DEALLOC, &rqsr, 0, NULL)); | |||||
leak(fd); | |||||
} | |||||
/* A component of the search path lacks execute permissions */ | /* A component of the search path lacks execute permissions */ | ||||
TEST_F(Lookup, eacces) | TEST_F(Lookup, eacces) | ||||
{ | { | ||||
const char FULLPATH[] = "mountpoint/some_dir/some_file.txt"; | const char FULLPATH[] = "mountpoint/some_dir/some_file.txt"; | ||||
const char RELDIRPATH[] = "some_dir"; | const char RELDIRPATH[] = "some_dir"; | ||||
uint64_t dir_ino = 42; | uint64_t dir_ino = 42; | ||||
expect_getattr(FUSE_ROOT_ID, S_IFDIR | 0755, UINT64_MAX, 1); | expect_getattr(FUSE_ROOT_ID, S_IFDIR | 0755, UINT64_MAX, 1); | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | TEST_F(PosixFallocate, clear_suid) | ||||
EXPECT_EQ(0, posix_fallocate(fd, off, len)) << strerror(errno); | EXPECT_EQ(0, posix_fallocate(fd, off, len)) << strerror(errno); | ||||
ASSERT_EQ(0, fstat(fd, &sb)) << strerror(errno); | ASSERT_EQ(0, fstat(fd, &sb)) << strerror(errno); | ||||
EXPECT_EQ(S_IFREG | newmode, sb.st_mode); | EXPECT_EQ(S_IFREG | newmode, sb.st_mode); | ||||
leak(fd); | leak(fd); | ||||
} | } | ||||
/* | /* | ||||
* posix_fallcoate() of a file without writable permissions should succeed as | * posix_fallocate() of a file without writable permissions should succeed as | ||||
* long as the file descriptor is writable. This is important when combined | * long as the file descriptor is writable. This is important when combined | ||||
* with O_CREAT | * with O_CREAT | ||||
*/ | */ | ||||
TEST_F(PosixFallocate, posix_fallocate_of_newly_created_file) | TEST_F(PosixFallocate, posix_fallocate_of_newly_created_file) | ||||
{ | { | ||||
const char FULLPATH[] = "mountpoint/some_file.txt"; | const char FULLPATH[] = "mountpoint/some_file.txt"; | ||||
const char RELPATH[] = "some_file.txt"; | const char RELPATH[] = "some_file.txt"; | ||||
const uint64_t ino = 42; | const uint64_t ino = 42; | ||||
▲ Show 20 Lines • Show All 558 Lines • Show Last 20 Lines |