mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-29 11:41:21 +03:00
Linux: Use faccessat2 to implement faccessat (bug 18683)
This provides correct AT_EACCESS handling and also takes Linux security modules into account. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
This commit is contained in:
@ -30,6 +30,13 @@
|
|||||||
int
|
int
|
||||||
faccessat (int fd, const char *file, int mode, int flag)
|
faccessat (int fd, const char *file, int mode, int flag)
|
||||||
{
|
{
|
||||||
|
int ret = INLINE_SYSCALL_CALL (faccessat2, fd, file, mode, flag);
|
||||||
|
#if __ASSUME_FACCESSAT2
|
||||||
|
return ret;
|
||||||
|
#else
|
||||||
|
if (ret == 0 || errno != ENOSYS)
|
||||||
|
return ret;
|
||||||
|
|
||||||
if (flag & ~(AT_SYMLINK_NOFOLLOW | AT_EACCESS))
|
if (flag & ~(AT_SYMLINK_NOFOLLOW | AT_EACCESS))
|
||||||
return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
|
return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
|
||||||
|
|
||||||
@ -41,9 +48,9 @@ faccessat (int fd, const char *file, int mode, int flag)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
mode &= (X_OK | W_OK | R_OK); /* Clear any bogus bits. */
|
mode &= (X_OK | W_OK | R_OK); /* Clear any bogus bits. */
|
||||||
#if R_OK != S_IROTH || W_OK != S_IWOTH || X_OK != S_IXOTH
|
# if R_OK != S_IROTH || W_OK != S_IWOTH || X_OK != S_IXOTH
|
||||||
# error Oops, portability assumptions incorrect.
|
# error Oops, portability assumptions incorrect.
|
||||||
#endif
|
# endif
|
||||||
|
|
||||||
if (mode == F_OK)
|
if (mode == F_OK)
|
||||||
return 0; /* The file exists. */
|
return 0; /* The file exists. */
|
||||||
@ -68,4 +75,5 @@ faccessat (int fd, const char *file, int mode, int flag)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return INLINE_SYSCALL_ERROR_RETURN_VALUE (EACCES);
|
return INLINE_SYSCALL_ERROR_RETURN_VALUE (EACCES);
|
||||||
|
#endif /* !__ASSUME_FACCESSAT2 */
|
||||||
}
|
}
|
||||||
|
@ -214,4 +214,12 @@
|
|||||||
# define __ASSUME_WAITID_PID0_P_PGID
|
# define __ASSUME_WAITID_PID0_P_PGID
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* The faccessat2 system call was introduced across all architectures
|
||||||
|
in Linux 5.8. */
|
||||||
|
#if __LINUX_KERNEL_VERSION >= 0x050800
|
||||||
|
# define __ASSUME_FACCESSAT2 1
|
||||||
|
#else
|
||||||
|
# define __ASSUME_FACCESSAT2 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* kernel-features.h */
|
#endif /* kernel-features.h */
|
||||||
|
Reference in New Issue
Block a user