main.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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/ConnectionFromClient.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. #ifdef SIGINFO
  25. signal(SIGINFO, [](int) { RequestServer::ConnectionCache::dump_jobs(); });
  26. #endif
  27. if constexpr (TLS_SSL_KEYLOG_DEBUG)
  28. TRY(Core::System::pledge("stdio inet accept unix cpath wpath rpath sendfd recvfd"));
  29. else
  30. TRY(Core::System::pledge("stdio inet accept unix rpath sendfd recvfd"));
  31. // Ensure the certificates are read out here.
  32. // FIXME: Allow specifying extra certificates on the command line, or in other configuration.
  33. [[maybe_unused]] auto& certs = DefaultRootCACertificates::the();
  34. Core::EventLoop event_loop;
  35. // FIXME: Establish a connection to LookupServer and then drop "unix"?
  36. TRY(Core::System::unveil("/tmp/portal/lookup", "rw"));
  37. TRY(Core::System::unveil("/etc/timezone", "r"));
  38. if constexpr (TLS_SSL_KEYLOG_DEBUG)
  39. TRY(Core::System::unveil("/home/anon", "rwc"));
  40. TRY(Core::System::unveil(nullptr, nullptr));
  41. [[maybe_unused]] auto gemini = make<RequestServer::GeminiProtocol>();
  42. [[maybe_unused]] auto http = make<RequestServer::HttpProtocol>();
  43. [[maybe_unused]] auto https = make<RequestServer::HttpsProtocol>();
  44. auto client = TRY(IPC::take_over_accepted_client_from_system_server<RequestServer::ConnectionFromClient>());
  45. auto result = event_loop.exec();
  46. // FIXME: We exit instead of returning, so that protocol destructors don't get called.
  47. // The Protocol base class should probably do proper de-registration instead of
  48. // just VERIFY_NOT_REACHED().
  49. exit(result);
  50. }