Serenity Operating System
at master 45 lines 1.4 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <AK/RefPtr.h> 8#include <Kernel/FileSystem/Custody.h> 9#include <Kernel/FileSystem/OpenFileDescription.h> 10#include <Kernel/FileSystem/VirtualFileSystem.h> 11#include <Kernel/Process.h> 12 13namespace Kernel { 14 15ErrorOr<FlatPtr> Process::sys$fchown(int fd, UserID uid, GroupID gid) 16{ 17 VERIFY_NO_PROCESS_BIG_LOCK(this); 18 TRY(require_promise(Pledge::chown)); 19 auto description = TRY(open_file_description(fd)); 20 TRY(description->chown(credentials(), uid, gid)); 21 return 0; 22} 23 24ErrorOr<FlatPtr> Process::sys$chown(Userspace<Syscall::SC_chown_params const*> user_params) 25{ 26 VERIFY_NO_PROCESS_BIG_LOCK(this); 27 TRY(require_promise(Pledge::chown)); 28 auto params = TRY(copy_typed_from_user(user_params)); 29 auto path = TRY(get_syscall_path_argument(params.path)); 30 31 RefPtr<Custody> base; 32 if (params.dirfd == AT_FDCWD) { 33 base = current_directory(); 34 } else { 35 auto base_description = TRY(open_file_description(params.dirfd)); 36 if (!base_description->custody()) 37 return EINVAL; 38 base = base_description->custody(); 39 } 40 41 TRY(VirtualFileSystem::the().chown(credentials(), path->view(), params.uid, params.gid, *base, params.follow_symlinks ? 0 : O_NOFOLLOW_NOERROR)); 42 return 0; 43} 44 45}