Skip to content

Commit 9c450c3

Browse files
committed
CDRIVER-642 detect auth error from usersInfo
Starting with MongoDB 2.7.1 the scope of the localhost exception for authentication was dramatically narrowed. It is no longer possible to call the userInfo command unauthenticated, even when the localhost exception is in effect. A workaround for this issue is to catch the exception and call createUser if the error code is 13 (Unauthorized). Any exception from the createUser call should propagate to the user application.
1 parent 2aeecdd commit 9c450c3

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/mongoc/mongoc-database.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,8 @@ mongoc_database_add_user (mongoc_database_t *database,
425425

426426
if (!ret && (lerror.code == MONGOC_ERROR_QUERY_COMMAND_NOT_FOUND)) {
427427
ret = mongoc_database_add_user_legacy (database, username, password, error);
428-
} else if (ret) {
428+
} else if (ret || (lerror.code == 13)) {
429+
/* usersInfo succeeded or failed with auth err, we're on modern mongod */
429430
input = bson_strdup_printf ("%s:mongo:%s", username, password);
430431
hashed_password = _mongoc_hex_md5 (input);
431432
bson_free (input);

0 commit comments

Comments
 (0)