diff --git a/Userland/Applications/Browser/main.cpp b/Userland/Applications/Browser/main.cpp index 339deb19aa..393dc5e0c7 100644 --- a/Userland/Applications/Browser/main.cpp +++ b/Userland/Applications/Browser/main.cpp @@ -54,11 +54,8 @@ ErrorOr serenity_main(Main::Arguments arguments) // Connect to LaunchServer immediately and let it know that we won't ask for anything other than opening // the user's downloads directory. // FIXME: This should go away with a standalone download manager at some point. - if (!Desktop::Launcher::add_allowed_url(URL::create_with_file_protocol(Core::StandardPaths::downloads_directory())) - || !Desktop::Launcher::seal_allowlist()) { - warnln("Failed to set up allowed launch URLs"); - return 1; - } + TRY(Desktop::Launcher::add_allowed_url(URL::create_with_file_protocol(Core::StandardPaths::downloads_directory()))); + TRY(Desktop::Launcher::seal_allowlist()); TRY(Core::System::unveil("/home", "rwc")); TRY(Core::System::unveil("/res", "r")); diff --git a/Userland/Applications/FontEditor/main.cpp b/Userland/Applications/FontEditor/main.cpp index b9c6e9c413..388454448b 100644 --- a/Userland/Applications/FontEditor/main.cpp +++ b/Userland/Applications/FontEditor/main.cpp @@ -24,13 +24,8 @@ ErrorOr serenity_main(Main::Arguments arguments) auto app = TRY(GUI::Application::try_create(arguments)); - if (!Desktop::Launcher::add_allowed_handler_with_only_specific_urls( - "/bin/Help", - { URL::create_with_file_protocol("/usr/share/man/man1/FontEditor.md") }) - || !Desktop::Launcher::seal_allowlist()) { - warnln("Failed to set up allowed launch URLs"); - return 1; - } + TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_protocol("/usr/share/man/man1/FontEditor.md") })); + TRY(Desktop::Launcher::seal_allowlist()); TRY(Core::System::pledge("stdio recvfd sendfd thread rpath cpath wpath", nullptr)); diff --git a/Userland/Applications/ImageViewer/main.cpp b/Userland/Applications/ImageViewer/main.cpp index b9fc9a88a5..e6cc44b60a 100644 --- a/Userland/Applications/ImageViewer/main.cpp +++ b/Userland/Applications/ImageViewer/main.cpp @@ -38,21 +38,9 @@ ErrorOr serenity_main(Main::Arguments arguments) auto app = TRY(GUI::Application::try_create(arguments)); - if (!Desktop::Launcher::add_allowed_handler_with_any_url("/bin/ImageViewer")) { - warnln("Failed to set up allowed launch URLs"); - return 1; - } - - if (!Desktop::Launcher::add_allowed_handler_with_only_specific_urls( - "/bin/Help", { URL::create_with_file_protocol("/usr/share/man/man1/ImageViewer.md") })) { - warnln("Failed to set up allowed launch URLs"); - return 1; - } - - if (!Desktop::Launcher::seal_allowlist()) { - warnln("Failed to seal allowed launch URLs"); - return 1; - } + TRY(Desktop::Launcher::add_allowed_handler_with_any_url("/bin/ImageViewer")); + TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_protocol("/usr/share/man/man1/ImageViewer.md") })); + TRY(Desktop::Launcher::seal_allowlist()); auto app_icon = GUI::Icon::default_icon("filetype-image"); diff --git a/Userland/DevTools/Inspector/main.cpp b/Userland/DevTools/Inspector/main.cpp index d3abcaa10f..e9a5fe3682 100644 --- a/Userland/DevTools/Inspector/main.cpp +++ b/Userland/DevTools/Inspector/main.cpp @@ -79,13 +79,8 @@ ErrorOr serenity_main(Main::Arguments arguments) } } - if (!Desktop::Launcher::add_allowed_handler_with_only_specific_urls( - "/bin/Help", - { URL::create_with_file_protocol("/usr/share/man/man1/Inspector.md") }) - || !Desktop::Launcher::seal_allowlist()) { - warnln("Failed to set up allowed launch URLs"); - return 1; - } + TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_protocol("/usr/share/man/man1/Inspector.md") })); + TRY(Desktop::Launcher::seal_allowlist()); window->set_title("Inspector"); window->resize(685, 500); diff --git a/Userland/DevTools/Playground/main.cpp b/Userland/DevTools/Playground/main.cpp index f35f5543c2..ce7f4b1b08 100644 --- a/Userland/DevTools/Playground/main.cpp +++ b/Userland/DevTools/Playground/main.cpp @@ -66,13 +66,9 @@ ErrorOr serenity_main(Main::Arguments arguments) auto app = TRY(GUI::Application::try_create(arguments)); TRY(Core::System::pledge("stdio thread recvfd sendfd rpath cpath wpath unix", nullptr)); - if (!Desktop::Launcher::add_allowed_handler_with_only_specific_urls( - "/bin/Help", - { URL::create_with_file_protocol("/usr/share/man/man1/Playground.md") }) - || !Desktop::Launcher::seal_allowlist()) { - warnln("Failed to set up allowed launch URLs"); - return 1; - } + + TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_protocol("/usr/share/man/man1/Playground.md") })); + TRY(Desktop::Launcher::seal_allowlist()); TRY(Core::System::pledge("stdio thread recvfd sendfd rpath cpath wpath", nullptr)); diff --git a/Userland/DevTools/Profiler/main.cpp b/Userland/DevTools/Profiler/main.cpp index 162ce7d536..822660755a 100644 --- a/Userland/DevTools/Profiler/main.cpp +++ b/Userland/DevTools/Profiler/main.cpp @@ -78,13 +78,8 @@ ErrorOr serenity_main(Main::Arguments arguments) auto window = TRY(GUI::Window::try_create()); - if (!Desktop::Launcher::add_allowed_handler_with_only_specific_urls( - "/bin/Help", - { URL::create_with_file_protocol("/usr/share/man/man1/Profiler.md") }) - || !Desktop::Launcher::seal_allowlist()) { - warnln("Failed to set up allowed launch URLs"); - return 1; - } + TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_protocol("/usr/share/man/man1/Profiler.md") })); + TRY(Desktop::Launcher::seal_allowlist()); window->set_title("Profiler"); window->set_icon(app_icon.bitmap_for_size(16)); diff --git a/Userland/Libraries/LibDesktop/Launcher.cpp b/Userland/Libraries/LibDesktop/Launcher.cpp index 36a2af332c..4af7c4c8de 100644 --- a/Userland/Libraries/LibDesktop/Launcher.cpp +++ b/Userland/Libraries/LibDesktop/Launcher.cpp @@ -50,44 +50,36 @@ static LaunchServerConnection& connection() return connection; } -bool Launcher::add_allowed_url(const URL& url) +ErrorOr Launcher::add_allowed_url(URL const& url) { auto response_or_error = connection().try_add_allowed_url(url); - if (response_or_error.is_error()) { - dbgln("Launcher::add_allowed_url: Failed"); - return false; - } - return true; + if (response_or_error.is_error()) + return Error::from_string_literal("Launcher::add_allowed_url: Failed"sv); + return {}; } -bool Launcher::add_allowed_handler_with_any_url(const String& handler) +ErrorOr Launcher::add_allowed_handler_with_any_url(String const& handler) { auto response_or_error = connection().try_add_allowed_handler_with_any_url(handler); - if (response_or_error.is_error()) { - dbgln("Launcher::add_allowed_handler_with_any_url: Failed"); - return false; - } - return true; + if (response_or_error.is_error()) + return Error::from_string_literal("Launcher::add_allowed_handler_with_any_url: Failed"sv); + return {}; } -bool Launcher::add_allowed_handler_with_only_specific_urls(const String& handler, const Vector& urls) +ErrorOr Launcher::add_allowed_handler_with_only_specific_urls(String const& handler, Vector const& urls) { auto response_or_error = connection().try_add_allowed_handler_with_only_specific_urls(handler, urls); - if (response_or_error.is_error()) { - dbgln("Launcher::add_allowed_handler_with_only_specific_urls: Failed"); - return false; - } - return true; + if (response_or_error.is_error()) + return Error::from_string_literal("Launcher::add_allowed_handler_with_only_specific_urls: Failed"sv); + return {}; } -bool Launcher::seal_allowlist() +ErrorOr Launcher::seal_allowlist() { auto response_or_error = connection().try_seal_allowlist(); - if (response_or_error.is_error()) { - dbgln("Launcher::seal_allowlist: Failed"); - return false; - } - return true; + if (response_or_error.is_error()) + return Error::from_string_literal("Launcher::seal_allowlist: Failed"sv); + return {}; } bool Launcher::open(const URL& url, const String& handler_name) diff --git a/Userland/Libraries/LibDesktop/Launcher.h b/Userland/Libraries/LibDesktop/Launcher.h index 4612eb6afc..a74a6505a6 100644 --- a/Userland/Libraries/LibDesktop/Launcher.h +++ b/Userland/Libraries/LibDesktop/Launcher.h @@ -31,10 +31,10 @@ public: static NonnullRefPtr
from_details_str(const String&); }; - [[nodiscard]] static bool add_allowed_url(const URL&); - [[nodiscard]] static bool add_allowed_handler_with_any_url(const String& handler); - [[nodiscard]] static bool add_allowed_handler_with_only_specific_urls(const String& handler, const Vector&); - [[nodiscard]] static bool seal_allowlist(); + static ErrorOr add_allowed_url(URL const&); + static ErrorOr add_allowed_handler_with_any_url(String const& handler); + static ErrorOr add_allowed_handler_with_only_specific_urls(String const& handler, Vector const&); + static ErrorOr seal_allowlist(); static bool open(const URL&, const String& handler_name = {}); static bool open(const URL&, const Details& details); static Vector get_handlers_for_url(const URL&);