0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 01:21:03 +01:00

make security work for repl pairs

This commit is contained in:
dwight 2009-01-24 16:05:12 -05:00
parent 8ba2174076
commit ec434bd7c1

View File

@ -194,26 +194,39 @@ namespace mongo {
class CmdIsMaster : public Command {
public:
virtual bool requiresAuth() { return false; }
virtual bool slaveOk() {
return true;
}
CmdIsMaster() : Command("ismaster") { }
virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool /*fromRepl*/) {
/* currently request to arbiter is (somewhat arbitrarily) an ismaster request that is not
authenticated.
we allow unauthenticated ismaster but we aren't as verbose informationally if
one is not authenticated for admin db to be safe.
*/
AuthenticationInfo *ai = authInfo.get();
bool authed = ai == 0 || ai->isAuthorized("admin");
if ( allDead ) {
result.append("ismaster", 0.0);
if ( replPair )
result.append("remote", replPair->remote);
result.append("info", allDead);
if( authed ) {
if ( replPair )
result.append("remote", replPair->remote);
result.append("info", allDead);
}
}
else if ( replPair ) {
result.append("ismaster", replPair->state);
result.append("remote", replPair->remote);
if ( replPair->info.empty() )
result.append("info", replPair->info);
}
if( authed ) {
result.append("remote", replPair->remote);
if ( !replPair->info.empty() )
result.append("info", replPair->info);
}
}
else {
result.append("ismaster", 1);
result.append("msg", "not paired");
result.append("msg", "not paired");
}
return true;