Serenity Operating System
at master 59 lines 2.2 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <AK/OwnPtr.h> 8#include <LibCore/EventLoop.h> 9#include <LibCore/LocalServer.h> 10#include <LibCore/System.h> 11#include <LibIPC/SingleServer.h> 12#include <LibMain/Main.h> 13#include <LibTLS/Certificate.h> 14#include <RequestServer/ConnectionFromClient.h> 15#include <RequestServer/GeminiProtocol.h> 16#include <RequestServer/HttpProtocol.h> 17#include <RequestServer/HttpsProtocol.h> 18#include <signal.h> 19 20ErrorOr<int> serenity_main(Main::Arguments) 21{ 22 if constexpr (TLS_SSL_KEYLOG_DEBUG) 23 TRY(Core::System::pledge("stdio inet accept unix cpath wpath rpath sendfd recvfd sigaction")); 24 else 25 TRY(Core::System::pledge("stdio inet accept unix rpath sendfd recvfd sigaction")); 26 27#ifdef SIGINFO 28 signal(SIGINFO, [](int) { RequestServer::ConnectionCache::dump_jobs(); }); 29#endif 30 31 if constexpr (TLS_SSL_KEYLOG_DEBUG) 32 TRY(Core::System::pledge("stdio inet accept unix cpath wpath rpath sendfd recvfd")); 33 else 34 TRY(Core::System::pledge("stdio inet accept unix rpath sendfd recvfd")); 35 36 // Ensure the certificates are read out here. 37 [[maybe_unused]] auto& certs = DefaultRootCACertificates::the(); 38 39 Core::EventLoop event_loop; 40 // FIXME: Establish a connection to LookupServer and then drop "unix"? 41 TRY(Core::System::unveil("/tmp/portal/lookup", "rw")); 42 TRY(Core::System::unveil("/etc/timezone", "r")); 43 if constexpr (TLS_SSL_KEYLOG_DEBUG) 44 TRY(Core::System::unveil("/home/anon", "rwc")); 45 TRY(Core::System::unveil(nullptr, nullptr)); 46 47 [[maybe_unused]] auto gemini = make<RequestServer::GeminiProtocol>(); 48 [[maybe_unused]] auto http = make<RequestServer::HttpProtocol>(); 49 [[maybe_unused]] auto https = make<RequestServer::HttpsProtocol>(); 50 51 auto client = TRY(IPC::take_over_accepted_client_from_system_server<RequestServer::ConnectionFromClient>()); 52 53 auto result = event_loop.exec(); 54 55 // FIXME: We exit instead of returning, so that protocol destructors don't get called. 56 // The Protocol base class should probably do proper de-registration instead of 57 // just VERIFY_NOT_REACHED(). 58 exit(result); 59}