Skip to content

Commit 4a5dc19

Browse files
author
Andy Schwerin
committed
SERVER-8100 Do not expect a code in sasl commands that return ok: 1.
Also, correctly report error messages when ok: 0 and code field is present.
1 parent 71214c2 commit 4a5dc19

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/mongo/client/sasl_client_authenticate.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,21 @@ namespace {
218218
if (!conversationId.eoo())
219219
commandBuilder.append(conversationId);
220220

221-
if (!client->runCommand(targetDatabase, commandBuilder.obj(), inputObj)) {
222-
return Status(ErrorCodes::UnknownError,
223-
inputObj[saslCommandErrmsgFieldName].str());
221+
// Server versions 2.3.2 and earlier may return "ok: 1" with a non-zero "code" field,
222+
// indicating a failure. Subsequent versions should return "ok: 0" on failure with a
223+
// non-zero "code" field to indicate specific failure. In all versions, ok: 1, code: >0
224+
// and ok: 0, code optional, indicate failure.
225+
bool ok = client->runCommand(targetDatabase, commandBuilder.obj(), inputObj);
226+
ErrorCodes::Error code = ErrorCodes::fromInt(
227+
inputObj[saslCommandCodeFieldName].numberInt());
228+
229+
if (!ok || code != ErrorCodes::OK) {
230+
if (code == ErrorCodes::OK)
231+
code = ErrorCodes::UnknownError;
232+
233+
return Status(code, inputObj[saslCommandErrmsgFieldName].str());
224234
}
225235

226-
int statusCodeInt = inputObj[saslCommandCodeFieldName].Int();
227-
if (0 != statusCodeInt)
228-
return Status(ErrorCodes::fromInt(statusCodeInt),
229-
inputObj[saslCommandErrmsgFieldName].str());
230-
231236
isServerDone = inputObj[saslCommandDoneFieldName].trueValue();
232237
saslCommandPrefix = saslFollowupCommandPrefix;
233238
}

0 commit comments

Comments
 (0)