summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/commands.cpp')
-rw-r--r--src/mongo/db/commands.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/mongo/db/commands.cpp b/src/mongo/db/commands.cpp
index 5f5982d76f4..c8f99250182 100644
--- a/src/mongo/db/commands.cpp
+++ b/src/mongo/db/commands.cpp
@@ -189,7 +189,7 @@ BSONObj Command::runCommandDirectly(OperationContext* opCtx, const OpMsgRequest&
BSONObjBuilder out;
try {
- bool ok = command->enhancedRun(opCtx, request, out);
+ bool ok = command->publicRun(opCtx, request, out);
appendCommandStatus(out, ok);
} catch (const StaleConfigException& ex) {
// These exceptions are intended to be handled at a higher level and cannot losslessly
@@ -321,6 +321,20 @@ Status Command::checkAuthorization(Command* c,
return status;
}
+bool Command::publicRun(OperationContext* opCtx,
+ const OpMsgRequest& request,
+ BSONObjBuilder& result) {
+ try {
+ return enhancedRun(opCtx, request, result);
+ } catch (const DBException& e) {
+ if (e.code() == ErrorCodes::Unauthorized) {
+ audit::logCommandAuthzCheck(
+ opCtx->getClient(), request, this, ErrorCodes::Unauthorized);
+ }
+ throw;
+ }
+}
+
bool Command::isHelpRequest(const BSONElement& helpElem) {
return !helpElem.eoo() && helpElem.trueValue();
}