access(2) System Calls Manual access(2) access, faccessat, faccessat2 - C (libc, -lc) #include int access(const char *pathname, int mode); #include /* AT_* */ #include int faccessat(int dirfd, const char *pathname, int mode, int flags); /* But see C library/kernel differences, below */ #include /* AT_* */ #include /* SYS_* */ #include int syscall(SYS_faccessat2, int dirfd, const char *pathname, int mode, int flags); glibc (. feature_test_macros(7)): faccessat(): glibc 2.10: _POSIX_C_SOURCE >= 200809L glibc 2.10: _ATFILE_SOURCE access , pathname. pathname , , . mode - ; F_OK, R_OK, W_OK X_OK. F_OK . R_OK, W_OK X_OK , , , . real (), () (UID) (GID) . (, open(2)). , root, , ; root- . set-user-ID (setuid) . access() << // ?>>. ( , setuid) : << the user who invoked me ( , ) // ?>>. set-user-ID , . (, UID 0), X_OK , , . faccessat() faccessat() , access(), , . pathname , , dirfd ( , access()). pathname dirfd AT_FDCWD, pathname ( access()). pathname , dirfd . flags : AT_EACCESS , . faccessat() ( access()). AT_EMPTY_PATH ( Linux 5.8) pathname - , , dirfd (, , open(2) O_PATH). , dirfd , . dirfd AT_FDCWD, . Linux; _GNU_SOURCE, . AT_SYMLINK_NOFOLLOW pathname , , . openat(2) faccessat(). faccessat2() faccessat() POSIX.1 , glibc. glibc (. ""), , Linux faccessat() flags. , Linux 5.8 faccessat2(), flags - faccessat(). ( , mode - F_OK ), . ( , - , mode mode - F_OK , - ) -1 errno . EACCES , pathname. ( path_resolution(7)). EBADF (faccessat()) pathname , dirfd AT_FDCWD (faccessat()), . EFAULT pathname . EINVAL mode . EINVAL (faccessat()) flags. EIO -. ELOOP pathname . ENAMETOOLONG pathname. ENOENT pathname ", " . ENOMEM . ENOTDIR , pathname, . ENOTDIR (faccessat()) pathname dirfd , , . EPERM , . FS_IOC_SETFLAGS(const). EROFS , , . ETXTBSY , . (, ), POSIX.1-2001 X_OK, . Linux . C raw faccessat() . AT_EACCESS AT_SYMLINK_NOFOLLOW - glibc faccessat(). , - fstatat(2) , . glibc , faccessat() ( AT_EACCESS AT_SYMLINK_NOFOLLOW), - glibc access(). pathname , glibc /proc/self/fd, dirfd. access() faccessat() POSIX.1-2008. faccessat2() Linux. access() SVr4, 4.3BSD, POSIX.1-2001. faccessat() Linux 2.6.16, glibc 2.4. faccessat2() Linux 5.8. Warning (): , , open(2), , . ( , open(2)). access() . , faccessat() AT_SYMLINK_NOFOLLOW. , mode, . , , pathname, ( , ). - , access() , . , . , , , , , , , , . , DOS , execve(2) . access() NFSv2 UID, , ( NFS 3 ). FUSE. faccessat() Linux flags, - glibc faccessat(), glibc 2.32 , , faccessat() fstatat(2). . glibc 2.33, - , faccessat 2(), . Linux 2.4 ( ) X_OK . , , access(), -1, , mode X_OK; R_OK W_OK mode, access() 0 . Linux 2.6 ( Linux 2.6.3 ) , Linux 2.4. Linux 2.6.20 MS_NOEXEC, mount(2) . Linux 2.6.20, MS_NOEXEC . chmod(2), chown(2), open(2), setgid(2), setuid(2), stat(2), euidaccess(3), credentials(7), path_resolution(7), symlink(7) () Dmitry Bolkhovskikh , Yuri Kozlov Aleksandr Felda ; GNU (GNU General Public License - GPL, 3 ) , - . - , , () () () <>. Linux man-pages 6.9.1 2024-06-13 access(2)