65
66
("username,u",po::value<string>(), "username" )
66
67
("password,p", new PasswordValue( &_password ), "password" )
68
("authenticationDatabase",
69
po::value<string>(&_authenticationDatabase)->default_value(""),
70
"user source (defaults to dbname)" )
71
("authenticationMechanism",
72
po::value<string>(&_authenticationMechanism)->default_value("MONGODB-CR"),
73
"authentication mechanism")
69
76
if ( access & LOCAL_SERVER )
72
79
"files in the given path, instead of connecting to a mongod "
73
80
"server - needs to lock the data directory, so cannot be "
74
81
"used if a mongod is currently accessing the same path" )
75
("directoryperdb", "if dbpath specified, each db is in a separate directory" )
76
("journal", "enable journaling" )
82
("directoryperdb", "each db is in a separate directly (relevant only if dbpath specified)" )
83
("journal", "enable journaling (relevant only if dbpath specified)" )
79
86
if ( access & SPECIFY_DBCOL )
118
125
// we want durability to be disabled.
119
126
cmdLine.dur = false;
121
#if( BOOST_VERSION >= 104500 )
122
boost::filesystem::path::default_name_check( boost::filesystem2::no_check );
124
boost::filesystem::path::default_name_check( boost::filesystem::no_check );
129
130
/* using the same style as db.cpp */
273
if (!useDirectClient && !_noconnection)
274
277
catch ( DBException& e ) {
275
278
cerr << "assertion: " << e.toString() << endl;
278
catch(const boost::filesystem::filesystem_error &fse) {
280
https://jira.mongodb.org/browse/SERVER-2904
282
Simple tools that don't access the database, such as
283
bsondump, aren't throwing DBExceptions, but are throwing
286
The currently available set of error codes don't seem to match
287
boost documentation. boost::filesystem::not_found_error
288
(from http://www.boost.org/doc/libs/1_31_0/libs/filesystem/doc/exception.htm)
289
doesn't seem to exist in our headers. Also, fse.code() isn't
290
boost::system::errc::no_such_file_or_directory when this
291
happens, as you would expect. And, determined from
292
experimentation that the command-line argument gets turned into
293
"\\?" instead of "/?" !!!
281
catch(const boost::filesystem::filesystem_error &fse) {
283
https://jira.mongodb.org/browse/SERVER-2904
285
Simple tools that don't access the database, such as
286
bsondump, aren't throwing DBExceptions, but are throwing
289
The currently available set of error codes don't seem to match
290
boost documentation. boost::filesystem::not_found_error
291
(from http://www.boost.org/doc/libs/1_31_0/libs/filesystem/doc/exception.htm)
292
doesn't seem to exist in our headers. Also, fse.code() isn't
293
boost::system::errc::no_such_file_or_directory when this
294
happens, as you would expect. And, determined from
295
experimentation that the command-line argument gets turned into
296
"\\?" instead of "/?" !!!
295
298
#if defined(_WIN32)
296
if (/*(fse.code() == boost::system::errc::no_such_file_or_directory) &&*/
297
(fse.path1() == "\\?"))
299
if (/*(fse.code() == boost::system::errc::no_such_file_or_directory) &&*/
300
(fse.path1() == "\\?"))
301
cerr << "error: " << fse.what() << endl;
304
cerr << "error: " << fse.what() << endl;
306
309
if ( currentClient.get() )
307
310
currentClient.get()->shutdown();
317
320
DBClientBase& Tool::conn( bool slaveIfPaired ) {
318
321
if ( slaveIfPaired && _conn->type() == ConnectionString::SET ) {
320
_slaveConn = &((DBClientReplicaSet*)_conn)->slaveConn();
323
DBClientReplicaSet* rs = static_cast<DBClientReplicaSet*>(_conn);
324
_slaveConn = &rs->slaveConn();
321
326
return *_slaveConn;
401
406
throw UserException( 9998 , "you need to specify fields" );
409
std::string Tool::getAuthenticationDatabase() {
410
if (!_authenticationDatabase.empty()) {
411
return _authenticationDatabase;
405
* Validate authentication on the server for the given dbname. populates
406
* level (if supplied) with the user's credentials.
422
* Validate authentication on the server for the given dbname.
408
void Tool::auth( string dbname, Auth::Level * level ) {
410
if ( ! dbname.size() )
413
if ( ! ( _username.size() || _password.size() ) ) {
426
if ( _username.empty() ) {
414
427
// Make sure that we don't need authentication to connect to this db
415
428
// findOne throws an AssertionException if it's not authenticated.
416
429
if (_coll.size() > 0) {
418
431
conn().findOne(getNS(), Query("{}"), 0, QueryOption_SlaveOk);
421
// set write-level access if authentication is disabled
423
*level = Auth::WRITE;
430
if ( _conn->auth( dbname , _username , _password , errmsg, true, level ) ) {
435
// try against the admin db
436
if ( _conn->auth( "admin" , _username , _password , errmsg, true, level ) ) {
440
throw UserException( 9997 , (string)"authentication failed: " + errmsg );
437
_conn->auth( BSON( saslCommandPrincipalSourceFieldName << getAuthenticationDatabase() <<
438
saslCommandPrincipalFieldName << _username <<
439
saslCommandPasswordFieldName << _password <<
440
saslCommandMechanismFieldName << _authenticationMechanism ) );
443
443
BSONTool::BSONTool( const char * name, DBAccess access , bool objcheck )
444
444
: Tool( name , access , "" , "" , false ) , _objcheck( objcheck ) {
447
("objcheck" , "validate object before inserting" )
447
("objcheck" , "validate object before inserting (default)" )
448
("noobjcheck" , "don't validate object before inserting" )
448
449
("filter" , po::value<string>() , "filter to apply before inserting" )
453
454
int BSONTool::run() {
454
_objcheck = hasParam( "objcheck" );
455
if ( hasParam( "objcheck" ) )
457
else if ( hasParam( "noobjcheck" ) )
456
460
if ( hasParam( "filter" ) )
457
461
_matcher.reset( new Matcher( fromjson( getParam( "filter" ) ) ) );