Skip to content

Commit 2dc4f56

Browse files
author
Andy Schwerin
committed
SERVER-8983 Include AuthenticationFailed error code in failed MONGODB-CR authentications.
1 parent e72ca6c commit 2dc4f56

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/mongo/db/commands/authentication_commands.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <vector>
2222

2323
#include "mongo/base/status.h"
24+
#include "mongo/client/sasl_client_authenticate.h"
2425
#include "mongo/db/auth/action_set.h"
2526
#include "mongo/db/auth/action_type.h"
2627
#include "mongo/db/auth/authorization_manager.h"
@@ -102,6 +103,7 @@ namespace mongo {
102103
if (dbname != StringData("local", StringData::LiteralTag()) ||
103104
user != internalSecurity.user) {
104105
errmsg = _nonceAuthenticateCommandsDisabledMessage;
106+
result.append(saslCommandCodeFieldName, ErrorCodes::AuthenticationFailed);
105107
return false;
106108
}
107109
}
@@ -115,6 +117,7 @@ namespace mongo {
115117
<< endl;
116118
errmsg = "auth fails";
117119
sleepmillis(10);
120+
result.append(saslCommandCodeFieldName, ErrorCodes::AuthenticationFailed);
118121
return false;
119122
}
120123

@@ -142,6 +145,7 @@ namespace mongo {
142145
log() << "auth: bad nonce received or getnonce not called. could be a driver bug or a security attack. db:" << dbname << endl;
143146
errmsg = "auth fails";
144147
sleepmillis(30);
148+
result.append(saslCommandCodeFieldName, ErrorCodes::AuthenticationFailed);
145149
return false;
146150
}
147151
}
@@ -153,6 +157,7 @@ namespace mongo {
153157
if (!status.isOK()) {
154158
log() << status.reason() << std::endl;
155159
errmsg = "auth fails";
160+
result.append(saslCommandCodeFieldName, ErrorCodes::AuthenticationFailed);
156161
return false;
157162
}
158163
pwd = userObj["pwd"].String();
@@ -173,6 +178,7 @@ namespace mongo {
173178
if ( key != computed ) {
174179
log() << "auth: key mismatch " << user << ", ns:" << dbname << endl;
175180
errmsg = "auth fails";
181+
result.append(saslCommandCodeFieldName, ErrorCodes::AuthenticationFailed);
176182
return false;
177183
}
178184

0 commit comments

Comments
 (0)