summaryrefslogtreecommitdiff
path: root/src/mongo/tools/tool.cpp
diff options
context:
space:
mode:
authorAntonin Kral <a.kral@bobek.cz>2013-04-17 21:51:49 +0200
committerAntonin Kral <a.kral@bobek.cz>2013-04-17 21:51:49 +0200
commit3c0811b838ca6b5e26855e6850b2f1d7fd8ea20a (patch)
treeb0c6fec4fa8578d9215c7fdcadd89b705aad2c64 /src/mongo/tools/tool.cpp
parentf0db7048a1748ec5ee8a55eaf964b2b1ca886cef (diff)
Imported Upstream version 2.4.2upstream/2.4.2
Diffstat (limited to 'src/mongo/tools/tool.cpp')
-rw-r--r--src/mongo/tools/tool.cpp26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/mongo/tools/tool.cpp b/src/mongo/tools/tool.cpp
index dfa20f2c8ea..c2728b88af0 100644
--- a/src/mongo/tools/tool.cpp
+++ b/src/mongo/tools/tool.cpp
@@ -270,7 +270,7 @@ namespace mongo {
int ret = -1;
try {
- if (!useDirectClient)
+ if (!useDirectClient && !_noconnection)
auth();
ret = run();
}
@@ -406,6 +406,18 @@ namespace mongo {
throw UserException( 9998 , "you need to specify fields" );
}
+ std::string Tool::getAuthenticationDatabase() {
+ if (!_authenticationDatabase.empty()) {
+ return _authenticationDatabase;
+ }
+
+ if (!_db.empty()) {
+ return _db;
+ }
+
+ return "admin";
+ }
+
/**
* Validate authentication on the server for the given dbname.
*/
@@ -422,17 +434,7 @@ namespace mongo {
return;
}
- std::string userSource = _authenticationDatabase;
- if ( userSource.empty() ) {
- if ( !_db.empty() ) {
- userSource = _db;
- }
- else {
- userSource = "admin";
- }
- }
-
- _conn->auth( BSON( saslCommandPrincipalSourceFieldName << userSource <<
+ _conn->auth( BSON( saslCommandPrincipalSourceFieldName << getAuthenticationDatabase() <<
saslCommandPrincipalFieldName << _username <<
saslCommandPasswordFieldName << _password <<
saslCommandMechanismFieldName << _authenticationMechanism ) );