summaryrefslogtreecommitdiff
path: root/src/mongo/rpc/metadata/impersonated_user_metadata.cpp
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
commit4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch)
tree1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/rpc/metadata/impersonated_user_metadata.cpp
parentaa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff)
parent8f0827553e09872941945a093b647a4211a9db7f (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/rpc/metadata/impersonated_user_metadata.cpp')
-rw-r--r--src/mongo/rpc/metadata/impersonated_user_metadata.cpp50
1 files changed, 0 insertions, 50 deletions
diff --git a/src/mongo/rpc/metadata/impersonated_user_metadata.cpp b/src/mongo/rpc/metadata/impersonated_user_metadata.cpp
index 3ee1a8c4320..64b78931f39 100644
--- a/src/mongo/rpc/metadata/impersonated_user_metadata.cpp
+++ b/src/mongo/rpc/metadata/impersonated_user_metadata.cpp
@@ -95,55 +95,5 @@ void writeAuthDataToImpersonatedUserMetadata(OperationContext* opCtx, BSONObjBui
metadata.serialize(&section);
}
-std::size_t estimateImpersonatedUserMetadataSize(OperationContext* opCtx) {
- if (!opCtx) {
- return 0;
- }
-
- // Otherwise construct a metadata section from the list of authenticated users/roles
- auto authSession = AuthorizationSession::get(opCtx->getClient());
- auto userNames = authSession->getImpersonatedUserNames();
- auto roleNames = authSession->getImpersonatedRoleNames();
- if (!userNames.more() && !roleNames.more()) {
- userNames = authSession->getAuthenticatedUserNames();
- roleNames = authSession->getAuthenticatedRoleNames();
- }
-
- // If there are no users/roles being impersonated just exit
- if (!userNames.more() && !roleNames.more()) {
- return 0;
- }
-
- std::size_t ret = 4 + // BSONObj size
- 1 + kImpersonationMetadataSectionName.size() + 1 + // "$audit" sub-object key
- 4; // $audit object length
-
- // BSONArrayType + "impersonatedUsers" + NULL + BSONArray Length
- ret += 1 + ImpersonatedUserMetadata::kUsersFieldName.size() + 1 + 4;
- for (std::size_t i = 0; userNames.more(); userNames.next(), ++i) {
- // BSONType::Object + strlen(indexId) + NULL byte
- // to_string(i).size() will be log10(i) plus some rounding and fuzzing.
- // Increment prior to taking the log so that we never take log10(0) which is NAN.
- // This estimates one extra byte every time we reach (i % 10) == 9.
- ret += 1 + static_cast<std::size_t>(1.1 + log10(i + 1)) + 1;
- ret += userNames.get().getBSONObjSize();
- }
- // EOD terminator for impersonatedUsers
- ++ret;
-
- // BSONArrayType + "impersonatedRoles" + NULL + BSONArray Length
- ret += 1 + ImpersonatedUserMetadata::kRolesFieldName.size() + 1 + 4;
- for (std::size_t i = 0; roleNames.more(); roleNames.next(), ++i) {
- // Same calculation as for UserNames above.
- ret += 1 + static_cast<std::size_t>(1.1 + log10(i + 1)) + 1;
- ret += roleNames.get().getBSONObjSize();
- }
-
- // EOD terminators for: impersonatedRoles, $audit, and metadata
- ret += 1 + 1 + 1;
-
- return ret;
-}
-
} // namespace rpc
} // namespace mongo