--- src/auth/mech-cyrus-sasl2.c.orig	Wed Jun 25 08:26:43 2003
+++ src/auth/mech-cyrus-sasl2.c	Tue Oct 19 21:07:03 2004
@@ -39,6 +39,7 @@
 	struct auth_login_reply reply;
 	const char *serverout;
 	unsigned int serveroutlen;
+	const char *authenid, *default_realm;
 	int ret;
 
 	ret = sasl_server_step(cyrus_request->conn, data, request->data_size,
@@ -55,6 +56,12 @@
 		reply.result = AUTH_LOGIN_RESULT_SUCCESS;
 		cyrus_request->success = TRUE;
 
+		ret = sasl_getprop(cyrus_request->conn, SASL_USERNAME, (const void **) &authenid);
+		if (ret != SASL_OK || ! authenid) {
+			i_warning("sasl_getprop() failed: %s", sasl_errstring(ret, NULL, NULL));
+			return FALSE;
+		}
+
 		serverout = mech_auth_success(&reply, auth_request,
 					      serverout, serveroutlen);
 	} else {
@@ -200,6 +217,8 @@
 		cyrus_sasl_auth_continue;
 	cyrus_request->auth_request.auth_free =
 		cyrus_sasl_auth_free;
+
+	cyrus_request->conn = sasl_conn;
 
 	reply.result = AUTH_LOGIN_RESULT_CONTINUE;
 
