Add most system calls for POSIX extended API set, part 2, with test cases:

faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
This commit is contained in:
manu 2012-11-18 17:41:51 +00:00
parent a7aa627f8a
commit a76c1cc17f
42 changed files with 4472 additions and 287 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.1788 2012/11/09 19:47:11 skrll Exp $
# $NetBSD: mi,v 1.1789 2012/11/18 17:41:51 manu Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@ -4785,10 +4785,13 @@
./usr/share/man/cat2/extattr_set_fd.0 comp-c-catman .cat
./usr/share/man/cat2/extattr_set_file.0 comp-c-catman .cat
./usr/share/man/cat2/extattr_set_link.0 comp-c-catman .cat
./usr/share/man/cat2/faccessat.0 comp-c-catman .cat
./usr/share/man/cat2/fchdir.0 comp-c-catman .cat
./usr/share/man/cat2/fchflags.0 comp-c-catman .cat
./usr/share/man/cat2/fchmod.0 comp-c-catman .cat
./usr/share/man/cat2/fchmodat.0 comp-c-catman .cat
./usr/share/man/cat2/fchown.0 comp-c-catman .cat
./usr/share/man/cat2/fchownat.0 comp-c-catman .cat
./usr/share/man/cat2/fchroot.0 comp-c-catman .cat
./usr/share/man/cat2/fcntl.0 comp-c-catman .cat
./usr/share/man/cat2/fdatasync.0 comp-c-catman .cat
@ -4802,6 +4805,7 @@
./usr/share/man/cat2/fork.0 comp-c-catman .cat
./usr/share/man/cat2/fpathconf.0 comp-c-catman .cat
./usr/share/man/cat2/fstat.0 comp-c-catman .cat
./usr/share/man/cat2/fstatat.0 comp-c-catman .cat
./usr/share/man/cat2/fstatfs.0 comp-obsolete obsolete
./usr/share/man/cat2/fstatvfs.0 comp-c-catman .cat
./usr/share/man/cat2/fstatvfs1.0 comp-c-catman .cat
@ -4872,8 +4876,11 @@
./usr/share/man/cat2/mincore.0 comp-c-catman .cat
./usr/share/man/cat2/minherit.0 comp-c-catman .cat
./usr/share/man/cat2/mkdir.0 comp-c-catman .cat
./usr/share/man/cat2/mkdirat.0 comp-c-catman .cat
./usr/share/man/cat2/mkfifo.0 comp-c-catman .cat
./usr/share/man/cat2/mkfifoat.0 comp-c-catman .cat
./usr/share/man/cat2/mknod.0 comp-c-catman .cat
./usr/share/man/cat2/mknodat.0 comp-c-catman .cat
./usr/share/man/cat2/mlock.0 comp-c-catman .cat
./usr/share/man/cat2/mlockall.0 comp-c-catman .cat
./usr/share/man/cat2/mmap.0 comp-c-catman .cat
@ -4894,6 +4901,7 @@
./usr/share/man/cat2/ntp_adjtime.0 comp-c-catman .cat
./usr/share/man/cat2/ntp_gettime.0 comp-c-catman .cat
./usr/share/man/cat2/open.0 comp-c-catman .cat
./usr/share/man/cat2/openat.0 comp-c-catman .cat
./usr/share/man/cat2/paccept.0 comp-c-catman .cat
./usr/share/man/cat2/pathconf.0 comp-c-catman .cat
./usr/share/man/cat2/pipe.0 comp-c-catman .cat
@ -4915,6 +4923,7 @@
./usr/share/man/cat2/rasctl.0 comp-c-catman .cat
./usr/share/man/cat2/read.0 comp-c-catman .cat
./usr/share/man/cat2/readlink.0 comp-c-catman .cat
./usr/share/man/cat2/readlinkat.0 comp-c-catman .cat
./usr/share/man/cat2/readv.0 comp-c-catman .cat
./usr/share/man/cat2/reboot.0 comp-c-catman .cat
./usr/share/man/cat2/recv.0 comp-c-catman .cat
@ -4922,6 +4931,7 @@
./usr/share/man/cat2/recvmmsg.0 comp-c-catman .cat
./usr/share/man/cat2/recvmsg.0 comp-c-catman .cat
./usr/share/man/cat2/rename.0 comp-c-catman .cat
./usr/share/man/cat2/renameat.0 comp-c-catman .cat
./usr/share/man/cat2/revoke.0 comp-c-catman .cat
./usr/share/man/cat2/rmdir.0 comp-c-catman .cat
./usr/share/man/cat2/sa_enable.0 comp-obsolete obsolete
@ -4983,6 +4993,7 @@
./usr/share/man/cat2/swapctl.0 comp-c-catman .cat
./usr/share/man/cat2/swapon.0 comp-obsolete obsolete
./usr/share/man/cat2/symlink.0 comp-c-catman .cat
./usr/share/man/cat2/symlinkat.0 comp-c-catman .cat
./usr/share/man/cat2/sync.0 comp-c-catman .cat
./usr/share/man/cat2/sysarch.0 comp-c-catman .cat
./usr/share/man/cat2/syscall.0 comp-c-catman .cat
@ -4996,6 +5007,7 @@
./usr/share/man/cat2/umask.0 comp-c-catman .cat
./usr/share/man/cat2/undelete.0 comp-c-catman .cat
./usr/share/man/cat2/unlink.0 comp-c-catman .cat
./usr/share/man/cat2/unlinkat.0 comp-c-catman .cat
./usr/share/man/cat2/unmount.0 comp-c-catman .cat
./usr/share/man/cat2/utimensat.0 comp-c-catman .cat
./usr/share/man/cat2/utimes.0 comp-c-catman .cat
@ -11311,10 +11323,13 @@
./usr/share/man/html2/extattr_set_fd.html comp-c-htmlman html
./usr/share/man/html2/extattr_set_file.html comp-c-htmlman html
./usr/share/man/html2/extattr_set_link.html comp-c-htmlman html
./usr/share/man/html2/faccessat.html comp-c-htmlman html
./usr/share/man/html2/fchdir.html comp-c-htmlman html
./usr/share/man/html2/fchflags.html comp-c-htmlman html
./usr/share/man/html2/fchmod.html comp-c-htmlman html
./usr/share/man/html2/fchmodat.html comp-c-htmlman html
./usr/share/man/html2/fchown.html comp-c-htmlman html
./usr/share/man/html2/fchownat.html comp-c-htmlman html
./usr/share/man/html2/fchroot.html comp-c-htmlman html
./usr/share/man/html2/fcntl.html comp-c-htmlman html
./usr/share/man/html2/fdatasync.html comp-c-htmlman html
@ -11327,6 +11342,7 @@
./usr/share/man/html2/fork.html comp-c-htmlman html
./usr/share/man/html2/fpathconf.html comp-c-htmlman html
./usr/share/man/html2/fstat.html comp-c-htmlman html
./usr/share/man/html2/fstatat.html comp-c-htmlman html
./usr/share/man/html2/fstatvfs.html comp-c-htmlman html
./usr/share/man/html2/fstatvfs1.html comp-c-htmlman html
./usr/share/man/html2/fsync.html comp-c-htmlman html
@ -11392,8 +11408,11 @@
./usr/share/man/html2/mincore.html comp-c-htmlman html
./usr/share/man/html2/minherit.html comp-c-htmlman html
./usr/share/man/html2/mkdir.html comp-c-htmlman html
./usr/share/man/html2/mkdirat.html comp-c-htmlman html
./usr/share/man/html2/mkfifo.html comp-c-htmlman html
./usr/share/man/html2/mkfifoat.html comp-c-htmlman html
./usr/share/man/html2/mknod.html comp-c-htmlman html
./usr/share/man/html2/mknodat.html comp-c-htmlman html
./usr/share/man/html2/mlock.html comp-c-htmlman html
./usr/share/man/html2/mlockall.html comp-c-htmlman html
./usr/share/man/html2/mmap.html comp-c-htmlman html
@ -11414,6 +11433,7 @@
./usr/share/man/html2/ntp_adjtime.html comp-c-htmlman html
./usr/share/man/html2/ntp_gettime.html comp-c-htmlman html
./usr/share/man/html2/open.html comp-c-htmlman html
./usr/share/man/html2/openat.html comp-c-htmlman html
./usr/share/man/html2/paccept.html comp-c-htmlman html
./usr/share/man/html2/pathconf.html comp-c-htmlman html
./usr/share/man/html2/pipe.html comp-c-htmlman html
@ -11435,6 +11455,7 @@
./usr/share/man/html2/rasctl.html comp-c-htmlman html
./usr/share/man/html2/read.html comp-c-htmlman html
./usr/share/man/html2/readlink.html comp-c-htmlman html
./usr/share/man/html2/readlinkat.html comp-c-htmlman html
./usr/share/man/html2/readv.html comp-c-htmlman html
./usr/share/man/html2/reboot.html comp-c-htmlman html
./usr/share/man/html2/recv.html comp-c-htmlman html
@ -11442,6 +11463,7 @@
./usr/share/man/html2/recvmmsg.html comp-c-htmlman html
./usr/share/man/html2/recvmsg.html comp-c-htmlman html
./usr/share/man/html2/rename.html comp-c-htmlman html
./usr/share/man/html2/renameat.html comp-c-htmlman html
./usr/share/man/html2/revoke.html comp-c-htmlman html
./usr/share/man/html2/rmdir.html comp-c-htmlman html
./usr/share/man/html2/sbrk.html comp-c-htmlman html
@ -11495,6 +11517,7 @@
./usr/share/man/html2/statvfs1.html comp-c-htmlman html
./usr/share/man/html2/swapctl.html comp-c-htmlman html
./usr/share/man/html2/symlink.html comp-c-htmlman html
./usr/share/man/html2/symlinkat.html comp-c-htmlman html
./usr/share/man/html2/sync.html comp-c-htmlman html
./usr/share/man/html2/sysarch.html comp-c-htmlman html
./usr/share/man/html2/syscall.html comp-c-htmlman html
@ -11508,6 +11531,7 @@
./usr/share/man/html2/umask.html comp-c-htmlman html
./usr/share/man/html2/undelete.html comp-c-htmlman html
./usr/share/man/html2/unlink.html comp-c-htmlman html
./usr/share/man/html2/unlinkat.html comp-c-htmlman html
./usr/share/man/html2/unmount.html comp-c-htmlman html
./usr/share/man/html2/utimensat.html comp-c-htmlman html
./usr/share/man/html2/utimes.html comp-c-htmlman html
@ -17607,10 +17631,13 @@
./usr/share/man/man2/extattr_set_fd.2 comp-c-man .man
./usr/share/man/man2/extattr_set_file.2 comp-c-man .man
./usr/share/man/man2/extattr_set_link.2 comp-c-man .man
./usr/share/man/man2/faccessat.2 comp-c-man .man
./usr/share/man/man2/fchdir.2 comp-c-man .man
./usr/share/man/man2/fchflags.2 comp-c-man .man
./usr/share/man/man2/fchmod.2 comp-c-man .man
./usr/share/man/man2/fchmodat.2 comp-c-man .man
./usr/share/man/man2/fchown.2 comp-c-man .man
./usr/share/man/man2/fchownat.2 comp-c-man .man
./usr/share/man/man2/fchroot.2 comp-c-man .man
./usr/share/man/man2/fcntl.2 comp-c-man .man
./usr/share/man/man2/fdatasync.2 comp-c-man .man
@ -17624,6 +17651,7 @@
./usr/share/man/man2/fork.2 comp-c-man .man
./usr/share/man/man2/fpathconf.2 comp-c-man .man
./usr/share/man/man2/fstat.2 comp-c-man .man
./usr/share/man/man2/fstatat.2 comp-c-man .man
./usr/share/man/man2/fstatfs.2 comp-obsolete obsolete
./usr/share/man/man2/fstatvfs.2 comp-c-man .man
./usr/share/man/man2/fstatvfs1.2 comp-c-man .man
@ -17693,8 +17721,11 @@
./usr/share/man/man2/mincore.2 comp-c-man .man
./usr/share/man/man2/minherit.2 comp-c-man .man
./usr/share/man/man2/mkdir.2 comp-c-man .man
./usr/share/man/man2/mkdirat.2 comp-c-man .man
./usr/share/man/man2/mkfifo.2 comp-c-man .man
./usr/share/man/man2/mkfifoat.2 comp-c-man .man
./usr/share/man/man2/mknod.2 comp-c-man .man
./usr/share/man/man2/mknodat.2 comp-c-man .man
./usr/share/man/man2/mlock.2 comp-c-man .man
./usr/share/man/man2/mlockall.2 comp-c-man .man
./usr/share/man/man2/mmap.2 comp-c-man .man
@ -17715,6 +17746,7 @@
./usr/share/man/man2/ntp_adjtime.2 comp-c-man .man
./usr/share/man/man2/ntp_gettime.2 comp-c-man .man
./usr/share/man/man2/open.2 comp-c-man .man
./usr/share/man/man2/openat.2 comp-c-man .man
./usr/share/man/man2/paccept.2 comp-c-man .man
./usr/share/man/man2/pathconf.2 comp-c-man .man
./usr/share/man/man2/pipe.2 comp-c-man .man
@ -17736,6 +17768,7 @@
./usr/share/man/man2/rasctl.2 comp-c-man .man
./usr/share/man/man2/read.2 comp-c-man .man
./usr/share/man/man2/readlink.2 comp-c-man .man
./usr/share/man/man2/readlinkat.2 comp-c-man .man
./usr/share/man/man2/readv.2 comp-c-man .man
./usr/share/man/man2/reboot.2 comp-c-man .man
./usr/share/man/man2/recv.2 comp-c-man .man
@ -17743,6 +17776,7 @@
./usr/share/man/man2/recvmmsg.2 comp-c-man .man
./usr/share/man/man2/recvmsg.2 comp-c-man .man
./usr/share/man/man2/rename.2 comp-c-man .man
./usr/share/man/man2/renameat.2 comp-c-man .man
./usr/share/man/man2/revoke.2 comp-c-man .man
./usr/share/man/man2/rmdir.2 comp-c-man .man
./usr/share/man/man2/sa_enable.2 comp-obsolete obsolete
@ -17803,6 +17837,7 @@
./usr/share/man/man2/statvfs1.2 comp-c-man .man
./usr/share/man/man2/swapctl.2 comp-c-man .man
./usr/share/man/man2/symlink.2 comp-c-man .man
./usr/share/man/man2/symlinkat.2 comp-c-man .man
./usr/share/man/man2/sync.2 comp-c-man .man
./usr/share/man/man2/sysarch.2 comp-c-man .man
./usr/share/man/man2/syscall.2 comp-c-man .man
@ -17816,6 +17851,7 @@
./usr/share/man/man2/umask.2 comp-c-man .man
./usr/share/man/man2/undelete.2 comp-c-man .man
./usr/share/man/man2/unlink.2 comp-c-man .man
./usr/share/man/man2/unlinkat.2 comp-c-man .man
./usr/share/man/man2/unmount.2 comp-c-man .man
./usr/share/man/man2/utimensat.2 comp-c-man .man
./usr/share/man/man2/utimes.2 comp-c-man .man

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.505 2012/11/17 21:55:24 joerg Exp $
# $NetBSD: mi,v 1.506 2012/11/18 17:41:52 manu Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@ -2203,6 +2203,24 @@
./usr/tests/lib/libbluetooth/t_sdp_set tests-lib-tests atf
./usr/tests/lib/libc tests-lib-tests
./usr/tests/lib/libc/Atffile tests-lib-tests atf
./usr/tests/lib/libc/c063 tests-lib-tests
./usr/tests/lib/libc/c063/Atffile tests-lib-tests atf
./usr/tests/lib/libc/c063/t_faccessat tests-lib-tests atf
./usr/tests/lib/libc/c063/t_fchmodat tests-lib-tests atf
./usr/tests/lib/libc/c063/t_fchownat tests-lib-tests atf
./usr/tests/lib/libc/c063/t_fexecve tests-lib-tests atf
./usr/tests/lib/libc/c063/t_fstatat tests-lib-tests atf
./usr/tests/lib/libc/c063/t_linkat tests-lib-tests atf
./usr/tests/lib/libc/c063/t_mkdirat tests-lib-tests atf
./usr/tests/lib/libc/c063/t_mkfifoat tests-lib-tests atf
./usr/tests/lib/libc/c063/t_mknodat tests-lib-tests atf
./usr/tests/lib/libc/c063/t_o_search tests-lib-tests atf
./usr/tests/lib/libc/c063/t_openat tests-lib-tests atf
./usr/tests/lib/libc/c063/t_readlinkat tests-lib-tests atf
./usr/tests/lib/libc/c063/t_renameat tests-lib-tests atf
./usr/tests/lib/libc/c063/t_symlinkat tests-lib-tests atf
./usr/tests/lib/libc/c063/t_unlinkat tests-lib-tests atf
./usr/tests/lib/libc/c063/t_utimensat tests-lib-tests atf
./usr/tests/lib/libc/db tests-lib-tests
./usr/tests/lib/libc/db/Atffile tests-lib-tests atf
./usr/tests/lib/libc/db/README tests-lib-tests atf

View File

@ -1,4 +1,4 @@
# $NetBSD: NetBSD.dist.tests,v 1.87 2012/11/12 09:03:52 njoly Exp $
# $NetBSD: NetBSD.dist.tests,v 1.88 2012/11/18 17:41:52 manu Exp $
./usr/libdata/debug/usr/tests
./usr/libdata/debug/usr/tests/atf
@ -190,6 +190,7 @@
./usr/tests/lib/csu
./usr/tests/lib/libbluetooth
./usr/tests/lib/libc
./usr/tests/lib/libc/c063
./usr/tests/lib/libc/db
./usr/tests/lib/libc/gen
./usr/tests/lib/libc/gen/posix_spawn

View File

@ -1,4 +1,4 @@
/* $NetBSD: limits.h,v 1.32 2012/03/28 17:04:41 christos Exp $ */
/* $NetBSD: limits.h,v 1.33 2012/11/18 17:41:53 manu Exp $ */
/*
* Copyright (c) 1988, 1993
@ -144,21 +144,7 @@
* we are done implementing them.
*/
#if !defined(_INCOMPLETE_XOPEN_C063)
#define __stub_linkat
#define __stub_renameat
#define __stub_mkfifoat
#define __stub_mknodat
#define __stub_mkdirat
#define __stub_faccessat
#define __stub_fchmodat
#define __stub_fchownat
#define __stub_fexecve
#define __stub_fstatat
#define __stub_utimensat
#define __stub_openat
#define __stub_readlinkat
#define __stub_symlinkat
#define __stub_unlinkat
#endif
#include <machine/limits.h>

View File

@ -1,4 +1,4 @@
/* $NetBSD: unistd.h,v 1.135 2012/07/14 15:06:26 darrenr Exp $ */
/* $NetBSD: unistd.h,v 1.136 2012/11/18 17:41:53 manu Exp $ */
/*-
* Copyright (c) 1998, 1999, 2008 The NetBSD Foundation, Inc.
@ -294,7 +294,8 @@ ssize_t pwrite(int, const void *, size_t, off_t);
/*
* X/Open Extended API set 2 (a.k.a. C063)
*/
#if defined(_INCOMPLETE_XOPEN_C063)
#if (_POSIX_C_SOURCE - 0) >= 200809L || (_XOPEN_SOURCE - 0 >= 700) || \
defined(_INCOMPLETE_XOPEN_C063) || defined(_KERNEL)
int linkat(int, const char *, int, const char *, int);
int renameat(int, const char *, int, const char *);
int mkfifoat(int, const char *, mode_t);
@ -303,11 +304,13 @@ int mkdirat(int, const char *, mode_t);
int faccessat(int, const char *, int, int);
int fchmodat(int, const char *, mode_t, int);
int fchownat(int, const char *, uid_t, gid_t, int);
int fexecve(int, char * const *, char * const *);
int readlinkat(int, const char *, char *, size_t);
int symlinkat(const char *, int, const char *);
int unlinkat(int, const char *, int);
#endif
#if defined(_INCOMPLETE_XOPEN_C063) || defined(_KERNEL)
int fexecve(int, char * const *, char * const *);
#endif
/*

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile.inc,v 1.217 2012/10/02 01:46:40 christos Exp $
# $NetBSD: Makefile.inc,v 1.218 2012/11/18 17:41:53 manu Exp $
# @(#)Makefile.inc 8.3 (Berkeley) 10/24/94
# sys sources
@ -275,7 +275,11 @@ MLINKS+=extattr_get_file.2 extattr_set_file.2 \
extattr_get_file.2 extattr_set_link.2 \
extattr_get_file.2 extattr_delete_link.2 \
extattr_get_file.2 extattr_list_link.2
MLINKS+=access.2 faccessat.2
MLINKS+=chmod.2 fchmodat.2
MLINKS+=chown.2 fchownat.2
MLINKS+=fhopen.2 fhstat.2 fhopen.2 fhstatvfs.2 fhopen.2 fhstatvfs1.2
MLINKS+=stat.2 fstatat.2
MLINKS+=fsync.2 fsync_range.2
MLINKS+=getcontext.2 setcontext.2
MLINKS+=getgid.2 getegid.2
@ -299,18 +303,25 @@ MLINKS+=_lwp_getprivate.2 _lwp_setprivate.2
MLINKS+=madvise.2 posix_madvise.2
MLINKS+=mlock.2 munlock.2
MLINKS+=mlockall.2 munlockall.2
MLINKS+=mkdir.2 mkdirat.2
MLINKS+=mkfifo.2 mkfifoat.2
MLINKS+=mknod.2 mknodat.2
MLINKS+=mount.2 unmount.2
MLINKS+=open.2 openat.2
MLINKS+=ntp_adjtime.2 ntp_gettime.2
MLINKS+=pathconf.2 fpathconf.2
MLINKS+=pmc_control.2 pmc_get_info.2
MLINKS+=poll.2 pollts.2
MLINKS+=read.2 readv.2 read.2 pread.2 read.2 preadv.2
MLINKS+=readlink.2 readlinkat.2
MLINKS+=recv.2 recvfrom.2 recv.2 recvmsg.2 recv.2 recvmmsg.2
MLINKS+=rename.2 renameat.2
MLINKS+=select.2 pselect.2
MLINKS+=send.2 sendmsg.2 send.2 sendto.2 send.2 sendmmsg.2
MLINKS+=setpgid.2 setpgrp.2
MLINKS+=setuid.2 setegid.2 setuid.2 seteuid.2 setuid.2 setgid.2
MLINKS+=shmat.2 shmdt.2
MLINKS+=symlink.2 symlinkat.2
MLINKS+=timer_settime.2 timer_gettime.2 timer_settime.2 timer_getoverrun.2
MLINKS+=sigqueue.2 sigqueueinfo.2
MLINKS+=sigtimedwait.2 sigwaitinfo.2
@ -321,6 +332,7 @@ MLINKS+=statvfs.2 statvfs1.2
MLINKS+=statvfs.2 fstatvfs1.2
MLINKS+=syscall.2 __syscall.2
MLINKS+=truncate.2 ftruncate.2
MLINKS+=unlink.2 unlinkat.2
MLINKS+=utimes.2 futimes.2 utimes.2 lutimes.2
MLINKS+=utimes.2 futimens.2 utimes.2 utimensat.2
MLINKS+=wait.2 wait3.2 wait.2 wait4.2 wait.2 waitpid.2

View File

@ -1,4 +1,4 @@
.\" $NetBSD: access.2,v 1.26 2010/05/03 05:53:56 jruoho Exp $
.\" $NetBSD: access.2,v 1.27 2012/11/18 17:41:53 manu Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -33,7 +33,8 @@
.Dt ACCESS 2
.Os
.Sh NAME
.Nm access
.Nm access ,
.Nm faccessat
.Nd check access permissions of a file or pathname
.Sh LIBRARY
.Lb libc
@ -41,6 +42,9 @@
.In unistd.h
.Ft int
.Fn access "const char *path" "int mode"
.In fcntl.h
.Ft int
.Fn faccessat "int fd" "const char *path" "int mode" "int flag"
.Sh DESCRIPTION
The
.Fn access
@ -65,10 +69,34 @@ All components of the pathname
are checked for access permissions (including
.Dv F_OK ) .
.Pp
.Fn faccessat
works the same way as
.Fn access
except if
.Fa path
is relative. In that case, it is looked up from a directory whose file
descriptor was passed as
.Fa fd .
Search permission is required on
.Fa fd
except if that file descriptor was open with
.Dv O_SEARCH
option.
.Fa fd
can be set to
.Dv AT_FDCWD
in order to specify current directory.
.Pp
The real user ID is used in place of the effective user ID
and the real group access list
(including the real group ID) are
used in place of the effective ID for verifying permission.
.Fn faccessat
can use
effective user ID and effective group ID if the
.Dv AT_EACCESS
is passed in
.Fa flag .
.Pp
If a process has super-user privileges and indicates success for
.Dv R_OK
@ -136,6 +164,9 @@ The
.Fn access
function conforms to
.St -p1003.1-90 .
.Fn faccessat
function conforms to
.St -p1003.1-2008 .
.Sh SECURITY CONSIDERATIONS
The
.Fn access

View File

@ -1,4 +1,4 @@
.\" $NetBSD: chmod.2,v 1.40 2012/03/04 11:58:31 wiz Exp $
.\" $NetBSD: chmod.2,v 1.41 2012/11/18 17:41:53 manu Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -35,7 +35,8 @@
.Sh NAME
.Nm chmod ,
.Nm lchmod ,
.Nm fchmod
.Nm fchmod ,
.Nm fchmodat
.Nd change mode of file
.Sh LIBRARY
.Lb libc
@ -47,6 +48,9 @@
.Fn lchmod "const char *path" "mode_t mode"
.Ft int
.Fn fchmod "int fd" "mode_t mode"
.In fcntl.h
.Ft int
.Fn fchmodat "int fd" "const char *path" "mode_t mode" "int flag"
.Sh DESCRIPTION
The function
.Fn chmod
@ -70,6 +74,31 @@ sets the permission bits of the link,
while
.Fn chmod
sets the bits of the file the link references.
.Pp
.Fn fchmodat
works the same way as
.Fn chmod
(or
.Fn lchmod
if
.Dv AT_SYMLINK_NOFOLLOW
is set in
.Fa flag )
except if
.Fa path
is relative. In that case, it is looked up from a directory whose file
descriptor was passed as
.Fa fd .
Search permission is required on
.Fa fd
except if that file descriptor was open with
.Dv O_SEARCH
option.
.Fa fd
can be set to
.Dv AT_FDCWD
in order to specify current directory.
.Pp
.Fn chmod
verifies that the process owner (user) either owns
the file specified by
@ -225,6 +254,9 @@ The
.Fn chmod
function conforms to
.St -p1003.1-90 .
.Fn fchmodat
function conforms to
.St -p1003.1-2008 .
.Sh HISTORY
The
.Fn fchmod

View File

@ -1,4 +1,4 @@
.\" $NetBSD: chown.2,v 1.31 2010/05/31 12:16:20 njoly Exp $
.\" $NetBSD: chown.2,v 1.32 2012/11/18 17:41:53 manu Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993, 1994
.\" The Regents of the University of California. All rights reserved.
@ -35,7 +35,8 @@
.Sh NAME
.Nm chown ,
.Nm lchown ,
.Nm fchown
.Nm fchown ,
.Nm fchownat
.Nd change owner and group of a file
.Sh LIBRARY
.Lb libc
@ -47,6 +48,9 @@
.Fn lchown "const char *path" "uid_t owner" "gid_t group"
.Ft int
.Fn fchown "int fd" "uid_t owner" "gid_t group"
.In fcntl.h
.Ft int
.Fn fchownat "int fd" "const char *path" "uid_t owner" "gid_t group" "int flag"
.Sh DESCRIPTION
The owner ID and group ID of the file
named by
@ -99,6 +103,30 @@ changes the owner and group of the file the link references.
is particularly useful when used in conjunction
with the file locking primitives (see
.Xr flock 2 ) .
.Pp
.Fn fchownat
works the same way as
.Fn chown
(or
.Fn lchown
if
.Dv AT_SYMLINK_NOFOLLOW
is set in
.Fa flag )
except if
.Fa path
is relative. In that case, it is looked up from a directory whose file
descriptor was passed as
.Fa fd .
Search permission is required on
.Fa fd
except if that file descriptor was open with
.Dv O_SEARCH
option.
.Fa fd
can be set to
.Dv AT_FDCWD
in order to specify current directory.
.Pp
One of the owner or group id's
may be left unchanged by specifying it as (uid_t)\-1 or (gid_t)\-1 respectively.
@ -175,6 +203,9 @@ and
functions, as defined by
.St -xpg4.2 ,
provide the same semantics.
.Fn fchownat
conforms to
.St -p1003.1-2008 .
.Pp
To retain conformance to these standards, compatibility interfaces
are provided by the

View File

@ -1,4 +1,4 @@
.\" $NetBSD: link.2,v 1.26 2011/08/08 19:50:17 wiz Exp $
.\" $NetBSD: link.2,v 1.27 2012/11/18 17:41:53 manu Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993, 2011
.\" The Regents of the University of California. All rights reserved.
@ -41,6 +41,7 @@
.In unistd.h
.Ft int
.Fn link "const char *name1" "const char *name2"
.In fcntl.h
.Ft int
.Fn linkat "int fd1" "const char *name1" "int fd2" "const char *name2" "int flags"
.Sh DESCRIPTION
@ -79,6 +80,30 @@ must be in the same file system.
.Fa name1
may not be a directory unless the caller is the super-user
and the file system containing it supports linking to directories.
.Pp
.Fn linkat
works the same way as
.Fn link
except if
.Fa name1
(resp.
.Fa name2 )
is relative. In that case, it is looked up from a directory whose file
descriptor was passed as
.Fa fd1
(resp.
.Fa fd2 ).
Search permission is required on
passed directory file descriptors
except if they were open with the
.Dv O_SEARCH
option.
.Fa fd1
or
.Fa fd2
can be set to
.Dv AT_FDCWD
in order to specify current directory.
.Pp
When operating on a symlink,
.Fn link
@ -89,18 +114,6 @@ will do the same if
is set in
.Fa flags ,
but it will link on the symlink itself if the flag is clear.
.Pp
At the moment,
.Fn linkat
is partially implemented.
It will return
.Er ENOSYS
for
.Fa fd1
and
.Fa fd2
values different than
.Dv AT_FDCWD .
.Sh RETURN VALUES
Upon successful completion, a value of 0 is returned.
Otherwise, a value of \-1 is returned and
@ -183,6 +196,7 @@ The
.Fn link
function conforms to
.St -p1003.1-90 .
.Sh BUGS
.Fn linkat
is partially implemented.
conforms to
.St -p1003.1-2008 .

View File

@ -1,4 +1,4 @@
.\" $NetBSD: mkdir.2,v 1.24 2010/05/31 12:16:20 njoly Exp $
.\" $NetBSD: mkdir.2,v 1.25 2012/11/18 17:41:53 manu Exp $
.\"
.\" Copyright (c) 1983, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -33,7 +33,8 @@
.Dt MKDIR 2
.Os
.Sh NAME
.Nm mkdir
.Nm mkdir ,
.Nm mkdirat
.Nd make a directory file
.Sh LIBRARY
.Lb libc
@ -41,6 +42,8 @@
.In sys/stat.h
.Ft int
.Fn mkdir "const char *path" "mode_t mode"
.Ft int
.Fn mkdirat "int fd" "const char *path" "mode_t mode"
.Sh DESCRIPTION
The directory
.Fa path
@ -50,6 +53,24 @@ and restricted by the
.Xr umask 2
of the calling process.
.Pp
.Fn mkdirat
works the same way as
.Fn mkdir
except if
.Fa path
is relative. In that case, it is looked up from a directory whose file
descriptor was passed as
.Fa fd .
Search permission is required on
.Fa fd
except if that file descriptor was open with
.Dv O_SEARCH
option.
.Fa fd
can be set to
.Dv AT_FDCWD
in order to specify current directory.
.Pp
The directory's owner ID is set to the process's effective user ID.
The directory's group ID is set to that of the parent directory in
which it is created.
@ -109,3 +130,7 @@ The
.Fn mkdir
function conforms to
.St -p1003.1-90 .
.Fn mkdirat
conforms to
.St -p1003.1-2008 .

View File

@ -1,4 +1,4 @@
.\" $NetBSD: mkfifo.2,v 1.20 2010/05/31 12:16:20 njoly Exp $
.\" $NetBSD: mkfifo.2,v 1.21 2012/11/18 17:41:53 manu Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -33,7 +33,8 @@
.Dt MKFIFO 2
.Os
.Sh NAME
.Nm mkfifo
.Nm mkfifo ,
.Nm mkfifoat
.Nd make a fifo file
.Sh LIBRARY
.Lb libc
@ -41,6 +42,8 @@
.In sys/stat.h
.Ft int
.Fn mkfifo "const char *path" "mode_t mode"
.Ft int
.Fn mkfifoat "int fd" "const char *path" "mode_t mode"
.Sh DESCRIPTION
.Fn mkfifo
creates a new fifo file with name
@ -52,6 +55,24 @@ and restricted by the
.Xr umask 2
of the calling process.
.Pp
.Fn mkfifoat
works the same way as
.Fn mkfifo
except if
.Fa path
is relative. In that case, it is looked up from a directory whose file
descriptor was passed as
.Fa fd .
Search permission is required on
.Fa fd
except if that file descriptor was open with
.Dv O_SEARCH
option.
.Fa fd
can be set to
.Dv AT_FDCWD
in order to specify current directory.
.Pp
The fifo's owner ID is set to the process's effective user ID.
The fifo's group ID is set to that of the parent directory in
which it is created.
@ -119,3 +140,7 @@ The
.Nm mkfifo
function call conforms to
.St -p1003.1-90 .
.Fn mkfifoat
conforms to
.St -p1003.1-2008 .

View File

@ -1,4 +1,4 @@
.\" $NetBSD: mknod.2,v 1.22 2011/07/08 19:25:51 wiz Exp $
.\" $NetBSD: mknod.2,v 1.23 2012/11/18 17:41:53 manu Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -33,7 +33,8 @@
.Dt MKNOD 2
.Os
.Sh NAME
.Nm mknod
.Nm mknod ,
.Nm mknodat
.Nd make a special file node
.Sh LIBRARY
.Lb libc
@ -41,6 +42,8 @@
.In sys/stat.h
.Ft int
.Fn mknod "const char *path" "mode_t mode" "dev_t dev"
.Ft int
.Fn mknodat "int fd" "const char *path" "mode_t mode" "dev_t dev"
.Sh DESCRIPTION
The device special file
.Fa path
@ -55,6 +58,24 @@ modified by the
.Xr umask 2
of the parent process.
.Pp
.Fn mknodat
works the same way as
.Fn mknod
except if
.Fa path
is relative. In that case, it is looked up from a directory whose file
descriptor was passed as
.Fa fd .
Search permission is required on
.Fa fd
except if that file descriptor was open with
.Dv O_SEARCH
option.
.Fa fd
can be set to
.Dv AT_FDCWD
in order to specify current directory.
.Pp
.Fn mknod
requires super-user privileges.
.Sh RETURN VALUES
@ -116,6 +137,14 @@ The named file resides on a read-only file system.
.Xr mkfifo 2 ,
.Xr stat 2 ,
.Xr umask 2
.Sh STANDARDS
The
.Fn mknod
function conforms to
.St -p1003.1-90 .
.Fn mknodat
conforms to
.St -p1003.1-2008 .
.Sh HISTORY
A
.Fn mknod

View File

@ -1,4 +1,4 @@
.\" $NetBSD: open.2,v 1.51 2012/01/25 00:28:35 christos Exp $
.\" $NetBSD: open.2,v 1.52 2012/11/18 17:41:53 manu Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -33,7 +33,8 @@
.Dt OPEN 2
.Os
.Sh NAME
.Nm open
.Nm open ,
.Nm openat
.Nd open or create a file for reading or writing
.Sh LIBRARY
.Lb libc
@ -41,6 +42,8 @@
.In fcntl.h
.Ft int
.Fn open "const char *path" "int flags" "..."
.Ft int
.Fn openat "int fd" "const char *path" "int flags" "..."
.Sh DESCRIPTION
The file name specified by
.Fa path
@ -49,6 +52,25 @@ for reading and/or writing as specified by the
argument
.Fa flags
and the file descriptor returned to the calling process.
.Pp
.Fn openat
works the same way as
.Fn open
except if
.Fa path
is relative. In that case, it is looked up from a directory whose file
descriptor was passed as
.Fa fd .
Search permission is required on
.Fa fd
except if that file descriptor was open with
.Dv O_SEARCH
option.
.Fa fd
can be set to
.Dv AT_FDCWD
in order to specify current directory.
.Pp
The
.Fa flags
are specified by
@ -164,6 +186,23 @@ Enable the
signal to be sent to the process group
when I/O is possible, e.g.,
upon availability of data to be read.
.It Dv O_SEARCH
If opening a directory, search permission check will not be performed on
subsequent usage of the file descriptor for looking up relative paths by
.Xr faccessat 2 ,
.Xr fchmodat 2 ,
.Xr fchownat 2 ,
.Xr fstatat 2 ,
.Xr linkat 2 ,
.Xr mkdirat 2 ,
.Xr mkfifoat 2 ,
.Xr mknodat 2 ,
.Xr openat 2 ,
.Xr readlinkat 2 ,
.Xr symlinkat 2 ,
.Xr unlinkat 2 ,
and
.Xr utimensat 2 .
.El
.Pp
Opening a file with
@ -361,9 +400,22 @@ call requests write access.
.Xr chmod 2 ,
.Xr close 2 ,
.Xr dup 2 ,
.Xr faccessat 2 ,
.Xr fchmodat 2 ,
.Xr fchownat 2 ,
.Xr fstatat 2 ,
.Xr linkat 2 ,
.Xr lseek 2 ,
.Xr mkdirat 2 ,
.Xr mkfifoat 2 ,
.Xr mknodat 2 ,
.Xr openat 2 ,
.Xr read 2 ,
.Xr readlinkat 2 ,
.Xr symlinkat 2 ,
.Xr umask 2 ,
.Xr unlinkat 2 ,
.Xr utimensat 2 ,
.Xr write 2 ,
.Xr getdtablesize 3
.Sh STANDARDS
@ -371,6 +423,10 @@ The
.Fn open
function conforms to
.St -p1003.1-90 .
.Fn openat
conforms to
.St -p1003.1-2008 .
.Pp
The
.Fa flags
values
@ -380,6 +436,9 @@ and
.Dv O_RSYNC
are extensions defined in
.St -p1003.1b-93 .
.Dv O_SEARCH
is defined in
.St -p1003.1-2008
.Pp
The
.Dv O_SHLOCK

View File

@ -1,4 +1,4 @@
.\" $NetBSD: readlink.2,v 1.26 2010/05/31 12:16:20 njoly Exp $
.\" $NetBSD: readlink.2,v 1.27 2012/11/18 17:41:53 manu Exp $
.\"
.\" Copyright (c) 1983, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -33,7 +33,8 @@
.Dt READLINK 2
.Os
.Sh NAME
.Nm readlink
.Nm readlink ,
.Nm readlinkat
.Nd read value of a symbolic link
.Sh LIBRARY
.Lb libc
@ -41,6 +42,9 @@
.In unistd.h
.Ft ssize_t
.Fn readlink "const char * restrict path" "char * restrict buf" "size_t bufsiz"
.Ft ssize_t
.Fn readlinkat "int fd" "const char * restrict path" "char * restrict buf"\
"size_t bufsiz"
.Sh DESCRIPTION
.Fn readlink
places the contents of the symbolic link
@ -54,6 +58,24 @@ does not append a
.Dv NUL
character to
.Fa buf .
.Pp
.Fn readlinkat
works the same way as
.Fn readlink
except if
.Fa path
is relative. In that case, it is looked up from a directory whose file
descriptor was passed as
.Fa fd .
Search permission is required on
.Fa fd
except if that file descriptor was open with
.Dv O_SEARCH
option.
.Fa fd
can be set to
.Dv AT_FDCWD
in order to specify current directory.
.Sh RETURN VALUES
The call returns the count of characters placed in the buffer
if it succeeds, or a \-1 if an error occurs, placing the error
@ -111,6 +133,9 @@ The
.Fn readlink
function conforms to
.St -p1003.1-2001 .
.Fn readlinkat
conforms to
.St -p1003.1-2008 .
.Sh HISTORY
The
.Fn readlink

View File

@ -1,4 +1,4 @@
.\" $NetBSD: rename.2,v 1.23 2010/05/31 12:16:20 njoly Exp $
.\" $NetBSD: rename.2,v 1.24 2012/11/18 17:41:53 manu Exp $
.\"
.\" Copyright (c) 1983, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -33,7 +33,8 @@
.Dt RENAME 2
.Os
.Sh NAME
.Nm rename
.Nm rename ,
.Nm renameat ,
.Nd change the name of a file
.Sh LIBRARY
.Lb libc
@ -41,6 +42,8 @@
.In stdio.h
.Ft int
.Fn rename "const char *from" "const char *to"
.Ft int
.Fn rename "int fromfd" "const char *from" "int tofd" "const char *to"
.Sh DESCRIPTION
.Fn rename
causes the link named
@ -76,6 +79,30 @@ and
are pathnames of the same existing file in the file system's name space,
.Fn rename
returns successfully and performs no other action.
.Pp
.Fn renameat
works the same way as
.Fn rename
except if
.Fa from
(resp.
.Fa to )
is relative. In that case, it is looked up from a directory whose file
descriptor was passed as
.Fa fromfd
(resp.
.Fa tofd ).
Search permission is required on
passed directory file descriptors
except if they were open with the
.Dv O_SEARCH
option.
.Fa fromfd
or
.Fa tofd
can be set to
.Dv AT_FDCWD
in order to specify current directory.
.Sh RETURN VALUES
A 0 value is returned if the operation succeeds, otherwise
.Fn rename
@ -213,6 +240,9 @@ function conforms to
.St -p1003.1-90
and
.St -xpg4.2 .
.Fn renameat
conforms to
.St -p1003.1-2008 .
.Sh BUGS
The system can deadlock if a loop in the file system graph is present.
This loop takes the form of an entry in directory

View File

@ -1,4 +1,4 @@
.\" $NetBSD: stat.2,v 1.50 2012/01/04 10:53:39 wiz Exp $
.\" $NetBSD: stat.2,v 1.51 2012/11/18 17:41:53 manu Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993, 1994
.\" The Regents of the University of California. All rights reserved.
@ -35,7 +35,8 @@
.Sh NAME
.Nm stat ,
.Nm lstat ,
.Nm fstat
.Nm fstat ,
.Nm fstatat ,
.Nd get file status
.Sh LIBRARY
.Lb libc
@ -47,6 +48,8 @@
.Fn lstat "const char *path" "struct stat *sb"
.Ft int
.Fn fstat "int fd" "struct stat *sb"
.Ft int
.Fn fstatat "int fd" "const char *path" "struct stat *sb" "int flag"
.Sh DESCRIPTION
The
.Fn stat
@ -72,6 +75,30 @@ The
function obtains the same information about an open file
known by the file descriptor
.Fa fd .
.Pp
.Fn fstatat
works the same way as
.Fn stat
(or
.Fn lstat
if
.Dv AT_SYMLINK_NOFOLLOW
is set in
.Fa flag )
except if
.Fa path
is relative. In that case, it is looked up from a directory whose file
descriptor was passed as
.Fa fd .
Search permission is required on
.Fa fd
except if that file descriptor was open with
.Dv O_SEARCH
option.
.Fa fd
can be set to
.Dv AT_FDCWD
in order to specify current directory.
.Pp
The
.Fa sb
@ -340,8 +367,16 @@ An I/O error occurred while reading from or writing to the file system.
.Xr types 3 ,
.Xr symlink 7
.Sh STANDARDS
The described functions conform to
.Fn stat ,
.Fn lstat ,
and
.Fn fstat
conform to
.St -p1003.1-2004 .
.Fn fstatat
conforms to
.St -p1003.1-2008 .
.Sh HISTORY
A
.Fn stat

View File

@ -1,4 +1,4 @@
.\" $NetBSD: symlink.2,v 1.20 2010/05/31 12:16:20 njoly Exp $
.\" $NetBSD: symlink.2,v 1.21 2012/11/18 17:41:53 manu Exp $
.\"
.\" Copyright (c) 1983, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -33,7 +33,8 @@
.Dt SYMLINK 2
.Os
.Sh NAME
.Nm symlink
.Nm symlink ,
.Nm symlinkat
.Nd make symbolic link to a file
.Sh LIBRARY
.Lb libc
@ -41,6 +42,8 @@
.In unistd.h
.Ft int
.Fn symlink "const char *name1" "const char *name2"
.Ft int
.Fn symlinkat "const char *name1" "int fd" "const char *name2"
.Sh DESCRIPTION
A symbolic link
.Fa name2
@ -54,6 +57,24 @@ is the string
used in creating the symbolic link).
Either name may be an arbitrary path name; the files need neither
to be on the same file system nor to exist.
.Pp
.Fn symlinkat
works the same way as
.Fn symlink
except if
.Fa path2
is relative. In that case, it is looked up from a directory whose file
descriptor was passed as
.Fa fd .
Search permission is required on
.Fa fd
except if that file descriptor was open with
.Dv O_SEARCH
option.
.Fa fd
can be set to
.Dv AT_FDCWD
in order to specify current directory.
.Sh RETURN VALUES
Upon successful completion, a zero value is returned.
If an error occurs, the error code is stored in
@ -133,6 +154,14 @@ points outside the process's allocated address space.
.Xr readlink 2 ,
.Xr unlink 2 ,
.Xr symlink 7
.Sh STANDARDS
The
.Fn symlink
function conforms to
.St -p1003.1-90 .
.Fn symlinkat
conforms to
.St -p1003.1-2008 .
.Sh HISTORY
The
.Fn symlink

View File

@ -1,4 +1,4 @@
.\" $NetBSD: unlink.2,v 1.23 2010/05/31 12:16:20 njoly Exp $
.\" $NetBSD: unlink.2,v 1.24 2012/11/18 17:41:53 manu Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -33,7 +33,8 @@
.Dt UNLINK 2
.Os
.Sh NAME
.Nm unlink
.Nm unlink ,
.Nm unlinkat ,
.Nd remove directory entry
.Sh LIBRARY
.Lb libc
@ -41,6 +42,9 @@
.In unistd.h
.Ft int
.Fn unlink "const char *path"
.In fcntl.h
.Ft int
.Fn unlinkat "int fd" "const char *path" "int flag"
.Sh DESCRIPTION
The
.Fn unlink
@ -56,6 +60,32 @@ all resources associated with the file are reclaimed.
If one or more process have the file open when the last link is removed,
the link is removed, but the removal of the file is delayed until
all references to it have been closed.
.Pp
.Fn unlinkat
works the same way as
.Fn unlink
except if
.Fa path
is relative. In that case, it is looked up from a directory whose file
descriptor was passed as
.Fa fd .
Search permission is required on
.Fa fd
except if that file descriptor was open with
.Dv O_SEARCH
option.
.Fa fd
can be set to
.Dv AT_FDCWD
in order to specify current directory.
.Pp
.Fn unlinkat
will remove directories just like
.Fn rmdir
provided
.Dv AT_REMOVEDIR
is set in
.Fa flag .
.Sh RETURN VALUES
Upon successful completion, a value of 0 is returned.
Otherwise, a value of \-1 is returned and
@ -113,6 +143,9 @@ The
.Fn unlink
function conforms to
.St -p1003.1-90 .
.Fn unlinkat
conforms to
.St -p1003.1-2008 .
.Sh HISTORY
An
.Fn unlink

View File

@ -1,4 +1,4 @@
.\" $NetBSD: utimes.2,v 1.32 2012/11/04 10:57:33 wiz Exp $
.\" $NetBSD: utimes.2,v 1.33 2012/11/18 17:41:53 manu Exp $
.\"
.\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@ -57,8 +57,10 @@
.Fn futimes "int fd" "const struct timeval times[2]"
.Ft int
.Fn futimens "int fd" "const struct timespec times[2]"
.In fcntl
.Ft int
.Fn utimensat "int fd" "const char *path" "const struct timespec times[2]" "int flag"
.Fn utimensat "int fd" "const char *path" "const struct timespec times[2]" \
"int flag"
.Sh DESCRIPTION
The access and modification times of the file named by
.Fa path
@ -119,15 +121,30 @@ respectively except that time is specified with nanosecond instead of
microsecond precision.
.Pp
.Fn utimensat
also allows time to be specifed with nanoseconds.
When it operates on a symbolic link, it will change the target's time if
.Ar follow
is unset.
If
.Ar follow
is set to
.Dv AT_SYMLINK_NOFOLLOW ,
the symbolic link's dates are changed.
works the same way as
.Fn utimens
except if
.Fa path
is relative. In that case, it is looked up from a directory whose file
descriptor was passed as
.Fa fd .
Search permission is required on
.Fa fd
except if that file descriptor was open with
.Dv O_SEARCH
option.
.Fa fd
can be set to
.Dv AT_FDCWD
in order to specify current directory.
.Pp
When it operates on a symbolic link,
.Fn utimensat
will change the target's time unless
.Dv AT_SYMLINK_NOFOLLOW
is set in
.Fa flag .
In that later case, the symbolic link's dates are changed.
.Pp
The nanosecond fields for
.Fn utimens ,
@ -141,15 +158,6 @@ to set the current time, or to
.Dv UTIME_OMIT
to let the time unchanged (this allows changing access time but not
modification time, and vice-versa).
.Pp
.Fn utimensat
is partially implemented.
It will return
.Er ENOSYS
for
.Fa fd
values different than
.Dv AT_FDCWD .
.Sh RETURN VALUES
Upon successful completion, a value of 0 is returned.
Otherwise, a value of \-1 is returned and
@ -271,6 +279,3 @@ and
.Fn utimensat
functions calls appreared in
.Nx 6.0 .
.Sh BUGS
.Fn utimensat
is partially implemented.

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_lookup.c,v 1.199 2012/11/05 21:35:28 para Exp $ */
/* $NetBSD: vfs_lookup.c,v 1.200 2012/11/18 17:41:53 manu Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_lookup.c,v 1.199 2012/11/05 21:35:28 para Exp $");
__KERNEL_RCSID(0, "$NetBSD: vfs_lookup.c,v 1.200 2012/11/18 17:41:53 manu Exp $");
#include "opt_magiclinks.h"
@ -677,6 +677,10 @@ namei_start(struct namei_state *state, int isnfsd,
namei_ktrace(state);
}
/* NDAT may feed us with a non directory namei_getstartdir */
if (startdir->v_type != VDIR)
return ENOTDIR;
vn_lock(startdir, LK_EXCLUSIVE | LK_RETRY);
*startdir_ret = startdir;
@ -1793,7 +1797,14 @@ namei_simple_convert_flags(namei_simple_flags_t sflags)
int
namei_simple_kernel(const char *path, namei_simple_flags_t sflags,
struct vnode **vp_ret)
struct vnode **vp_ret)
{
return nameiat_simple_kernel(NULL, path, sflags, vp_ret);
}
int
nameiat_simple_kernel(struct vnode *dvp, const char *path,
namei_simple_flags_t sflags, struct vnode **vp_ret)
{
struct nameidata nd;
struct pathbuf *pb;
@ -1808,6 +1819,10 @@ namei_simple_kernel(const char *path, namei_simple_flags_t sflags,
LOOKUP,
namei_simple_convert_flags(sflags),
pb);
if (dvp != NULL)
NDAT(&nd, dvp);
err = namei(&nd);
if (err != 0) {
pathbuf_destroy(pb);
@ -1820,7 +1835,14 @@ namei_simple_kernel(const char *path, namei_simple_flags_t sflags,
int
namei_simple_user(const char *path, namei_simple_flags_t sflags,
struct vnode **vp_ret)
struct vnode **vp_ret)
{
return nameiat_simple_user(NULL, path, sflags, vp_ret);
}
int
nameiat_simple_user(struct vnode *dvp, const char *path,
namei_simple_flags_t sflags, struct vnode **vp_ret)
{
struct pathbuf *pb;
struct nameidata nd;
@ -1835,6 +1857,10 @@ namei_simple_user(const char *path, namei_simple_flags_t sflags,
LOOKUP,
namei_simple_convert_flags(sflags),
pb);
if (dvp != NULL)
NDAT(&nd, dvp);
err = namei(&nd);
if (err != 0) {
pathbuf_destroy(pb);

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* $NetBSD: fcntl.h,v 1.42 2012/01/25 00:28:35 christos Exp $ */
/* $NetBSD: fcntl.h,v 1.43 2012/11/18 17:41:54 manu Exp $ */
/*-
* Copyright (c) 1983, 1990, 1993
@ -114,7 +114,8 @@
#define O_DIRECTORY 0x00200000 /* fail if not a directory */
#define O_CLOEXEC 0x00400000 /* set close on exec */
#if defined(_INCOMPLETE_XOPEN_C063) || defined(_KERNEL)
#if (_POSIX_C_SOURCE - 0) >= 200809L || (_XOPEN_SOURCE - 0 >= 700) || \
defined(_INCOMPLETE_XOPEN_C063) || defined(_KERNEL)
#define O_SEARCH 0x00800000 /* skip search permission checks */
#endif
#if defined(_NETBSD_SOURCE)
@ -130,7 +131,7 @@
#define O_MASK (O_ACCMODE|O_NONBLOCK|O_APPEND|O_SHLOCK|O_EXLOCK|\
O_ASYNC|O_SYNC|O_CREAT|O_TRUNC|O_EXCL|O_DSYNC|\
O_RSYNC|O_NOCTTY|O_ALT_IO|O_NOFOLLOW|O_DIRECT|\
O_DIRECTORY|O_CLOEXEC|O_NOSIGPIPE)
O_DIRECTORY|O_CLOEXEC|O_NOSIGPIPE|O_SEARCH)
#define FMARK 0x00001000 /* mark during gc() */
#define FDEFER 0x00002000 /* defer for next gc pass */
@ -140,7 +141,7 @@
#define FKIOCTL 0x80000000 /* kernel originated ioctl */
/* bits settable by fcntl(F_SETFL, ...) */
#define FCNTLFLAGS (FAPPEND|FASYNC|FFSYNC|FNONBLOCK|FDSYNC|FRSYNC|FALTIO|\
FDIRECT|FNOSIGPIPE)
FDIRECT|FNOSIGPIPE|FSEARCH)
/* bits to save after open(2) */
#define FMASK (FREAD|FWRITE|FCNTLFLAGS)
#endif /* _KERNEL */
@ -165,6 +166,7 @@
#define FRSYNC O_RSYNC /* kernel */
#define FALTIO O_ALT_IO /* kernel */
#define FDIRECT O_DIRECT /* kernel */
#define FSEARCH O_SEARCH /* kernel */
#endif
/*
@ -289,7 +291,8 @@ struct flock {
/*
* Constants for X/Open Extended API set 2 (a.k.a. C063)
*/
#if defined(_INCOMPLETE_XOPEN_C063) || defined(_KERNEL)
#if (_POSIX_C_SOURCE - 0) >= 200809L || (_XOPEN_SOURCE - 0 >= 700) || \
defined(_INCOMPLETE_XOPEN_C063) || defined(_KERNEL)
#define AT_FDCWD -100 /* Use cwd for relative link target */
#define AT_EACCESS 0x100 /* Use euig/egid for access checks */
#define AT_SYMLINK_NOFOLLOW 0x200 /* Do not follow symlinks */

View File

@ -1,4 +1,4 @@
/* $NetBSD: namei.h,v 1.85 2012/11/05 19:06:39 dholland Exp $ */
/* $NetBSD: namei.h,v 1.86 2012/11/18 17:41:54 manu Exp $ */
/*
@ -233,7 +233,7 @@ extern pool_cache_t pnbuf_cache; /* pathname buffer cache */
#define PNBUF_PUT(pnb) pool_cache_put(pnbuf_cache, (pnb))
/*
* Typesafe flags for namei_simple.
* Typesafe flags for namei_simple/nameiat_simple.
*
* This encoding is not optimal but serves the important purpose of
* not being type-compatible with the regular namei flags.
@ -247,11 +247,13 @@ extern const namei_simple_flags_t
NSM_FOLLOW_TRYEMULROOT;
/*
* namei_simple_* - the simple cases of namei, with no struct
* nameidata involved.
* namei(at)?_simple_* - the simple cases of namei, with no struct
* nameidata involved.
*
* namei_simple_kernel takes a kernel-space path as the first argument.
* namei_simple_user takes a user-space path as the first argument.
* The nameiat_simple_* variants handle relative path using the given
* directory vnode instead of current directory.
*
* A namei call can be converted to namei_simple_* if:
* - the second arg to NDINIT is LOOKUP;
@ -261,6 +263,10 @@ extern const namei_simple_flags_t
*/
int namei_simple_kernel(const char *, namei_simple_flags_t, struct vnode **);
int namei_simple_user(const char *, namei_simple_flags_t, struct vnode **);
int nameiat_simple_kernel(struct vnode *, const char *, namei_simple_flags_t,
struct vnode **);
int nameiat_simple_user(struct vnode *, const char *, namei_simple_flags_t,
struct vnode **);
int namei(struct nameidata *);
uint32_t namei_hash(const char *, const char **);

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.43 2012/09/27 00:38:57 joerg Exp $
# $NetBSD: Makefile,v 1.44 2012/11/18 17:41:54 manu Exp $
.include "Makefile.inc"
.include <bsd.sys.mk>
@ -6,7 +6,7 @@
SUBDIR+= tls_dso .WAIT
TESTS_SUBDIRS+= db gen hash inet locale net regex rpc setjmp stdlib
TESTS_SUBDIRS+= c063 db gen hash inet locale net regex rpc setjmp stdlib
TESTS_SUBDIRS+= stdio string sys termios time tls ttyio
.if ${HAS_SSP} == "yes"

View File

@ -0,0 +1,26 @@
# $NetBSD: Makefile,v 1.1 2012/11/18 17:41:54 manu Exp $
.include <bsd.own.mk>
TESTSDIR= ${TESTSBASE}/lib/libc/c063
TESTS_C+= t_faccessat
TESTS_C+= t_fchmodat
TESTS_C+= t_fchownat
TESTS_C+= t_fexecve
TESTS_C+= t_fstatat
TESTS_C+= t_linkat
TESTS_C+= t_mkdirat
TESTS_C+= t_mkfifoat
TESTS_C+= t_mknodat
TESTS_C+= t_o_search
TESTS_C+= t_openat
TESTS_C+= t_readlinkat
TESTS_C+= t_renameat
TESTS_C+= t_symlinkat
TESTS_C+= t_unlinkat
TESTS_C+= t_utimensat
COPTS+= -D_INCOMPLETE_XOPEN_C063
.include <bsd.test.mk>

View File

@ -0,0 +1,241 @@
/* $NetBSD: t_faccessat.c,v 1.1 2012/11/18 17:41:54 manu Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Emmanuel Dreyfus.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_faccessat.c,v 1.1 2012/11/18 17:41:54 manu Exp $");
#include <atf-c.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <paths.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/param.h>
#define DIR "dir"
#define FILE "dir/faccessat"
#define BASEFILE "faccessat"
#define LINK "dir/symlink"
#define BASELINK "symlink"
#define FILEERR "dir/faccessaterr"
ATF_TC_WITH_CLEANUP(faccessat_fd);
ATF_TC_HEAD(faccessat_fd, tc)
{
atf_tc_set_md_var(tc, "descr", "See that faccessat works with fd");
}
ATF_TC_BODY(faccessat_fd, tc)
{
int dfd;
int fd;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE(faccessat(dfd, BASEFILE, F_OK, 0) == 0);
ATF_REQUIRE(close(dfd) == 0);
}
ATF_TC_CLEANUP(faccessat_fd, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(faccessat_fdcwd);
ATF_TC_HEAD(faccessat_fdcwd, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that faccessat works with fd as AT_FDCWD");
}
ATF_TC_BODY(faccessat_fdcwd, tc)
{
int fd;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE(chdir(DIR) == 0);
ATF_REQUIRE(faccessat(AT_FDCWD, BASEFILE, F_OK, 0) == 0);
}
ATF_TC_CLEANUP(faccessat_fdcwd, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(faccessat_fdcwderr);
ATF_TC_HEAD(faccessat_fdcwderr, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that faccessat fails with fd as AT_FDCWD and bad path");
}
ATF_TC_BODY(faccessat_fdcwderr, tc)
{
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE(faccessat(AT_FDCWD, FILEERR, F_OK, 0) == -1);
}
ATF_TC_CLEANUP(faccessat_fdcwderr, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(faccessat_fderr1);
ATF_TC_HEAD(faccessat_fderr1, tc)
{
atf_tc_set_md_var(tc, "descr", "See that faccessat fail with bad path");
}
ATF_TC_BODY(faccessat_fderr1, tc)
{
int dfd;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE(faccessat(dfd, FILEERR, F_OK, 0) == -1);
ATF_REQUIRE(close(dfd) == 0);
}
ATF_TC_CLEANUP(faccessat_fderr1, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(faccessat_fderr2);
ATF_TC_HEAD(faccessat_fderr2, tc)
{
atf_tc_set_md_var(tc, "descr", "See that faccessat fails with bad fdat");
}
ATF_TC_BODY(faccessat_fderr2, tc)
{
int dfd;
int fd;
char cwd[MAXPATHLEN];
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE((dfd = open(getcwd(cwd, MAXPATHLEN), O_RDONLY, 0)) != -1);
ATF_REQUIRE(faccessat(dfd, BASEFILE, F_OK, 0) == -1);
ATF_REQUIRE(close(dfd) == 0);
}
ATF_TC_CLEANUP(faccessat_fderr2, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(faccessat_fderr3);
ATF_TC_HEAD(faccessat_fderr3, tc)
{
atf_tc_set_md_var(tc, "descr", "See that faccessat fails with fd as -1");
}
ATF_TC_BODY(faccessat_fderr3, tc)
{
int fd;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE(faccessat(-1, FILE, F_OK, 0) == -1);
}
ATF_TC_CLEANUP(faccessat_fderr3, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(faccessat_fdlink);
ATF_TC_HEAD(faccessat_fdlink, tc)
{
atf_tc_set_md_var(tc, "descr", "See that faccessat works on symlink");
}
ATF_TC_BODY(faccessat_fdlink, tc)
{
int dfd;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE(symlink(FILE, LINK) == 0); /* NB: FILE does not exists */
ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE(faccessat(dfd, BASELINK, F_OK, 0) == -1);
ATF_REQUIRE(errno == ENOENT);
ATF_REQUIRE(faccessat(dfd, BASELINK, F_OK, AT_SYMLINK_NOFOLLOW) == 0);
ATF_REQUIRE(close(dfd) == 0);
}
ATF_TC_CLEANUP(faccessat_fdlink, tc)
{
(void)unlink(LINK);
(void)rmdir(DIR);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, faccessat_fd);
ATF_TP_ADD_TC(tp, faccessat_fdcwd);
ATF_TP_ADD_TC(tp, faccessat_fdcwderr);
ATF_TP_ADD_TC(tp, faccessat_fderr1);
ATF_TP_ADD_TC(tp, faccessat_fderr2);
ATF_TP_ADD_TC(tp, faccessat_fderr3);
ATF_TP_ADD_TC(tp, faccessat_fdlink);
return atf_no_error();
}

View File

@ -0,0 +1,253 @@
/* $NetBSD: t_fchmodat.c,v 1.1 2012/11/18 17:41:54 manu Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Emmanuel Dreyfus.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_fchmodat.c,v 1.1 2012/11/18 17:41:54 manu Exp $");
#include <atf-c.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <paths.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/param.h>
#define DIR "dir"
#define FILE "dir/fchmodat"
#define BASEFILE "fchmodat"
#define LINK "dir/symlink"
#define BASELINK "symlink"
#define FILEERR "dir/fchmodaterr"
ATF_TC_WITH_CLEANUP(fchmodat_fd);
ATF_TC_HEAD(fchmodat_fd, tc)
{
atf_tc_set_md_var(tc, "descr", "See that fchmodat works with fd");
}
ATF_TC_BODY(fchmodat_fd, tc)
{
int dfd;
int fd;
struct stat st;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE(fchmodat(dfd, BASEFILE, 0600, 0) == 0);
ATF_REQUIRE(close(dfd) == 0);
ATF_REQUIRE(stat(FILE, &st) == 0);
ATF_REQUIRE(st.st_mode = 0600);
}
ATF_TC_CLEANUP(fchmodat_fd, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(fchmodat_fdcwd);
ATF_TC_HEAD(fchmodat_fdcwd, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that fchmodat works with fd as AT_FDCWD");
}
ATF_TC_BODY(fchmodat_fdcwd, tc)
{
int fd;
struct stat st;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE(chdir(DIR) == 0);
ATF_REQUIRE(fchmodat(AT_FDCWD, BASEFILE, 0600, 0) == 0);
ATF_REQUIRE(stat(BASEFILE, &st) == 0);
ATF_REQUIRE(st.st_mode = 0600);
}
ATF_TC_CLEANUP(fchmodat_fdcwd, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(fchmodat_fdcwderr);
ATF_TC_HEAD(fchmodat_fdcwderr, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that fchmodat fails with fd as AT_FDCWD and bad path");
}
ATF_TC_BODY(fchmodat_fdcwderr, tc)
{
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE(fchmodat(AT_FDCWD, FILEERR, 0600, 0) == -1);
}
ATF_TC_CLEANUP(fchmodat_fdcwderr, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(fchmodat_fderr1);
ATF_TC_HEAD(fchmodat_fderr1, tc)
{
atf_tc_set_md_var(tc, "descr", "See that fchmodat fail with bad path");
}
ATF_TC_BODY(fchmodat_fderr1, tc)
{
int dfd;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE(fchmodat(dfd, FILEERR, 0600, 0) == -1);
ATF_REQUIRE(close(dfd) == 0);
}
ATF_TC_CLEANUP(fchmodat_fderr1, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(fchmodat_fderr2);
ATF_TC_HEAD(fchmodat_fderr2, tc)
{
atf_tc_set_md_var(tc, "descr", "See that fchmodat fails with bad fdat");
}
ATF_TC_BODY(fchmodat_fderr2, tc)
{
int dfd;
int fd;
char cwd[MAXPATHLEN];
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE((dfd = open(getcwd(cwd, MAXPATHLEN), O_RDONLY, 0)) != -1);
ATF_REQUIRE(fchmodat(dfd, BASEFILE, 0600, 0) == -1);
ATF_REQUIRE(close(dfd) == 0);
}
ATF_TC_CLEANUP(fchmodat_fderr2, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(fchmodat_fderr3);
ATF_TC_HEAD(fchmodat_fderr3, tc)
{
atf_tc_set_md_var(tc, "descr", "See that fchmodat fails with fd as -1");
}
ATF_TC_BODY(fchmodat_fderr3, tc)
{
int fd;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE(fchmodat(-1, FILE, 0600, 0) == -1);
}
ATF_TC_CLEANUP(fchmodat_fderr3, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(fchmodat_fdlink);
ATF_TC_HEAD(fchmodat_fdlink, tc)
{
atf_tc_set_md_var(tc, "descr", "See that fchmodat works on symlink");
}
ATF_TC_BODY(fchmodat_fdlink, tc)
{
int dfdlink;
struct stat st;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE(symlink(FILE, LINK) == 0);
ATF_REQUIRE((dfdlink = open(DIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE(fchmodat(dfdlink, BASELINK, 0600, 0) == -1);
ATF_REQUIRE(errno = ENOENT);
ATF_REQUIRE(fchmodat(dfdlink, BASELINK, 0600, AT_SYMLINK_NOFOLLOW) == 0);
ATF_REQUIRE(close(dfdlink) == 0);
ATF_REQUIRE(lstat(LINK, &st) == 0);
ATF_REQUIRE(st.st_mode = 0600);
}
ATF_TC_CLEANUP(fchmodat_fdlink, tc)
{
(void)unlink(LINK);
(void)rmdir(DIR);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, fchmodat_fd);
ATF_TP_ADD_TC(tp, fchmodat_fdcwd);
ATF_TP_ADD_TC(tp, fchmodat_fdcwderr);
ATF_TP_ADD_TC(tp, fchmodat_fderr1);
ATF_TP_ADD_TC(tp, fchmodat_fderr2);
ATF_TP_ADD_TC(tp, fchmodat_fderr3);
ATF_TP_ADD_TC(tp, fchmodat_fdlink);
return atf_no_error();
}

View File

@ -0,0 +1,295 @@
/* $NetBSD: t_fchownat.c,v 1.1 2012/11/18 17:41:54 manu Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Emmanuel Dreyfus.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_fchownat.c,v 1.1 2012/11/18 17:41:54 manu Exp $");
#include <atf-c.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <paths.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <pwd.h>
#include <sys/param.h>
#define DIR "dir"
#define FILE "dir/fchownat"
#define BASEFILE "fchownat"
#define LINK "dir/symlink"
#define BASELINK "symlink"
#define FILEERR "dir/fchownaterr"
#define USER "nobody"
static int getuser(uid_t *, gid_t *);
static int getuser(uid_t *uid, gid_t *gid)
{
struct passwd *pw;
if ((pw = getpwnam(USER)) == NULL)
return -1;
*uid = pw->pw_uid;
*gid = pw->pw_gid;
return 0;
}
ATF_TC_WITH_CLEANUP(fchownat_fd);
ATF_TC_HEAD(fchownat_fd, tc)
{
atf_tc_set_md_var(tc, "descr", "See that fchownat works with fd");
}
ATF_TC_BODY(fchownat_fd, tc)
{
int dfd;
int fd;
uid_t uid;
gid_t gid;
struct stat st;
ATF_REQUIRE(getuser(&uid, &gid) == 0);
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE(fchownat(dfd, BASEFILE, uid, gid, 0) == 0);
ATF_REQUIRE(close(dfd) == 0);
ATF_REQUIRE(stat(FILE, &st) == 0);
ATF_REQUIRE(st.st_uid == uid);
ATF_REQUIRE(st.st_gid == gid);
}
ATF_TC_CLEANUP(fchownat_fd, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(fchownat_fdcwd);
ATF_TC_HEAD(fchownat_fdcwd, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that fchownat works with fd as AT_FDCWD");
}
ATF_TC_BODY(fchownat_fdcwd, tc)
{
int fd;
uid_t uid;
gid_t gid;
struct stat st;
ATF_REQUIRE(getuser(&uid, &gid) == 0);
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE(chdir(DIR) == 0);
ATF_REQUIRE(fchownat(AT_FDCWD, BASEFILE, uid, gid, 0) == 0);
ATF_REQUIRE(stat(BASEFILE, &st) == 0);
ATF_REQUIRE(st.st_uid == uid);
ATF_REQUIRE(st.st_gid == gid);
}
ATF_TC_CLEANUP(fchownat_fdcwd, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(fchownat_fdcwderr);
ATF_TC_HEAD(fchownat_fdcwderr, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that fchownat fails with fd as AT_FDCWD and bad path");
}
ATF_TC_BODY(fchownat_fdcwderr, tc)
{
uid_t uid;
gid_t gid;
ATF_REQUIRE(getuser(&uid, &gid) == 0);
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE(fchownat(AT_FDCWD, FILEERR, uid, gid, 0) == -1);
}
ATF_TC_CLEANUP(fchownat_fdcwderr, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(fchownat_fderr1);
ATF_TC_HEAD(fchownat_fderr1, tc)
{
atf_tc_set_md_var(tc, "descr", "See that fchownat fail with bad path");
}
ATF_TC_BODY(fchownat_fderr1, tc)
{
int dfd;
uid_t uid;
gid_t gid;
ATF_REQUIRE(getuser(&uid, &gid) == 0);
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE(fchownat(dfd, FILEERR, uid, gid, 0) == -1);
ATF_REQUIRE(close(dfd) == 0);
}
ATF_TC_CLEANUP(fchownat_fderr1, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(fchownat_fderr2);
ATF_TC_HEAD(fchownat_fderr2, tc)
{
atf_tc_set_md_var(tc, "descr", "See that fchownat fails with bad fdat");
}
ATF_TC_BODY(fchownat_fderr2, tc)
{
int dfd;
int fd;
char cwd[MAXPATHLEN];
uid_t uid;
gid_t gid;
ATF_REQUIRE(getuser(&uid, &gid) == 0);
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE((dfd = open(getcwd(cwd, MAXPATHLEN), O_RDONLY, 0)) != -1);
ATF_REQUIRE(fchownat(dfd, BASEFILE, uid, gid, 0) == -1);
ATF_REQUIRE(close(dfd) == 0);
}
ATF_TC_CLEANUP(fchownat_fderr2, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(fchownat_fderr3);
ATF_TC_HEAD(fchownat_fderr3, tc)
{
atf_tc_set_md_var(tc, "descr", "See that fchownat fails with fd as -1");
}
ATF_TC_BODY(fchownat_fderr3, tc)
{
int fd;
uid_t uid;
gid_t gid;
ATF_REQUIRE(getuser(&uid, &gid) == 0);
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE(fchownat(-1, FILE, uid, gid, 0) == -1);
}
ATF_TC_CLEANUP(fchownat_fderr3, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(fchownat_fdlink);
ATF_TC_HEAD(fchownat_fdlink, tc)
{
atf_tc_set_md_var(tc, "descr", "See that fchownat works on symlink");
}
ATF_TC_BODY(fchownat_fdlink, tc)
{
int dfd;
uid_t uid;
gid_t gid;
struct stat st;
ATF_REQUIRE(getuser(&uid, &gid) == 0);
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE(symlink(FILE, LINK) == 0); /* Target does not exists */
ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE(fchownat(dfd, BASELINK, uid, gid, 0) == -1);
ATF_REQUIRE(errno == ENOENT);
ATF_REQUIRE(fchownat(dfd, BASELINK, uid, gid,
AT_SYMLINK_NOFOLLOW) == 0);
ATF_REQUIRE(close(dfd) == 0);
ATF_REQUIRE(lstat(LINK, &st) == 0);
ATF_REQUIRE(st.st_uid == uid);
ATF_REQUIRE(st.st_gid == gid);
}
ATF_TC_CLEANUP(fchownat_fdlink, tc)
{
(void)unlink(LINK);
(void)rmdir(DIR);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, fchownat_fd);
ATF_TP_ADD_TC(tp, fchownat_fdcwd);
ATF_TP_ADD_TC(tp, fchownat_fdcwderr);
ATF_TP_ADD_TC(tp, fchownat_fderr1);
ATF_TP_ADD_TC(tp, fchownat_fderr2);
ATF_TP_ADD_TC(tp, fchownat_fderr3);
ATF_TP_ADD_TC(tp, fchownat_fdlink);
return atf_no_error();
}

View File

@ -0,0 +1,81 @@
/* $NetBSD: t_fexecve.c,v 1.1 2012/11/18 17:41:54 manu Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Emmanuel Dreyfus.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_fexecve.c,v 1.1 2012/11/18 17:41:54 manu Exp $");
#include <atf-c.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <paths.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/param.h>
#define FILE "test"
ATF_TC_WITH_CLEANUP(fexecve);
ATF_TC_HEAD(fexecve, tc)
{
atf_tc_set_md_var(tc, "descr", "See that fexecve works");
}
ATF_TC_BODY(fexecve, tc)
{
int fd;
pid_t pid;
const char *const argv[] = { "touch", FILE, NULL };
const char *const envp[] = { NULL };
ATF_REQUIRE((pid = fork()) != -1);
if (pid != 0) { /* parent */
sleep(1);
ATF_REQUIRE(access(FILE, F_OK) == 0);
} else { /* child */
ATF_REQUIRE((fd = open("/usr/bin/touch", O_RDONLY, 0)) != -1);
ATF_REQUIRE(fexecve(fd, __UNCONST(argv), __UNCONST(envp)) == 0);
}
}
ATF_TC_CLEANUP(fexecve, tc)
{
(void)unlink(FILE);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, fexecve);
return atf_no_error();
}

View File

@ -0,0 +1,253 @@
/* $NetBSD: t_fstatat.c,v 1.1 2012/11/18 17:41:54 manu Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Emmanuel Dreyfus.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_fstatat.c,v 1.1 2012/11/18 17:41:54 manu Exp $");
#include <atf-c.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <paths.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/param.h>
#define DIR "dir"
#define FILE "dir/fstatat"
#define BASEFILE "fstatat"
#define LINK "dir/symlink"
#define BASELINK "symlink"
#define FILEERR "dir/symlink"
ATF_TC_WITH_CLEANUP(fstatat_fd);
ATF_TC_HEAD(fstatat_fd, tc)
{
atf_tc_set_md_var(tc, "descr", "See that fstatat works with fd");
}
ATF_TC_BODY(fstatat_fd, tc)
{
int dfd;
int fd;
struct stat st1, st2;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE(fstatat(dfd, BASEFILE, &st1, 0) == 0);
ATF_REQUIRE(close(dfd) == 0);
ATF_REQUIRE(stat(FILE, &st2) == 0);
ATF_REQUIRE(memcmp(&st1, &st2, sizeof(st1)) == 0);
}
ATF_TC_CLEANUP(fstatat_fd, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(fstatat_fdcwd);
ATF_TC_HEAD(fstatat_fdcwd, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that fstatat works with fd as AT_FDCWD");
}
ATF_TC_BODY(fstatat_fdcwd, tc)
{
int fd;
struct stat st;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE(chdir(DIR) == 0);
ATF_REQUIRE(fstatat(AT_FDCWD, BASEFILE, &st, 0) == 0);
}
ATF_TC_CLEANUP(fstatat_fdcwd, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(fstatat_fdcwderr);
ATF_TC_HEAD(fstatat_fdcwderr, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that fstatat fails with fd as AT_FDCWD and bad path");
}
ATF_TC_BODY(fstatat_fdcwderr, tc)
{
struct stat st;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE(fstatat(AT_FDCWD, FILEERR, &st, 0) == -1);
}
ATF_TC_CLEANUP(fstatat_fdcwderr, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(fstatat_fderr1);
ATF_TC_HEAD(fstatat_fderr1, tc)
{
atf_tc_set_md_var(tc, "descr", "See that fstatat fail with bad path");
}
ATF_TC_BODY(fstatat_fderr1, tc)
{
int dfd;
struct stat st;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE(fstatat(dfd, FILEERR, &st, 0) == -1);
ATF_REQUIRE(close(dfd) == 0);
}
ATF_TC_CLEANUP(fstatat_fderr1, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(fstatat_fderr2);
ATF_TC_HEAD(fstatat_fderr2, tc)
{
atf_tc_set_md_var(tc, "descr", "See that fstatat fails with bad fdat");
}
ATF_TC_BODY(fstatat_fderr2, tc)
{
int dfd;
int fd;
char cwd[MAXPATHLEN];
struct stat st;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE((dfd = open(getcwd(cwd, MAXPATHLEN), O_RDONLY, 0)) != -1);
ATF_REQUIRE(fstatat(dfd, BASEFILE, &st, 0) == -1);
ATF_REQUIRE(close(dfd) == 0);
}
ATF_TC_CLEANUP(fstatat_fderr2, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(fstatat_fderr3);
ATF_TC_HEAD(fstatat_fderr3, tc)
{
atf_tc_set_md_var(tc, "descr", "See that fstatat fails with fd as -1");
}
ATF_TC_BODY(fstatat_fderr3, tc)
{
int fd;
struct stat st;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE(fstatat(-1, FILE, &st, 0) == -1);
}
ATF_TC_CLEANUP(fstatat_fderr3, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(fstatat_fdlink);
ATF_TC_HEAD(fstatat_fdlink, tc)
{
atf_tc_set_md_var(tc, "descr", "See that fstatat works on symlink");
}
ATF_TC_BODY(fstatat_fdlink, tc)
{
int dfd;
struct stat st;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE(symlink(FILE, LINK) == 0); /* target does not exists */
ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE(fstatat(dfd, BASELINK, &st, 0) == -1);
ATF_REQUIRE(errno == ENOENT);
ATF_REQUIRE(fstatat(dfd, BASELINK, &st, AT_SYMLINK_NOFOLLOW) == 0);
ATF_REQUIRE(close(dfd) == 0);
}
ATF_TC_CLEANUP(fstatat_fdlink, tc)
{
(void)unlink(LINK);
(void)rmdir(DIR);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, fstatat_fd);
ATF_TP_ADD_TC(tp, fstatat_fdcwd);
ATF_TP_ADD_TC(tp, fstatat_fdcwderr);
ATF_TP_ADD_TC(tp, fstatat_fderr1);
ATF_TP_ADD_TC(tp, fstatat_fderr2);
ATF_TP_ADD_TC(tp, fstatat_fderr3);
ATF_TP_ADD_TC(tp, fstatat_fdlink);
return atf_no_error();
}

View File

@ -0,0 +1,275 @@
/* $NetBSD: t_linkat.c,v 1.1 2012/11/18 17:41:54 manu Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Emmanuel Dreyfus.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_linkat.c,v 1.1 2012/11/18 17:41:54 manu Exp $");
#include <atf-c.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <paths.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/param.h>
#include <sys/stat.h>
#define ODIR "olddir"
#define NDIR "newdir"
#define FILE "olddir/old"
#define BASEFILE "old"
#define RELFILE "../olddir/old"
#define TARGET "newdir/new"
#define BASETARGET "new"
#define LINK "olddir/symlink"
#define BASELINK "symlink"
#define FILEERR "olddir/olderr"
ATF_TC_WITH_CLEANUP(linkat_fd);
ATF_TC_HEAD(linkat_fd, tc)
{
atf_tc_set_md_var(tc, "descr", "See that linkat works with fd");
}
ATF_TC_BODY(linkat_fd, tc)
{
int ofd, nfd, fd;
struct stat ost, nst;
ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) != -1);
ATF_REQUIRE((ofd = open(ODIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE((nfd = open(NDIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE(linkat(ofd, BASEFILE, nfd, BASETARGET, 0) == 0);
ATF_REQUIRE(close(ofd) == 0);
ATF_REQUIRE(close(nfd) == 0);
ATF_REQUIRE(stat(FILE, &ost) == 0);
ATF_REQUIRE(stat(TARGET, &nst) == 0);
ATF_REQUIRE(ost.st_ino == nst.st_ino);
}
ATF_TC_CLEANUP(linkat_fd, tc)
{
(void)unlink(FILE);
(void)unlink(TARGET);
(void)rmdir(NDIR);
(void)rmdir(ODIR);
}
ATF_TC_WITH_CLEANUP(linkat_fdcwd);
ATF_TC_HEAD(linkat_fdcwd, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that linkat works with fd as AT_FDCWD");
}
ATF_TC_BODY(linkat_fdcwd, tc)
{
int fd;
struct stat ost, nst;
ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) != -1);
ATF_REQUIRE(linkat(AT_FDCWD, FILE, AT_FDCWD, TARGET, 0) == 0);
ATF_REQUIRE(stat(FILE, &ost) == 0);
ATF_REQUIRE(stat(TARGET, &nst) == 0);
ATF_REQUIRE(ost.st_ino == nst.st_ino);
}
ATF_TC_CLEANUP(linkat_fdcwd, tc)
{
(void)unlink(FILE);
(void)unlink(TARGET);
(void)rmdir(NDIR);
(void)rmdir(ODIR);
}
ATF_TC_WITH_CLEANUP(linkat_fdcwderr);
ATF_TC_HEAD(linkat_fdcwderr, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that linkat fails with fd as AT_FDCWD and bad path");
}
ATF_TC_BODY(linkat_fdcwderr, tc)
{
int fd;
ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) != -1);
ATF_REQUIRE(linkat(AT_FDCWD, FILEERR, AT_FDCWD, TARGET, 0) == -1);
}
ATF_TC_CLEANUP(linkat_fdcwderr, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)unlink(TARGET);
(void)rmdir(NDIR);
(void)rmdir(ODIR);
}
ATF_TC_WITH_CLEANUP(linkat_fderr);
ATF_TC_HEAD(linkat_fderr, tc)
{
atf_tc_set_md_var(tc, "descr", "See that linkat fails with fd as -1");
}
ATF_TC_BODY(linkat_fderr, tc)
{
int fd;
ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) != -1);
ATF_REQUIRE(linkat(-1, FILE, AT_FDCWD, TARGET, 0) == -1);
ATF_REQUIRE(linkat(AT_FDCWD, FILE, -1, TARGET, 0) == -1);
ATF_REQUIRE(linkat(-1, FILE, -1, TARGET, 0) == -1);
}
ATF_TC_CLEANUP(linkat_fderr, tc)
{
(void)unlink(FILE);
(void)unlink(TARGET);
(void)rmdir(NDIR);
(void)rmdir(ODIR);
}
ATF_TC_WITH_CLEANUP(linkat_fdlink1);
ATF_TC_HEAD(linkat_fdlink1, tc)
{
atf_tc_set_md_var(tc, "descr", "See that linkat works on symlink target");
}
ATF_TC_BODY(linkat_fdlink1, tc)
{
int ofd, nfd, fd;
struct stat ost, nst;
ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) != -1);
ATF_REQUIRE(symlink(RELFILE, LINK) == 0);
ATF_REQUIRE((ofd = open(ODIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE((nfd = open(NDIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE(linkat(ofd, BASELINK, nfd, BASETARGET,
AT_SYMLINK_FOLLOW) == 0);
ATF_REQUIRE(close(ofd) == 0);
ATF_REQUIRE(close(nfd) == 0);
ATF_REQUIRE(lstat(LINK, &ost) == 0);
ATF_REQUIRE(lstat(TARGET, &nst) == 0);
ATF_REQUIRE(ost.st_ino != nst.st_ino);
ATF_REQUIRE(lstat(FILE, &ost) == 0);
ATF_REQUIRE(lstat(TARGET, &nst) == 0);
ATF_REQUIRE(ost.st_ino == nst.st_ino);
}
ATF_TC_CLEANUP(linkat_fdlink1, tc)
{
(void)unlink(FILE);
(void)unlink(LINK);
(void)unlink(TARGET);
(void)rmdir(NDIR);
(void)rmdir(ODIR);
}
ATF_TC_WITH_CLEANUP(linkat_fdlink2);
ATF_TC_HEAD(linkat_fdlink2, tc)
{
atf_tc_set_md_var(tc, "descr", "See that linkat works on symlink source");
}
ATF_TC_BODY(linkat_fdlink2, tc)
{
int ofd, nfd, fd;
struct stat ost, nst;
ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) != -1);
ATF_REQUIRE(symlink(RELFILE, LINK) == 0);
ATF_REQUIRE((ofd = open(ODIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE((nfd = open(NDIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE(linkat(ofd, BASELINK, nfd, BASETARGET, 0) == 0);
ATF_REQUIRE(close(ofd) == 0);
ATF_REQUIRE(close(nfd) == 0);
ATF_REQUIRE(lstat(LINK, &ost) == 0);
ATF_REQUIRE(lstat(TARGET, &nst) == 0);
ATF_REQUIRE(ost.st_ino == nst.st_ino);
ATF_REQUIRE(lstat(FILE, &ost) == 0);
ATF_REQUIRE(lstat(TARGET, &nst) == 0);
ATF_REQUIRE(ost.st_ino != nst.st_ino);
}
ATF_TC_CLEANUP(linkat_fdlink2, tc)
{
(void)unlink(FILE);
(void)unlink(LINK);
(void)unlink(TARGET);
(void)rmdir(NDIR);
(void)rmdir(ODIR);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, linkat_fd);
ATF_TP_ADD_TC(tp, linkat_fdcwd);
ATF_TP_ADD_TC(tp, linkat_fdcwderr);
ATF_TP_ADD_TC(tp, linkat_fderr);
ATF_TP_ADD_TC(tp, linkat_fdlink1);
ATF_TP_ADD_TC(tp, linkat_fdlink2);
return atf_no_error();
}

View File

@ -0,0 +1,154 @@
/* $NetBSD: t_mkdirat.c,v 1.1 2012/11/18 17:41:54 manu Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Emmanuel Dreyfus.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_mkdirat.c,v 1.1 2012/11/18 17:41:54 manu Exp $");
#include <atf-c.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <paths.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/param.h>
#include <sys/stat.h>
#define DIR "dir"
#define SDIR "dir/openat"
#define BASESDIR "openat"
#define SDIRERR "dir/openaterr"
ATF_TC_WITH_CLEANUP(mkdirat_fd);
ATF_TC_HEAD(mkdirat_fd, tc)
{
atf_tc_set_md_var(tc, "descr", "See that mkdirat works with fd");
}
ATF_TC_BODY(mkdirat_fd, tc)
{
int dfd;
mode_t mode = 0755;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE(mkdirat(dfd, BASESDIR, mode) != -1);
ATF_REQUIRE(close(dfd) == 0);
ATF_REQUIRE(access(SDIR, F_OK) == 0);
}
ATF_TC_CLEANUP(mkdirat_fd, tc)
{
(void)unlink(SDIR);
(void)unlink(SDIRERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(mkdirat_fdcwd);
ATF_TC_HEAD(mkdirat_fdcwd, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that mkdirat works with fd as AT_FDCWD");
}
ATF_TC_BODY(mkdirat_fdcwd, tc)
{
mode_t mode = 0755;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE(mkdirat(AT_FDCWD, SDIR, mode) != -1);
ATF_REQUIRE(access(SDIR, F_OK) == 0);
}
ATF_TC_CLEANUP(mkdirat_fdcwd, tc)
{
(void)unlink(SDIR);
(void)unlink(SDIRERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(mkdirat_fdcwderr);
ATF_TC_HEAD(mkdirat_fdcwderr, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that mkdirat fails with fd as AT_FDCWD and bad path");
}
ATF_TC_BODY(mkdirat_fdcwderr, tc)
{
mode_t mode = 0755;
ATF_REQUIRE(mkdirat(AT_FDCWD, SDIRERR, mode) == -1);
}
ATF_TC_CLEANUP(mkdirat_fdcwderr, tc)
{
(void)unlink(SDIR);
(void)unlink(SDIRERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(mkdirat_fderr);
ATF_TC_HEAD(mkdirat_fderr, tc)
{
atf_tc_set_md_var(tc, "descr", "See that mkdirat fails with fd as -1");
}
ATF_TC_BODY(mkdirat_fderr, tc)
{
int fd;
mode_t mode = 0755;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(SDIR, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE(mkdirat(-1, SDIR, mode) == -1);
}
ATF_TC_CLEANUP(mkdirat_fderr, tc)
{
(void)unlink(SDIR);
(void)unlink(SDIRERR);
(void)rmdir(DIR);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, mkdirat_fd);
ATF_TP_ADD_TC(tp, mkdirat_fdcwd);
ATF_TP_ADD_TC(tp, mkdirat_fdcwderr);
ATF_TP_ADD_TC(tp, mkdirat_fderr);
return atf_no_error();
}

View File

@ -0,0 +1,158 @@
/* $NetBSD: t_mkfifoat.c,v 1.1 2012/11/18 17:41:54 manu Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Emmanuel Dreyfus.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_mkfifoat.c,v 1.1 2012/11/18 17:41:54 manu Exp $");
#include <atf-c.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <paths.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/param.h>
#include <sys/stat.h>
#define DIR "dir"
#define FIFO "dir/openat"
#define BASEFIFO "openat"
#define FIFOERR "dir/openaterr"
ATF_TC_WITH_CLEANUP(mkfifoat_fd);
ATF_TC_HEAD(mkfifoat_fd, tc)
{
atf_tc_set_md_var(tc, "descr", "See that mkfifoat works with fd");
}
ATF_TC_BODY(mkfifoat_fd, tc)
{
int dfd;
int fd;
mode_t mode = 0600;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE((fd = mkfifoat(dfd, BASEFIFO, mode)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE(access(FIFO, F_OK) == 0);
}
ATF_TC_CLEANUP(mkfifoat_fd, tc)
{
(void)unlink(FIFO);
(void)unlink(FIFOERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(mkfifoat_fdcwd);
ATF_TC_HEAD(mkfifoat_fdcwd, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that mkfifoat works with fd as AT_FDCWD");
}
ATF_TC_BODY(mkfifoat_fdcwd, tc)
{
int fd;
mode_t mode = 0600;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = mkfifoat(AT_FDCWD, FIFO, mode)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE(access(FIFO, F_OK) == 0);
}
ATF_TC_CLEANUP(mkfifoat_fdcwd, tc)
{
(void)unlink(FIFO);
(void)unlink(FIFOERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(mkfifoat_fdcwderr);
ATF_TC_HEAD(mkfifoat_fdcwderr, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that mkfifoat fails with fd as AT_FDCWD and bad path");
}
ATF_TC_BODY(mkfifoat_fdcwderr, tc)
{
int fd;
mode_t mode = 0600;
ATF_REQUIRE((fd = mkfifoat(AT_FDCWD, FIFOERR, mode)) == -1);
}
ATF_TC_CLEANUP(mkfifoat_fdcwderr, tc)
{
(void)unlink(FIFO);
(void)unlink(FIFOERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(mkfifoat_fderr);
ATF_TC_HEAD(mkfifoat_fderr, tc)
{
atf_tc_set_md_var(tc, "descr", "See that mkfifoat fails with fd as -1");
}
ATF_TC_BODY(mkfifoat_fderr, tc)
{
int fd;
mode_t mode = 0600;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FIFO, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE((fd = mkfifoat(-1, FIFO, mode)) == -1);
}
ATF_TC_CLEANUP(mkfifoat_fderr, tc)
{
(void)unlink(FIFO);
(void)unlink(FIFOERR);
(void)rmdir(DIR);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, mkfifoat_fd);
ATF_TP_ADD_TC(tp, mkfifoat_fdcwd);
ATF_TP_ADD_TC(tp, mkfifoat_fdcwderr);
ATF_TP_ADD_TC(tp, mkfifoat_fderr);
return atf_no_error();
}

View File

@ -0,0 +1,180 @@
/* $NetBSD: t_mknodat.c,v 1.1 2012/11/18 17:41:54 manu Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Emmanuel Dreyfus.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_mknodat.c,v 1.1 2012/11/18 17:41:54 manu Exp $");
#include <atf-c.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <paths.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/param.h>
#include <sys/stat.h>
#define DIR "dir"
#define FILE "dir/openat"
#define BASEFILE "openat"
#define FILEERR "dir/openaterr"
static dev_t get_devnull(void);
static dev_t
get_devnull(void)
{
struct stat st;
if (stat(_PATH_DEVNULL, &st) != 0)
return NODEV;
return st.st_rdev;
}
ATF_TC_WITH_CLEANUP(mknodat_fd);
ATF_TC_HEAD(mknodat_fd, tc)
{
atf_tc_set_md_var(tc, "descr", "See that mknodat works with fd");
}
ATF_TC_BODY(mknodat_fd, tc)
{
int dfd;
int fd;
dev_t dev;
mode_t mode = S_IFCHR|0600;
ATF_REQUIRE((dev = get_devnull()) != NODEV);
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE((fd = mknodat(dfd, BASEFILE, mode, dev)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE(access(FILE, F_OK) == 0);
}
ATF_TC_CLEANUP(mknodat_fd, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(mknodat_fdcwd);
ATF_TC_HEAD(mknodat_fdcwd, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that mknodat works with fd as AT_FDCWD");
}
ATF_TC_BODY(mknodat_fdcwd, tc)
{
int fd;
dev_t dev;
mode_t mode = S_IFCHR|0600;
ATF_REQUIRE((dev = get_devnull()) != NODEV);
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = mknodat(AT_FDCWD, FILE, mode, dev)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE(access(FILE, F_OK) == 0);
}
ATF_TC_CLEANUP(mknodat_fdcwd, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(mknodat_fdcwderr);
ATF_TC_HEAD(mknodat_fdcwderr, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that mknodat fails with fd as AT_FDCWD and bad path");
}
ATF_TC_BODY(mknodat_fdcwderr, tc)
{
int fd;
dev_t dev;
mode_t mode = S_IFCHR|0600;
ATF_REQUIRE((dev = get_devnull()) != NODEV);
ATF_REQUIRE((fd = mknodat(AT_FDCWD, FILEERR, mode, dev)) == -1);
}
ATF_TC_CLEANUP(mknodat_fdcwderr, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(mknodat_fderr);
ATF_TC_HEAD(mknodat_fderr, tc)
{
atf_tc_set_md_var(tc, "descr", "See that mknodat fails with fd as -1");
}
ATF_TC_BODY(mknodat_fderr, tc)
{
int fd;
dev_t dev;
mode_t mode = S_IFCHR|0600;
ATF_REQUIRE((dev = get_devnull()) != NODEV);
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE((fd = mknodat(-1, FILE, mode, dev)) == -1);
}
ATF_TC_CLEANUP(mknodat_fderr, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, mknodat_fd);
ATF_TP_ADD_TC(tp, mknodat_fdcwd);
ATF_TP_ADD_TC(tp, mknodat_fdcwderr);
ATF_TP_ADD_TC(tp, mknodat_fderr);
return atf_no_error();
}

View File

@ -0,0 +1,226 @@
/* $NetBSD: t_o_search.c,v 1.1 2012/11/18 17:41:54 manu Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Emmanuel Dreyfus.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_o_search.c,v 1.1 2012/11/18 17:41:54 manu Exp $");
#include <atf-c.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <paths.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <pwd.h>
#include <sys/param.h>
#define DIR "dir"
#define FILE "dir/o_search"
#define BASEFILE "o_search"
ATF_TC_WITH_CLEANUP(o_search_perm1);
ATF_TC_HEAD(o_search_perm1, tc)
{
atf_tc_set_md_var(tc, "descr", "See that openat enforce search permission");
atf_tc_set_md_var(tc, "require.user", "unprivileged");
}
ATF_TC_BODY(o_search_perm1, tc)
{
int dfd;
int fd;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE(fchmod(dfd, 644) == 0);
ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) == -1);
ATF_REQUIRE(errno == EACCES);
ATF_REQUIRE(close(dfd) == 0);
}
ATF_TC_CLEANUP(o_search_perm1, tc)
{
(void)unlink(FILE);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(o_search_flag1);
ATF_TC_HEAD(o_search_flag1, tc)
{
atf_tc_set_md_var(tc, "descr", "See that openat honours O_SEARCH");
}
ATF_TC_BODY(o_search_flag1, tc)
{
int dfd;
int fd;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE((dfd = open(DIR, O_RDONLY|O_SEARCH, 0)) != -1);
ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE(fchmod(dfd, 644) == 0);
ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE(fchmod(dfd, 444) == 0);
ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) != -1);
ATF_REQUIRE(close(dfd) == 0);
}
ATF_TC_CLEANUP(o_search_flag1, tc)
{
(void)unlink(FILE);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(o_search_perm2);
ATF_TC_HEAD(o_search_perm2, tc)
{
atf_tc_set_md_var(tc, "descr", "See that fstatat enforce search permission");
atf_tc_set_md_var(tc, "require.user", "unprivileged");
}
ATF_TC_BODY(o_search_perm2, tc)
{
int dfd;
int fd;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == 0);
ATF_REQUIRE(fchmod(dfd, 644) == 0);
ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == -1);
ATF_REQUIRE(errno == EACCES);
ATF_REQUIRE(close(dfd) == 0);
}
ATF_TC_CLEANUP(o_search_perm2, tc)
{
(void)unlink(FILE);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(o_search_flag2);
ATF_TC_HEAD(o_search_flag2, tc)
{
atf_tc_set_md_var(tc, "descr", "See that fstatat honours O_SEARCH");
}
ATF_TC_BODY(o_search_flag2, tc)
{
int dfd;
int fd;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE((dfd = open(DIR, O_RDONLY|O_SEARCH, 0)) != -1);
ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == 0);
ATF_REQUIRE(fchmod(dfd, 644) == 0);
ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == 0);
ATF_REQUIRE(fchmod(dfd, 444) == 0);
ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == 0);
ATF_REQUIRE(close(dfd) == 0);
}
ATF_TC_CLEANUP(o_search_flag2, tc)
{
(void)unlink(FILE);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(o_search_notdir);
ATF_TC_HEAD(o_search_notdir, tc)
{
atf_tc_set_md_var(tc, "descr", "See that openat fails with non dir fd");
}
ATF_TC_BODY(o_search_notdir, tc)
{
int dfd;
int fd;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((dfd = open(FILE, O_CREAT|O_RDWR|O_SEARCH, 0644)) != -1);
ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) == -1);
ATF_REQUIRE(errno == ENOTDIR);
}
ATF_TC_CLEANUP(o_search_notdir, tc)
{
(void)unlink(FILE);
(void)rmdir(DIR);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, o_search_perm1);
ATF_TP_ADD_TC(tp, o_search_flag1);
ATF_TP_ADD_TC(tp, o_search_perm2);
ATF_TP_ADD_TC(tp, o_search_flag2);
ATF_TP_ADD_TC(tp, o_search_notdir);
return atf_no_error();
}

View File

@ -0,0 +1,214 @@
/* $NetBSD: t_openat.c,v 1.1 2012/11/18 17:41:54 manu Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Emmanuel Dreyfus.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_openat.c,v 1.1 2012/11/18 17:41:54 manu Exp $");
#include <atf-c.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <paths.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/param.h>
#define DIR "dir"
#define FILE "dir/openat"
#define BASEFILE "openat"
#define FILEERR "dir/openaterr"
ATF_TC_WITH_CLEANUP(openat_fd);
ATF_TC_HEAD(openat_fd, tc)
{
atf_tc_set_md_var(tc, "descr", "See that openat works with fd");
}
ATF_TC_BODY(openat_fd, tc)
{
int dfd;
int fd;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDONLY, 0)) != -1);
ATF_REQUIRE(close(dfd) == 0);
ATF_REQUIRE(close(fd) == 0);
}
ATF_TC_CLEANUP(openat_fd, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(openat_fdcwd);
ATF_TC_HEAD(openat_fdcwd, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that openat works with fd as AT_FDCWD");
}
ATF_TC_BODY(openat_fdcwd, tc)
{
int fd;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE(chdir(DIR) == 0);
ATF_REQUIRE((fd = openat(AT_FDCWD, BASEFILE, O_RDONLY, 0)) != -1);
ATF_REQUIRE(close(fd) == 0);
}
ATF_TC_CLEANUP(openat_fdcwd, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(openat_fdcwderr);
ATF_TC_HEAD(openat_fdcwderr, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that openat fails with fd as AT_FDCWD and bad path");
}
ATF_TC_BODY(openat_fdcwderr, tc)
{
int fd;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = openat(AT_FDCWD, FILEERR, O_RDONLY, 0)) == -1);
}
ATF_TC_CLEANUP(openat_fdcwderr, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(openat_fderr1);
ATF_TC_HEAD(openat_fderr1, tc)
{
atf_tc_set_md_var(tc, "descr", "See that openat fail with bad path");
}
ATF_TC_BODY(openat_fderr1, tc)
{
int dfd;
int fd;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE((fd = openat(dfd, FILEERR, O_RDONLY, 0)) == -1);
ATF_REQUIRE(close(dfd) == 0);
}
ATF_TC_CLEANUP(openat_fderr1, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(openat_fderr2);
ATF_TC_HEAD(openat_fderr2, tc)
{
atf_tc_set_md_var(tc, "descr", "See that openat fails with bad fdat");
}
ATF_TC_BODY(openat_fderr2, tc)
{
int dfd;
int fd;
char cwd[MAXPATHLEN];
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE((dfd = open(getcwd(cwd, MAXPATHLEN), O_RDONLY, 0)) != -1);
ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDONLY, 0)) == -1);
ATF_REQUIRE(close(dfd) == 0);
}
ATF_TC_CLEANUP(openat_fderr2, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(openat_fderr3);
ATF_TC_HEAD(openat_fderr3, tc)
{
atf_tc_set_md_var(tc, "descr", "See that openat fails with fd as -1");
}
ATF_TC_BODY(openat_fderr3, tc)
{
int fd;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE((fd = openat(-1, FILE, O_RDONLY, 0)) == -1);
}
ATF_TC_CLEANUP(openat_fderr3, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, openat_fd);
ATF_TP_ADD_TC(tp, openat_fdcwd);
ATF_TP_ADD_TC(tp, openat_fdcwderr);
ATF_TP_ADD_TC(tp, openat_fderr1);
ATF_TP_ADD_TC(tp, openat_fderr2);
ATF_TP_ADD_TC(tp, openat_fderr3);
return atf_no_error();
}

View File

@ -0,0 +1,197 @@
/* $NetBSD: t_readlinkat.c,v 1.1 2012/11/18 17:41:54 manu Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Emmanuel Dreyfus.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_readlinkat.c,v 1.1 2012/11/18 17:41:54 manu Exp $");
#include <atf-c.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <paths.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/param.h>
#define DIR "dir"
#define FILE "dir/readlinkat"
#define BASEFILE "readlinkat"
#define LINK "dir/symlink"
#define BASELINK "symlink"
#define FILEERR "dir/readlinkaterr"
ATF_TC_WITH_CLEANUP(readlinkat_fd);
ATF_TC_HEAD(readlinkat_fd, tc)
{
atf_tc_set_md_var(tc, "descr", "See that readlinkat works with fd");
}
ATF_TC_BODY(readlinkat_fd, tc)
{
int dfd;
int fd;
char buf[MAXPATHLEN];
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE(symlink(FILE, LINK) == 0);
ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE(readlinkat(dfd, BASELINK, buf, sizeof(buf)) != -1);
ATF_REQUIRE(close(dfd) == 0);
ATF_REQUIRE(strcmp(buf, FILE) == 0);
}
ATF_TC_CLEANUP(readlinkat_fd, tc)
{
(void)unlink(FILE);
(void)unlink(LINK);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(readlinkat_fdcwd);
ATF_TC_HEAD(readlinkat_fdcwd, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that readlinkat works with fd as AT_FDCWD");
}
ATF_TC_BODY(readlinkat_fdcwd, tc)
{
int fd;
char buf[MAXPATHLEN];
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE(symlink(FILE, LINK) == 0);
ATF_REQUIRE(readlinkat(AT_FDCWD, LINK, buf, sizeof(buf)) != -1);
ATF_REQUIRE(strcmp(buf, FILE) == 0);
}
ATF_TC_CLEANUP(readlinkat_fdcwd, tc)
{
(void)unlink(FILE);
(void)unlink(LINK);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(readlinkat_fdcwderr);
ATF_TC_HEAD(readlinkat_fdcwderr, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that readlinkat fails with fd as AT_FDCWD and bad path");
}
ATF_TC_BODY(readlinkat_fdcwderr, tc)
{
char buf[MAXPATHLEN];
ATF_REQUIRE(readlinkat(AT_FDCWD, LINK, buf, sizeof(buf)) == -1);
}
ATF_TC_CLEANUP(readlinkat_fdcwderr, tc)
{
(void)unlink(FILE);
(void)unlink(LINK);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(readlinkat_fderr1);
ATF_TC_HEAD(readlinkat_fderr1, tc)
{
atf_tc_set_md_var(tc, "descr", "See that readlinkat fail with bad path");
}
ATF_TC_BODY(readlinkat_fderr1, tc)
{
int dfd;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE(readlinkat(dfd, FILEERR, F_OK, 0) == -1);
ATF_REQUIRE(close(dfd) == 0);
}
ATF_TC_CLEANUP(readlinkat_fderr1, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(readlinkat_fderr2);
ATF_TC_HEAD(readlinkat_fderr2, tc)
{
atf_tc_set_md_var(tc, "descr", "See that readlinkat fails with fd as -1");
}
ATF_TC_BODY(readlinkat_fderr2, tc)
{
int fd;
char buf[MAXPATHLEN];
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE(symlink(FILE, LINK) == 0);
ATF_REQUIRE(readlinkat(-1, LINK, buf, sizeof(buf)) == -1);
}
ATF_TC_CLEANUP(readlinkat_fderr2, tc)
{
(void)unlink(FILE);
(void)unlink(LINK);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, readlinkat_fd);
ATF_TP_ADD_TC(tp, readlinkat_fdcwd);
ATF_TP_ADD_TC(tp, readlinkat_fdcwderr);
ATF_TP_ADD_TC(tp, readlinkat_fderr1);
ATF_TP_ADD_TC(tp, readlinkat_fderr2);
return atf_no_error();
}

View File

@ -0,0 +1,189 @@
/* $NetBSD: t_renameat.c,v 1.1 2012/11/18 17:41:54 manu Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Emmanuel Dreyfus.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_renameat.c,v 1.1 2012/11/18 17:41:54 manu Exp $");
#include <atf-c.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <paths.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/param.h>
#include <sys/stat.h>
#define ODIR "olddir"
#define NDIR "newdir"
#define FILE "olddir/old"
#define BASEFILE "old"
#define RELFILE "../olddir/old"
#define TARGET "newdir/new"
#define BASETARGET "new"
#define FILEERR "olddir/olderr"
ATF_TC_WITH_CLEANUP(renameat_fd);
ATF_TC_HEAD(renameat_fd, tc)
{
atf_tc_set_md_var(tc, "descr", "See that renameat works with fd");
}
ATF_TC_BODY(renameat_fd, tc)
{
int ofd, nfd, fd;
struct stat ost, nst;
ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) != -1);
ATF_REQUIRE(stat(FILE, &ost) == 0);
ATF_REQUIRE((ofd = open(ODIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE((nfd = open(NDIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE(renameat(ofd, BASEFILE, nfd, BASETARGET) == 0);
ATF_REQUIRE(close(ofd) == 0);
ATF_REQUIRE(close(nfd) == 0);
ATF_REQUIRE(stat(TARGET, &nst) == 0);
ATF_REQUIRE(ost.st_ino == nst.st_ino);
}
ATF_TC_CLEANUP(renameat_fd, tc)
{
(void)unlink(FILE);
(void)unlink(TARGET);
(void)rmdir(NDIR);
(void)rmdir(ODIR);
}
ATF_TC_WITH_CLEANUP(renameat_fdcwd);
ATF_TC_HEAD(renameat_fdcwd, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that renameat works with fd as AT_FDCWD");
}
ATF_TC_BODY(renameat_fdcwd, tc)
{
int fd;
struct stat ost, nst;
ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) != -1);
ATF_REQUIRE(stat(FILE, &ost) == 0);
ATF_REQUIRE(renameat(AT_FDCWD, FILE, AT_FDCWD, TARGET) == 0);
ATF_REQUIRE(stat(TARGET, &nst) == 0);
ATF_REQUIRE(ost.st_ino == nst.st_ino);
}
ATF_TC_CLEANUP(renameat_fdcwd, tc)
{
(void)unlink(FILE);
(void)unlink(TARGET);
(void)rmdir(NDIR);
(void)rmdir(ODIR);
}
ATF_TC_WITH_CLEANUP(renameat_fdcwderr);
ATF_TC_HEAD(renameat_fdcwderr, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that renameat fails with fd as AT_FDCWD and bad path");
}
ATF_TC_BODY(renameat_fdcwderr, tc)
{
int fd;
ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) != -1);
ATF_REQUIRE(renameat(AT_FDCWD, FILEERR, AT_FDCWD, TARGET) == -1);
}
ATF_TC_CLEANUP(renameat_fdcwderr, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)unlink(TARGET);
(void)rmdir(NDIR);
(void)rmdir(ODIR);
}
ATF_TC_WITH_CLEANUP(renameat_fderr);
ATF_TC_HEAD(renameat_fderr, tc)
{
atf_tc_set_md_var(tc, "descr", "See that renameat fails with fd as -1");
}
ATF_TC_BODY(renameat_fderr, tc)
{
int fd;
ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) != -1);
ATF_REQUIRE(renameat(-1, FILE, AT_FDCWD, TARGET) == -1);
ATF_REQUIRE(renameat(AT_FDCWD, FILE, -1, TARGET) == -1);
ATF_REQUIRE(renameat(-1, FILE, -1, TARGET) == -1);
}
ATF_TC_CLEANUP(renameat_fderr, tc)
{
(void)unlink(FILE);
(void)unlink(TARGET);
(void)rmdir(NDIR);
(void)rmdir(ODIR);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, renameat_fd);
ATF_TP_ADD_TC(tp, renameat_fdcwd);
ATF_TP_ADD_TC(tp, renameat_fdcwderr);
ATF_TP_ADD_TC(tp, renameat_fderr);
return atf_no_error();
}

View File

@ -0,0 +1,188 @@
/* $NetBSD: t_symlinkat.c,v 1.1 2012/11/18 17:41:54 manu Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Emmanuel Dreyfus.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_symlinkat.c,v 1.1 2012/11/18 17:41:54 manu Exp $");
#include <atf-c.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <paths.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/param.h>
#include <sys/stat.h>
#define ODIR "olddir"
#define NDIR "newdir"
#define FILE "olddir/old"
#define BASEFILE "old"
#define RELFILE "../olddir/old"
#define LINK "newdir/symlink"
#define BASELINK "symlink"
#define FILEERR "olddir/olderr"
ATF_TC_WITH_CLEANUP(symlinkat_fd);
ATF_TC_HEAD(symlinkat_fd, tc)
{
atf_tc_set_md_var(tc, "descr", "See that symlinkat works with fd");
}
ATF_TC_BODY(symlinkat_fd, tc)
{
int dfd, fd;
struct stat ost, nst;
ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) != -1);
ATF_REQUIRE((dfd = open(NDIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE(symlinkat(RELFILE, dfd, BASELINK) == 0);
ATF_REQUIRE(close(dfd) == 0);
ATF_REQUIRE(stat(FILE, &ost) == 0);
ATF_REQUIRE(stat(LINK, &nst) == 0);
ATF_REQUIRE(ost.st_ino == nst.st_ino);
}
ATF_TC_CLEANUP(symlinkat_fd, tc)
{
(void)unlink(FILE);
(void)unlink(LINK);
(void)rmdir(NDIR);
(void)rmdir(ODIR);
}
ATF_TC_WITH_CLEANUP(symlinkat_fdcwd);
ATF_TC_HEAD(symlinkat_fdcwd, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that symlinkat works with fd as AT_FDCWD");
}
ATF_TC_BODY(symlinkat_fdcwd, tc)
{
int fd;
struct stat ost, nst;
ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) != -1);
ATF_REQUIRE(symlinkat(RELFILE, AT_FDCWD, LINK) == 0);
ATF_REQUIRE(stat(FILE, &ost) == 0);
ATF_REQUIRE(stat(LINK, &nst) == 0);
ATF_REQUIRE(ost.st_ino == nst.st_ino);
}
ATF_TC_CLEANUP(symlinkat_fdcwd, tc)
{
(void)unlink(FILE);
(void)unlink(LINK);
(void)rmdir(NDIR);
(void)rmdir(ODIR);
}
ATF_TC_WITH_CLEANUP(symlinkat_fdcwderr);
ATF_TC_HEAD(symlinkat_fdcwderr, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that symlinkat works with fd as AT_FDCWD and bad path");
}
ATF_TC_BODY(symlinkat_fdcwderr, tc)
{
int fd;
struct stat st;
ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) != -1);
ATF_REQUIRE(symlinkat(FILEERR, AT_FDCWD, LINK) == 0);
ATF_REQUIRE(lstat(LINK, &st) == 0);
ATF_REQUIRE(stat(LINK, &st) == -1);
ATF_REQUIRE(errno == ENOENT);
}
ATF_TC_CLEANUP(symlinkat_fdcwderr, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)unlink(LINK);
(void)rmdir(NDIR);
(void)rmdir(ODIR);
}
ATF_TC_WITH_CLEANUP(symlinkat_fderr);
ATF_TC_HEAD(symlinkat_fderr, tc)
{
atf_tc_set_md_var(tc, "descr", "See that symlinkat fails with fd as -1");
}
ATF_TC_BODY(symlinkat_fderr, tc)
{
int fd;
ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) != -1);
ATF_REQUIRE(symlinkat(RELFILE, -1, LINK) == -1);
}
ATF_TC_CLEANUP(symlinkat_fderr, tc)
{
(void)unlink(FILE);
(void)unlink(LINK);
(void)rmdir(NDIR);
(void)rmdir(ODIR);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, symlinkat_fd);
ATF_TP_ADD_TC(tp, symlinkat_fdcwd);
ATF_TP_ADD_TC(tp, symlinkat_fdcwderr);
ATF_TP_ADD_TC(tp, symlinkat_fderr);
return atf_no_error();
}

View File

@ -0,0 +1,231 @@
/* $NetBSD: t_unlinkat.c,v 1.1 2012/11/18 17:41:54 manu Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Emmanuel Dreyfus.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_unlinkat.c,v 1.1 2012/11/18 17:41:54 manu Exp $");
#include <atf-c.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <paths.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/param.h>
#define DIR "dir"
#define FILE "dir/unlinkat"
#define BASEFILE "unlinkat"
#define FILEERR "dir/unlinkaterr"
ATF_TC_WITH_CLEANUP(unlinkat_fd);
ATF_TC_HEAD(unlinkat_fd, tc)
{
atf_tc_set_md_var(tc, "descr", "See that unlinkat works with fd");
}
ATF_TC_BODY(unlinkat_fd, tc)
{
int dfd;
int fd;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE(unlinkat(dfd, BASEFILE, 0) == 0);
ATF_REQUIRE(close(dfd) == 0);
}
ATF_TC_CLEANUP(unlinkat_fd, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(unlinkat_fdcwd);
ATF_TC_HEAD(unlinkat_fdcwd, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that unlinkat works with fd as AT_FDCWD");
}
ATF_TC_BODY(unlinkat_fdcwd, tc)
{
int fd;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE(chdir(DIR) == 0);
ATF_REQUIRE(unlinkat(AT_FDCWD, BASEFILE, 0) == 0);
}
ATF_TC_CLEANUP(unlinkat_fdcwd, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(unlinkat_fdcwderr);
ATF_TC_HEAD(unlinkat_fdcwderr, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that unlinkat fails with fd as AT_FDCWD and bad path");
}
ATF_TC_BODY(unlinkat_fdcwderr, tc)
{
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE(unlinkat(AT_FDCWD, FILEERR, 0) == -1);
}
ATF_TC_CLEANUP(unlinkat_fdcwderr, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(unlinkat_fderr1);
ATF_TC_HEAD(unlinkat_fderr1, tc)
{
atf_tc_set_md_var(tc, "descr", "See that unlinkat fail with bad path");
}
ATF_TC_BODY(unlinkat_fderr1, tc)
{
int dfd;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE(unlinkat(dfd, FILEERR, 0) == -1);
ATF_REQUIRE(close(dfd) == 0);
}
ATF_TC_CLEANUP(unlinkat_fderr1, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(unlinkat_fderr2);
ATF_TC_HEAD(unlinkat_fderr2, tc)
{
atf_tc_set_md_var(tc, "descr", "See that unlinkat fails with bad fdat");
}
ATF_TC_BODY(unlinkat_fderr2, tc)
{
int dfd;
int fd;
char cwd[MAXPATHLEN];
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE((dfd = open(getcwd(cwd, MAXPATHLEN), O_RDONLY, 0)) != -1);
ATF_REQUIRE(unlinkat(dfd, BASEFILE, 0) == -1);
ATF_REQUIRE(close(dfd) == 0);
}
ATF_TC_CLEANUP(unlinkat_fderr2, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(unlinkat_fderr3);
ATF_TC_HEAD(unlinkat_fderr3, tc)
{
atf_tc_set_md_var(tc, "descr", "See that unlinkat fails with fd as -1");
}
ATF_TC_BODY(unlinkat_fderr3, tc)
{
int fd;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE(unlinkat(-1, FILE, 0) == -1);
}
ATF_TC_CLEANUP(unlinkat_fderr3, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(unlinkat_dir);
ATF_TC_HEAD(unlinkat_dir, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that unlinkat can remove directories");
}
ATF_TC_BODY(unlinkat_dir, tc)
{
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE(unlinkat(AT_FDCWD, DIR, 0) == -1);
ATF_REQUIRE(errno == EPERM);
ATF_REQUIRE(unlinkat(AT_FDCWD, DIR, AT_REMOVEDIR) == 0);
}
ATF_TC_CLEANUP(unlinkat_dir, tc)
{
(void)rmdir(DIR);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, unlinkat_fd);
ATF_TP_ADD_TC(tp, unlinkat_fdcwd);
ATF_TP_ADD_TC(tp, unlinkat_fdcwderr);
ATF_TP_ADD_TC(tp, unlinkat_fderr1);
ATF_TP_ADD_TC(tp, unlinkat_fderr2);
ATF_TP_ADD_TC(tp, unlinkat_fderr3);
ATF_TP_ADD_TC(tp, unlinkat_dir);
return atf_no_error();
}

View File

@ -0,0 +1,267 @@
/* $NetBSD: t_utimensat.c,v 1.1 2012/11/18 17:41:54 manu Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Emmanuel Dreyfus.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_utimensat.c,v 1.1 2012/11/18 17:41:54 manu Exp $");
#include <atf-c.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <paths.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/param.h>
#include <sys/time.h>
#define DIR "dir"
#define FILE "dir/utimensat"
#define BASEFILE "utimensat"
#define LINK "dir/symlink"
#define BASELINK "symlink"
#define FILEERR "dir/symlink"
const struct timespec tptr[] = {
{ 0x12345678, 0x87654321 },
{ 0x15263748, 0x84736251 },
};
ATF_TC_WITH_CLEANUP(utimensat_fd);
ATF_TC_HEAD(utimensat_fd, tc)
{
atf_tc_set_md_var(tc, "descr", "See that utimensat works with fd");
}
ATF_TC_BODY(utimensat_fd, tc)
{
int dfd;
int fd;
struct stat st;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE(utimensat(dfd, BASEFILE, tptr, 0) == 0);
ATF_REQUIRE(close(dfd) == 0);
ATF_REQUIRE(stat(FILE, &st) == 0);
ATF_REQUIRE(st.st_atimespec.tv_sec = tptr[1].tv_sec);
ATF_REQUIRE(st.st_atimespec.tv_nsec = tptr[1].tv_nsec);
ATF_REQUIRE(st.st_ctimespec.tv_sec = tptr[2].tv_sec);
ATF_REQUIRE(st.st_ctimespec.tv_nsec = tptr[2].tv_nsec);
}
ATF_TC_CLEANUP(utimensat_fd, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(utimensat_fdcwd);
ATF_TC_HEAD(utimensat_fdcwd, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that utimensat works with fd as AT_FDCWD");
}
ATF_TC_BODY(utimensat_fdcwd, tc)
{
int fd;
struct stat st;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE(chdir(DIR) == 0);
ATF_REQUIRE(utimensat(AT_FDCWD, BASEFILE, tptr, 0) == 0);
ATF_REQUIRE(stat(BASEFILE, &st) == 0);
ATF_REQUIRE(st.st_atimespec.tv_sec = tptr[1].tv_sec);
ATF_REQUIRE(st.st_atimespec.tv_nsec = tptr[1].tv_nsec);
ATF_REQUIRE(st.st_ctimespec.tv_sec = tptr[2].tv_sec);
ATF_REQUIRE(st.st_ctimespec.tv_nsec = tptr[2].tv_nsec);
}
ATF_TC_CLEANUP(utimensat_fdcwd, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(utimensat_fdcwderr);
ATF_TC_HEAD(utimensat_fdcwderr, tc)
{
atf_tc_set_md_var(tc, "descr",
"See that utimensat fails with fd as AT_FDCWD and bad path");
}
ATF_TC_BODY(utimensat_fdcwderr, tc)
{
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE(utimensat(AT_FDCWD, FILEERR, tptr, 0) == -1);
}
ATF_TC_CLEANUP(utimensat_fdcwderr, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(utimensat_fderr1);
ATF_TC_HEAD(utimensat_fderr1, tc)
{
atf_tc_set_md_var(tc, "descr", "See that utimensat fail with bad path");
}
ATF_TC_BODY(utimensat_fderr1, tc)
{
int dfd;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE(utimensat(dfd, FILEERR, tptr, 0) == -1);
ATF_REQUIRE(close(dfd) == 0);
}
ATF_TC_CLEANUP(utimensat_fderr1, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(utimensat_fderr2);
ATF_TC_HEAD(utimensat_fderr2, tc)
{
atf_tc_set_md_var(tc, "descr", "See that utimensat fails with bad fdat");
}
ATF_TC_BODY(utimensat_fderr2, tc)
{
int dfd;
int fd;
char cwd[MAXPATHLEN];
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE((dfd = open(getcwd(cwd, MAXPATHLEN), O_RDONLY, 0)) != -1);
ATF_REQUIRE(utimensat(dfd, BASEFILE, tptr, 0) == -1);
ATF_REQUIRE(close(dfd) == 0);
}
ATF_TC_CLEANUP(utimensat_fderr2, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(utimensat_fderr3);
ATF_TC_HEAD(utimensat_fderr3, tc)
{
atf_tc_set_md_var(tc, "descr", "See that utimensat fails with fd as -1");
}
ATF_TC_BODY(utimensat_fderr3, tc)
{
int fd;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE(utimensat(-1, FILE, tptr, 0) == -1);
}
ATF_TC_CLEANUP(utimensat_fderr3, tc)
{
(void)unlink(FILE);
(void)unlink(FILEERR);
(void)rmdir(DIR);
}
ATF_TC_WITH_CLEANUP(utimensat_fdlink);
ATF_TC_HEAD(utimensat_fdlink, tc)
{
atf_tc_set_md_var(tc, "descr", "See that utimensat works on symlink");
}
ATF_TC_BODY(utimensat_fdlink, tc)
{
int dfd;
struct stat st;
ATF_REQUIRE(mkdir(DIR, 0755) == 0);
ATF_REQUIRE(symlink(FILE, LINK) == 0); /* NB: FILE does not exists */
ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
ATF_REQUIRE(utimensat(dfd, BASELINK, tptr, 0) == -1);
ATF_REQUIRE(errno = ENOENT);
ATF_REQUIRE(utimensat(dfd, BASELINK, tptr, AT_SYMLINK_NOFOLLOW) == 0);
ATF_REQUIRE(close(dfd) == 0);
ATF_REQUIRE(lstat(LINK, &st) == 0);
ATF_REQUIRE(st.st_atimespec.tv_sec = tptr[1].tv_sec);
ATF_REQUIRE(st.st_atimespec.tv_nsec = tptr[1].tv_nsec);
ATF_REQUIRE(st.st_ctimespec.tv_sec = tptr[2].tv_sec);
ATF_REQUIRE(st.st_ctimespec.tv_nsec = tptr[2].tv_nsec);
}
ATF_TC_CLEANUP(utimensat_fdlink, tc)
{
(void)unlink(LINK);
(void)rmdir(DIR);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, utimensat_fd);
ATF_TP_ADD_TC(tp, utimensat_fdcwd);
ATF_TP_ADD_TC(tp, utimensat_fdcwderr);
ATF_TP_ADD_TC(tp, utimensat_fderr1);
ATF_TP_ADD_TC(tp, utimensat_fderr2);
ATF_TP_ADD_TC(tp, utimensat_fderr3);
ATF_TP_ADD_TC(tp, utimensat_fdlink);
return atf_no_error();
}