diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-18 17:02:53 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-18 17:02:53 -0300 |
| commit | 959575a5ca598bf5f37fb5cebe7ed1d80d3d71f7 (patch) | |
| tree | acc8d60aedb12b70048e676e8a7349deb0010db8 /src/mongo/client | |
| parent | 76588293975fc059cf076779e4283e6ffaf8afff (diff) | |
New upstream version 6.0.20upstream
Diffstat (limited to 'src/mongo/client')
| -rw-r--r-- | src/mongo/client/SConscript | 2 | ||||
| -rw-r--r-- | src/mongo/client/cyrus_sasl_client_session.cpp | 28 | ||||
| -rw-r--r-- | src/mongo/client/mongo_uri_test.cpp | 3 | ||||
| -rw-r--r-- | src/mongo/client/read_preference.cpp | 8 | ||||
| -rw-r--r-- | src/mongo/client/read_preference.h | 11 | ||||
| -rw-r--r-- | src/mongo/client/replica_set_monitor_manager.cpp | 36 | ||||
| -rw-r--r-- | src/mongo/client/replica_set_monitor_manager.h | 5 | ||||
| -rw-r--r-- | src/mongo/client/sasl_client_session.cpp | 2 |
8 files changed, 65 insertions, 30 deletions
diff --git a/src/mongo/client/SConscript b/src/mongo/client/SConscript index 5010be181f0..cdaa0819473 100644 --- a/src/mongo/client/SConscript +++ b/src/mongo/client/SConscript @@ -72,6 +72,7 @@ if get_option('ssl') == 'on': ], LIBDEPS_PRIVATE=[ '$BUILD_DIR/mongo/base', + '$BUILD_DIR/mongo/bson/bson_validate', '$BUILD_DIR/mongo/db/server_options_core', # For object_check.h '$BUILD_DIR/mongo/idl/idl_parser', '$BUILD_DIR/third_party/shim_kms_message', @@ -117,6 +118,7 @@ saslClientEnv.Library( source=saslClientSource, LIBDEPS=[ '$BUILD_DIR/mongo/base/secure_allocator', + '$BUILD_DIR/mongo/bson/bson_validate', '$BUILD_DIR/mongo/bson/util/bson_extract', '$BUILD_DIR/mongo/executor/remote_command', '$BUILD_DIR/mongo/rpc/command_status', diff --git a/src/mongo/client/cyrus_sasl_client_session.cpp b/src/mongo/client/cyrus_sasl_client_session.cpp index 84ae1ab0b5a..2bca7e1b1de 100644 --- a/src/mongo/client/cyrus_sasl_client_session.cpp +++ b/src/mongo/client/cyrus_sasl_client_session.cpp @@ -47,7 +47,8 @@ void saslSetError(sasl_conn_t* conn, const std::string& msg) { } SaslClientSession* createCyrusSaslClientSession(const std::string& mech) { - if ((mech == "SCRAM-SHA-1") || (mech == "SCRAM-SHA-256") || mech == "MONGODB-AWS") { + if ((mech == "SCRAM-SHA-1") || (mech == "SCRAM-SHA-256") || (mech == "PLAIN") || + mech == "MONGODB-AWS") { return new NativeSaslClientSession(); } return new CyrusSaslClientSession(); @@ -121,6 +122,28 @@ int saslClientLogSwallow(void* context, int priority, const char* message) throw } /** + * Implements the Cyrus SASL default_verifyfile_cb interface registered in the + * Cyrus SASL library to verify, and then accept or reject, the loading of + * plugin libraries from the target directory. + * + * On Windows environments, disable loading of plugin files. + */ +int saslClientVerifyPluginFile(void*, const char*, sasl_verify_type_t type) { + + if (type != SASL_VRFY_PLUGIN) { + return SASL_OK; + } + +#ifdef _WIN32 + return SASL_CONTINUE; // A non-SASL_OK response indicates to Cyrus SASL that it + // should not load a file. This effectively disables + // loading plugins from path on Windows. +#else + return SASL_OK; +#endif +} + +/** * Initializes the client half of the SASL library, but is effectively a no-op if the client * application has already done it. * @@ -136,6 +159,7 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(CyrusSaslClientContext, (InitializerContext* context) { static sasl_callback_t saslClientGlobalCallbacks[] = { {SASL_CB_LOG, SaslCallbackFn(saslClientLogSwallow), nullptr /* context */}, + {SASL_CB_VERIFYFILE, SaslCallbackFn(saslClientVerifyPluginFile), nullptr /*context*/}, {SASL_CB_LIST_END}}; // If the client application has previously called sasl_client_init(), the callbacks passed @@ -240,7 +264,7 @@ void CyrusSaslClientSession::setParameter(Parameter id, StringData value) { _secret.reset(new char[sizeof(sasl_secret_t) + value.size() + 1]); sasl_secret_t* secret = static_cast<sasl_secret_t*>(static_cast<void*>(_secret.get())); secret->len = value.size(); - value.copyTo(static_cast<char*>(static_cast<void*>(&secret->data[0])), false); + value.copy(static_cast<char*>(static_cast<void*>(&secret->data[0])), value.size()); } SaslClientSession::setParameter(id, value); } diff --git a/src/mongo/client/mongo_uri_test.cpp b/src/mongo/client/mongo_uri_test.cpp index f8c3027fb20..723f03f6c60 100644 --- a/src/mongo/client/mongo_uri_test.cpp +++ b/src/mongo/client/mongo_uri_test.cpp @@ -34,6 +34,7 @@ #include <fstream> #include "mongo/base/string_data.h" +#include "mongo/bson/bson_validate.h" #include "mongo/bson/bsonobj.h" #include "mongo/bson/bsontypes.h" #include "mongo/bson/json.h" @@ -582,7 +583,7 @@ BSONObj getBsonFromJsonFile(std::string fileName) { std::ifstream infile(filename.c_str()); std::string data((std::istreambuf_iterator<char>(infile)), std::istreambuf_iterator<char>()); BSONObj obj = fromjson(data); - ASSERT_TRUE(obj.valid()); + ASSERT_TRUE(validateBSON(obj).isOK()); ASSERT_TRUE(obj.hasField("tests")); BSONObj arr = obj.getField("tests").embeddedObject().getOwned(); ASSERT_TRUE(arr.couldBeArray()); diff --git a/src/mongo/client/read_preference.cpp b/src/mongo/client/read_preference.cpp index 6851e1a8af7..6322e5ac84f 100644 --- a/src/mongo/client/read_preference.cpp +++ b/src/mongo/client/read_preference.cpp @@ -106,13 +106,17 @@ ReadPreferenceSetting::ReadPreferenceSetting(ReadPreference pref, hedgingMode(std::move(hedgingMode)) {} ReadPreferenceSetting::ReadPreferenceSetting(ReadPreference pref, Seconds maxStalenessSeconds) - : ReadPreferenceSetting(pref, defaultTagSetForMode(pref), maxStalenessSeconds) {} + : ReadPreferenceSetting(pref, defaultTagSetForMode(pref), maxStalenessSeconds) { + _usedDefaultReadPrefValue = true; +} ReadPreferenceSetting::ReadPreferenceSetting(ReadPreference pref, TagSet tags) : pref(std::move(pref)), tags(std::move(tags)) {} ReadPreferenceSetting::ReadPreferenceSetting(ReadPreference pref) - : ReadPreferenceSetting(pref, defaultTagSetForMode(pref)) {} + : ReadPreferenceSetting(pref, defaultTagSetForMode(pref)) { + _usedDefaultReadPrefValue = true; +} StatusWith<ReadPreferenceSetting> ReadPreferenceSetting::fromInnerBSON(const BSONObj& readPrefObj) { std::string modeStr; diff --git a/src/mongo/client/read_preference.h b/src/mongo/client/read_preference.h index 837d7391f41..b660f8a5709 100644 --- a/src/mongo/client/read_preference.h +++ b/src/mongo/client/read_preference.h @@ -123,7 +123,9 @@ struct ReadPreferenceSetting { ReadPreferenceSetting(ReadPreference pref, Seconds maxStalenessSeconds); ReadPreferenceSetting(ReadPreference pref, TagSet tags); explicit ReadPreferenceSetting(ReadPreference pref); - ReadPreferenceSetting() : ReadPreferenceSetting(ReadPreference::PrimaryOnly) {} + ReadPreferenceSetting() : ReadPreferenceSetting(ReadPreference::PrimaryOnly) { + _usedDefaultReadPrefValue = true; + } inline bool equals(const ReadPreferenceSetting& other) const { auto hedgingModeEquals = [](const boost::optional<HedgingMode>& hedgingModeA, @@ -168,7 +170,9 @@ struct ReadPreferenceSetting { toContainingBSON(&bob); return bob.obj(); } - + bool usedDefaultReadPrefValue() const { + return _usedDefaultReadPrefValue; + } /** * Parses a ReadPreferenceSetting from a BSON document of the form: * { mode: <mode>, tags: <array of tags>, maxStalenessSeconds: Number, hedge: <hedgingMode>}. @@ -226,6 +230,9 @@ struct ReadPreferenceSetting { * Either way, it must be that a node opTime of X implies ClusterTime >= X. */ Timestamp minClusterTime{}; + +private: + bool _usedDefaultReadPrefValue = false; }; } // namespace mongo diff --git a/src/mongo/client/replica_set_monitor_manager.cpp b/src/mongo/client/replica_set_monitor_manager.cpp index 5fe13f2be81..c440f5b0b8f 100644 --- a/src/mongo/client/replica_set_monitor_manager.cpp +++ b/src/mongo/client/replica_set_monitor_manager.cpp @@ -141,10 +141,6 @@ void ReplicaSetMonitorManager::_setupTaskExecutorAndStatsInLock() { return; } - if (!_stats) { - _stats = std::make_shared<ReplicaSetMonitorManagerStats>(); - } - // construct task executor auto hookList = std::make_unique<rpc::EgressMetadataHookList>(); auto networkConnectionHook = std::make_unique<ReplicaSetMonitorManagerNetworkConnectionHook>(); @@ -223,7 +219,6 @@ shared_ptr<ReplicaSetMonitor> ReplicaSetMonitorManager::getMonitorForHost(const vector<string> ReplicaSetMonitorManager::getAllSetNames() const { vector<string> allNames; - stdx::lock_guard<Latch> lk(_mutex); for (const auto& entry : _monitors) { @@ -317,30 +312,31 @@ void ReplicaSetMonitorManager::removeAllMonitors() { } void ReplicaSetMonitorManager::report(BSONObjBuilder* builder, bool forFTDC) { - // Don't hold _mutex the whole time to avoid ever taking a monitor's mutex while holding the - // manager's mutex. Otherwise we could get a deadlock between the manager's, monitor's, and - // ShardRegistry's mutex due to the ReplicaSetMonitor's AsynchronousConfigChangeHook - // potentially calling ShardRegistry::updateConfigServerConnectionString. - auto setNames = getAllSetNames(); - - builder->appendNumber("numReplicaSetMonitorsCreated", _numMonitorsCreated); + std::vector<std::shared_ptr<ReplicaSetMonitor>> monitors; + int numMonitorsCreated; + // Gather relevant data under the lock. Separate out writing it to BSON. + { + stdx::lock_guard lk(_mutex); + _doGarbageCollectionLocked(lk); + for (const auto& [_, weakMonitor] : _monitors) { + if (auto monitor = weakMonitor.lock()) + monitors.push_back(std::move(monitor)); + } + numMonitorsCreated = _numMonitorsCreated; + } + // Now write out the data. + builder->appendNumber("numReplicaSetMonitorsCreated", numMonitorsCreated); { BSONObjBuilder setStats( builder->subobjStart(forFTDC ? "replicaSetPingTimesMillis" : "replicaSets")); - for (const auto& setName : setNames) { - auto monitor = getMonitor(setName); - if (!monitor) { - continue; - } + for (const auto& monitor : monitors) { monitor->appendInfo(setStats, forFTDC); } } - if (_stats) { - _stats->report(builder, forFTDC); - } + _stats->report(builder, forFTDC); } std::shared_ptr<executor::TaskExecutor> ReplicaSetMonitorManager::getExecutor() { diff --git a/src/mongo/client/replica_set_monitor_manager.h b/src/mongo/client/replica_set_monitor_manager.h index 59c9b0b9853..1bb632ab85c 100644 --- a/src/mongo/client/replica_set_monitor_manager.h +++ b/src/mongo/client/replica_set_monitor_manager.h @@ -227,8 +227,9 @@ private: // Used for tests. Counter64 _monitorsGarbageCollected; - // Internally synchronized. - std::shared_ptr<ReplicaSetMonitorManagerStats> _stats; + // Pointee is internally synchronized. + const std::shared_ptr<ReplicaSetMonitorManagerStats> _stats = + std::make_shared<ReplicaSetMonitorManagerStats>(); }; } // namespace mongo diff --git a/src/mongo/client/sasl_client_session.cpp b/src/mongo/client/sasl_client_session.cpp index 4c92134a094..f1be7a64b10 100644 --- a/src/mongo/client/sasl_client_session.cpp +++ b/src/mongo/client/sasl_client_session.cpp @@ -54,7 +54,7 @@ void SaslClientSession::setParameter(Parameter id, StringData value) { // Note that we append a terminal NUL to buffer.data, so it may be treated as a C-style // string. This is required for parameterServiceName, parameterServiceHostname, // parameterMechanism and parameterUser. - value.copyTo(buffer.data.get(), true); + str::copyAsCString(buffer.data.get(), value); } bool SaslClientSession::hasParameter(Parameter id) { |
