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. --- sysdeps/mach/hurd/access.c | 141 +-------------------------------------------- 1 file changed, 3 insertions(+), 138 deletions(-) (limited to 'sysdeps/mach/hurd/access.c') diff --git a/sysdeps/mach/hurd/access.c b/sysdeps/mach/hurd/access.c index 9195bd61ff..31fd5bea56 100644 --- a/sysdeps/mach/hurd/access.c +++ b/sysdeps/mach/hurd/access.c @@ -15,145 +15,10 @@ License along with the GNU C Library; if not, see . */ +#include #include -#include -#include -#include -#include #include -static int -hurd_fail_seterrno (error_t err) -{ - return __hurd_fail (err); -} - -static int -hurd_fail_noerrno (error_t err) -{ - return -1; -} - -static int -access_common (const char *file, int type, int (*errfunc) (error_t)) -{ - error_t err; - file_t rcrdir, rcwdir, io; - int flags, allowed; - - error_t reauthenticate (int which, file_t *result) - { - /* Get a port to our root directory, authenticated with the real IDs. */ - error_t err; - mach_port_t ref; - ref = __mach_reply_port (); - err = HURD_PORT_USE - (&_hurd_ports[which], - ({ - err = __io_reauthenticate (port, ref, MACH_MSG_TYPE_MAKE_SEND); - if (!err) - err = __auth_user_authenticate (_hurd_id.rid_auth, - ref, MACH_MSG_TYPE_MAKE_SEND, - result); - err; - })); - __mach_port_destroy (__mach_task_self (), ref); - return err; - } - - error_t init_port (int which, error_t (*operate) (mach_port_t)) - { - switch (which) - { - case INIT_PORT_AUTH: - return (*operate) (_hurd_id.rid_auth); - case INIT_PORT_CRDIR: - return (reauthenticate (INIT_PORT_CRDIR, &rcrdir) ?: - (*operate) (rcrdir)); - case INIT_PORT_CWDIR: - return (reauthenticate (INIT_PORT_CWDIR, &rcwdir) ?: - (*operate) (rcwdir)); - default: - return _hurd_ports_use (which, operate); - } - } - - rcrdir = rcwdir = MACH_PORT_NULL; - - HURD_CRITICAL_BEGIN; - - __mutex_lock (&_hurd_id.lock); - /* Get _hurd_id up to date. */ - if (err = _hurd_check_ids ()) - goto lose; - - if (_hurd_id.rid_auth == MACH_PORT_NULL) - { - /* Set up _hurd_id.rid_auth. This is a special auth server port - which uses the real uid and gid (the first aux uid and gid) as - the only effective uid and gid. */ - - if (_hurd_id.aux.nuids < 1 || _hurd_id.aux.ngids < 1) - { - /* We do not have a real UID and GID. Lose, lose, lose! */ - err = EGRATUITOUS; - goto lose; - } - - /* Create a new auth port using our real UID and GID (the first - auxiliary UID and GID) as the only effective IDs. */ - if (err = __USEPORT (AUTH, - __auth_makeauth (port, - NULL, MACH_MSG_TYPE_COPY_SEND, 0, - _hurd_id.aux.uids, 1, - _hurd_id.aux.uids, - _hurd_id.aux.nuids, - _hurd_id.aux.gids, 1, - _hurd_id.aux.gids, - _hurd_id.aux.ngids, - &_hurd_id.rid_auth))) - goto lose; - } - - if (!err) - /* Look up the file name using the modified init ports. */ - err = __hurd_file_name_lookup (&init_port, &__getdport, 0, - file, 0, 0, &io); - - /* We are done with _hurd_id.rid_auth now. */ - lose: - __mutex_unlock (&_hurd_id.lock); - - HURD_CRITICAL_END; - - if (rcrdir != MACH_PORT_NULL) - __mach_port_deallocate (__mach_task_self (), rcrdir); - if (rcwdir != MACH_PORT_NULL) - __mach_port_deallocate (__mach_task_self (), rcwdir); - if (err) - return errfunc (err); - - /* Find out what types of access we are allowed to this file. */ - err = __file_check_access (io, &allowed); - __mach_port_deallocate (__mach_task_self (), io); - if (err) - return errfunc (err); - - flags = 0; - if (type & R_OK) - flags |= O_READ; - if (type & W_OK) - flags |= O_WRITE; - if (type & X_OK) - flags |= O_EXEC; - - if (flags & ~allowed) - /* We are not allowed all the requested types of access. */ - return errfunc (EACCES); - - return 0; -} - /* Test for access to FILE by our real user and group IDs without setting errno. This may be unsafe to run during initialization of tunables since access_common calls __hurd_file_name_lookup, which calls @@ -161,13 +26,13 @@ access_common (const char *file, int type, int (*errfunc) (error_t)) int __access_noerrno (const char *file, int type) { - return access_common (file, type, hurd_fail_noerrno); + return __faccessat_noerrno (AT_FDCWD, file, type, 0); } /* Test for access to FILE by our real user and group IDs. */ int __access (const char *file, int type) { - return access_common (file, type, hurd_fail_seterrno); + return __faccessat (AT_FDCWD, file, type, 0); } weak_alias (__access, access) -- cgit 1.4.1