6 #include "pthread_impl.h"
14 static const int errors[] = {
15 0, -EACCES, -ELOOP, -ENAMETOOLONG, -ENOENT, -ENOTDIR,
16 -EROFS, -EBADF, -EINVAL, -ETXTBSY,
17 -EFAULT, -EIO, -ENOMEM,
21 static int checker(void *p)
26 if (__syscall(SYS_setregid, __syscall(SYS_getegid), -1)
27 || __syscall(SYS_setreuid, __syscall(SYS_geteuid), -1))
28 __syscall(SYS_exit, 1);
29 ret = __syscall(SYS_faccessat, c->fd, c->filename, c->amode, 0);
30 for (i=0; i < sizeof errors/sizeof *errors - 1 && ret!=errors[i]; i++);
34 int faccessat(int fd, const char *filename, int amode, int flag)
36 if (!flag || (flag==AT_EACCESS && getuid()==geteuid() && getgid()==getegid()))
37 return syscall(SYS_faccessat, fd, filename, amode, flag);
39 if (flag != AT_EACCESS)
40 return __syscall_ret(-EINVAL);
46 struct ctx c = { .fd = fd, .filename = filename, .amode = amode };
48 __block_all_sigs(&set);
50 pid = __clone(checker, stack+sizeof stack, 0, &c);
54 __syscall(SYS_wait4, pid, &status, __WCLONE, 0);
55 } while (!WIFEXITED(status) && !WIFSIGNALED(status));
56 if (WIFEXITED(status))
57 ret = errors[WEXITSTATUS(status)];
62 return __syscall_ret(ret);