From ab31b8edb6a2df2fcef4fb4e93f94b3d7e78c241 Mon Sep 17 00:00:00 2001 From: Tomasz Sterna Date: Tue, 6 Dec 2011 20:50:30 +0100 Subject: [PATCH] Send any remaining SASL data with authentication response --- sx/sasl_gsasl.c | 31 ++++++++++++++++++++++++------- 1 files changed, 24 insertions(+), 7 deletions(-) diff --git a/sx/sasl_gsasl.c b/sx/sasl_gsasl.c index 9ef5f50..46b197b 100644 --- a/sx/sasl_gsasl.c +++ b/sx/sasl_gsasl.c @@ -138,7 +138,7 @@ struct _Gsasl_digest_md5_server_state typedef struct _Gsasl_digest_md5_server_state _Gsasl_digest_md5_server_state; /** utility: generate a success nad */ -static nad_t _sx_sasl_success(sx_t s) { +static nad_t _sx_sasl_success(sx_t s, char *data, int dlen) { nad_t nad; int ns; @@ -146,6 +146,8 @@ static nad_t _sx_sasl_success(sx_t s) { ns = nad_add_namespace(nad, uri_SASL, NULL); nad_append_elem(nad, ns, "success", 0); + if(data != NULL) + nad_append_cdata(nad, data, dlen, 1); return nad; } @@ -533,14 +535,24 @@ static void _sx_sasl_client_process(sx_t s, sx_plugin_t p, Gsasl_session *sd, ch if(ret == GSASL_OK) { _sx_debug(ZONE, "sasl handshake completed"); - if(out != NULL) free(out); + /* encode the leftover response */ + ret = gsasl_base64_to(out, outlen, &buf, &buflen); + if (ret == GSASL_OK) { + /* send success */ + _sx_nad_write(s, _sx_sasl_success(s, buf, buflen), 0); + free(buf); - /* send success */ - _sx_nad_write(s, _sx_sasl_success(s), 0); + /* set a notify on the success nad buffer */ + ((sx_buf_t) s->wbufq->front->data)->notify = _sx_sasl_notify_success; + ((sx_buf_t) s->wbufq->front->data)->notify_arg = (void *) p; + } + else { + _sx_debug(ZONE, "gsasl_base64_to failed, no sasl for this conn; (%d): %s", ret, gsasl_strerror(ret)); + _sx_nad_write(s, _sx_sasl_failure(s, _sasl_err_INCORRECT_ENCODING), 0); + if(buf != NULL) free(buf); + } - /* set a notify on the success nad buffer */ - ((sx_buf_t) s->wbufq->front->data)->notify = _sx_sasl_notify_success; - ((sx_buf_t) s->wbufq->front->data)->notify_arg = (void *) p; + if(out != NULL) free(out); return; } @@ -555,6 +567,11 @@ static void _sx_sasl_client_process(sx_t s, sx_plugin_t p, Gsasl_session *sd, ch _sx_nad_write(s, _sx_sasl_challenge(s, buf, buflen), 0); free(buf); } + else { + _sx_debug(ZONE, "gsasl_base64_to failed, no sasl for this conn; (%d): %s", ret, gsasl_strerror(ret)); + _sx_nad_write(s, _sx_sasl_failure(s, _sasl_err_INCORRECT_ENCODING), 0); + if(buf != NULL) free(buf); + } if(out != NULL) free(out); -- 1.7.7.3