faccessat.cpp 1014 B

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/StringView.h>
  7. #include <Kernel/FileSystem/VirtualFileSystem.h>
  8. #include <Kernel/Tasks/Process.h>
  9. namespace Kernel {
  10. ErrorOr<FlatPtr> Process::sys$faccessat(Userspace<Syscall::SC_faccessat_params const*> user_params)
  11. {
  12. VERIFY_NO_PROCESS_BIG_LOCK(this);
  13. TRY(require_promise(Pledge::rpath));
  14. auto params = TRY(copy_typed_from_user(user_params));
  15. auto pathname = TRY(get_syscall_path_argument(params.pathname));
  16. if ((params.flags & ~(AT_SYMLINK_NOFOLLOW | AT_EACCESS)) != 0)
  17. return EINVAL;
  18. auto flags = AccessFlags::None;
  19. if (params.flags & AT_SYMLINK_NOFOLLOW)
  20. flags |= AccessFlags::DoNotFollowSymlinks;
  21. if (params.flags & AT_EACCESS)
  22. flags |= AccessFlags::EffectiveAccess;
  23. TRY(VirtualFileSystem::the().access(credentials(), pathname->view(), params.mode, TRY(custody_for_dirfd(params.dirfd)), flags));
  24. return 0;
  25. }
  26. }