From a8aab6f98a6c792eff72ca5f6cd6ceeb87ac6c09 Mon Sep 17 00:00:00 2001 From: Guillaume Delannoy Date: Tue, 4 May 2010 10:47:20 -0400 Subject: [PATCH] All tools (including shell) take -p should allow it to be blank and do password input SERVER-764 --- SConstruct | 2 +- shell/dbshell.cpp | 9 ++++++++- tools/tool.cpp | 9 ++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/SConstruct b/SConstruct index 5ca15b43981..d923b365581 100644 --- a/SConstruct +++ b/SConstruct @@ -382,7 +382,7 @@ if GetOption( "extralib" ) is not None: commonFiles = Split( "pch.cpp buildinfo.cpp db/common.cpp db/jsobj.cpp db/json.cpp db/lasterror.cpp db/nonce.cpp db/queryutil.cpp shell/mongo.cpp" ) commonFiles += [ "util/background.cpp" , "util/mmap.cpp" , "util/ramstore.cpp", "util/sock.cpp" , "util/util.cpp" , "util/message.cpp" , "util/assert_util.cpp" , "util/httpclient.cpp" , "util/md5main.cpp" , "util/base64.cpp", "util/debug_util.cpp", - "util/thread_pool.cpp" ] + "util/thread_pool.cpp", "util/password.cpp" ] commonFiles += Glob( "util/*.c" ) commonFiles += Split( "client/connpool.cpp client/dbclient.cpp client/dbclientcursor.cpp client/model.cpp client/syncclusterconnection.cpp" ) commonFiles += [ "scripting/engine.cpp" , "scripting/utils.cpp" ] diff --git a/shell/dbshell.cpp b/shell/dbshell.cpp index 202b9de7947..a2a5b7b4b34 100644 --- a/shell/dbshell.cpp +++ b/shell/dbshell.cpp @@ -30,6 +30,7 @@ jmp_buf jbuf; #include "../util/unittest.h" #include "../db/cmdline.h" #include "utils.h" +#include "../util/password.h" using namespace std; using namespace boost::filesystem; @@ -318,7 +319,8 @@ int _main(int argc, char* argv[]) { ("host", po::value(&dbhost), "server to connect to") ("eval", po::value(&script), "evaluate javascript") ("username,u", po::value(&username), "username for authentication") - ("password,p", po::value(&password), "password for authentication") + ("password,p", new mongo::PasswordValue(&password), + "password for authentication") ("help,h", "show this usage information") ("version", "show version information") ("ipv6", "enable IPv6 support (disabled by default)") @@ -419,6 +421,11 @@ int _main(int argc, char* argv[]) { mongo::shellUtils::_dbConnect = ss.str(); + if ( params.count( "password" ) + && ( password.empty() ) ) { + password = mongo::askPassword(); + } + if ( username.size() && password.size() ){ stringstream ss; ss << "if ( ! db.auth( \"" << username << "\" , \"" << password << "\" ) ){ throw 'login failed'; }"; diff --git a/tools/tool.cpp b/tools/tool.cpp index 158769f7cd8..4e5914f0832 100644 --- a/tools/tool.cpp +++ b/tools/tool.cpp @@ -24,6 +24,7 @@ #include #include "util/file_allocator.h" +#include "util/password.h" using namespace std; using namespace mongo; @@ -47,7 +48,7 @@ namespace mongo { ("db,d",po::value(), "database to use" ) ("collection,c",po::value(), "collection to use (some commands)" ) ("username,u",po::value(), "username" ) - ("password,p",po::value(), "password" ) + ("password,p", new PasswordValue( &_password ), "password" ) ("ipv6", "enable IPv6 support (disabled by default)") ; if ( localDBAllowed ) @@ -196,8 +197,10 @@ namespace mongo { if ( _params.count( "username" ) ) _username = _params["username"].as(); - if ( _params.count( "password" ) ) - _password = _params["password"].as(); + if ( _params.count( "password" ) + && ( _password.empty() ) ) { + _password = askPassword(); + } if (_params.count("ipv6")) enableIPv6();