]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Fix indentation of CheckRoot() and error in non-interactive mode.
authorPeter Powell <petpow@saberuk.com>
Mon, 9 Dec 2019 00:10:59 +0000 (00:10 +0000)
committerPeter Powell <petpow@saberuk.com>
Mon, 9 Dec 2019 00:10:59 +0000 (00:10 +0000)
include/exitcodes.h
src/inspircd.cpp

index 737433def77b4cd9bd1b9ed3a29d77d08705abb3..b1090d1414c438ed91c1a7e11841246d0d0b0dfe 100644 (file)
@@ -33,7 +33,7 @@ enum ExitStatus
        EXIT_STATUS_ARGV = 5,                   /* Invalid program arguments */
        EXIT_STATUS_PID = 6,                    /* Couldn't write PID file */
        EXIT_STATUS_SOCKETENGINE = 7,   /* Couldn't start socket engine */
-       EXIT_STATUS_ROOT = 8,                   /* DEPRECATED */
+       EXIT_STATUS_ROOT = 8,                   /* Refusing to start as root */
        EXIT_STATUS_MODULE = 9,                 /* Couldn't load a required module */
        EXIT_STATUS_SIGTERM = 10                /* Received SIGTERM */
 };
index 94894557b8a9c3282437cd39ea2a44f758f614d3..f60797ad3b188d2241131875a708e659ef5d8193 100644 (file)
@@ -71,7 +71,7 @@ const char* ExitCodes[] =
                "Bad commandline parameters",                   // 5
                "Can't write PID file",                                 // 6
                "SocketEngine could not initialize",    // 7
-               "UNUSED",                                                               // 8
+               "Refusing to start up as root",                 // 8
                "Couldn't load module on startup",              // 9
                "Received SIGTERM"                                              // 10
 };
@@ -84,16 +84,25 @@ namespace
        void CheckRoot()
        {
 #ifndef _WIN32
-       if (getegid() != 0 && geteuid() != 0)
-               return;
+               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
-               << "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);
+               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
        }