1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:27:35 +00:00

Kernel+LibC+LibCore: Add lchown and fchownat functions

This modifies sys$chown to allow specifying whether or not to follow
symlinks and in which directory.

This was then used to implement lchown and fchownat in LibC and LibCore.
This commit is contained in:
circl 2021-12-31 19:20:17 +01:00 committed by Andreas Kling
parent 344cfa0db4
commit 63760603f3
8 changed files with 64 additions and 7 deletions

View file

@ -368,13 +368,13 @@ ErrorOr<void> fchmod(int fd, mode_t mode)
return {};
}
ErrorOr<void> chown(StringView pathname, uid_t uid, gid_t gid)
ErrorOr<void> lchown(StringView pathname, uid_t uid, gid_t gid)
{
if (!pathname.characters_without_null_termination())
return Error::from_syscall("chown"sv, -EFAULT);
#ifdef __serenity__
Syscall::SC_chown_params params = { { pathname.characters_without_null_termination(), pathname.length() }, uid, gid };
Syscall::SC_chown_params params = { { pathname.characters_without_null_termination(), pathname.length() }, uid, gid, AT_FDCWD, false };
int rc = syscall(SC_chown, &params);
HANDLE_SYSCALL_RETURN_VALUE("chown"sv, rc, {});
#else
@ -385,6 +385,23 @@ ErrorOr<void> chown(StringView pathname, uid_t uid, gid_t gid)
#endif
}
ErrorOr<void> chown(StringView pathname, uid_t uid, gid_t gid)
{
if (!pathname.characters_without_null_termination())
return Error::from_syscall("chown"sv, -EFAULT);
#ifdef __serenity__
Syscall::SC_chown_params params = { { pathname.characters_without_null_termination(), pathname.length() }, uid, gid, AT_FDCWD, true };
int rc = syscall(SC_chown, &params);
HANDLE_SYSCALL_RETURN_VALUE("chown"sv, rc, {});
#else
String path = pathname;
if (::lchown(path.characters(), uid, gid) < 0)
return Error::from_syscall("lchown"sv, -errno);
return {};
#endif
}
ErrorOr<Optional<struct passwd>> getpwnam(StringView name)
{
::setpwent();