summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2014-05-13 13:48:04 -0400
committerMark Benvenuto <mark.benvenuto@mongodb.com>2014-05-20 16:27:17 -0400
commit650c98468737c2ae9aa7f278111e863276c79e55 (patch)
tree2ed8b6d99c8d1d62f7b9ed2c59afd2677bf2565c
parent3f1b15b8fa5e9a59030db37341163935b1df39ef (diff)
downloadmongo-650c98468737c2ae9aa7f278111e863276c79e55.tar.gz
SERVER-13463: Option Validation for NT Services
The current working directory for NT Services differs between installation time and execution time. This leads to subtle user bugs where the service can fail to start because directories do not exist. In the worst situation, the log file directory may not exist which makes the debugging near impossible.
-rw-r--r--src/mongo/db/mongod_options.cpp19
-rw-r--r--src/mongo/db/server_options_helpers.cpp38
-rw-r--r--src/mongo/util/net/ssl_options.cpp34
-rw-r--r--src/mongo/util/net/ssl_options.h2
4 files changed, 91 insertions, 2 deletions
diff --git a/src/mongo/db/mongod_options.cpp b/src/mongo/db/mongod_options.cpp
index 7555075e5aa..66462ef2e03 100644
--- a/src/mongo/db/mongod_options.cpp
+++ b/src/mongo/db/mongod_options.cpp
@@ -28,6 +28,7 @@
#include "mongo/db/mongod_options.h"
+#include <boost/filesystem.hpp>
#include <string>
#include <vector>
@@ -155,9 +156,13 @@ namespace mongo {
// Storage Options
#ifdef _WIN32
+ boost::filesystem::path currentPath = boost::filesystem::current_path();
+
+ std::string defaultPath = currentPath.root_name().string() + "\\data\\db\\";
general_options.addOptionChaining("storage.dbPath", "dbpath", moe::String,
- "directory for datafiles - defaults to \\data\\db\\")
- .setDefault(moe::Value(std::string("\\data\\db\\")));
+ "directory for datafiles - defaults to \\data\\db\\ which is " + defaultPath +
+ " based on the current working drive")
+ .setDefault(moe::Value(defaultPath));
#else
general_options.addOptionChaining("storage.dbPath", "dbpath", moe::String,
@@ -525,6 +530,16 @@ namespace mongo {
}
}
+#ifdef _WIN32
+ if (params.count("install") || params.count("reinstall")) {
+ if (params.count("storage.dbPath") &&
+ !boost::filesystem::path(params["storage.dbPath"].as<string>()).is_absolute()) {
+ return Status(ErrorCodes::BadValue,
+ "dbPath requires an absolute file path with Windows services");
+ }
+ }
+#endif
+
return Status::OK();
}
diff --git a/src/mongo/db/server_options_helpers.cpp b/src/mongo/db/server_options_helpers.cpp
index 5c789660283..d8bd1f55633 100644
--- a/src/mongo/db/server_options_helpers.cpp
+++ b/src/mongo/db/server_options_helpers.cpp
@@ -35,6 +35,7 @@
#include <syslog.h>
#endif
#include <boost/filesystem.hpp>
+#include <boost/filesystem/operations.hpp>
#include "mongo/base/status.h"
#include "mongo/bson/util/builder.h"
@@ -400,6 +401,43 @@ namespace {
}
}
+#ifdef _WIN32
+ if (params.count("install") || params.count("reinstall")) {
+ if (params.count("logpath") &&
+ !boost::filesystem::path(params["logpath"].as<string>()).is_absolute()) {
+ return Status(ErrorCodes::BadValue,
+ "logpath requires an absolute file path with Windows services");
+ }
+
+ if (params.count("config") &&
+ !boost::filesystem::path(params["config"].as<string>()).is_absolute()) {
+ return Status(ErrorCodes::BadValue,
+ "config requires an absolute file path with Windows services");
+ }
+
+ if (params.count("processManagement.pidFilePath") &&
+ !boost::filesystem::path(
+ params["processManagement.pidFilePath"].as<string>()).is_absolute()) {
+ return Status(ErrorCodes::BadValue,
+ "pidFilePath requires an absolute file path with Windows services");
+ }
+
+ if (params.count("security.keyFile") &&
+ !boost::filesystem::path(params["security.keyFile"].as<string>()).is_absolute()) {
+ return Status(ErrorCodes::BadValue,
+ "keyFile requires an absolute file path with Windows services");
+ }
+
+ }
+#endif
+
+#ifdef MONGO_SSL
+ Status ret = validateSSLServerOptions(params);
+ if (!ret.isOK()) {
+ return ret;
+ }
+#endif
+
return Status::OK();
}
diff --git a/src/mongo/util/net/ssl_options.cpp b/src/mongo/util/net/ssl_options.cpp
index f468bcea754..382513c7079 100644
--- a/src/mongo/util/net/ssl_options.cpp
+++ b/src/mongo/util/net/ssl_options.cpp
@@ -108,6 +108,40 @@ namespace mongo {
return Status::OK();
}
+ Status validateSSLServerOptions(const moe::Environment& params) {
+#ifdef _WIN32
+ if (params.count("install") || params.count("reinstall")) {
+ if (params.count("net.ssl.PEMKeyFile") &&
+ !boost::filesystem::path(params["net.ssl.PEMKeyFile"].as<string>()).is_absolute()) {
+ return Status(ErrorCodes::BadValue,
+ "PEMKeyFile requires an absolute file path with Windows services");
+ }
+
+ if (params.count("net.ssl.clusterFile") &&
+ !boost::filesystem::path(
+ params["net.ssl.clusterFile"].as<string>()).is_absolute()) {
+ return Status(ErrorCodes::BadValue,
+ "clusterFile requires an absolute file path with Windows services");
+ }
+
+ if (params.count("net.ssl.CAFile") &&
+ !boost::filesystem::path(params["net.ssl.CAFile"].as<string>()).is_absolute()) {
+ return Status(ErrorCodes::BadValue,
+ "CAFile requires an absolute file path with Windows services");
+ }
+
+ if (params.count("net.ssl.CRLFile") &&
+ !boost::filesystem::path(params["net.ssl.CRLFile"].as<string>()).is_absolute()) {
+ return Status(ErrorCodes::BadValue,
+ "CRLFile requires an absolute file path with Windows services");
+ }
+
+ }
+#endif
+
+ return Status::OK();
+ }
+
Status canonicalizeSSLServerOptions(moe::Environment* params) {
if (params->count("net.ssl.sslOnNormalPorts") &&
diff --git a/src/mongo/util/net/ssl_options.h b/src/mongo/util/net/ssl_options.h
index 7ca67eb9381..7ef6fab940a 100644
--- a/src/mongo/util/net/ssl_options.h
+++ b/src/mongo/util/net/ssl_options.h
@@ -94,5 +94,7 @@ namespace mongo {
*/
Status canonicalizeSSLServerOptions(moe::Environment* params);
+ Status validateSSLServerOptions(const moe::Environment& params);
+
Status storeSSLClientOptions(const moe::Environment& params);
}