2020-01-18 05:38:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2021-08-31 05:19:20 -03:00
|
|
|
#include <AK/OwnPtr.h>
|
2020-02-06 11:04:03 -03:00
|
|
|
#include <LibCore/EventLoop.h>
|
|
|
|
|
#include <LibCore/LocalServer.h>
|
2021-11-23 06:59:50 -03:00
|
|
|
#include <LibCore/System.h>
|
2021-12-06 14:11:05 -03:00
|
|
|
#include <LibIPC/SingleServer.h>
|
2021-11-23 06:41:57 -03:00
|
|
|
#include <LibMain/Main.h>
|
2020-10-30 05:27:32 -03:00
|
|
|
#include <LibTLS/Certificate.h>
|
2022-02-25 07:18:30 -03:00
|
|
|
#include <RequestServer/ConnectionFromClient.h>
|
2021-04-23 17:45:52 -03:00
|
|
|
#include <RequestServer/GeminiProtocol.h>
|
|
|
|
|
#include <RequestServer/HttpProtocol.h>
|
|
|
|
|
#include <RequestServer/HttpsProtocol.h>
|
2021-10-23 16:42:07 -03:00
|
|
|
#include <signal.h>
|
2019-11-23 17:45:33 -03:00
|
|
|
|
2021-11-23 06:41:57 -03:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments)
|
2019-11-23 17:45:33 -03:00
|
|
|
{
|
2022-02-09 16:42:56 -03:00
|
|
|
if constexpr (TLS_SSL_KEYLOG_DEBUG)
|
|
|
|
|
TRY(Core::System::pledge("stdio inet accept unix cpath wpath rpath sendfd recvfd sigaction"));
|
|
|
|
|
else
|
|
|
|
|
TRY(Core::System::pledge("stdio inet accept unix rpath sendfd recvfd sigaction"));
|
|
|
|
|
|
2022-07-04 13:04:00 -03:00
|
|
|
#ifdef SIGINFO
|
2021-10-01 14:59:51 -03:00
|
|
|
signal(SIGINFO, [](int) { RequestServer::ConnectionCache::dump_jobs(); });
|
2022-07-04 13:04:00 -03:00
|
|
|
#endif
|
2022-02-09 16:42:56 -03:00
|
|
|
|
|
|
|
|
if constexpr (TLS_SSL_KEYLOG_DEBUG)
|
|
|
|
|
TRY(Core::System::pledge("stdio inet accept unix cpath wpath rpath sendfd recvfd"));
|
|
|
|
|
else
|
|
|
|
|
TRY(Core::System::pledge("stdio inet accept unix rpath sendfd recvfd"));
|
2021-10-01 14:59:51 -03:00
|
|
|
|
2020-10-30 05:27:32 -03:00
|
|
|
// Ensure the certificates are read out here.
|
2020-12-20 20:09:48 -03:00
|
|
|
[[maybe_unused]] auto& certs = DefaultRootCACertificates::the();
|
2020-10-30 05:27:32 -03:00
|
|
|
|
2020-02-02 08:34:39 -03:00
|
|
|
Core::EventLoop event_loop;
|
2020-01-17 07:12:06 -03:00
|
|
|
// FIXME: Establish a connection to LookupServer and then drop "unix"?
|
2021-11-23 06:59:50 -03:00
|
|
|
TRY(Core::System::unveil("/tmp/portal/lookup", "rw"));
|
2022-01-23 14:01:59 -03:00
|
|
|
TRY(Core::System::unveil("/etc/timezone", "r"));
|
2022-02-09 16:42:56 -03:00
|
|
|
if constexpr (TLS_SSL_KEYLOG_DEBUG)
|
|
|
|
|
TRY(Core::System::unveil("/home/anon", "rwc"));
|
2021-11-23 06:59:50 -03:00
|
|
|
TRY(Core::System::unveil(nullptr, nullptr));
|
2020-05-04 13:48:20 -03:00
|
|
|
|
2021-08-31 05:19:20 -03:00
|
|
|
[[maybe_unused]] auto gemini = make<RequestServer::GeminiProtocol>();
|
|
|
|
|
[[maybe_unused]] auto http = make<RequestServer::HttpProtocol>();
|
|
|
|
|
[[maybe_unused]] auto https = make<RequestServer::HttpsProtocol>();
|
2020-07-06 08:27:25 -03:00
|
|
|
|
2022-02-25 07:18:30 -03:00
|
|
|
auto client = TRY(IPC::take_over_accepted_client_from_system_server<RequestServer::ConnectionFromClient>());
|
2021-12-06 14:11:05 -03:00
|
|
|
|
2021-09-05 14:31:39 -03:00
|
|
|
auto result = event_loop.exec();
|
|
|
|
|
|
|
|
|
|
// FIXME: We exit instead of returning, so that protocol destructors don't get called.
|
|
|
|
|
// The Protocol base class should probably do proper de-registration instead of
|
|
|
|
|
// just VERIFY_NOT_REACHED().
|
|
|
|
|
exit(result);
|
2019-11-23 17:45:33 -03:00
|
|
|
}
|