2 * Copyright (c) 2008 Robert N. M. Watson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * This regression test attempts to confirm that the flags used at open-time
29 * for a file descriptor properly limit system calls that should be affected
30 * by those flags. Currently:
32 * System call Policy Tested
33 * __acl_aclcheck_fd(2) any no
34 * __acl_delete_fd(2) any no
35 * __acl_get_fd(2) any no
36 * __acl_set_fd(2) any no
38 * aio_read(2) O_RDONLY or O_RDWR yes
39 * aio_write(2) O_WRONLY or O_RDWR yes
42 * extattr_delete_fd(2) O_WRONLY or O_RDWR no
43 * extattr_get_fd(2) O_RDONLY or O_RDWR no
44 * extattr_list_fd(2) O_RDONLY or O_RDWR no
45 * extattr_set_fd(2) O_WRONLY or O_RDWR no
46 * fchdir(2) any directory yes
51 * fpathconf(2) any yes
55 * ftruncate(2) O_WRONLY or O_RDWR yes
57 * getdents(2) O_RDONLY directory yes
59 * mmap(2) PROT_READ O_RDONLY or O_RDWR yes
60 * mmap(2) PROT_WRITE O_WRONLY or O_RDWR yes
61 * mmap(2) PROT_WRITE + MAP_PRIV O_RDONLY or O_RDWR yes
62 * mmap(2) PROT_EXEC O_RDONLY or O_RDWR yes
63 * pread(2) O_RDONLY or O_RDWR yes
64 * preadv(2) O_RDONLY or O_RDWR yes
65 * pwrite(2) O_WRONLY or O_RDWR yes
66 * pwritev(2) O_WRONLY or O_RDWR yes
67 * read(2) O_RDONLY or O_RDWR yes
68 * readv(2) O_RDONLY or O_RDWR yes
69 * sendfile(2) O_RDONLY or O_RDWR on file yes
70 * write(2) O_WRONLY or O_RDWR yes
71 * writev(2) O_WRONLY or O_RDWR yes
73 * These checks do not verify that original permissions would allow the
74 * operation or that open is properly impacted by permissions, just that once
75 * a file descriptor is held, open-time limitations are implemented.
77 * We do, however, test that directories cannot be opened as writable.
79 * XXXRW: Arguably we should also test combinations of bits to mmap(2).
81 * XXXRW: Should verify mprotect() remapping limits.
83 * XXXRW: kqueue(2)/kevent(2), poll(2), select(2)
85 * XXXRW: oaio_read(2), oaio_write(2), freebsd6_*(2).
89 * XXXRW: message queue and shared memory fds?
92 #include <sys/cdefs.h>
93 __FBSDID("$FreeBSD$");
95 #include <sys/param.h>
97 #include <sys/mount.h>
98 #include <sys/socket.h>
100 #include <sys/sysctl.h>
114 #define PERM_FILE 0644 /* Allow read, write. Someday exec? */
115 #define PERM_DIR 0755 /* Allow read, write, exec. */
118 * Modes to try all tests with.
120 static const int file_modes[] = { O_RDONLY, O_WRONLY, O_RDWR,
121 O_RDONLY | O_TRUNC, O_WRONLY | O_TRUNC, O_RDWR | O_TRUNC };
122 static const int file_modes_count = nitems(file_modes);
124 static const int dir_modes[] = { O_RDONLY };
125 static const int dir_modes_count = nitems(dir_modes);
128 static int aio_present;
131 ok_mode(const char *testname, const char *comment, int mode)
136 printf("ok %d - %s # mode 0x%x\n", testnum, testname, mode);
138 printf("ok %d - %s # mode 0x%x - %s\n", testnum, testname,
143 notok_mode(const char *testname, const char *comment, int mode)
148 printf("not ok %d - %s # mode 0x%x\n", testnum, testname,
151 printf("not ok %d - %s # mode 0x%x - %s\n", testnum, testname,
156 * Before we get started, confirm that we can't open directories writable.
159 try_directory_open(const char *testname, const char *directory,
160 int mode, int expected_errno)
164 dfd = open(directory, mode);
167 notok_mode(testname, "opened", mode);
169 ok_mode(testname, NULL, mode);
172 if (expected_errno && expected_errno == errno)
173 ok_mode(testname, NULL, mode);
174 else if (expected_errno != 0)
175 notok_mode(testname, "wrong errno", mode);
177 notok_mode(testname, "failed", mode);
182 check_directory_open_modes(const char *directory, const int *modes,
185 int expected_errno, i, mode;
188 * Directories should only open with O_RDONLY. Notice that we use
189 * file_modes and not dirmodes.
191 for (i = 0; i < modes_count; i++) {
193 if (mode == O_RDONLY)
196 expected_errno = EISDIR;
197 try_directory_open(__func__, directory, mode,
203 check_dup(const char *testname, const char *path, const int *modes,
206 int dfd, fd, i, mode;
209 * dup() should work regardless of open mode.
211 for (i = 0; i < modes_count; i++) {
213 fd = open(path, mode);
215 notok_mode(testname, "open", mode);
220 ok_mode(testname, NULL, mode);
223 notok_mode(testname, NULL, mode);
229 check_dup2(const char *testname, const char *path, const int *modes,
232 int dfd, fd, i, mode;
235 * dup2() should work regardless of open mode.
237 for (i = 0; i < modes_count; i++) {
239 fd = open(path, mode);
241 notok_mode(testname, "open", mode);
244 dfd = dup2(fd, 500); /* Arbitrary but high number. */
246 ok_mode(testname, NULL, mode);
249 notok_mode(testname, NULL, mode);
255 check_fchdir(const char *testname, const char *path, const int *modes,
261 * fchdir() should work regardless of open mode.
263 for (i = 0; i < modes_count; i++) {
265 fd = open(path, mode);
267 notok_mode(testname, "open", mode);
271 ok_mode(testname, NULL, mode);
273 notok_mode(testname, "failed", mode);
279 check_fchflags(const char *testname, const char *path, const int *modes,
285 * fchflags() should work regardless of open mode.
287 for (i = 0; i < modes_count; i++) {
289 fd = open(path, mode);
291 notok_mode(testname, "open", mode);
294 if (fchflags(fd, UF_NODUMP) == 0)
295 ok_mode(testname, NULL, mode);
297 notok_mode(testname, "failed", mode);
303 check_fchmod(const char *testname, const char *path, int setmode,
304 const int *modes, int modes_count)
309 * fchmod() should work regardless of open mode.
311 for (i = 0; i < modes_count; i++) {
313 fd = open(path, mode);
315 notok_mode(testname, "open", mode);
318 if (fchmod(fd, setmode) == 0)
319 ok_mode(testname, NULL, mode);
321 notok_mode(testname, "failed", mode);
327 check_fchown(const char *testname, const char *path, const int *modes,
333 * fchown() should work regardless of open mode.
335 for (i = 0; i < modes_count; i++) {
337 fd = open(path, mode);
339 notok_mode(testname, "open", mode);
342 if (fchown(fd, -1, -1) == 0)
343 ok_mode(testname, NULL, mode);
345 notok_mode(testname, "failed", mode);
351 check_flock(const char *testname, const char *path, const int *modes,
357 * flock() should work regardless of open mode.
359 for (i = 0; i < modes_count; i++) {
361 fd = open(path, mode);
363 notok_mode(testname, "open", mode);
366 if (flock(fd, LOCK_EX) == 0)
367 ok_mode(testname, NULL, mode);
369 notok_mode(testname, "failed", mode);
375 check_fpathconf(const char *testname, const char *path, const int *modes,
382 * fpathconf() should work regardless of open mode.
384 for (i = 0; i < modes_count; i++) {
386 fd = open(path, mode);
388 notok_mode(testname, "open", mode);
391 l = fpathconf(fd, _PC_FILESIZEBITS);
393 ok_mode(testname, NULL, mode);
395 notok_mode(testname, "failed", mode);
401 check_fstat(const char *testname, const char *path, const int *modes,
408 * fstat() should work regardless of open mode.
410 for (i = 0; i < modes_count; i++) {
412 fd = open(path, mode);
414 notok_mode(testname, "open", mode);
417 if (fstat(fd, &sb) == 0)
418 ok_mode(testname, NULL, mode);
420 notok_mode(testname, "failed", mode);
426 check_fstatfs(const char *testname, const char *path, const int *modes,
429 struct statfs statfs;
433 * fstatfs() should work regardless of open mode.
435 for (i = 0; i < modes_count; i++) {
437 fd = open(path, mode);
439 notok_mode(testname, "open", mode);
442 if (fstatfs(fd, &statfs) == 0)
443 ok_mode(testname, NULL, mode);
445 notok_mode(testname, "failed", mode);
451 check_fsync(const char *testname, const char *path, const int *modes,
457 * fstatfs() should work regardless of open mode.
459 for (i = 0; i < modes_count; i++) {
461 fd = open(path, mode);
463 notok_mode(testname, "open", mode);
467 ok_mode(testname, NULL, mode);
469 notok_mode(testname, "failed", mode);
475 check_ftruncate(const char *testname, const char *path, const int *modes,
482 * ftruncate() should work as long as long as (mode & O_ACCMODE) is
483 * O_RDWR or O_WRONLY.
485 * Directories should never be writable, so this test should always
486 * pass for directories...
488 for (i = 0; i < modes_count; i++) {
490 fd = open(path, mode);
492 notok_mode(testname, "open", mode);
493 notok_mode(testname, "truncate1 skipped", mode);
494 notok_mode(testname, "truncate2 skipped", mode);
495 notok_mode(testname, "truncate3 skipped", mode);
498 if (fstat(fd, &sb) < 0) {
499 notok_mode(testname, "fstat", mode);
500 notok_mode(testname, "truncate1 skipped", mode);
501 notok_mode(testname, "truncate2 skipped", mode);
502 notok_mode(testname, "truncate3 skipped", mode);
506 ok_mode(testname, "setup", mode);
508 /* Truncate to grow file. */
509 if (ftruncate(fd, sb.st_size + 1) == 0) {
510 if (((mode & O_ACCMODE) == O_WRONLY) ||
511 ((mode & O_ACCMODE) == O_RDWR))
512 ok_mode(testname, "truncate1 succeeded",
515 notok_mode(testname, "truncate1 succeeded",
517 notok_mode(testname, "truncate2 skipped",
519 notok_mode(testname, "truncate3 skipped",
525 if (((mode & O_ACCMODE) == O_WRONLY) ||
526 ((mode & O_ACCMODE) == O_RDWR)) {
527 notok_mode(testname, "truncate1 failed",
529 notok_mode(testname, "truncate2 skipped",
531 notok_mode(testname, "truncate3 skipped",
536 ok_mode(testname, "truncate1 failed", mode);
539 /* Truncate to same size. */
540 if (ftruncate(fd, sb.st_size + 1) == 0) {
541 if (((mode & O_ACCMODE) == O_WRONLY) ||
542 ((mode & O_ACCMODE) == O_RDWR))
543 ok_mode(testname, "truncate2 succeeded",
546 notok_mode(testname, "truncate2 succeeded",
548 notok_mode(testname, "truncate3 skipped",
554 if (((mode & O_ACCMODE) == O_WRONLY) ||
555 ((mode & O_ACCMODE) == O_RDWR)) {
556 notok_mode(testname, "truncate2 failed",
558 notok_mode(testname, "truncate3 skipped",
563 ok_mode(testname, "truncate2 failed", mode);
566 /* Truncate to shrink. */
567 if (ftruncate(fd, sb.st_size) == 0) {
568 if (((mode & O_ACCMODE) == O_WRONLY) ||
569 ((mode & O_ACCMODE) == O_RDWR))
570 ok_mode(testname, "truncate3 succeeded",
573 notok_mode(testname, "truncate3 succeeded",
576 if (((mode & O_ACCMODE) == O_WRONLY) ||
577 ((mode & O_ACCMODE) == O_RDWR))
578 notok_mode(testname, "truncate3 failed",
581 ok_mode(testname, "truncate3 failed", mode);
588 check_futimes(const char *testname, const char *path, const int *modes,
594 * futimes() should work regardless of open mode.
596 for (i = 0; i < modes_count; i++) {
598 fd = open(path, mode);
600 notok_mode(testname, "open", mode);
603 if (futimes(fd, NULL) == 0)
604 ok_mode(testname, NULL, mode);
606 notok_mode(testname, "failed", mode);
612 check_lseek(const char *testname, const char *path, const int *modes,
618 * lseek() should work regardless of open mode.
620 for (i = 0; i < modes_count; i++) {
622 fd = open(path, mode);
624 notok_mode(testname, "open", mode);
627 if (lseek(fd, 100, SEEK_SET) == 100)
628 ok_mode(testname, NULL, mode);
630 notok_mode(testname, "failed", mode);
636 check_getdents(const char *testname, const char *path, int isdir,
637 const int *modes, int modes_count)
643 * getdents() should always work on directories and never on files,
644 * assuming directories are always opened for read (which they are).
646 for (i = 0; i < modes_count; i++) {
648 fd = open(path, mode);
650 notok_mode(testname, "open", mode);
653 if (getdents(fd, buf, sizeof(buf)) >= 0) {
654 if (isdir && ((mode & O_ACCMODE) == O_RDONLY))
655 ok_mode(testname, "directory succeeded",
658 notok_mode(testname, "directory succeeded",
661 notok_mode(testname, "file succeeded", mode);
663 if (isdir && ((mode & O_ACCMODE) == O_RDONLY))
664 notok_mode(testname, "directory failed",
667 ok_mode(testname, "directory failed", mode);
669 ok_mode(testname, "file failed", mode);
676 check_sendfile(const char *testname, const char *path, int isdir,
677 const int *modes, int modes_count)
679 int fd, i, mode, sv[2];
683 * sendfile() should work only on files, and only when the access mode
684 * is O_RDONLY or O_RDWR.
686 for (i = 0; i < modes_count; i++) {
688 fd = open(path, mode);
690 notok_mode(testname, "open", mode);
693 if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) < 0) {
694 notok_mode(testname, "socketpair", mode);
697 if (sendfile(fd, sv[0], 0, 1, NULL, &sent, 0) == 0) {
699 notok_mode(testname, "directory succeeded",
701 else if (((mode & O_ACCMODE) == O_RDONLY) ||
702 ((mode & O_ACCMODE) == O_RDWR))
703 ok_mode(testname, "succeeded", mode);
705 notok_mode(testname, "succeeded", mode);
708 ok_mode(testname, "directory failed", mode);
709 else if (((mode & O_ACCMODE) == O_RDONLY) ||
710 ((mode & O_ACCMODE) == O_RDWR))
711 notok_mode(testname, "failed", mode);
713 ok_mode(testname, "failed", mode);
722 * Various functions write, so just make write-like wrappers for them.
724 typedef ssize_t (*write_fn)(int d, const void *buf, size_t nbytes);
727 writev_wrapper(int d, const void *buf, size_t nbytes)
731 iov.iov_base = (void *)buf;
732 iov.iov_len = nbytes;
733 return (writev(d, &iov, 1));
737 pwrite_wrapper(int d, const void *buf, size_t nbytes)
740 return (pwrite(d, buf, nbytes, 0));
744 pwritev_wrapper(int d, const void *buf, size_t nbytes)
748 iov.iov_base = (void *)buf;
749 iov.iov_len = nbytes;
750 return (pwritev(d, &iov, 1, 0));
754 aio_write_wrapper(int d, const void *buf, size_t nbytes)
757 struct aiocb const *aiocb_array[] = { &aiocb };
759 bzero(&aiocb, sizeof(aiocb));
760 aiocb.aio_fildes = d;
761 aiocb.aio_buf = (void *)buf;
762 aiocb.aio_nbytes = nbytes;
763 if (aio_write(&aiocb) < 0)
765 aiocb_array[0] = &aiocb;
766 if (aio_suspend(aiocb_array, 1, NULL) < 0)
768 return (aio_return(&aiocb));
772 check_write(const char *testname, write_fn fn, const char *path,
773 const int *modes, int modes_count)
779 * write() should never succeed for directories, but especially
780 * because they can only be opened read-only. write() on files
781 * should succeed for O_WRONLY and O_RDWR descriptors.
784 for (i = 0; i < modes_count; i++) {
786 fd = open(path, mode);
788 notok_mode(testname, "open", mode);
791 if (fn(fd, &ch, sizeof(ch)) < 0) {
792 if ((mode & O_ACCMODE) == O_WRONLY ||
793 (mode & O_ACCMODE) == O_RDWR)
794 notok_mode(testname, "write failed", mode);
796 ok_mode(testname, "write failed", mode);
798 if (!((mode & O_ACCMODE) == O_WRONLY ||
799 (mode & O_ACCMODE) == O_RDWR))
800 notok_mode(testname, "write succeeded", mode);
802 ok_mode(testname, "write succeeded", mode);
809 * Various functions read, so just make read-like wrappers for them.
811 typedef ssize_t (*read_fn)(int d, void *buf, size_t nbytes);
814 readv_wrapper(int d, void *buf, size_t nbytes)
819 iov.iov_len = nbytes;
820 return (readv(d, &iov, 1));
824 pread_wrapper(int d, void *buf, size_t nbytes)
827 return (pread(d, buf, nbytes, 0));
831 preadv_wrapper(int d, void *buf, size_t nbytes)
836 iov.iov_len = nbytes;
837 return (preadv(d, &iov, 1, 0));
841 aio_read_wrapper(int d, void *buf, size_t nbytes)
844 struct aiocb const *aiocb_array[] = { &aiocb };
846 bzero(&aiocb, sizeof(aiocb));
847 aiocb.aio_fildes = d;
849 aiocb.aio_nbytes = nbytes;
850 if (aio_read(&aiocb) < 0)
852 if (aio_suspend(aiocb_array, 1, NULL) < 0)
854 return (aio_return(&aiocb));
858 check_read(const char *testname, read_fn fn, const char *path,
859 const int *modes, int modes_count)
865 * read() should (generally) succeeded on directories. read() on
866 * files should succeed for O_RDONLY and O_RDWR descriptors.
868 for (i = 0; i < modes_count; i++) {
870 fd = open(path, mode);
872 notok_mode(testname, "open", mode);
875 if (fn(fd, &ch, sizeof(ch)) < 0) {
876 if ((mode & O_ACCMODE) == O_RDONLY ||
877 (mode & O_ACCMODE) == O_RDWR)
878 notok_mode(testname, "read failed", mode);
880 ok_mode(testname, "read failed", mode);
882 if (!((mode & O_ACCMODE) == O_RDONLY ||
883 (mode & O_ACCMODE) == O_RDWR))
884 notok_mode(testname, "read succeeded", mode);
886 ok_mode(testname, "read succeeded", mode);
893 check_mmap_read(const char *testname, const char *path, int isdir,
894 const int *modes, int modes_count)
900 * mmap() read should fail for directories (ideally?) but succeed for
901 * O_RDONLY and O_RDWR file descriptors.
903 for (i = 0; i < modes_count; i++) {
905 fd = open(path, mode);
907 notok_mode(testname, "open", mode);
910 addr = mmap(NULL, getpagesize(), PROT_READ, MAP_SHARED, fd,
912 if (addr == MAP_FAILED) {
914 ok_mode(testname, "mmap dir failed", mode);
915 else if ((mode & O_ACCMODE) == O_RDONLY ||
916 (mode & O_ACCMODE) == O_RDWR)
917 notok_mode(testname, "mmap file failed",
920 ok_mode(testname, "mmap file failed", mode);
923 notok_mode(testname, "mmap dir succeeded",
925 else if ((mode & O_ACCMODE) == O_RDONLY ||
926 (mode & O_ACCMODE) == O_RDWR)
927 ok_mode(testname, "mmap file succeeded",
930 notok_mode(testname, "mmap file succeeded",
932 (void)munmap(addr, getpagesize());
939 check_mmap_write(const char *testname, const char *path, const int *modes,
946 * mmap() will always fail for directories (ideally) as they are
947 * always open O_RDONLY. Check for O_WRONLY or O_RDWR to permit a
948 * write mapping. This variant does a MAP_SHARED mapping, but we
949 * are also interested in MAP_PRIVATE.
951 for (i = 0; i < modes_count; i++) {
953 fd = open(path, mode);
955 notok_mode(testname, "open", mode);
958 addr = mmap(NULL, getpagesize(), PROT_WRITE, MAP_SHARED, fd,
960 if (addr == MAP_FAILED) {
961 if ((mode & O_ACCMODE) == O_WRONLY ||
962 (mode & O_ACCMODE) == O_RDWR)
963 notok_mode(testname, "mmap failed",
966 ok_mode(testname, "mmap failed", mode);
968 if ((mode & O_ACCMODE) == O_WRONLY ||
969 (mode & O_ACCMODE) == O_RDWR)
970 ok_mode(testname, "mmap succeeded",
973 notok_mode(testname, "mmap succeeded", mode);
974 (void)munmap(addr, getpagesize());
981 check_mmap_exec(const char *testname, const char *path, int isdir,
982 const int *modes, int modes_count)
988 * mmap() exec should fail for directories (ideally?) but succeed for
989 * O_RDONLY and O_RDWR file descriptors.
991 for (i = 0; i < modes_count; i++) {
993 fd = open(path, mode);
995 notok_mode(testname, "open", mode);
998 addr = mmap(NULL, getpagesize(), PROT_EXEC, MAP_SHARED, fd,
1000 if (addr == MAP_FAILED) {
1002 ok_mode(testname, "mmap dir failed", mode);
1003 else if ((mode & O_ACCMODE) == O_RDONLY ||
1004 (mode & O_ACCMODE) == O_RDWR)
1005 notok_mode(testname, "mmap file failed",
1008 ok_mode(testname, "mmap file failed", mode);
1011 notok_mode(testname, "mmap dir succeeded",
1014 ok_mode(testname, "mmap file succeeded",
1016 (void)munmap(addr, getpagesize());
1023 check_mmap_write_private(const char *testname, const char *path, int isdir,
1024 const int *modes, int modes_count)
1030 * mmap() write private should succeed for readable descriptors
1031 * except for directories.
1033 for (i = 0; i < modes_count; i++) {
1035 fd = open(path, mode);
1037 notok_mode(testname, "open", mode);
1040 addr = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE,
1041 MAP_PRIVATE, fd, 0);
1042 if (addr == MAP_FAILED) {
1044 ok_mode(testname, "mmap dir failed", mode);
1045 else if ((mode & O_ACCMODE) == O_RDONLY ||
1046 (mode & O_ACCMODE) == O_RDWR)
1047 notok_mode(testname, "mmap file failed",
1050 ok_mode(testname, "mmap file failed", mode);
1053 notok_mode(testname, "mmap dir succeeded",
1055 else if ((mode & O_ACCMODE) == O_RDONLY ||
1056 (mode & O_ACCMODE) == O_RDWR)
1057 ok_mode(testname, "mmap file succeeded",
1060 notok_mode(testname, "mmap file succeeded",
1062 (void)munmap(addr, getpagesize());
1071 char dir_path[PATH_MAX], file_path[PATH_MAX];
1076 size = sizeof(dummy);
1077 if (sysctlbyname("vfs.aio", &dummy, &size, NULL, 0) < 0) {
1078 if (errno == EISDIR)
1082 strlcpy(dir_path, "/tmp/open-dir.XXXXXXXXXXX", sizeof(dir_path));
1083 if (mkdtemp(dir_path) == NULL)
1085 if (chmod(dir_path, PERM_DIR) < 0) {
1086 warn("chmod %s", dir_path);
1087 (void)rmdir(dir_path);
1090 strlcpy(file_path, "/tmp/open-file.XXXXXXXXXXX", sizeof(file_path));
1091 fd = mkstemp(file_path);
1094 (void)rmdir(dir_path);
1098 if (chmod(file_path, PERM_FILE) < 0) {
1099 warn("chmod %s", file_path);
1100 (void)unlink(file_path);
1101 (void)rmdir(dir_path);
1104 check_directory_open_modes(dir_path, file_modes, file_modes_count);
1106 check_dup("check_dup_dir", dir_path, dir_modes, dir_modes_count);
1107 check_dup("check_dup_file", file_path, file_modes, file_modes_count);
1109 check_dup2("check_dup2_dir", dir_path, dir_modes, dir_modes_count);
1110 check_dup2("check_dup2_file", file_path, file_modes,
1113 check_fchdir("check_fchdir", dir_path, dir_modes, dir_modes_count);
1115 check_fchflags("check_fchflags_dir", dir_path, dir_modes,
1117 check_fchflags("check_fchflags_file", file_path, file_modes,
1120 check_fchmod("check_fchmod_dir", dir_path, PERM_DIR, dir_modes,
1122 check_fchmod("check_fchmod_file", file_path, PERM_FILE, file_modes,
1125 check_fchown("check_fchown_dir", dir_path, dir_modes,
1127 check_fchown("check_fchown_file", file_path, file_modes,
1130 check_flock("check_flock_dir", dir_path, dir_modes, dir_modes_count);
1131 check_flock("check_flock_file", file_path, file_modes,
1134 check_fpathconf("check_fpathconf_dir", dir_path, dir_modes,
1136 check_fpathconf("check_fpathconf_file", file_path, file_modes,
1139 check_fstat("check_fstat_dir", dir_path, dir_modes, dir_modes_count);
1140 check_fstat("check_fstat_file", file_path, file_modes,
1143 check_fstatfs("check_fstatfs_dir", dir_path, dir_modes,
1145 check_fstatfs("check_fstatfs_file", file_path, file_modes,
1148 check_fsync("check_fsync_dir", dir_path, dir_modes, dir_modes_count);
1149 check_fsync("check_fsync_file", file_path, file_modes,
1152 check_ftruncate("check_ftruncate_dir", dir_path, dir_modes,
1154 check_ftruncate("check_ftruncate_file", file_path, file_modes,
1157 check_futimes("check_futimes_dir", dir_path, dir_modes,
1159 check_futimes("check_futimes_file", file_path, file_modes,
1162 check_lseek("check_lseek_dir", dir_path, dir_modes, dir_modes_count);
1163 check_lseek("check_lseek_file", file_path, file_modes,
1166 check_getdents("check_getdents_dir", dir_path, 1, dir_modes,
1168 check_getdents("check_getdents_file", file_path, 0, file_modes,
1171 check_sendfile("check_sendfile_dir", dir_path, 1, dir_modes,
1173 check_sendfile("check_sendfile_file", file_path, 0, file_modes,
1176 check_write("check_write_dir", write, dir_path, dir_modes,
1178 check_write("check_write_file", write, file_path, file_modes,
1181 check_write("check_writev_dir", writev_wrapper, dir_path, dir_modes,
1183 check_write("check_writev_file", writev_wrapper, file_path,
1184 file_modes, file_modes_count);
1186 check_write("check_pwrite_dir", pwrite_wrapper, dir_path, dir_modes,
1188 check_write("check_pwrite_file", pwrite_wrapper, file_path,
1189 file_modes, file_modes_count);
1191 check_write("check_pwritev_dir", pwritev_wrapper, dir_path,
1192 dir_modes, dir_modes_count);
1193 check_write("check_pwritev_file", pwritev_wrapper, file_path,
1194 file_modes, file_modes_count);
1197 check_write("check_aio_write_dir", aio_write_wrapper,
1198 dir_path, dir_modes, dir_modes_count);
1199 check_write("check_aio_write_file", aio_write_wrapper,
1200 file_path, file_modes, file_modes_count);
1203 check_read("check_read_dir", read, dir_path, dir_modes,
1205 check_read("check_read_file", read, file_path, file_modes,
1208 check_read("check_readv_dir", readv_wrapper, dir_path, dir_modes,
1210 check_read("check_readv_file", readv_wrapper, file_path,
1211 file_modes, file_modes_count);
1213 check_read("check_pread_dir", pread_wrapper, dir_path, dir_modes,
1215 check_read("check_pread_file", pread_wrapper, file_path,
1216 file_modes, file_modes_count);
1218 check_read("check_preadv_dir", preadv_wrapper, dir_path,
1219 dir_modes, dir_modes_count);
1220 check_read("check_preadv_file", preadv_wrapper, file_path,
1221 file_modes, file_modes_count);
1224 check_read("check_aio_read_dir", aio_read_wrapper, dir_path,
1225 dir_modes, dir_modes_count);
1226 check_read("check_aio_read_file", aio_read_wrapper,
1227 file_path, file_modes, file_modes_count);
1230 check_mmap_read("check_mmap_read_dir", dir_path, 1, dir_modes,
1232 check_mmap_read("check_mmap_read_file", file_path, 0, file_modes,
1235 check_mmap_write("check_mmap_write_dir", dir_path, dir_modes,
1237 check_mmap_write("check_mmap_write_file", file_path, file_modes,
1240 check_mmap_exec("check_mmap_exec_dir", dir_path, 1, dir_modes,
1242 check_mmap_exec("check_mmap_exec_file", file_path, 0, file_modes,
1245 check_mmap_write_private("check_mmap_write_private_dir", dir_path, 1,
1246 dir_modes, dir_modes_count);
1247 check_mmap_write_private("check_mmap_write_private_file", file_path,
1248 0, file_modes, file_modes_count);
1250 (void)unlink(file_path);
1251 (void)rmdir(dir_path);