summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/write_commands/write_commands_common.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/commands/write_commands/write_commands_common.cpp')
-rw-r--r--src/mongo/db/commands/write_commands/write_commands_common.cpp87
1 files changed, 40 insertions, 47 deletions
diff --git a/src/mongo/db/commands/write_commands/write_commands_common.cpp b/src/mongo/db/commands/write_commands/write_commands_common.cpp
index 69ca1014140..82f3ab4db67 100644
--- a/src/mongo/db/commands/write_commands/write_commands_common.cpp
+++ b/src/mongo/db/commands/write_commands/write_commands_common.cpp
@@ -42,62 +42,55 @@
namespace mongo {
namespace auth {
- using std::string;
- using std::vector;
-
- Status checkAuthForWriteCommand( AuthorizationSession* authzSession,
- BatchedCommandRequest::BatchType cmdType,
- const NamespaceString& cmdNSS,
- const BSONObj& cmdObj ) {
-
- vector<Privilege> privileges;
- ActionSet actionsOnCommandNSS;
-
- if (shouldBypassDocumentValidationForCommand(cmdObj)) {
- actionsOnCommandNSS.addAction(ActionType::bypassDocumentValidation);
- }
-
- if ( cmdType == BatchedCommandRequest::BatchType_Insert ) {
+using std::string;
+using std::vector;
+
+Status checkAuthForWriteCommand(AuthorizationSession* authzSession,
+ BatchedCommandRequest::BatchType cmdType,
+ const NamespaceString& cmdNSS,
+ const BSONObj& cmdObj) {
+ vector<Privilege> privileges;
+ ActionSet actionsOnCommandNSS;
+
+ if (shouldBypassDocumentValidationForCommand(cmdObj)) {
+ actionsOnCommandNSS.addAction(ActionType::bypassDocumentValidation);
+ }
- if ( !cmdNSS.isSystemDotIndexes() ) {
- actionsOnCommandNSS.addAction(ActionType::insert);
+ if (cmdType == BatchedCommandRequest::BatchType_Insert) {
+ if (!cmdNSS.isSystemDotIndexes()) {
+ actionsOnCommandNSS.addAction(ActionType::insert);
+ } else {
+ // Special-case indexes until we have a command
+ string nsToIndex, errMsg;
+ if (!BatchedCommandRequest::getIndexedNS(cmdObj, &nsToIndex, &errMsg)) {
+ return Status(ErrorCodes::FailedToParse, errMsg);
}
- else {
- // Special-case indexes until we have a command
- string nsToIndex, errMsg;
- if ( !BatchedCommandRequest::getIndexedNS( cmdObj, &nsToIndex, &errMsg ) ) {
- return Status( ErrorCodes::FailedToParse, errMsg );
- }
- NamespaceString nssToIndex( nsToIndex );
- privileges.push_back( Privilege( ResourcePattern::forExactNamespace( nssToIndex ),
- ActionType::createIndex ) );
- }
+ NamespaceString nssToIndex(nsToIndex);
+ privileges.push_back(
+ Privilege(ResourcePattern::forExactNamespace(nssToIndex), ActionType::createIndex));
}
- else if ( cmdType == BatchedCommandRequest::BatchType_Update ) {
- actionsOnCommandNSS.addAction(ActionType::update);
+ } else if (cmdType == BatchedCommandRequest::BatchType_Update) {
+ actionsOnCommandNSS.addAction(ActionType::update);
- // Upsert also requires insert privs
- if ( BatchedCommandRequest::containsUpserts( cmdObj ) ) {
- actionsOnCommandNSS.addAction(ActionType::insert);
- }
- }
- else {
- fassert( 17251, cmdType == BatchedCommandRequest::BatchType_Delete );
- actionsOnCommandNSS.addAction(ActionType::remove);
- }
-
-
- if (!actionsOnCommandNSS.empty()) {
- privileges.emplace_back(ResourcePattern::forExactNamespace(cmdNSS),
- actionsOnCommandNSS);
+ // Upsert also requires insert privs
+ if (BatchedCommandRequest::containsUpserts(cmdObj)) {
+ actionsOnCommandNSS.addAction(ActionType::insert);
}
+ } else {
+ fassert(17251, cmdType == BatchedCommandRequest::BatchType_Delete);
+ actionsOnCommandNSS.addAction(ActionType::remove);
+ }
- if ( authzSession->isAuthorizedForPrivileges( privileges ) )
- return Status::OK();
- return Status( ErrorCodes::Unauthorized, "unauthorized" );
+ if (!actionsOnCommandNSS.empty()) {
+ privileges.emplace_back(ResourcePattern::forExactNamespace(cmdNSS), actionsOnCommandNSS);
}
+ if (authzSession->isAuthorizedForPrivileges(privileges))
+ return Status::OK();
+
+ return Status(ErrorCodes::Unauthorized, "unauthorized");
+}
}
}