From 09085ede12fb9650f286bdcd805609ae69f80618 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Wed, 10 Jan 2018 01:58:23 +0100 Subject: hurd: Implement faccessat without AT_EACCESS flag * hurd/hurd/fd.h: Include (__hurd_at_flags): New function. * hurd/lookup-at.c (__file_name_lookup_at): Replace flag computation with call to __hurd_at_flags. * include/unistd.h (__faccessat, __faccessat_noerrno): Add declaration. * sysdeps/mach/hurd/access.c (access_common): Move implementation to __faccessat (hurd_fail_seterrno, hurd_fail_noerrno): Move to sysdeps/mach/hurd/faccessat.c. (__access_noerrno): Use __faccessat_common instead of access_common. (__access): Likewise. * sysdeps/mach/hurd/euidaccess.c (__euidaccess): Replace implementation with a call to __faccessat. * sysdeps/mach/hurd/faccessat.c (faccessat): Rename into... (__faccessat_common): ... this. Move implementation of __access into it when AT_FLAGS does not contain AT_EACCESS. Make it call __hurd_at_flags, add reauthenticate_cwdir_at helper to implement AT mechanism. (__faccessat_noerrno): New function, just calls __faccessat_common. (__faccessat): New function, just calls __faccessat_common. (faccessat): Define weak alias. --- hurd/hurd/fd.h | 21 +++++++++++++++++++++ hurd/lookup-at.c | 13 +++---------- 2 files changed, 24 insertions(+), 10 deletions(-) (limited to 'hurd') diff --git a/hurd/hurd/fd.h b/hurd/hurd/fd.h index 7fd2297779..809a73f5dd 100644 --- a/hurd/hurd/fd.h +++ b/hurd/hurd/fd.h @@ -26,6 +26,7 @@ #include #include #include +#include /* Structure representing a file descriptor. */ @@ -254,6 +255,26 @@ extern int _hurd_select (int nfds, struct pollfd *pollfds, const struct timespec *timeout, const sigset_t *sigmask); +/* Apply AT_FLAGS on FLAGS, in preparation for calling + __hurd_file_name_lookup. */ + +_HURD_FD_H_EXTERN_INLINE error_t +__hurd_at_flags (int *at_flags, int *flags) +{ + if ((*at_flags & AT_SYMLINK_FOLLOW) && (*at_flags & AT_SYMLINK_NOFOLLOW)) + return EINVAL; + + *flags |= (*at_flags & AT_SYMLINK_NOFOLLOW) ? O_NOLINK : 0; + *at_flags &= ~AT_SYMLINK_NOFOLLOW; + if (*at_flags & AT_SYMLINK_FOLLOW) + *flags &= ~O_NOLINK; + *at_flags &= ~AT_SYMLINK_FOLLOW; + if (*at_flags != 0) + return EINVAL; + + return 0; +} + /* Variant of file_name_lookup used in *at function implementations. AT_FLAGS may only contain AT_SYMLINK_FOLLOW or AT_SYMLINK_NOFOLLOW, which will remove and add O_NOLINK from FLAGS respectively. diff --git a/hurd/lookup-at.c b/hurd/lookup-at.c index abf9047e57..deddc2264c 100644 --- a/hurd/lookup-at.c +++ b/hurd/lookup-at.c @@ -29,16 +29,9 @@ __file_name_lookup_at (int fd, int at_flags, error_t err; file_t result; - if ((at_flags & AT_SYMLINK_FOLLOW) && (at_flags & AT_SYMLINK_NOFOLLOW)) - return (__hurd_fail (EINVAL), MACH_PORT_NULL); - - flags |= (at_flags & AT_SYMLINK_NOFOLLOW) ? O_NOLINK : 0; - at_flags &= ~AT_SYMLINK_NOFOLLOW; - if (at_flags & AT_SYMLINK_FOLLOW) - flags &= ~O_NOLINK; - at_flags &= ~AT_SYMLINK_FOLLOW; - if (at_flags != 0) - return (__hurd_fail (EINVAL), MACH_PORT_NULL); + err = __hurd_at_flags (&at_flags, &flags); + if (err) + return (__hurd_fail (err), MACH_PORT_NULL); if (fd == AT_FDCWD || file_name[0] == '/') return __file_name_lookup (file_name, flags, mode); -- cgit v1.2.3