diff options
-rw-r--r-- | include/exitcodes.h | 2 | ||||
-rw-r--r-- | src/inspircd.cpp | 29 |
2 files changed, 20 insertions, 11 deletions
diff --git a/include/exitcodes.h b/include/exitcodes.h index 737433def..b1090d141 100644 --- a/include/exitcodes.h +++ b/include/exitcodes.h @@ -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 */ }; diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 94894557b..f60797ad3 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -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 } |