main.cpp 2.1 KB

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