]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd.cpp
Fix indentation of CheckRoot() and error in non-interactive mode.
[user/henk/code/inspircd.git] / src / inspircd.cpp
index f35da105d6174a8c14731de5cab289bb8dd808e8..f60797ad3b188d2241131875a708e659ef5d8193 100644 (file)
@@ -80,6 +80,32 @@ namespace
 {
        void VoidSignalHandler(int);
 
+       // Warns a user running as root that they probably shouldn't.
+       void CheckRoot()
+       {
+#ifndef _WIN32
+               if (getegid() != 0 && geteuid() != 0)
+                       return;
+
+               std::cout << con_red << "Warning!" << con_reset << " You have started as root. Running as root is generally not required" << std::endl
+                       << "and may allow an attacker to gain access to your system if they find a way to" << std::endl
+                       << "exploit your IRC server." << std::endl
+                       << std::endl;
+               if (isatty(fileno(stdout)))
+               {
+                       std::cout << "InspIRCd will start in 30 seconds. If you are sure that you need to run as root" << std::endl
+                               << "then you can pass the " << con_bright << "--runasroot" << con_reset << " option to disable this wait." << std::endl;
+                       sleep(30);
+               }
+               else
+               {
+                       std::cout << "If you are sure that you need to run as root then you can pass the " << con_bright << "--runasroot" << con_reset << std::endl
+                               << "option to disable this error." << std::endl;
+                               ServerInstance->Exit(EXIT_STATUS_ROOT);
+               }
+#endif
+       }
+
        // Collects performance statistics for the STATS command.
        void CollectStats()
        {
@@ -465,24 +491,9 @@ InspIRCd::InspIRCd(int argc, char** argv)
                Exit(EXIT_STATUS_CONFIG);
        }
 
-#ifndef _WIN32
-       if (!do_root)
-               this->CheckRoot();
-       else
-       {
-               std::cout << "* WARNING * WARNING * WARNING * WARNING * WARNING *" << std::endl
-               << "YOU ARE RUNNING INSPIRCD AS ROOT. THIS IS UNSUPPORTED" << std::endl
-               << "AND IF YOU ARE HACKED, CRACKED, SPINDLED OR MUTILATED" << std::endl
-               << "OR ANYTHING ELSE UNEXPECTED HAPPENS TO YOU OR YOUR" << std::endl
-               << "SERVER, THEN IT IS YOUR OWN FAULT. IF YOU DID NOT MEAN" << std::endl
-               << "TO START INSPIRCD AS ROOT, HIT CTRL+C NOW AND RESTART" << std::endl
-               << "THE PROGRAM AS A NORMAL USER. YOU HAVE BEEN WARNED!" << std::endl << std::endl
-               << "InspIRCd starting in 20 seconds, ctrl+c to abort..." << std::endl;
-               sleep(20);
-       }
-#endif
-
        SetSignals();
+       if (!do_root)
+               CheckRoot();
 
        if (!Config->cmdline.nofork && !ForkIntoBackground())
        {