Skip to content

Commit 426d233

Browse files
committed
CDRIVER-2000 Implement user canonicalization
1 parent fa00474 commit 426d233

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/mongoc/mongoc-cluster-sasl.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,15 @@ _mongoc_cluster_auth_node_sasl (mongoc_cluster_t *cluster,
210210

211211
if (sasl.step == 1) {
212212
_mongoc_cluster_build_sasl_start (
213-
&cmd, mechanism ? mechanism : "GSSAPI", (const char *)buf, buflen);
213+
&cmd, mechanism ? mechanism : "GSSAPI", (const char *) buf, buflen);
214214
} else {
215-
_mongoc_cluster_build_sasl_continue (&cmd, conv_id, (const char *)buf, buflen);
215+
_mongoc_cluster_build_sasl_continue (
216+
&cmd, conv_id, (const char *) buf, buflen);
216217
}
217218

218219
TRACE ("SASL: authenticating (step %d)", sasl.step);
219220

221+
TRACE ("Sending: %s", bson_as_json (&cmd, NULL));
220222
if (!mongoc_cluster_run_command (cluster,
221223
stream,
222224
0,
@@ -225,10 +227,12 @@ _mongoc_cluster_auth_node_sasl (mongoc_cluster_t *cluster,
225227
&cmd,
226228
&reply,
227229
error)) {
230+
TRACE ("Replied with: %s", bson_as_json (&reply, NULL));
228231
bson_destroy (&cmd);
229232
bson_destroy (&reply);
230233
goto failure;
231234
}
235+
TRACE ("Replied with: %s", bson_as_json (&reply, NULL));
232236

233237
bson_destroy (&cmd);
234238

@@ -252,6 +256,7 @@ _mongoc_cluster_auth_node_sasl (mongoc_cluster_t *cluster,
252256
}
253257

254258
tmpstr = bson_iter_utf8 (&iter, &buflen);
259+
TRACE ("Got string: %s, (len=%" PRIu32 ")\n", tmpstr, buflen);
255260

256261
if (buflen > sizeof buf) {
257262
bson_set_error (error,

src/mongoc/mongoc-sasl.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "mongoc-error.h"
2424
#include "mongoc-sasl-private.h"
2525
#include "mongoc-util-private.h"
26+
#include "mongoc-trace-private.h"
2627

2728

2829
#ifndef SASL_CALLBACK_FN
@@ -70,6 +71,23 @@ _mongoc_sasl_set_pass (mongoc_sasl_t *sasl, const char *pass)
7071
}
7172

7273

74+
static int
75+
_mongoc_sasl_canon_user (sasl_conn_t *conn,
76+
void *context,
77+
const char *in,
78+
unsigned inlen,
79+
unsigned flags,
80+
const char *user_realm,
81+
char *out,
82+
unsigned out_max,
83+
unsigned *out_len)
84+
{
85+
TRACE ("Canonicalizing %s (%" PRIu32 ")\n", in, inlen);
86+
strcpy (out, in);
87+
*out_len = inlen;
88+
return SASL_OK;
89+
}
90+
7391
static int
7492
_mongoc_sasl_get_user (mongoc_sasl_t *sasl,
7593
int param_id,
@@ -185,6 +203,7 @@ _mongoc_sasl_init (mongoc_sasl_t *sasl)
185203
{SASL_CB_AUTHNAME, SASL_CALLBACK_FN (_mongoc_sasl_get_user), sasl},
186204
{SASL_CB_USER, SASL_CALLBACK_FN (_mongoc_sasl_get_user), sasl},
187205
{SASL_CB_PASS, SASL_CALLBACK_FN (_mongoc_sasl_get_pass), sasl},
206+
{SASL_CB_CANON_USER, SASL_CALLBACK_FN (_mongoc_sasl_canon_user), sasl},
188207
{SASL_CB_LIST_END}};
189208

190209
BSON_ASSERT (sasl);
@@ -352,6 +371,7 @@ _mongoc_sasl_step (mongoc_sasl_t *sasl,
352371
BSON_ASSERT (outbuf);
353372
BSON_ASSERT (outbuflen);
354373

374+
TRACE ("Running %d, inbuflen: %" PRIu32, sasl->step, inbuflen);
355375
sasl->step++;
356376

357377
if (sasl->step == 1) {
@@ -364,11 +384,13 @@ _mongoc_sasl_step (mongoc_sasl_t *sasl,
364384
return false;
365385
}
366386

387+
TRACE ("Running %d, inbuflen: %" PRIu32, sasl->step, inbuflen);
367388
if (!inbuflen) {
368389
bson_set_error (error,
369390
MONGOC_ERROR_SASL,
370391
MONGOC_ERROR_CLIENT_AUTHENTICATE,
371-
"SASL Failure: no payload provided from server.");
392+
"SASL Failure: no payload provided from server: %s",
393+
sasl_errdetail (sasl->conn));
372394
return false;
373395
}
374396

0 commit comments

Comments
 (0)