mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-29 16:21:29 +00:00
Userland: Allow our access check to pass flags to faccessat syscall
This commit is contained in:
parent
639aee037f
commit
059904371f
Notes:
sideshowbarker
2024-07-18 05:37:06 +09:00
Author: https://github.com/fdellwing Commit: https://github.com/SerenityOS/serenity/commit/059904371f Pull-request: https://github.com/SerenityOS/serenity/pull/18545 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/BenWiederhake Reviewed-by: https://github.com/LucasChollet Reviewed-by: https://github.com/kennethmyhra Reviewed-by: https://github.com/trflynn89
|
@ -1549,7 +1549,7 @@ ErrorOr<void> unlockpt(int fildes)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> access(StringView pathname, int mode)
|
ErrorOr<void> access(StringView pathname, int mode, int flags)
|
||||||
{
|
{
|
||||||
if (pathname.is_null())
|
if (pathname.is_null())
|
||||||
return Error::from_syscall("access"sv, -EFAULT);
|
return Error::from_syscall("access"sv, -EFAULT);
|
||||||
|
@ -1559,12 +1559,13 @@ ErrorOr<void> access(StringView pathname, int mode)
|
||||||
.dirfd = AT_FDCWD,
|
.dirfd = AT_FDCWD,
|
||||||
.pathname = { pathname.characters_without_null_termination(), pathname.length() },
|
.pathname = { pathname.characters_without_null_termination(), pathname.length() },
|
||||||
.mode = mode,
|
.mode = mode,
|
||||||
.flags = 0,
|
.flags = flags,
|
||||||
};
|
};
|
||||||
int rc = ::syscall(Syscall::SC_faccessat, ¶ms);
|
int rc = ::syscall(Syscall::SC_faccessat, ¶ms);
|
||||||
HANDLE_SYSCALL_RETURN_VALUE("access", rc, {});
|
HANDLE_SYSCALL_RETURN_VALUE("access", rc, {});
|
||||||
#else
|
#else
|
||||||
DeprecatedString path_string = pathname;
|
DeprecatedString path_string = pathname;
|
||||||
|
(void)flags;
|
||||||
if (::access(path_string.characters(), mode) < 0)
|
if (::access(path_string.characters(), mode) < 0)
|
||||||
return Error::from_syscall("access"sv, -errno);
|
return Error::from_syscall("access"sv, -errno);
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -228,7 +228,7 @@ ErrorOr<void> putenv(StringView);
|
||||||
ErrorOr<int> posix_openpt(int flags);
|
ErrorOr<int> posix_openpt(int flags);
|
||||||
ErrorOr<void> grantpt(int fildes);
|
ErrorOr<void> grantpt(int fildes);
|
||||||
ErrorOr<void> unlockpt(int fildes);
|
ErrorOr<void> unlockpt(int fildes);
|
||||||
ErrorOr<void> access(StringView pathname, int mode);
|
ErrorOr<void> access(StringView pathname, int mode, int flags = 0);
|
||||||
ErrorOr<DeprecatedString> readlink(StringView pathname);
|
ErrorOr<DeprecatedString> readlink(StringView pathname);
|
||||||
ErrorOr<int> poll(Span<struct pollfd>, int timeout);
|
ErrorOr<int> poll(Span<struct pollfd>, int timeout);
|
||||||
|
|
||||||
|
|
|
@ -359,14 +359,14 @@ ErrorOr<void> link_file(StringView destination_path, StringView source_path)
|
||||||
return TRY(Core::System::symlink(source_path, TRY(get_duplicate_file_name(destination_path))));
|
return TRY(Core::System::symlink(source_path, TRY(get_duplicate_file_name(destination_path))));
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<String> resolve_executable_from_environment(StringView filename)
|
ErrorOr<String> resolve_executable_from_environment(StringView filename, int flags)
|
||||||
{
|
{
|
||||||
if (filename.is_empty())
|
if (filename.is_empty())
|
||||||
return Error::from_errno(ENOENT);
|
return Error::from_errno(ENOENT);
|
||||||
|
|
||||||
// Paths that aren't just a file name generally count as already resolved.
|
// Paths that aren't just a file name generally count as already resolved.
|
||||||
if (filename.contains('/')) {
|
if (filename.contains('/')) {
|
||||||
TRY(Core::System::access(filename, X_OK));
|
TRY(Core::System::access(filename, X_OK, flags));
|
||||||
return TRY(String::from_utf8(filename));
|
return TRY(String::from_utf8(filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,7 +382,7 @@ ErrorOr<String> resolve_executable_from_environment(StringView filename)
|
||||||
for (auto directory : directories) {
|
for (auto directory : directories) {
|
||||||
auto file = TRY(String::formatted("{}/{}", directory, filename));
|
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;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ bool can_delete_or_move(StringView path);
|
||||||
ErrorOr<String> read_link(StringView link_path);
|
ErrorOr<String> read_link(StringView link_path);
|
||||||
ErrorOr<void> link_file(StringView destination_path, StringView source_path);
|
ErrorOr<void> link_file(StringView destination_path, StringView source_path);
|
||||||
|
|
||||||
ErrorOr<String> resolve_executable_from_environment(StringView filename);
|
ErrorOr<String> resolve_executable_from_environment(StringView filename, int flags = 0);
|
||||||
bool looks_like_shared_library(StringView path);
|
bool looks_like_shared_library(StringView path);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue