From 6659323a82628d53eb67f86927edb05c76327ed8 Mon Sep 17 00:00:00 2001 From: Cathy Fitzpatrick Date: Sat, 23 Oct 2010 18:59:53 -0600 Subject: [PATCH] Added --server.uid option. --- src/main/main.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/main.cpp b/src/main/main.cpp index 62abb5e..3605cc9 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -55,7 +55,7 @@ const char *getPidFileName() { int initialise(int argc, char **argv, bool &daemon) { string configFile; - int port, databasePort, workerThreads; + int port, databasePort, workerThreads, serverUid; string serverName, welcomeFile, welcomeMessage; string databaseName, databaseHost, databaseUser, databasePassword; string authParameter, loginParameter, registerParameter; @@ -84,6 +84,9 @@ int initialise(int argc, char **argv, bool &daemon) { po::value(&workerThreads)->default_value( 20), "number of worker threads for network I/O") + ("server.uid", + po::value(&serverUid), + "UID to run the server process as") ("auth.vbulletin", po::value( &authParameter)->implicit_value("vbulletin"), @@ -164,6 +167,15 @@ int initialise(int argc, char **argv, bool &daemon) { po::notify(vm); } + if (vm.count("server.uid")) { + if (seteuid(serverUid)) { + // Failed to set the UID. + Log::out() << "Failed to set the effective UID to " << serverUid + << ". Try\n\n sudo shoddybattle2\n\ninstead." << endl; + return EXIT_FAILURE; + } + } + if (vm.count("server.welcome")) { ifstream file(welcomeFile.c_str()); if (!file.is_open()) {