diff options
Diffstat (limited to 'db/cmdline.cpp')
-rw-r--r-- | db/cmdline.cpp | 125 |
1 files changed, 119 insertions, 6 deletions
diff --git a/db/cmdline.cpp b/db/cmdline.cpp index 2a10fb5..fd759a7 100644 --- a/db/cmdline.cpp +++ b/db/cmdline.cpp @@ -19,14 +19,17 @@ #include "pch.h" #include "cmdline.h" #include "commands.h" +#include "../util/password.h" #include "../util/processinfo.h" -#include "../util/message.h" -#include "security_key.h" +#include "../util/net/listen.h" +#include "security_common.h" #ifdef _WIN32 #include <direct.h> #endif +#define MAX_LINE_LENGTH 256 + namespace po = boost::program_options; namespace fs = boost::filesystem; @@ -34,7 +37,8 @@ namespace mongo { void setupSignals( bool inFork ); string getHostNameCached(); - BSONArray argvArray; + static BSONArray argvArray; + static BSONObj parsedOpts; void CmdLine::addGlobalOptions( boost::program_options::options_description& general , boost::program_options::options_description& hidden ) { @@ -52,15 +56,25 @@ namespace mongo { ("port", po::value<int>(&cmdLine.port), "specify port number") ("bind_ip", po::value<string>(&cmdLine.bind_ip), "comma separated list of ip addresses to listen on - all local ips by default") ("maxConns",po::value<int>(), "max number of simultaneous connections") + ("objcheck", "inspect client data for validity on receipt") ("logpath", po::value<string>() , "log file to send write to instead of stdout - has to be a file, not directory" ) ("logappend" , "append to logpath instead of over-writing" ) ("pidfilepath", po::value<string>(), "full path to pidfile (if not set, no pidfile is created)") ("keyFile", po::value<string>(), "private key for cluster authentication (only for replica sets)") #ifndef _WIN32 + ("nounixsocket", "disable listening on unix sockets") ("unixSocketPrefix", po::value<string>(), "alternative directory for UNIX domain sockets (defaults to /tmp)") ("fork" , "fork server process" ) #endif ; + + hidden.add_options() +#ifdef MONGO_SSL + ("sslOnNormalPorts" , "use ssl on configured ports" ) + ("sslPEMKeyFile" , po::value<string>(&cmdLine.sslPEMKeyFile), "PEM file for ssl" ) + ("sslPEMKeyPassword" , new PasswordValue(&cmdLine.sslPEMKeyPassword) , "PEM file password" ) +#endif + ; } @@ -82,6 +96,32 @@ namespace mongo { } #endif + void CmdLine::parseConfigFile( istream &f, stringstream &ss ) { + string s; + char line[MAX_LINE_LENGTH]; + + while ( f ) { + f.getline(line, MAX_LINE_LENGTH); + s = line; + std::remove(s.begin(), s.end(), ' '); + std::remove(s.begin(), s.end(), '\t'); + boost::to_upper(s); + + if ( s.find( "FASTSYNC" ) != string::npos ) + cout << "warning \"fastsync\" should not be put in your configuration file" << endl; + + if ( s.c_str()[0] == '#' ) { + // skipping commented line + } else if ( s.find( "=FALSE" ) == string::npos ) { + ss << line << endl; + } else { + cout << "warning: remove or comment out this line by starting it with \'#\', skipping now : " << line << endl; + } + } + return; + } + + bool CmdLine::store( int argc , char ** argv , boost::program_options::options_description& visible, @@ -138,7 +178,9 @@ namespace mongo { return false; } - po::store( po::parse_config_file( f , all ) , params ); + stringstream ss; + CmdLine::parseConfigFile( f, ss ); + po::store( po::parse_config_file( ss , all ) , params ); f.close(); } @@ -178,6 +220,10 @@ namespace mongo { connTicketHolder.resize( newSize ); } + if (params.count("objcheck")) { + cmdLine.objcheck = true; + } + string logpath; #ifndef _WIN32 @@ -188,7 +234,11 @@ namespace mongo { ::exit(-1); } } - + + if (params.count("nounixsocket")) { + cmdLine.noUnixSocket = true; + } + if (params.count("fork")) { if ( ! params.count( "logpath" ) ) { cout << "--fork has to be used with --logpath" << endl; @@ -252,6 +302,7 @@ namespace mongo { setupCoreSignals(); setupSignals( true ); } + #endif if (params.count("logpath")) { if ( logpath.size() == 0 ) @@ -272,9 +323,66 @@ namespace mongo { dbexit(EXIT_BADOPTIONS); } + cmdLine.keyFile = true; noauth = false; } + else { + cmdLine.keyFile = false; + } +#ifdef MONGO_SSL + if (params.count("sslOnNormalPorts") ) { + cmdLine.sslOnNormalPorts = true; + + if ( cmdLine.sslPEMKeyPassword.size() == 0 ) { + log() << "need sslPEMKeyPassword" << endl; + dbexit(EXIT_BADOPTIONS); + } + + if ( cmdLine.sslPEMKeyFile.size() == 0 ) { + log() << "need sslPEMKeyFile" << endl; + dbexit(EXIT_BADOPTIONS); + } + + cmdLine.sslServerManager = new SSLManager( false ); + cmdLine.sslServerManager->setupPEM( cmdLine.sslPEMKeyFile , cmdLine.sslPEMKeyPassword ); + } +#endif + + { + BSONObjBuilder b; + for (po::variables_map::const_iterator it(params.begin()), end(params.end()); it != end; it++){ + if (!it->second.defaulted()){ + const string& key = it->first; + const po::variable_value& value = it->second; + const type_info& type = value.value().type(); + + if (type == typeid(string)){ + if (value.as<string>().empty()) + b.appendBool(key, true); // boost po uses empty string for flags like --quiet + else + b.append(key, value.as<string>()); + } + else if (type == typeid(int)) + b.append(key, value.as<int>()); + else if (type == typeid(double)) + b.append(key, value.as<double>()); + else if (type == typeid(bool)) + b.appendBool(key, value.as<bool>()); + else if (type == typeid(long)) + b.appendNumber(key, (long long)value.as<long>()); + else if (type == typeid(unsigned)) + b.appendNumber(key, (long long)value.as<unsigned>()); + else if (type == typeid(unsigned long long)) + b.appendNumber(key, (long long)value.as<unsigned long long>()); + else if (type == typeid(vector<string>)) + b.append(key, value.as<vector<string> >()); + else + b.append(key, "UNKNOWN TYPE: " + demangleName(type)); + } + } + parsedOpts = b.obj(); + } { BSONArrayBuilder b; @@ -286,6 +394,10 @@ namespace mongo { return true; } + void printCommandLineOpts() { + log() << "options: " << parsedOpts << endl; + } + void ignoreSignal( int sig ) {} void setupCoreSignals() { @@ -303,8 +415,9 @@ namespace mongo { virtual bool adminOnly() const { return true; } virtual bool slaveOk() const { return true; } - virtual bool run(const string&, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + virtual bool run(const string&, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { result.append("argv", argvArray); + result.append("parsed", parsedOpts); return true; } |