main.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "IRCAppWindow.h"
  7. #include "IRCClient.h"
  8. #include <LibCore/StandardPaths.h>
  9. #include <LibGUI/Application.h>
  10. #include <LibGUI/MessageBox.h>
  11. #include <stdio.h>
  12. #include <unistd.h>
  13. int main(int argc, char** argv)
  14. {
  15. if (pledge("stdio inet unix recvfd sendfd cpath rpath wpath", nullptr) < 0) {
  16. perror("pledge");
  17. return 1;
  18. }
  19. if (getuid() == 0) {
  20. warnln("Refusing to run as root");
  21. return 1;
  22. }
  23. auto app = GUI::Application::construct(argc, argv);
  24. if (unveil("/tmp/portal/lookup", "rw") < 0) {
  25. perror("unveil");
  26. return 1;
  27. }
  28. if (unveil("/tmp/portal/notify", "rw") < 0) {
  29. perror("unveil");
  30. return 1;
  31. }
  32. if (unveil("/etc/passwd", "r") < 0) {
  33. perror("unveil");
  34. return 1;
  35. }
  36. if (unveil(Core::StandardPaths::home_directory().characters(), "rwc") < 0) {
  37. perror("unveil");
  38. return 1;
  39. }
  40. if (unveil("/res", "r") < 0) {
  41. perror("unveil");
  42. return 1;
  43. }
  44. if (unveil(nullptr, nullptr) < 0) {
  45. perror("unveil");
  46. return 1;
  47. }
  48. URL url = "";
  49. if (app->args().size() >= 1) {
  50. url = URL::create_with_url_or_path(app->args()[0]);
  51. if (url.protocol().to_lowercase() == "ircs") {
  52. warnln("Secure IRC over SSL/TLS (ircs) is not supported");
  53. return 1;
  54. }
  55. if (url.protocol().to_lowercase() != "irc") {
  56. warnln("Unsupported protocol");
  57. return 1;
  58. }
  59. if (url.host().is_empty()) {
  60. warnln("Invalid URL");
  61. return 1;
  62. }
  63. if (!url.port() || url.port() == 80)
  64. url.set_port(6667);
  65. }
  66. auto app_window = IRCAppWindow::construct(url.host(), url.port());
  67. app_window->show();
  68. return app->exec();
  69. }