POSIX defines faccessat() as having a fourth "flags" argument, while the linux syscall doesn't have it. Glibc tries to emulate AT_EACCESS and AT_SYMLINK_NOFOLLOW, but AT_EACCESS emulation is broken. Add a new faccessat(2) syscall with the added flags argument and implement both flags. The value of AT_EACCESS is defined in glibc headers to be the same as AT_REMOVEDIR. Use this value for the kernel interface as well, together with the explanatory comment. Also add AT_EMPTY_PATH support, which is not documented by POSIX, but can be useful and is trivial to implement.
Showing the changes to include/uapi/linux (1 of 23 files). Show all
Unified · Split
| @@ -84,10 +84,20 @@ · 83 unmodified lines | |||
| 84 | #define DN_ATTRIB 0x00000020 /* File changed attibutes */ | 84 | #define DN_ATTRIB 0x00000020 /* File changed attibutes */ |
| 85 | #define DN_MULTISHOT 0x80000000 /* Don't remove notifier */ | 85 | #define DN_MULTISHOT 0x80000000 /* Don't remove notifier */ |
| 86 | 86 | ||
| 87 | /* | ||
| 88 | * The constants AT_REMOVEDIR and AT_EACCESS have the same value. AT_EACCESS is | ||
| 89 | * meaningful only to faccessat, while AT_REMOVEDIR is meaningful only to | ||
| 90 | * unlinkat. The two functions do completely different things and therefore, | ||
| 91 | * the flags can be allowed to overlap. For example, passing AT_REMOVEDIR to | ||
| 92 | * faccessat would be undefined behavior and thus treating it equivalent to | ||
| 93 | * AT_EACCESS is valid undefined behavior. | ||
| 94 | */ | ||
| 87 | #define AT_FDCWD -100 /* Special value used to indicate | 95 | #define AT_FDCWD -100 /* Special value used to indicate |
| 88 | openat should use the current | 96 | openat should use the current |
| 89 | working directory. */ | 97 | working directory. */ |
| 90 | #define AT_SYMLINK_NOFOLLOW 0x100 /* Do not follow symbolic links. */ | 98 | #define AT_SYMLINK_NOFOLLOW 0x100 /* Do not follow symbolic links. */ |
| 99 | #define AT_EACCESS 0x200 /* Test access permitted for | ||
| 100 | effective IDs, not real IDs. */ | ||
| 91 | #define AT_REMOVEDIR 0x200 /* Remove directory instead of | 101 | #define AT_REMOVEDIR 0x200 /* Remove directory instead of |
| 92 | unlinking file. */ | 102 | unlinking file. */ |
| 93 | #define AT_SYMLINK_FOLLOW 0x400 /* Follow symbolic links. */ | 103 | #define AT_SYMLINK_FOLLOW 0x400 /* Follow symbolic links. */ |