Skip to content

Commit 4ede394

Browse files
bjorihanumantmk
authored andcommitted
CDRIVER-486: There is no need to depend on sasl for PLAIN authentication
Closes #140
1 parent c735357 commit 4ede394

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/mongoc/mongoc-cluster.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#ifdef MONGOC_ENABLE_SASL
3838
#include "mongoc-sasl-private.h"
3939
#endif
40+
#include "mongoc-b64-private.h"
4041
#include "mongoc-scram-private.h"
4142
#include "mongoc-socket.h"
4243
#include "mongoc-stream-private.h"
@@ -1556,7 +1557,6 @@ _mongoc_cluster_auth_node_sasl (mongoc_cluster_t *cluster,
15561557
#endif
15571558

15581559

1559-
#ifdef MONGOC_ENABLE_SASL
15601560
/*
15611561
*--------------------------------------------------------------------------
15621562
*
@@ -1580,7 +1580,7 @@ _mongoc_cluster_auth_node_plain (mongoc_cluster_t *cluster,
15801580
bson_error_t *error)
15811581
{
15821582
char buf[4096];
1583-
unsigned buflen = 0;
1583+
int buflen = 0;
15841584
bson_iter_t iter;
15851585
const char *username;
15861586
const char *password;
@@ -1589,7 +1589,6 @@ _mongoc_cluster_auth_node_plain (mongoc_cluster_t *cluster,
15891589
bson_t reply;
15901590
size_t len;
15911591
char *str;
1592-
int ret;
15931592

15941593
BSON_ASSERT (cluster);
15951594
BSON_ASSERT (node);
@@ -1606,15 +1605,14 @@ _mongoc_cluster_auth_node_plain (mongoc_cluster_t *cluster,
16061605

16071606
str = bson_strdup_printf ("%c%s%c%s", '\0', username, '\0', password);
16081607
len = strlen (username) + strlen (password) + 2;
1609-
ret = sasl_encode64 (str, len, buf, sizeof buf, &buflen);
1608+
buflen = b64_ntop ((const uint8_t *) str, len, buf, sizeof buf);
16101609
bson_free (str);
16111610

1612-
if (ret != SASL_OK) {
1611+
if (buflen == -1) {
16131612
bson_set_error (error,
16141613
MONGOC_ERROR_CLIENT,
16151614
MONGOC_ERROR_CLIENT_AUTHENTICATE,
1616-
"sasl_encode64() returned %d.",
1617-
ret);
1615+
"failed base64 encoding message");
16181616
return false;
16191617
}
16201618

@@ -1648,7 +1646,6 @@ _mongoc_cluster_auth_node_plain (mongoc_cluster_t *cluster,
16481646

16491647
return true;
16501648
}
1651-
#endif
16521649

16531650

16541651
#ifdef MONGOC_ENABLE_SSL
@@ -1875,9 +1872,9 @@ _mongoc_cluster_auth_node (mongoc_cluster_t *cluster,
18751872
#ifdef MONGOC_ENABLE_SASL
18761873
} else if (0 == strcasecmp (mechanism, "GSSAPI")) {
18771874
ret = _mongoc_cluster_auth_node_sasl (cluster, node, error);
1875+
#endif
18781876
} else if (0 == strcasecmp (mechanism, "PLAIN")) {
18791877
ret = _mongoc_cluster_auth_node_plain (cluster, node, error);
1880-
#endif
18811878
} else {
18821879
bson_set_error (error,
18831880
MONGOC_ERROR_CLIENT,

0 commit comments

Comments
 (0)