Lines Matching +full:no +full:- +full:can +full:- +full:fd
17 #include "capsicum-test.h"
21 // capability-wrapped ones.
35 sprintf(shm_name, "/capsicum-test-%d", getuid()); in FORK_TEST()
37 if ((files["SHM"] == -1) && errno == ENOSYS) { in FORK_TEST()
38 // shm_open() is not implemented in user-mode Linux. in FORK_TEST()
46 std::string key = ii->first + " cap"; in FORK_TEST()
47 caps[key] = dup(ii->second); in FORK_TEST()
49 EXPECT_OK(caps[key]) << " on " << ii->first; in FORK_TEST()
57 // Ensure that we can fcntl() all the files that we opened above. in FORK_TEST()
61 EXPECT_OK(fcntl(ii->second, F_GETFL, 0)) << " on " << ii->first; in FORK_TEST()
62 int cap = dup(ii->second); in FORK_TEST()
63 EXPECT_OK(cap) << " on " << ii->first; in FORK_TEST()
64 EXPECT_OK(cap_rights_limit(cap, &r_ro)) << " on " << ii->first; in FORK_TEST()
65 EXPECT_EQ(-1, fcntl(cap, F_GETFL, 0)) << " on " << ii->first; in FORK_TEST()
66 EXPECT_EQ(ENOTCAPABLE, errno) << " on " << ii->first; in FORK_TEST()
70 close(ii->second); in FORK_TEST()
78 // F_DUPFD_CLOEXEC F_DUPFD_CLOEXEC NONE as dup(2) with close-on-exec
80 // F_DUP2FD_CLOEXEC NONE as dup2(2) with close-on-ex…
81 // F_GETFD F_GETFD F_GETFD NONE get close-on-exec flag
82 // F_SETFD F_SETFD F_SETFD NONE set close-on-exec flag
105 // CAP_FCNTL (marked with * above) can be further limited with cap_fcntls_limit(2).
134 int ok_index = -1; in CheckFcntl()
137 if (ok_index == -1) ok_index = ii; in CheckFcntl()
142 EXPECT_NE(-1, ok_index); in CheckFcntl()
154 int fd = open(TmpFile("cap_fcntl_cmds"), O_RDWR|O_CREAT, 0644); in TEST() local
155 EXPECT_OK(fd); in TEST()
156 write(fd, "TEST", 4); in TEST()
162 caps[ii] = dup(fd); in TEST()
170 // Check the things that need no rights against caps[0]. in TEST()
173 // dup()'ed FD should have same rights. in TEST()
181 // dup2()'ed FD should have same rights. in TEST()
210 close(fd); in TEST()
215 int fd = open(TmpFile("cap_fcntl_readlock"), O_RDWR|O_CREAT, 0644); in TEST() local
216 EXPECT_OK(fd); in TEST()
217 write(fd, "TEST", 4); in TEST()
219 int cap = dup(fd); in TEST()
230 // Write-Lock in TEST()
233 // Check write-locked (from another process). in TEST()
240 EXPECT_OK(fcntl(fd, F_GETLK, (long)&fl)); in TEST()
246 int rc = WIFEXITED(status) ? WEXITSTATUS(status) : -1; in TEST()
257 close(fd); in TEST()
263 int fd = open(TmpFile("cap_fcntl_subrightnorm"), O_RDWR|O_CREAT, 0644); in TEST() local
264 EXPECT_OK(fd); in TEST()
266 // Restrict the fcntl(2) subrights of a normal FD. in TEST()
267 EXPECT_OK(cap_fcntls_limit(fd, CAP_FCNTL_GETFL)); in TEST()
268 int fd_flag = fcntl(fd, F_GETFL, 0); in TEST()
270 EXPECT_NOTCAPABLE(fcntl(fd, F_SETFL, fd_flag)); in TEST()
274 EXPECT_OK(cap_rights_get(fd, &rights)); in TEST()
279 EXPECT_OK(cap_fcntls_get(fd, &fcntls)); in TEST()
282 // Can't widen the subrights. in TEST()
283 EXPECT_NOTCAPABLE(cap_fcntls_limit(fd, CAP_FCNTL_GETFL|CAP_FCNTL_SETFL)); in TEST()
285 close(fd); in TEST()
290 int fd = open(TmpFile("cap_fcntl_subrightpreserve"), O_RDWR|O_CREAT, 0644); in TEST() local
291 EXPECT_OK(fd); in TEST()
295 EXPECT_OK(cap_rights_limit(fd, &rights)); in TEST()
296 EXPECT_OK(cap_fcntls_limit(fd, CAP_FCNTL_GETFL)); in TEST()
300 EXPECT_OK(cap_rights_get(fd, &cur_rights)); in TEST()
302 EXPECT_OK(cap_fcntls_get(fd, &fcntls)); in TEST()
305 // Limiting the top-level rights leaves the subrights unaffected... in TEST()
307 EXPECT_OK(cap_rights_limit(fd, &rights)); in TEST()
308 EXPECT_OK(cap_fcntls_get(fd, &fcntls)); in TEST()
313 EXPECT_OK(cap_rights_limit(fd, &rights)); in TEST()
314 EXPECT_OK(cap_fcntls_get(fd, &fcntls)); in TEST()
316 EXPECT_EQ(-1, cap_fcntls_limit(fd, CAP_FCNTL_GETFL)); in TEST()
318 close(fd); in TEST()
323 int fd = open(TmpFile("cap_fcntl_subrights"), O_RDWR|O_CREAT, 0644); in TEST() local
324 EXPECT_OK(fd); in TEST()
325 write(fd, "TEST", 4); in TEST()
328 EXPECT_OK(cap_rights_limit(fd, &rights)); in TEST()
331 int fd_flag = fcntl(fd, F_GETFL, 0); in TEST()
333 EXPECT_OK(fcntl(fd, F_SETFL, fd_flag)); in TEST()
336 EXPECT_OK(cap_fcntls_limit(fd, CAP_FCNTL_ALL)); in TEST()
337 fd_flag = fcntl(fd, F_GETFL, 0); in TEST()
339 EXPECT_OK(fcntl(fd, F_SETFL, fd_flag)); in TEST()
342 int fd_get = dup(fd); in TEST()
343 int fd_set = dup(fd); in TEST()
355 // Check operations that need CAP_FCNTL with no subrights => ENOTCAPABLE. in TEST()
356 EXPECT_OK(cap_fcntls_limit(fd, 0)); in TEST()
357 EXPECT_NOTCAPABLE(fcntl(fd, F_GETFL, 0)); in TEST()
358 EXPECT_NOTCAPABLE(fcntl(fd, F_SETFL, fd_flag)); in TEST()
360 close(fd); in TEST()
371 // Check operations that need CAP_FCNTL with no subrights => OK. in TEST()
392 // Also check we can retrieve the subrights. in TEST()
398 // And that we can't widen the subrights. in TEST()
404 // Check operations that need CAP_FCNTL with no subrights => ENOTCAPABLE. in TEST()