diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
| commit | 4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch) | |
| tree | 1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/client/authenticate.cpp | |
| parent | aa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff) | |
| parent | 8f0827553e09872941945a093b647a4211a9db7f (diff) | |
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0'
with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/client/authenticate.cpp')
| -rw-r--r-- | src/mongo/client/authenticate.cpp | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/src/mongo/client/authenticate.cpp b/src/mongo/client/authenticate.cpp index 254227b9a46..26df7c56d0c 100644 --- a/src/mongo/client/authenticate.cpp +++ b/src/mongo/client/authenticate.cpp @@ -213,7 +213,7 @@ Future<std::string> negotiateSaslMechanism(RunCommandHook runCommand, } BSONObjBuilder builder; - builder.append("hello", 1); + builder.append("ismaster", 1); builder.append("saslSupportedMechs", username.getUnambiguousName()); if (stepDownBehavior == StepDownBehavior::kKeepConnectionOpen) { builder.append("hangUpOnStepDown", false); @@ -297,12 +297,11 @@ StringData getSaslCommandUserFieldName() { namespace { -StatusWith<std::shared_ptr<SaslClientSession>> _speculateSaslStart( - BSONObjBuilder* helloRequestBuilder, - const std::string& mechanism, - const HostAndPort& host, - StringData authDB, - BSONObj params) { +StatusWith<std::shared_ptr<SaslClientSession>> _speculateSaslStart(BSONObjBuilder* isMaster, + const std::string& mechanism, + const HostAndPort& host, + StringData authDB, + BSONObj params) { if (mechanism == kMechanismSaslPlain) { return {ErrorCodes::BadValue, "PLAIN mechanism not supported with speculativeSaslStart"}; } @@ -324,13 +323,13 @@ StatusWith<std::shared_ptr<SaslClientSession>> _speculateSaslStart( saslStart.append("mechanism", mechanism); saslStart.appendBinData("payload", int(payload.size()), BinDataGeneral, payload.c_str()); saslStart.append("db", authDB); - helloRequestBuilder->append(kSpeculativeAuthenticate, saslStart.obj()); + isMaster->append(kSpeculativeAuthenticate, saslStart.obj()); return session; } StatusWith<SpeculativeAuthType> _speculateAuth( - BSONObjBuilder* helloRequestBuilder, + BSONObjBuilder* isMaster, const std::string& mechanism, const HostAndPort& host, StringData authDB, @@ -338,18 +337,17 @@ StatusWith<SpeculativeAuthType> _speculateAuth( std::shared_ptr<SaslClientSession>* saslClientSession) { if (mechanism == kMechanismMongoX509) { // MONGODB-X509 - helloRequestBuilder->append(kSpeculativeAuthenticate, - BSON(kAuthenticateCommand - << "1" << saslCommandMechanismFieldName << mechanism - << saslCommandUserDBFieldName << "$external")); + isMaster->append(kSpeculativeAuthenticate, + BSON(kAuthenticateCommand << "1" << saslCommandMechanismFieldName + << mechanism << saslCommandUserDBFieldName + << "$external")); return SpeculativeAuthType::kAuthenticate; } // Proceed as if this is a SASL mech and we either have a password, // or we don't need one (e.g. MONGODB-AWS). // Failure is absolutely an option. - auto swSaslClientSession = - _speculateSaslStart(helloRequestBuilder, mechanism, host, authDB, params); + auto swSaslClientSession = _speculateSaslStart(isMaster, mechanism, host, authDB, params); if (!swSaslClientSession.isOK()) { return swSaslClientSession.getStatus(); } @@ -368,7 +366,7 @@ std::string getBSONString(BSONObj container, StringData field) { } } // namespace -SpeculativeAuthType speculateAuth(BSONObjBuilder* helloRequestBuilder, +SpeculativeAuthType speculateAuth(BSONObjBuilder* isMasterRequest, const MongoURI& uri, std::shared_ptr<SaslClientSession>* saslClientSession) { auto mechanism = uri.getOption("authMechanism").get_value_or(kMechanismScramSha256.toString()); @@ -380,7 +378,7 @@ SpeculativeAuthType speculateAuth(BSONObjBuilder* helloRequestBuilder, auto params = std::move(optParams.get()); - auto ret = _speculateAuth(helloRequestBuilder, + auto ret = _speculateAuth(isMasterRequest, mechanism, uri.getServers().front(), uri.getAuthenticationDatabase(), @@ -396,7 +394,7 @@ SpeculativeAuthType speculateAuth(BSONObjBuilder* helloRequestBuilder, SpeculativeAuthType speculateInternalAuth( const HostAndPort& remoteHost, - BSONObjBuilder* helloRequestBuilder, + BSONObjBuilder* isMasterRequest, std::shared_ptr<SaslClientSession>* saslClientSession) try { auto params = getInternalAuthParams(0, kMechanismScramSha256.toString()); if (params.isEmpty()) { @@ -406,8 +404,8 @@ SpeculativeAuthType speculateInternalAuth( auto mechanism = getBSONString(params, saslCommandMechanismFieldName); auto authDB = getBSONString(params, saslCommandUserDBFieldName); - auto ret = _speculateAuth( - helloRequestBuilder, mechanism, remoteHost, authDB, params, saslClientSession); + auto ret = + _speculateAuth(isMasterRequest, mechanism, remoteHost, authDB, params, saslClientSession); if (!ret.isOK()) { return SpeculativeAuthType::kNone; } |
