From 059904371fb93487d7931ae063364bf65f245d33 Mon Sep 17 00:00:00 2001 From: Fabian Dellwing Date: Tue, 9 May 2023 09:35:45 +0200 Subject: [PATCH] Userland: Allow our access check to pass flags to faccessat syscall --- Userland/Libraries/LibCore/System.cpp | 5 +++-- Userland/Libraries/LibCore/System.h | 2 +- Userland/Libraries/LibFileSystem/FileSystem.cpp | 6 +++--- Userland/Libraries/LibFileSystem/FileSystem.h | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index 24d37968103..a9ae27414ec 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -1549,7 +1549,7 @@ ErrorOr unlockpt(int fildes) return {}; } -ErrorOr access(StringView pathname, int mode) +ErrorOr access(StringView pathname, int mode, int flags) { if (pathname.is_null()) return Error::from_syscall("access"sv, -EFAULT); @@ -1559,12 +1559,13 @@ ErrorOr access(StringView pathname, int mode) .dirfd = AT_FDCWD, .pathname = { pathname.characters_without_null_termination(), pathname.length() }, .mode = mode, - .flags = 0, + .flags = flags, }; int rc = ::syscall(Syscall::SC_faccessat, ¶ms); HANDLE_SYSCALL_RETURN_VALUE("access", rc, {}); #else DeprecatedString path_string = pathname; + (void)flags; if (::access(path_string.characters(), mode) < 0) return Error::from_syscall("access"sv, -errno); return {}; diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index 54fa4c5a368..7da769eb96f 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -228,7 +228,7 @@ ErrorOr putenv(StringView); ErrorOr posix_openpt(int flags); ErrorOr grantpt(int fildes); ErrorOr unlockpt(int fildes); -ErrorOr access(StringView pathname, int mode); +ErrorOr access(StringView pathname, int mode, int flags = 0); ErrorOr readlink(StringView pathname); ErrorOr poll(Span, int timeout); diff --git a/Userland/Libraries/LibFileSystem/FileSystem.cpp b/Userland/Libraries/LibFileSystem/FileSystem.cpp index 908200c2e54..41c10b8f222 100644 --- a/Userland/Libraries/LibFileSystem/FileSystem.cpp +++ b/Userland/Libraries/LibFileSystem/FileSystem.cpp @@ -359,14 +359,14 @@ ErrorOr link_file(StringView destination_path, StringView source_path) return TRY(Core::System::symlink(source_path, TRY(get_duplicate_file_name(destination_path)))); } -ErrorOr resolve_executable_from_environment(StringView filename) +ErrorOr resolve_executable_from_environment(StringView filename, int flags) { if (filename.is_empty()) return Error::from_errno(ENOENT); // Paths that aren't just a file name generally count as already resolved. if (filename.contains('/')) { - TRY(Core::System::access(filename, X_OK)); + TRY(Core::System::access(filename, X_OK, flags)); return TRY(String::from_utf8(filename)); } @@ -382,7 +382,7 @@ ErrorOr resolve_executable_from_environment(StringView filename) for (auto directory : directories) { auto file = TRY(String::formatted("{}/{}", directory, filename)); - if (!Core::System::access(file, X_OK).is_error()) + if (!Core::System::access(file, X_OK, flags).is_error()) return file; } diff --git a/Userland/Libraries/LibFileSystem/FileSystem.h b/Userland/Libraries/LibFileSystem/FileSystem.h index 41ba5862b8c..a16b6e4836e 100644 --- a/Userland/Libraries/LibFileSystem/FileSystem.h +++ b/Userland/Libraries/LibFileSystem/FileSystem.h @@ -73,7 +73,7 @@ bool can_delete_or_move(StringView path); ErrorOr read_link(StringView link_path); ErrorOr link_file(StringView destination_path, StringView source_path); -ErrorOr resolve_executable_from_environment(StringView filename); +ErrorOr resolve_executable_from_environment(StringView filename, int flags = 0); bool looks_like_shared_library(StringView path); }