Kernel: Fix directory permissions

We did not care about X bit in directories and instead used only the
R bit for search/read.
This commit is contained in:
Bananymous
2023-09-08 11:46:53 +03:00
parent 660f7cbfeb
commit 39a5c52088
10 changed files with 73 additions and 34 deletions

View File

@@ -58,7 +58,7 @@ DIR* fdopendir(int fd)
DIR* opendir(const char* dirname)
{
int fd = open(dirname, O_SEARCH);
int fd = open(dirname, O_RDONLY);
if (fd == -1)
return nullptr;
return fdopendir(fd);

View File

@@ -52,6 +52,8 @@ __BEGIN_DECLS
#define SYS_SET_PGID 45
#define SYS_FCNTL 46
#define SYS_NANOSLEEP 47
#define SYS_FSTATAT 48
#define SYS_STAT 49 // stat/lstat
__END_DECLS

View File

@@ -11,38 +11,15 @@ int fstat(int fildes, struct stat* buf)
int fstatat(int fd, const char* __restrict path, struct stat* __restrict buf, int flag)
{
if (flag == AT_SYMLINK_NOFOLLOW)
flag = O_NOFOLLOW;
else if (flag)
{
errno = EINVAL;
return -1;
}
int target = openat(fd, path, O_SEARCH | flag);
if (target == -1)
return -1;
int ret = fstat(target, buf);
close(target);
return ret;
return syscall(SYS_FSTATAT, fd, path, buf, flag);
}
int lstat(const char* __restrict path, struct stat* __restrict buf)
{
int fd = open(path, O_SEARCH | O_NOFOLLOW);
if (fd == -1)
return -1;
int ret = fstat(fd, buf);
close(fd);
return ret;
return syscall(SYS_STAT, path, buf, AT_SYMLINK_NOFOLLOW);
}
int stat(const char* __restrict path, struct stat* __restrict buf)
{
int fd = open(path, O_SEARCH);
if (fd == -1)
return -1;
int ret = fstat(fd, buf);
close(fd);
return ret;
return syscall(SYS_STAT, path, buf, 0);
}