2020-07-30 23:38:15 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
2022-01-11 16:51:34 +01:00
|
|
|
* Copyright (c) 2022, Daniel Bertalan <dani@danielbertalan.dev>
|
2020-07-30 23:38:15 +02:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-07-30 23:38:15 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <AK/StringView.h>
|
|
|
|
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
2023-02-24 19:45:37 +02:00
|
|
|
#include <Kernel/Tasks/Process.h>
|
2020-07-30 23:38:15 +02:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2022-01-11 16:51:34 +01:00
|
|
|
ErrorOr<FlatPtr> Process::sys$chmod(Userspace<Syscall::SC_chmod_params const*> user_params)
|
2020-07-30 23:38:15 +02:00
|
|
|
{
|
2022-03-08 16:36:42 +01:00
|
|
|
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
2021-12-29 01:11:45 -08:00
|
|
|
TRY(require_promise(Pledge::fattr));
|
2022-01-11 16:51:34 +01:00
|
|
|
auto params = TRY(copy_typed_from_user(user_params));
|
|
|
|
auto path = TRY(get_syscall_path_argument(params.path));
|
2023-04-03 15:59:10 +02:00
|
|
|
auto base = TRY(custody_for_dirfd(params.dirfd));
|
2022-08-21 16:02:24 +02:00
|
|
|
TRY(VirtualFileSystem::the().chmod(credentials(), path->view(), params.mode, *base, params.follow_symlinks ? 0 : O_NOFOLLOW_NOERROR));
|
2021-11-08 00:51:39 +01:00
|
|
|
return 0;
|
2020-07-30 23:38:15 +02:00
|
|
|
}
|
|
|
|
|
2021-11-08 00:51:39 +01:00
|
|
|
ErrorOr<FlatPtr> Process::sys$fchmod(int fd, mode_t mode)
|
2020-07-30 23:38:15 +02:00
|
|
|
{
|
2022-03-08 16:32:29 +01:00
|
|
|
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
2021-12-29 01:11:45 -08:00
|
|
|
TRY(require_promise(Pledge::fattr));
|
2022-01-29 01:22:28 +01:00
|
|
|
auto description = TRY(open_file_description(fd));
|
2022-08-21 16:15:29 +02:00
|
|
|
TRY(description->chmod(credentials(), mode));
|
2021-11-08 00:51:39 +01:00
|
|
|
return 0;
|
2020-07-30 23:38:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|