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 #include <sys/param.h>
95 #include <sys/mount.h>
96 #include <sys/socket.h>
98 #include <sys/sysctl.h>
112 #define PERM_FILE 0644 /* Allow read, write. Someday exec? */
113 #define PERM_DIR 0755 /* Allow read, write, exec. */
116 * Modes to try all tests with.
118 static const int file_modes[] = { O_RDONLY, O_WRONLY, O_RDWR,
119 O_RDONLY | O_TRUNC, O_WRONLY | O_TRUNC, O_RDWR | O_TRUNC };
120 static const int file_modes_count = nitems(file_modes);
122 static const int dir_modes[] = { O_RDONLY };
123 static const int dir_modes_count = nitems(dir_modes);
126 static int aio_present;
129 ok_mode(const char *testname, const char *comment, int mode)
134 printf("ok %d - %s # mode 0x%x\n", testnum, testname, mode);
136 printf("ok %d - %s # mode 0x%x - %s\n", testnum, testname,
141 notok_mode(const char *testname, const char *comment, int mode)
146 printf("not ok %d - %s # mode 0x%x\n", testnum, testname,
149 printf("not ok %d - %s # mode 0x%x - %s\n", testnum, testname,
154 * Before we get started, confirm that we can't open directories writable.
157 try_directory_open(const char *testname, const char *directory,
158 int mode, int expected_errno)
162 dfd = open(directory, mode);
165 notok_mode(testname, "opened", mode);
167 ok_mode(testname, NULL, mode);
170 if (expected_errno && expected_errno == errno)
171 ok_mode(testname, NULL, mode);
172 else if (expected_errno != 0)
173 notok_mode(testname, "wrong errno", mode);
175 notok_mode(testname, "failed", mode);
180 check_directory_open_modes(const char *directory, const int *modes,
183 int expected_errno, i, mode;
186 * Directories should only open with O_RDONLY. Notice that we use
187 * file_modes and not dirmodes.
189 for (i = 0; i < modes_count; i++) {
191 if (mode == O_RDONLY)
194 expected_errno = EISDIR;
195 try_directory_open(__func__, directory, mode,
201 check_dup(const char *testname, const char *path, const int *modes,
204 int dfd, fd, i, mode;
207 * dup() should work regardless of open mode.
209 for (i = 0; i < modes_count; i++) {
211 fd = open(path, mode);
213 notok_mode(testname, "open", mode);
218 ok_mode(testname, NULL, mode);
221 notok_mode(testname, NULL, mode);
227 check_dup2(const char *testname, const char *path, const int *modes,
230 int dfd, fd, i, mode;
233 * dup2() should work regardless of open mode.
235 for (i = 0; i < modes_count; i++) {
237 fd = open(path, mode);
239 notok_mode(testname, "open", mode);
242 dfd = dup2(fd, 500); /* Arbitrary but high number. */
244 ok_mode(testname, NULL, mode);
247 notok_mode(testname, NULL, mode);
253 check_fchdir(const char *testname, const char *path, const int *modes,
259 * fchdir() should work regardless of open mode.
261 for (i = 0; i < modes_count; i++) {
263 fd = open(path, mode);
265 notok_mode(testname, "open", mode);
269 ok_mode(testname, NULL, mode);
271 notok_mode(testname, "failed", mode);
277 check_fchflags(const char *testname, const char *path, const int *modes,
283 * fchflags() should work regardless of open mode.
285 for (i = 0; i < modes_count; i++) {
287 fd = open(path, mode);
289 notok_mode(testname, "open", mode);
292 if (fchflags(fd, UF_NODUMP) == 0)
293 ok_mode(testname, NULL, mode);
295 notok_mode(testname, "failed", mode);
301 check_fchmod(const char *testname, const char *path, int setmode,
302 const int *modes, int modes_count)
307 * fchmod() should work regardless of open mode.
309 for (i = 0; i < modes_count; i++) {
311 fd = open(path, mode);
313 notok_mode(testname, "open", mode);
316 if (fchmod(fd, setmode) == 0)
317 ok_mode(testname, NULL, mode);
319 notok_mode(testname, "failed", mode);
325 check_fchown(const char *testname, const char *path, const int *modes,
331 * fchown() should work regardless of open mode.
333 for (i = 0; i < modes_count; i++) {
335 fd = open(path, mode);
337 notok_mode(testname, "open", mode);
340 if (fchown(fd, -1, -1) == 0)
341 ok_mode(testname, NULL, mode);
343 notok_mode(testname, "failed", mode);
349 check_flock(const char *testname, const char *path, const int *modes,
355 * flock() should work regardless of open mode.
357 for (i = 0; i < modes_count; i++) {
359 fd = open(path, mode);
361 notok_mode(testname, "open", mode);
364 if (flock(fd, LOCK_EX) == 0)
365 ok_mode(testname, NULL, mode);
367 notok_mode(testname, "failed", mode);
373 check_fpathconf(const char *testname, const char *path, const int *modes,
380 * fpathconf() should work regardless of open mode.
382 for (i = 0; i < modes_count; i++) {
384 fd = open(path, mode);
386 notok_mode(testname, "open", mode);
389 l = fpathconf(fd, _PC_FILESIZEBITS);
391 ok_mode(testname, NULL, mode);
393 notok_mode(testname, "failed", mode);
399 check_fstat(const char *testname, const char *path, const int *modes,
406 * fstat() should work regardless of open mode.
408 for (i = 0; i < modes_count; i++) {
410 fd = open(path, mode);
412 notok_mode(testname, "open", mode);
415 if (fstat(fd, &sb) == 0)
416 ok_mode(testname, NULL, mode);
418 notok_mode(testname, "failed", mode);
424 check_fstatfs(const char *testname, const char *path, const int *modes,
427 struct statfs statfs;
431 * fstatfs() should work regardless of open mode.
433 for (i = 0; i < modes_count; i++) {
435 fd = open(path, mode);
437 notok_mode(testname, "open", mode);
440 if (fstatfs(fd, &statfs) == 0)
441 ok_mode(testname, NULL, mode);
443 notok_mode(testname, "failed", mode);
449 check_fsync(const char *testname, const char *path, const int *modes,
455 * fstatfs() should work regardless of open mode.
457 for (i = 0; i < modes_count; i++) {
459 fd = open(path, mode);
461 notok_mode(testname, "open", mode);
465 ok_mode(testname, NULL, mode);
467 notok_mode(testname, "failed", mode);
473 check_ftruncate(const char *testname, const char *path, const int *modes,
480 * ftruncate() should work as long as long as (mode & O_ACCMODE) is
481 * O_RDWR or O_WRONLY.
483 * Directories should never be writable, so this test should always
484 * pass for directories...
486 for (i = 0; i < modes_count; i++) {
488 fd = open(path, mode);
490 notok_mode(testname, "open", mode);
491 notok_mode(testname, "truncate1 skipped", mode);
492 notok_mode(testname, "truncate2 skipped", mode);
493 notok_mode(testname, "truncate3 skipped", mode);
496 if (fstat(fd, &sb) < 0) {
497 notok_mode(testname, "fstat", mode);
498 notok_mode(testname, "truncate1 skipped", mode);
499 notok_mode(testname, "truncate2 skipped", mode);
500 notok_mode(testname, "truncate3 skipped", mode);
504 ok_mode(testname, "setup", mode);
506 /* Truncate to grow file. */
507 if (ftruncate(fd, sb.st_size + 1) == 0) {
508 if (((mode & O_ACCMODE) == O_WRONLY) ||
509 ((mode & O_ACCMODE) == O_RDWR))
510 ok_mode(testname, "truncate1 succeeded",
513 notok_mode(testname, "truncate1 succeeded",
515 notok_mode(testname, "truncate2 skipped",
517 notok_mode(testname, "truncate3 skipped",
523 if (((mode & O_ACCMODE) == O_WRONLY) ||
524 ((mode & O_ACCMODE) == O_RDWR)) {
525 notok_mode(testname, "truncate1 failed",
527 notok_mode(testname, "truncate2 skipped",
529 notok_mode(testname, "truncate3 skipped",
534 ok_mode(testname, "truncate1 failed", mode);
537 /* Truncate to same size. */
538 if (ftruncate(fd, sb.st_size + 1) == 0) {
539 if (((mode & O_ACCMODE) == O_WRONLY) ||
540 ((mode & O_ACCMODE) == O_RDWR))
541 ok_mode(testname, "truncate2 succeeded",
544 notok_mode(testname, "truncate2 succeeded",
546 notok_mode(testname, "truncate3 skipped",
552 if (((mode & O_ACCMODE) == O_WRONLY) ||
553 ((mode & O_ACCMODE) == O_RDWR)) {
554 notok_mode(testname, "truncate2 failed",
556 notok_mode(testname, "truncate3 skipped",
561 ok_mode(testname, "truncate2 failed", mode);
564 /* Truncate to shrink. */
565 if (ftruncate(fd, sb.st_size) == 0) {
566 if (((mode & O_ACCMODE) == O_WRONLY) ||
567 ((mode & O_ACCMODE) == O_RDWR))
568 ok_mode(testname, "truncate3 succeeded",
571 notok_mode(testname, "truncate3 succeeded",
574 if (((mode & O_ACCMODE) == O_WRONLY) ||
575 ((mode & O_ACCMODE) == O_RDWR))
576 notok_mode(testname, "truncate3 failed",
579 ok_mode(testname, "truncate3 failed", mode);
586 check_futimes(const char *testname, const char *path, const int *modes,
592 * futimes() should work regardless of open mode.
594 for (i = 0; i < modes_count; i++) {
596 fd = open(path, mode);
598 notok_mode(testname, "open", mode);
601 if (futimes(fd, NULL) == 0)
602 ok_mode(testname, NULL, mode);
604 notok_mode(testname, "failed", mode);
610 check_lseek(const char *testname, const char *path, const int *modes,
616 * lseek() should work regardless of open mode.
618 for (i = 0; i < modes_count; i++) {
620 fd = open(path, mode);
622 notok_mode(testname, "open", mode);
625 if (lseek(fd, 100, SEEK_SET) == 100)
626 ok_mode(testname, NULL, mode);
628 notok_mode(testname, "failed", mode);
634 check_getdents(const char *testname, const char *path, int isdir,
635 const int *modes, int modes_count)
641 * getdents() should always work on directories and never on files,
642 * assuming directories are always opened for read (which they are).
644 for (i = 0; i < modes_count; i++) {
646 fd = open(path, mode);
648 notok_mode(testname, "open", mode);
651 if (getdents(fd, buf, sizeof(buf)) >= 0) {
652 if (isdir && ((mode & O_ACCMODE) == O_RDONLY))
653 ok_mode(testname, "directory succeeded",
656 notok_mode(testname, "directory succeeded",
659 notok_mode(testname, "file succeeded", mode);
661 if (isdir && ((mode & O_ACCMODE) == O_RDONLY))
662 notok_mode(testname, "directory failed",
665 ok_mode(testname, "directory failed", mode);
667 ok_mode(testname, "file failed", mode);
674 check_sendfile(const char *testname, const char *path, int isdir,
675 const int *modes, int modes_count)
677 int fd, i, mode, sv[2];
681 * sendfile() should work only on files, and only when the access mode
682 * is O_RDONLY or O_RDWR.
684 for (i = 0; i < modes_count; i++) {
686 fd = open(path, mode);
688 notok_mode(testname, "open", mode);
691 if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) < 0) {
692 notok_mode(testname, "socketpair", mode);
695 if (sendfile(fd, sv[0], 0, 1, NULL, &sent, 0) == 0) {
697 notok_mode(testname, "directory succeeded",
699 else if (((mode & O_ACCMODE) == O_RDONLY) ||
700 ((mode & O_ACCMODE) == O_RDWR))
701 ok_mode(testname, "succeeded", mode);
703 notok_mode(testname, "succeeded", mode);
706 ok_mode(testname, "directory failed", mode);
707 else if (((mode & O_ACCMODE) == O_RDONLY) ||
708 ((mode & O_ACCMODE) == O_RDWR))
709 notok_mode(testname, "failed", mode);
711 ok_mode(testname, "failed", mode);
720 * Various functions write, so just make write-like wrappers for them.
722 typedef ssize_t (*write_fn)(int d, const void *buf, size_t nbytes);
725 writev_wrapper(int d, const void *buf, size_t nbytes)
729 iov.iov_base = (void *)buf;
730 iov.iov_len = nbytes;
731 return (writev(d, &iov, 1));
735 pwrite_wrapper(int d, const void *buf, size_t nbytes)
738 return (pwrite(d, buf, nbytes, 0));
742 pwritev_wrapper(int d, const void *buf, size_t nbytes)
746 iov.iov_base = (void *)buf;
747 iov.iov_len = nbytes;
748 return (pwritev(d, &iov, 1, 0));
752 aio_write_wrapper(int d, const void *buf, size_t nbytes)
755 struct aiocb const *aiocb_array[] = { &aiocb };
757 bzero(&aiocb, sizeof(aiocb));
758 aiocb.aio_fildes = d;
759 aiocb.aio_buf = (void *)buf;
760 aiocb.aio_nbytes = nbytes;
761 if (aio_write(&aiocb) < 0)
763 aiocb_array[0] = &aiocb;
764 if (aio_suspend(aiocb_array, 1, NULL) < 0)
766 return (aio_return(&aiocb));
770 check_write(const char *testname, write_fn fn, const char *path,
771 const int *modes, int modes_count)
777 * write() should never succeed for directories, but especially
778 * because they can only be opened read-only. write() on files
779 * should succeed for O_WRONLY and O_RDWR descriptors.
782 for (i = 0; i < modes_count; i++) {
784 fd = open(path, mode);
786 notok_mode(testname, "open", mode);
789 if (fn(fd, &ch, sizeof(ch)) < 0) {
790 if ((mode & O_ACCMODE) == O_WRONLY ||
791 (mode & O_ACCMODE) == O_RDWR)
792 notok_mode(testname, "write failed", mode);
794 ok_mode(testname, "write failed", mode);
796 if (!((mode & O_ACCMODE) == O_WRONLY ||
797 (mode & O_ACCMODE) == O_RDWR))
798 notok_mode(testname, "write succeeded", mode);
800 ok_mode(testname, "write succeeded", mode);
807 * Various functions read, so just make read-like wrappers for them.
809 typedef ssize_t (*read_fn)(int d, void *buf, size_t nbytes);
812 readv_wrapper(int d, void *buf, size_t nbytes)
817 iov.iov_len = nbytes;
818 return (readv(d, &iov, 1));
822 pread_wrapper(int d, void *buf, size_t nbytes)
825 return (pread(d, buf, nbytes, 0));
829 preadv_wrapper(int d, void *buf, size_t nbytes)
834 iov.iov_len = nbytes;
835 return (preadv(d, &iov, 1, 0));
839 aio_read_wrapper(int d, void *buf, size_t nbytes)
842 struct aiocb const *aiocb_array[] = { &aiocb };
844 bzero(&aiocb, sizeof(aiocb));
845 aiocb.aio_fildes = d;
847 aiocb.aio_nbytes = nbytes;
848 if (aio_read(&aiocb) < 0)
850 if (aio_suspend(aiocb_array, 1, NULL) < 0)
852 return (aio_return(&aiocb));
856 check_read(const char *testname, read_fn fn, const char *path,
857 const int *modes, int modes_count)
863 * read() should (generally) succeeded on directories. read() on
864 * files should succeed for O_RDONLY and O_RDWR descriptors.
866 for (i = 0; i < modes_count; i++) {
868 fd = open(path, mode);
870 notok_mode(testname, "open", mode);
873 if (fn(fd, &ch, sizeof(ch)) < 0) {
874 if ((mode & O_ACCMODE) == O_RDONLY ||
875 (mode & O_ACCMODE) == O_RDWR)
876 notok_mode(testname, "read failed", mode);
878 ok_mode(testname, "read failed", mode);
880 if (!((mode & O_ACCMODE) == O_RDONLY ||
881 (mode & O_ACCMODE) == O_RDWR))
882 notok_mode(testname, "read succeeded", mode);
884 ok_mode(testname, "read succeeded", mode);
891 check_mmap_read(const char *testname, const char *path, int isdir,
892 const int *modes, int modes_count)
898 * mmap() read should fail for directories (ideally?) but succeed for
899 * O_RDONLY and O_RDWR file descriptors.
901 for (i = 0; i < modes_count; i++) {
903 fd = open(path, mode);
905 notok_mode(testname, "open", mode);
908 addr = mmap(NULL, getpagesize(), PROT_READ, MAP_SHARED, fd,
910 if (addr == MAP_FAILED) {
912 ok_mode(testname, "mmap dir failed", mode);
913 else if ((mode & O_ACCMODE) == O_RDONLY ||
914 (mode & O_ACCMODE) == O_RDWR)
915 notok_mode(testname, "mmap file failed",
918 ok_mode(testname, "mmap file failed", mode);
921 notok_mode(testname, "mmap dir succeeded",
923 else if ((mode & O_ACCMODE) == O_RDONLY ||
924 (mode & O_ACCMODE) == O_RDWR)
925 ok_mode(testname, "mmap file succeeded",
928 notok_mode(testname, "mmap file succeeded",
930 (void)munmap(addr, getpagesize());
937 check_mmap_write(const char *testname, const char *path, const int *modes,
944 * mmap() will always fail for directories (ideally) as they are
945 * always open O_RDONLY. Check for O_WRONLY or O_RDWR to permit a
946 * write mapping. This variant does a MAP_SHARED mapping, but we
947 * are also interested in MAP_PRIVATE.
949 for (i = 0; i < modes_count; i++) {
951 fd = open(path, mode);
953 notok_mode(testname, "open", mode);
956 addr = mmap(NULL, getpagesize(), PROT_WRITE, MAP_SHARED, fd,
958 if (addr == MAP_FAILED) {
959 if ((mode & O_ACCMODE) == O_WRONLY ||
960 (mode & O_ACCMODE) == O_RDWR)
961 notok_mode(testname, "mmap failed",
964 ok_mode(testname, "mmap failed", mode);
966 if ((mode & O_ACCMODE) == O_WRONLY ||
967 (mode & O_ACCMODE) == O_RDWR)
968 ok_mode(testname, "mmap succeeded",
971 notok_mode(testname, "mmap succeeded", mode);
972 (void)munmap(addr, getpagesize());
979 check_mmap_exec(const char *testname, const char *path, int isdir,
980 const int *modes, int modes_count)
986 * mmap() exec should fail for directories (ideally?) but succeed for
987 * O_RDONLY and O_RDWR file descriptors.
989 for (i = 0; i < modes_count; i++) {
991 fd = open(path, mode);
993 notok_mode(testname, "open", mode);
996 addr = mmap(NULL, getpagesize(), PROT_EXEC, MAP_SHARED, fd,
998 if (addr == MAP_FAILED) {
1000 ok_mode(testname, "mmap dir failed", mode);
1001 else if ((mode & O_ACCMODE) == O_RDONLY ||
1002 (mode & O_ACCMODE) == O_RDWR)
1003 notok_mode(testname, "mmap file failed",
1006 ok_mode(testname, "mmap file failed", mode);
1009 notok_mode(testname, "mmap dir succeeded",
1012 ok_mode(testname, "mmap file succeeded",
1014 (void)munmap(addr, getpagesize());
1021 check_mmap_write_private(const char *testname, const char *path, int isdir,
1022 const int *modes, int modes_count)
1028 * mmap() write private should succeed for readable descriptors
1029 * except for directories.
1031 for (i = 0; i < modes_count; i++) {
1033 fd = open(path, mode);
1035 notok_mode(testname, "open", mode);
1038 addr = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE,
1039 MAP_PRIVATE, fd, 0);
1040 if (addr == MAP_FAILED) {
1042 ok_mode(testname, "mmap dir failed", mode);
1043 else if ((mode & O_ACCMODE) == O_RDONLY ||
1044 (mode & O_ACCMODE) == O_RDWR)
1045 notok_mode(testname, "mmap file failed",
1048 ok_mode(testname, "mmap file failed", mode);
1051 notok_mode(testname, "mmap dir succeeded",
1053 else if ((mode & O_ACCMODE) == O_RDONLY ||
1054 (mode & O_ACCMODE) == O_RDWR)
1055 ok_mode(testname, "mmap file succeeded",
1058 notok_mode(testname, "mmap file succeeded",
1060 (void)munmap(addr, getpagesize());
1069 char dir_path[PATH_MAX], file_path[PATH_MAX];
1074 size = sizeof(dummy);
1075 if (sysctlbyname("vfs.aio", &dummy, &size, NULL, 0) < 0) {
1076 if (errno == EISDIR)
1080 strlcpy(dir_path, "/tmp/open-dir.XXXXXXXXXXX", sizeof(dir_path));
1081 if (mkdtemp(dir_path) == NULL)
1083 if (chmod(dir_path, PERM_DIR) < 0) {
1084 warn("chmod %s", dir_path);
1085 (void)rmdir(dir_path);
1088 strlcpy(file_path, "/tmp/open-file.XXXXXXXXXXX", sizeof(file_path));
1089 fd = mkstemp(file_path);
1092 (void)rmdir(dir_path);
1096 if (chmod(file_path, PERM_FILE) < 0) {
1097 warn("chmod %s", file_path);
1098 (void)unlink(file_path);
1099 (void)rmdir(dir_path);
1102 check_directory_open_modes(dir_path, file_modes, file_modes_count);
1104 check_dup("check_dup_dir", dir_path, dir_modes, dir_modes_count);
1105 check_dup("check_dup_file", file_path, file_modes, file_modes_count);
1107 check_dup2("check_dup2_dir", dir_path, dir_modes, dir_modes_count);
1108 check_dup2("check_dup2_file", file_path, file_modes,
1111 check_fchdir("check_fchdir", dir_path, dir_modes, dir_modes_count);
1113 check_fchflags("check_fchflags_dir", dir_path, dir_modes,
1115 check_fchflags("check_fchflags_file", file_path, file_modes,
1118 check_fchmod("check_fchmod_dir", dir_path, PERM_DIR, dir_modes,
1120 check_fchmod("check_fchmod_file", file_path, PERM_FILE, file_modes,
1123 check_fchown("check_fchown_dir", dir_path, dir_modes,
1125 check_fchown("check_fchown_file", file_path, file_modes,
1128 check_flock("check_flock_dir", dir_path, dir_modes, dir_modes_count);
1129 check_flock("check_flock_file", file_path, file_modes,
1132 check_fpathconf("check_fpathconf_dir", dir_path, dir_modes,
1134 check_fpathconf("check_fpathconf_file", file_path, file_modes,
1137 check_fstat("check_fstat_dir", dir_path, dir_modes, dir_modes_count);
1138 check_fstat("check_fstat_file", file_path, file_modes,
1141 check_fstatfs("check_fstatfs_dir", dir_path, dir_modes,
1143 check_fstatfs("check_fstatfs_file", file_path, file_modes,
1146 check_fsync("check_fsync_dir", dir_path, dir_modes, dir_modes_count);
1147 check_fsync("check_fsync_file", file_path, file_modes,
1150 check_ftruncate("check_ftruncate_dir", dir_path, dir_modes,
1152 check_ftruncate("check_ftruncate_file", file_path, file_modes,
1155 check_futimes("check_futimes_dir", dir_path, dir_modes,
1157 check_futimes("check_futimes_file", file_path, file_modes,
1160 check_lseek("check_lseek_dir", dir_path, dir_modes, dir_modes_count);
1161 check_lseek("check_lseek_file", file_path, file_modes,
1164 check_getdents("check_getdents_dir", dir_path, 1, dir_modes,
1166 check_getdents("check_getdents_file", file_path, 0, file_modes,
1169 check_sendfile("check_sendfile_dir", dir_path, 1, dir_modes,
1171 check_sendfile("check_sendfile_file", file_path, 0, file_modes,
1174 check_write("check_write_dir", write, dir_path, dir_modes,
1176 check_write("check_write_file", write, file_path, file_modes,
1179 check_write("check_writev_dir", writev_wrapper, dir_path, dir_modes,
1181 check_write("check_writev_file", writev_wrapper, file_path,
1182 file_modes, file_modes_count);
1184 check_write("check_pwrite_dir", pwrite_wrapper, dir_path, dir_modes,
1186 check_write("check_pwrite_file", pwrite_wrapper, file_path,
1187 file_modes, file_modes_count);
1189 check_write("check_pwritev_dir", pwritev_wrapper, dir_path,
1190 dir_modes, dir_modes_count);
1191 check_write("check_pwritev_file", pwritev_wrapper, file_path,
1192 file_modes, file_modes_count);
1195 check_write("check_aio_write_dir", aio_write_wrapper,
1196 dir_path, dir_modes, dir_modes_count);
1197 check_write("check_aio_write_file", aio_write_wrapper,
1198 file_path, file_modes, file_modes_count);
1201 check_read("check_read_dir", read, dir_path, dir_modes,
1203 check_read("check_read_file", read, file_path, file_modes,
1206 check_read("check_readv_dir", readv_wrapper, dir_path, dir_modes,
1208 check_read("check_readv_file", readv_wrapper, file_path,
1209 file_modes, file_modes_count);
1211 check_read("check_pread_dir", pread_wrapper, dir_path, dir_modes,
1213 check_read("check_pread_file", pread_wrapper, file_path,
1214 file_modes, file_modes_count);
1216 check_read("check_preadv_dir", preadv_wrapper, dir_path,
1217 dir_modes, dir_modes_count);
1218 check_read("check_preadv_file", preadv_wrapper, file_path,
1219 file_modes, file_modes_count);
1222 check_read("check_aio_read_dir", aio_read_wrapper, dir_path,
1223 dir_modes, dir_modes_count);
1224 check_read("check_aio_read_file", aio_read_wrapper,
1225 file_path, file_modes, file_modes_count);
1228 check_mmap_read("check_mmap_read_dir", dir_path, 1, dir_modes,
1230 check_mmap_read("check_mmap_read_file", file_path, 0, file_modes,
1233 check_mmap_write("check_mmap_write_dir", dir_path, dir_modes,
1235 check_mmap_write("check_mmap_write_file", file_path, file_modes,
1238 check_mmap_exec("check_mmap_exec_dir", dir_path, 1, dir_modes,
1240 check_mmap_exec("check_mmap_exec_file", file_path, 0, file_modes,
1243 check_mmap_write_private("check_mmap_write_private_dir", dir_path, 1,
1244 dir_modes, dir_modes_count);
1245 check_mmap_write_private("check_mmap_write_private_file", file_path,
1246 0, file_modes, file_modes_count);
1248 (void)unlink(file_path);
1249 (void)rmdir(dir_path);