sbonazzo / rpms / cyrus-sasl

Forked from rpms/cyrus-sasl 2 years ago
Clone

Blame SOURCES/cyrus-sasl-2.1.26-gssapi-use-per-connection-mutex.patch

6611fc
From 70a144cc53d09b56aa088fa1f6d433acea31afa7 Mon Sep 17 00:00:00 2001
6611fc
From: Alexander Bokovoy <abokovoy@redhat.com>
6611fc
Date: Tue, 15 Sep 2015 12:21:22 +0300
6611fc
Subject: [PATCH] gssapi: use per-connection mutex where possible
6611fc
6611fc
If the same application uses SASL GSSAPI for both client and server operations,
6611fc
it may be possible to deadlock in plugins/gssapi.c due to use of a
6611fc
global mutex by both client and server code. Multiple outstanding connections should
6611fc
be possible, thus introduce per-context locking and use it where it
6611fc
makes sense. Note that there are still multiple places where context is
6611fc
not available and where a global lock should be in use.
6611fc
6611fc
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1263017
6611fc
---
6611fc
 plugins/gssapi.c | 225 +++++++++++++++++++++++++++++++------------------------
6611fc
 1 file changed, 126 insertions(+), 99 deletions(-)
6611fc
6611fc
diff --git a/plugins/gssapi.c b/plugins/gssapi.c
6611fc
index 2fd1b3b..f5d3354 100644
6611fc
--- a/plugins/gssapi.c
6611fc
+++ b/plugins/gssapi.c
6611fc
@@ -126,20 +126,29 @@ extern gss_OID gss_nt_service_name;
6611fc
  */
6611fc
 
6611fc
 #ifdef GSS_USE_MUTEXES
6611fc
-#define GSS_LOCK_MUTEX(utils)  \
6611fc
-    if(((sasl_utils_t *)(utils))->mutex_lock(gss_mutex) != 0) { \
6611fc
+#define GSS_LOCK_MUTEX_EXT(utils, mutex)  \
6611fc
+    if(((sasl_utils_t *)(utils))->mutex_lock(mutex) != 0) { \
6611fc
        return SASL_FAIL; \
6611fc
     }
6611fc
 
6611fc
-#define GSS_UNLOCK_MUTEX(utils) \
6611fc
-    if(((sasl_utils_t *)(utils))->mutex_unlock(gss_mutex) != 0) { \
6611fc
+#define GSS_UNLOCK_MUTEX_EXT(utils, mutex) \
6611fc
+    if(((sasl_utils_t *)(utils))->mutex_unlock(mutex) != 0) { \
6611fc
         return SASL_FAIL; \
6611fc
     }
6611fc
 
6611fc
+#define GSS_LOCK_MUTEX(utils) GSS_LOCK_MUTEX_EXT(utils, gss_mutex)
6611fc
+#define GSS_UNLOCK_MUTEX(utils) GSS_UNLOCK_MUTEX_EXT(utils, gss_mutex)
6611fc
+
6611fc
+#define GSS_LOCK_MUTEX_CTX(utils, ctx) GSS_LOCK_MUTEX_EXT(utils, (ctx)->ctx_mutex)
6611fc
+#define GSS_UNLOCK_MUTEX_CTX(utils, ctx) GSS_UNLOCK_MUTEX_EXT(utils, (ctx)->ctx_mutex)
6611fc
+
6611fc
+
6611fc
 static void *gss_mutex = NULL;
6611fc
 #else
6611fc
 #define GSS_LOCK_MUTEX(utils)
6611fc
 #define GSS_UNLOCK_MUTEX(utils)
6611fc
+#define GSS_LOCK_MUTEX_CTX(utils, ctx)
6611fc
+#define GSS_UNLOCK_MUTEX_CTX(utils, ctx)
6611fc
 #endif
6611fc
 
6611fc
 typedef struct context {
6611fc
@@ -176,6 +185,7 @@ typedef struct context {
6611fc
     
6611fc
     char *authid; /* hold the authid between steps - server */
6611fc
     const char *user;   /* hold the userid between steps - client */
6611fc
+    void *ctx_mutex; /* A per-context mutex */
6611fc
 } context_t;
6611fc
 
6611fc
 enum {
6611fc
@@ -355,7 +365,7 @@ sasl_gss_encode(void *context, const struct iovec *invec, unsigned numiov,
6611fc
     output_token->value = NULL;
6611fc
     output_token->length = 0;
6611fc
     
6611fc
-    GSS_LOCK_MUTEX(text->utils);
6611fc
+    GSS_LOCK_MUTEX_CTX(text->utils, text);
6611fc
     maj_stat = gss_wrap (&min_stat,
6611fc
 			 text->gss_ctx,
6611fc
 			 privacy,
6611fc
@@ -363,14 +373,14 @@ sasl_gss_encode(void *context, const struct iovec *invec, unsigned numiov,
6611fc
 			 input_token,
6611fc
 			 NULL,
6611fc
 			 output_token);
6611fc
-    GSS_UNLOCK_MUTEX(text->utils);
6611fc
+    GSS_UNLOCK_MUTEX_CTX(text->utils, text);
6611fc
     
6611fc
     if (GSS_ERROR(maj_stat)) {
6611fc
 	sasl_gss_seterror(text->utils, maj_stat, min_stat);
6611fc
 	if (output_token->value) {
6611fc
-	    GSS_LOCK_MUTEX(text->utils);
6611fc
+	    GSS_LOCK_MUTEX_CTX(text->utils, text);
6611fc
 	    gss_release_buffer(&min_stat, output_token);
6611fc
-	    GSS_UNLOCK_MUTEX(text->utils);
6611fc
+	    GSS_UNLOCK_MUTEX_CTX(text->utils, text);
6611fc
 	}
6611fc
 	return SASL_FAIL;
6611fc
     }
6611fc
@@ -384,9 +394,9 @@ sasl_gss_encode(void *context, const struct iovec *invec, unsigned numiov,
6611fc
 			      output_token->length + 4);
6611fc
 	
6611fc
 	if (ret != SASL_OK) {
6611fc
-	    GSS_LOCK_MUTEX(text->utils);
6611fc
+	    GSS_LOCK_MUTEX_CTX(text->utils, text);
6611fc
 	    gss_release_buffer(&min_stat, output_token);
6611fc
-	    GSS_UNLOCK_MUTEX(text->utils);
6611fc
+	    GSS_UNLOCK_MUTEX_CTX(text->utils, text);
6611fc
 	    return ret;
6611fc
 	}
6611fc
 
6611fc
@@ -407,9 +417,9 @@ sasl_gss_encode(void *context, const struct iovec *invec, unsigned numiov,
6611fc
     *output = text->encode_buf;
6611fc
     
6611fc
     if (output_token->value) {
6611fc
-	GSS_LOCK_MUTEX(text->utils);
6611fc
+	GSS_LOCK_MUTEX_CTX(text->utils, text);
6611fc
 	gss_release_buffer(&min_stat, output_token);
6611fc
-	GSS_UNLOCK_MUTEX(text->utils);
6611fc
+	GSS_UNLOCK_MUTEX_CTX(text->utils, text);
6611fc
     }
6611fc
 
6611fc
     return SASL_OK;
6611fc
@@ -455,21 +465,21 @@ gssapi_decode_packet(void *context,
6611fc
     output_token->value = NULL;
6611fc
     output_token->length = 0;
6611fc
     
6611fc
-    GSS_LOCK_MUTEX(text->utils);
6611fc
+    GSS_LOCK_MUTEX_CTX(text->utils, text);
6611fc
     maj_stat = gss_unwrap (&min_stat,
6611fc
 			   text->gss_ctx,
6611fc
 			   input_token,
6611fc
 			   output_token,
6611fc
 			   NULL,
6611fc
 			   NULL);
6611fc
-    GSS_UNLOCK_MUTEX(text->utils);
6611fc
+    GSS_UNLOCK_MUTEX_CTX(text->utils, text);
6611fc
     
6611fc
     if (GSS_ERROR(maj_stat)) {
6611fc
 	sasl_gss_seterror(text->utils,maj_stat,min_stat);
6611fc
 	if (output_token->value) {
6611fc
-	    GSS_LOCK_MUTEX(text->utils);
6611fc
+	    GSS_LOCK_MUTEX_CTX(text->utils, text);
6611fc
 	    gss_release_buffer(&min_stat, output_token);
6611fc
-	    GSS_UNLOCK_MUTEX(text->utils);
6611fc
+	    GSS_UNLOCK_MUTEX_CTX(text->utils, text);
6611fc
 	}
6611fc
 	return SASL_FAIL;
6611fc
     }
6611fc
@@ -484,17 +494,17 @@ gssapi_decode_packet(void *context,
6611fc
 				     &text->decode_once_buf_len,
6611fc
 				     *outputlen);
6611fc
 	    if (result != SASL_OK) {
6611fc
-		GSS_LOCK_MUTEX(text->utils);
6611fc
+		GSS_LOCK_MUTEX_CTX(text->utils, text);
6611fc
 		gss_release_buffer(&min_stat, output_token);
6611fc
-		GSS_UNLOCK_MUTEX(text->utils);
6611fc
+		GSS_UNLOCK_MUTEX_CTX(text->utils, text);
6611fc
 		return result;
6611fc
 	    }
6611fc
 	    *output = text->decode_once_buf;
6611fc
 	    memcpy(*output, output_token->value, *outputlen);
6611fc
 	}
6611fc
-	GSS_LOCK_MUTEX(text->utils);
6611fc
+	GSS_LOCK_MUTEX_CTX(text->utils, text);
6611fc
 	gss_release_buffer(&min_stat, output_token);
6611fc
-	GSS_UNLOCK_MUTEX(text->utils);
6611fc
+	GSS_UNLOCK_MUTEX_CTX(text->utils, text);
6611fc
     }
6611fc
     
6611fc
     return SASL_OK;
6611fc
@@ -525,7 +535,14 @@ static context_t *sasl_gss_new_context(const sasl_utils_t *utils)
6611fc
     
6611fc
     memset(ret,0,sizeof(context_t));
6611fc
     ret->utils = utils;
6611fc
-    
6611fc
+#ifdef GSS_USE_MUTEXES
6611fc
+    ret->ctx_mutex = utils->mutex_alloc();
6611fc
+    if (!ret->ctx_mutex) {
6611fc
+           utils->free(ret);
6611fc
+           return NULL;
6611fc
+    }
6611fc
+#endif
6611fc
+
6611fc
     return ret;
6611fc
 }
6611fc
 
6611fc
@@ -535,7 +552,11 @@ static int sasl_gss_free_context_contents(context_t *text)
6611fc
     
6611fc
     if (!text) return SASL_OK;
6611fc
     
6611fc
-    GSS_LOCK_MUTEX(text->utils);
6611fc
+#ifdef GSS_USE_MUTEXES
6611fc
+    if (text->ctx_mutex) {
6611fc
+        GSS_LOCK_MUTEX_CTX(text->utils, text);
6611fc
+    }
6611fc
+#endif
6611fc
 
6611fc
     if (text->gss_ctx != GSS_C_NO_CONTEXT) {
6611fc
 	maj_stat = gss_delete_sec_context(&min_stat,&text->gss_ctx,
6611fc
@@ -563,8 +584,6 @@ static int sasl_gss_free_context_contents(context_t *text)
6611fc
 	text->client_creds = GSS_C_NO_CREDENTIAL;
6611fc
     }
6611fc
 
6611fc
-    GSS_UNLOCK_MUTEX(text->utils);
6611fc
-    
6611fc
     if (text->out_buf) {
6611fc
 	text->utils->free(text->out_buf);
6611fc
 	text->out_buf = NULL;
6611fc
@@ -598,6 +617,14 @@ static int sasl_gss_free_context_contents(context_t *text)
6611fc
 	text->authid = NULL;
6611fc
     }
6611fc
 
6611fc
+#ifdef GSS_USE_MUTEXES
6611fc
+    if (text->ctx_mutex) {
6611fc
+        GSS_UNLOCK_MUTEX_CTX(text->utils, text);
6611fc
+        text->utils->mutex_free(text->ctx_mutex);
6611fc
+        text->ctx_mutex = NULL;
6611fc
+    }
6611fc
+#endif
6611fc
+
6611fc
     return SASL_OK;
6611fc
 
6611fc
 }
6611fc
@@ -692,12 +719,12 @@ gssapi_server_mech_authneg(context_t *text,
6611fc
 	}
6611fc
 	sprintf(name_token.value,"%s@%s", params->service, params->serverFQDN);
6611fc
 
6611fc
-	GSS_LOCK_MUTEX(params->utils);
6611fc
+	GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 	maj_stat = gss_import_name (&min_stat,
6611fc
 				    &name_token,
6611fc
 				    GSS_C_NT_HOSTBASED_SERVICE,
6611fc
 				    &text->server_name);
6611fc
-	GSS_UNLOCK_MUTEX(params->utils);
6611fc
+	GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 
6611fc
 	params->utils->free(name_token.value);
6611fc
 	name_token.value = NULL;
6611fc
@@ -709,15 +736,15 @@ gssapi_server_mech_authneg(context_t *text,
6611fc
 	}
6611fc
 
6611fc
 	if ( text->server_creds != GSS_C_NO_CREDENTIAL) {
6611fc
-	    GSS_LOCK_MUTEX(params->utils);
6611fc
+	    GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 	    maj_stat = gss_release_cred(&min_stat, &text->server_creds);
6611fc
-	    GSS_UNLOCK_MUTEX(params->utils);
6611fc
+	    GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 	    text->server_creds = GSS_C_NO_CREDENTIAL;
6611fc
 	}
6611fc
 
6611fc
 	/* If caller didn't provide creds already */
6611fc
 	if ( server_creds == GSS_C_NO_CREDENTIAL) {
6611fc
-	    GSS_LOCK_MUTEX(params->utils);
6611fc
+	    GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 	    maj_stat = gss_acquire_cred(&min_stat, 
6611fc
 					text->server_name,
6611fc
 					GSS_C_INDEFINITE, 
6611fc
@@ -726,7 +753,7 @@ gssapi_server_mech_authneg(context_t *text,
6611fc
 					&text->server_creds, 
6611fc
 					NULL, 
6611fc
 					NULL);
6611fc
-	    GSS_UNLOCK_MUTEX(params->utils);
6611fc
+	    GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 
6611fc
 	    if (GSS_ERROR(maj_stat)) {
6611fc
 		sasl_gss_seterror(text->utils, maj_stat, min_stat);
6611fc
@@ -743,7 +770,7 @@ gssapi_server_mech_authneg(context_t *text,
6611fc
     }
6611fc
 
6611fc
 
6611fc
-    GSS_LOCK_MUTEX(params->utils);
6611fc
+    GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
     maj_stat =
6611fc
 	gss_accept_sec_context(&min_stat,
6611fc
 			       &(text->gss_ctx),
6611fc
@@ -756,15 +783,15 @@ gssapi_server_mech_authneg(context_t *text,
6611fc
 			       &out_flags,
6611fc
 			       NULL,	/* context validity period */
6611fc
 			       &(text->client_creds));
6611fc
-    GSS_UNLOCK_MUTEX(params->utils);
6611fc
+    GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 
6611fc
     if (GSS_ERROR(maj_stat)) {
6611fc
 	sasl_gss_log(text->utils, maj_stat, min_stat);
6611fc
 	text->utils->seterror(text->utils->conn, SASL_NOLOG, "GSSAPI Failure: gss_accept_sec_context");
6611fc
 	if (output_token->value) {
6611fc
-	    GSS_LOCK_MUTEX(params->utils);
6611fc
+	    GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 	    gss_release_buffer(&min_stat, output_token);
6611fc
-	    GSS_UNLOCK_MUTEX(params->utils);
6611fc
+	    GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 	}
6611fc
 	sasl_gss_free_context_contents(text);
6611fc
 	return SASL_BADAUTH;
6611fc
@@ -778,18 +805,18 @@ gssapi_server_mech_authneg(context_t *text,
6611fc
 	    ret = _plug_buf_alloc(text->utils, &(text->out_buf),
6611fc
 				  &(text->out_buf_len), *serveroutlen);
6611fc
 	    if(ret != SASL_OK) {
6611fc
-		GSS_LOCK_MUTEX(params->utils);
6611fc
+		GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 		gss_release_buffer(&min_stat, output_token);
6611fc
-		GSS_UNLOCK_MUTEX(params->utils);
6611fc
+		GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 		return ret;
6611fc
 	    }
6611fc
 	    memcpy(text->out_buf, output_token->value, *serveroutlen);
6611fc
 	    *serverout = text->out_buf;
6611fc
 	}
6611fc
 
6611fc
-	GSS_LOCK_MUTEX(params->utils);
6611fc
+	GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 	gss_release_buffer(&min_stat, output_token);
6611fc
-	GSS_UNLOCK_MUTEX(params->utils);
6611fc
+	GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
     } else {
6611fc
 	/* No output token, send an empty string */
6611fc
 	*serverout = GSSAPI_BLANK_STRING;
6611fc
@@ -832,12 +859,12 @@ gssapi_server_mech_authneg(context_t *text,
6611fc
 	    /* continue with authentication */
6611fc
 	}
6611fc
 
6611fc
-    GSS_LOCK_MUTEX(params->utils);
6611fc
+    GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
     maj_stat = gss_canonicalize_name(&min_stat,
6611fc
 				     text->client_name,
6611fc
 				     mech_type,
6611fc
 				     &client_name_MN);
6611fc
-    GSS_UNLOCK_MUTEX(params->utils);
6611fc
+    GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 
6611fc
     if (GSS_ERROR(maj_stat)) {
6611fc
 	SETERROR(text->utils, "GSSAPI Failure: gss_canonicalize_name");
6611fc
@@ -848,12 +875,12 @@ gssapi_server_mech_authneg(context_t *text,
6611fc
     name_token.value = NULL;
6611fc
     name_without_realm.value = NULL;
6611fc
 
6611fc
-    GSS_LOCK_MUTEX(params->utils);
6611fc
+    GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
     maj_stat = gss_display_name (&min_stat,
6611fc
 				 client_name_MN,
6611fc
 				 &name_token,
6611fc
 				 NULL);
6611fc
-    GSS_UNLOCK_MUTEX(params->utils);
6611fc
+    GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 
6611fc
     if (GSS_ERROR(maj_stat)) {
6611fc
 	SETERROR(text->utils, "GSSAPI Failure: gss_display_name");
6611fc
@@ -883,7 +910,7 @@ gssapi_server_mech_authneg(context_t *text,
6611fc
 
6611fc
 	name_without_realm.length = strlen( (char *) name_without_realm.value );
6611fc
 
6611fc
-	GSS_LOCK_MUTEX(params->utils);
6611fc
+	GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 	maj_stat = gss_import_name (&min_stat,
6611fc
 				    &name_without_realm,
6611fc
 	    /* Solaris 8/9 gss_import_name doesn't accept GSS_C_NULL_OID here,
6611fc
@@ -894,7 +921,7 @@ gssapi_server_mech_authneg(context_t *text,
6611fc
 				    GSS_C_NULL_OID,
6611fc
 #endif
6611fc
 				    &without);
6611fc
-	GSS_UNLOCK_MUTEX(params->utils);
6611fc
+	GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 
6611fc
 	if (GSS_ERROR(maj_stat)) {
6611fc
 	    SETERROR(text->utils, "GSSAPI Failure: gss_import_name");
6611fc
@@ -903,12 +930,12 @@ gssapi_server_mech_authneg(context_t *text,
6611fc
 	    goto cleanup;
6611fc
 	}
6611fc
 
6611fc
-	GSS_LOCK_MUTEX(params->utils);
6611fc
+	GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 	maj_stat = gss_compare_name(&min_stat,
6611fc
 				    client_name_MN,
6611fc
 				    without,
6611fc
 				    &equal);
6611fc
-	GSS_UNLOCK_MUTEX(params->utils);
6611fc
+	GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 
6611fc
 	if (GSS_ERROR(maj_stat)) {
6611fc
 	    SETERROR(text->utils, "GSSAPI Failure: gss_compare_name");
6611fc
@@ -1053,7 +1080,7 @@ gssapi_server_mech_ssfcap(context_t *text,
6611fc
     real_input_token.value = (void *)sasldata;
6611fc
     real_input_token.length = 4;
6611fc
 
6611fc
-    GSS_LOCK_MUTEX(params->utils);
6611fc
+    GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
     maj_stat = gss_wrap(&min_stat,
6611fc
 			text->gss_ctx,
6611fc
 			0, /* Just integrity checking here */
6611fc
@@ -1061,14 +1088,14 @@ gssapi_server_mech_ssfcap(context_t *text,
6611fc
 			input_token,
6611fc
 			NULL,
6611fc
 			output_token);
6611fc
-    GSS_UNLOCK_MUTEX(params->utils);
6611fc
+    GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 
6611fc
     if (GSS_ERROR(maj_stat)) {
6611fc
 	sasl_gss_seterror(text->utils, maj_stat, min_stat);
6611fc
 	if (output_token->value) {
6611fc
-	    GSS_LOCK_MUTEX(params->utils);
6611fc
+	    GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 	    gss_release_buffer(&min_stat, output_token);
6611fc
-	    GSS_UNLOCK_MUTEX(params->utils);
6611fc
+	    GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 	}
6611fc
 	sasl_gss_free_context_contents(text);
6611fc
 	return SASL_FAIL;
6611fc
@@ -1082,18 +1109,18 @@ gssapi_server_mech_ssfcap(context_t *text,
6611fc
 	    ret = _plug_buf_alloc(text->utils, &(text->out_buf),
6611fc
 				  &(text->out_buf_len), *serveroutlen);
6611fc
 	    if(ret != SASL_OK) {
6611fc
-		GSS_LOCK_MUTEX(params->utils);
6611fc
+		GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 		gss_release_buffer(&min_stat, output_token);
6611fc
-		GSS_UNLOCK_MUTEX(params->utils);
6611fc
+		GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 		return ret;
6611fc
 	    }
6611fc
 	    memcpy(text->out_buf, output_token->value, *serveroutlen);
6611fc
 	    *serverout = text->out_buf;
6611fc
 	}
6611fc
 
6611fc
-	GSS_LOCK_MUTEX(params->utils);
6611fc
+	GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 	gss_release_buffer(&min_stat, output_token);
6611fc
-	GSS_UNLOCK_MUTEX(params->utils);
6611fc
+	GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
     }
6611fc
 
6611fc
     /* Wait for ssf request and authid */
6611fc
@@ -1124,14 +1151,14 @@ gssapi_server_mech_ssfreq(context_t *text,
6611fc
     real_input_token.value = (void *)clientin;
6611fc
     real_input_token.length = clientinlen;
6611fc
 
6611fc
-    GSS_LOCK_MUTEX(params->utils);
6611fc
+    GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
     maj_stat = gss_unwrap(&min_stat,
6611fc
 			  text->gss_ctx,
6611fc
 			  input_token,
6611fc
 			  output_token,
6611fc
 			  NULL,
6611fc
 			  NULL);
6611fc
-    GSS_UNLOCK_MUTEX(params->utils);
6611fc
+    GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 
6611fc
     if (GSS_ERROR(maj_stat)) {
6611fc
 	sasl_gss_seterror(text->utils, maj_stat, min_stat);
6611fc
@@ -1142,9 +1169,9 @@ gssapi_server_mech_ssfreq(context_t *text,
6611fc
     if (output_token->length < 4) {
6611fc
 	SETERROR(text->utils,
6611fc
 		 "token too short");
6611fc
-	GSS_LOCK_MUTEX(params->utils);
6611fc
+	GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 	gss_release_buffer(&min_stat, output_token);
6611fc
-	GSS_UNLOCK_MUTEX(params->utils);
6611fc
+	GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 	sasl_gss_free_context_contents(text);
6611fc
 	return SASL_FAIL;
6611fc
     }
6611fc
@@ -1175,9 +1202,9 @@ gssapi_server_mech_ssfreq(context_t *text,
6611fc
 	/* Mark that we attempted negotiation */
6611fc
 	oparams->mech_ssf = 2;
6611fc
 	if (output_token->value) {
6611fc
-	    GSS_LOCK_MUTEX(params->utils);
6611fc
+	    GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 	    gss_release_buffer(&min_stat, output_token);
6611fc
-	    GSS_UNLOCK_MUTEX(params->utils);
6611fc
+	    GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 	}
6611fc
 	sasl_gss_free_context_contents(text);
6611fc
 	return SASL_FAIL;
6611fc
@@ -1221,9 +1248,9 @@ gssapi_server_mech_ssfreq(context_t *text,
6611fc
 	}    
6611fc
     }
6611fc
 	
6611fc
-    GSS_LOCK_MUTEX(params->utils);
6611fc
+    GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
     gss_release_buffer(&min_stat, output_token);
6611fc
-    GSS_UNLOCK_MUTEX(params->utils);
6611fc
+    GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 
6611fc
     text->state = SASL_GSSAPI_STATE_AUTHENTICATED;
6611fc
 
6611fc
@@ -1547,12 +1574,12 @@ static int gssapi_client_mech_step(void *conn_context,
6611fc
 	    
6611fc
 	    sprintf(name_token.value,"%s@%s", params->service, params->serverFQDN);
6611fc
 	    
6611fc
-	    GSS_LOCK_MUTEX(params->utils);
6611fc
+	    GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 	    maj_stat = gss_import_name (&min_stat,
6611fc
 					&name_token,
6611fc
 					GSS_C_NT_HOSTBASED_SERVICE,
6611fc
 					&text->server_name);
6611fc
-	    GSS_UNLOCK_MUTEX(params->utils);
6611fc
+	    GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 	    
6611fc
 	    params->utils->free(name_token.value);
6611fc
 	    name_token.value = NULL;
6611fc
@@ -1576,9 +1603,9 @@ static int gssapi_client_mech_step(void *conn_context,
6611fc
 	     * and no input from the server.  However, thanks to Imap,
6611fc
 	     * which discards our first output, this happens all the time.
6611fc
 	     * Throw away the context and try again. */
6611fc
-	    GSS_LOCK_MUTEX(params->utils);
6611fc
+	    GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 	    maj_stat = gss_delete_sec_context (&min_stat,&text->gss_ctx,GSS_C_NO_BUFFER);
6611fc
-	    GSS_UNLOCK_MUTEX(params->utils);
6611fc
+	    GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 	    text->gss_ctx = GSS_C_NO_CONTEXT;
6611fc
 	}
6611fc
 
6611fc
@@ -1600,7 +1627,7 @@ static int gssapi_client_mech_step(void *conn_context,
6611fc
 	    req_flags = req_flags |  GSS_C_DELEG_FLAG;
6611fc
 	}
6611fc
 
6611fc
-	GSS_LOCK_MUTEX(params->utils);
6611fc
+	GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 	maj_stat = gss_init_sec_context(&min_stat,
6611fc
 					client_creds, /* GSS_C_NO_CREDENTIAL */
6611fc
 					&text->gss_ctx,
6611fc
@@ -1614,14 +1641,14 @@ static int gssapi_client_mech_step(void *conn_context,
6611fc
 					output_token,
6611fc
 					&out_req_flags,
6611fc
 					NULL);
6611fc
-	GSS_UNLOCK_MUTEX(params->utils);
6611fc
+	GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 	
6611fc
 	if (GSS_ERROR(maj_stat)) {
6611fc
 	    sasl_gss_seterror(text->utils, maj_stat, min_stat);
6611fc
 	    if (output_token->value) {
6611fc
-		GSS_LOCK_MUTEX(params->utils);
6611fc
+		GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 		gss_release_buffer(&min_stat, output_token);
6611fc
-		GSS_UNLOCK_MUTEX(params->utils);
6611fc
+		GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 	    }
6611fc
 	    sasl_gss_free_context_contents(text);
6611fc
 	    return SASL_FAIL;
6611fc
@@ -1652,22 +1679,22 @@ static int gssapi_client_mech_step(void *conn_context,
6611fc
 		ret = _plug_buf_alloc(text->utils, &(text->out_buf),
6611fc
 				      &(text->out_buf_len), *clientoutlen);
6611fc
 		if(ret != SASL_OK) {
6611fc
-		    GSS_LOCK_MUTEX(params->utils);
6611fc
+		    GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 		    gss_release_buffer(&min_stat, output_token);
6611fc
-		    GSS_UNLOCK_MUTEX(params->utils);
6611fc
+		    GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 		    return ret;
6611fc
 		}
6611fc
 		memcpy(text->out_buf, output_token->value, *clientoutlen);
6611fc
 		*clientout = text->out_buf;
6611fc
 	    }
6611fc
 	    
6611fc
-	    GSS_LOCK_MUTEX(params->utils);
6611fc
+	    GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 	    gss_release_buffer(&min_stat, output_token);
6611fc
-	    GSS_UNLOCK_MUTEX(params->utils);
6611fc
+	    GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 	}
6611fc
 	
6611fc
 	if (maj_stat == GSS_S_COMPLETE) {
6611fc
-	    GSS_LOCK_MUTEX(params->utils);
6611fc
+	    GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 	    maj_stat = gss_inquire_context(&min_stat,
6611fc
 					   text->gss_ctx,
6611fc
 					   &text->client_name,
6611fc
@@ -1678,7 +1705,7 @@ static int gssapi_client_mech_step(void *conn_context,
6611fc
 					   NULL,       /* flags */
6611fc
 					   NULL,       /* local init */
6611fc
 					   NULL);      /* open */
6611fc
-	    GSS_UNLOCK_MUTEX(params->utils);
6611fc
+	    GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 	    
6611fc
 	    if (GSS_ERROR(maj_stat)) {
6611fc
 		sasl_gss_seterror(text->utils, maj_stat, min_stat);
6611fc
@@ -1687,18 +1714,18 @@ static int gssapi_client_mech_step(void *conn_context,
6611fc
 	    }
6611fc
 	    
6611fc
 	    name_token.length = 0;
6611fc
-	    GSS_LOCK_MUTEX(params->utils);
6611fc
+	    GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 	    maj_stat = gss_display_name(&min_stat,
6611fc
 					text->client_name,
6611fc
 					&name_token,
6611fc
 					NULL);
6611fc
-	    GSS_UNLOCK_MUTEX(params->utils);
6611fc
+	    GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 	    
6611fc
 	    if (GSS_ERROR(maj_stat)) {
6611fc
 		if (name_token.value) {
6611fc
-		    GSS_LOCK_MUTEX(params->utils);
6611fc
+		    GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 		    gss_release_buffer(&min_stat, &name_token);
6611fc
-		    GSS_UNLOCK_MUTEX(params->utils);
6611fc
+		    GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 		}
6611fc
 		SETERROR(text->utils, "GSSAPI Failure");
6611fc
 		sasl_gss_free_context_contents(text);
6611fc
@@ -1719,9 +1746,9 @@ static int gssapi_client_mech_step(void *conn_context,
6611fc
 					 SASL_CU_AUTHID | SASL_CU_AUTHZID,
6611fc
 					 oparams);
6611fc
 	    }
6611fc
-	    GSS_LOCK_MUTEX(params->utils);
6611fc
+	    GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 	    gss_release_buffer(&min_stat, &name_token);
6611fc
-	    GSS_UNLOCK_MUTEX(params->utils);
6611fc
+	    GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 	    
6611fc
 	    if (ret != SASL_OK) return ret;
6611fc
 	    
6611fc
@@ -1747,32 +1774,32 @@ static int gssapi_client_mech_step(void *conn_context,
6611fc
 	real_input_token.value = (void *) serverin;
6611fc
 	real_input_token.length = serverinlen;
6611fc
 	
6611fc
-	GSS_LOCK_MUTEX(params->utils);
6611fc
+	GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 	maj_stat = gss_unwrap(&min_stat,
6611fc
 			      text->gss_ctx,
6611fc
 			      input_token,
6611fc
 			      output_token,
6611fc
 			      NULL,
6611fc
 			      NULL);
6611fc
-	GSS_UNLOCK_MUTEX(params->utils);
6611fc
+	GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 	
6611fc
 	if (GSS_ERROR(maj_stat)) {
6611fc
 	    sasl_gss_seterror(text->utils, maj_stat, min_stat);
6611fc
-	    sasl_gss_free_context_contents(text);
6611fc
 	    if (output_token->value) {
6611fc
-		GSS_LOCK_MUTEX(params->utils);
6611fc
+		GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 		gss_release_buffer(&min_stat, output_token);
6611fc
-		GSS_UNLOCK_MUTEX(params->utils);
6611fc
+		GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 	    }
6611fc
+	    sasl_gss_free_context_contents(text);
6611fc
 	    return SASL_FAIL;
6611fc
 	}
6611fc
 	
6611fc
 	if (output_token->length != 4) {
6611fc
 	    SETERROR(text->utils,
6611fc
 		     (output_token->length < 4) ? "token too short" : "token too long");
6611fc
-	    GSS_LOCK_MUTEX(params->utils);
6611fc
+	    GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 	    gss_release_buffer(&min_stat, output_token);
6611fc
-	    GSS_UNLOCK_MUTEX(params->utils);
6611fc
+	    GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 	    sasl_gss_free_context_contents(text);
6611fc
 	    return SASL_FAIL;
6611fc
 	}
6611fc
@@ -1873,9 +1900,9 @@ static int gssapi_client_mech_step(void *conn_context,
6611fc
 	    }
6611fc
 	}
6611fc
 	
6611fc
-	GSS_LOCK_MUTEX(params->utils);
6611fc
+	GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 	gss_release_buffer(&min_stat, output_token);
6611fc
-	GSS_UNLOCK_MUTEX(params->utils);
6611fc
+	GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 	
6611fc
 	/* oparams->user is always set, due to canon_user requirements.
6611fc
 	 * Make sure the client actually requested it though, by checking
6611fc
@@ -1921,7 +1948,7 @@ static int gssapi_client_mech_step(void *conn_context,
6611fc
 	}
6611fc
 	((unsigned char *)input_token->value)[0] = mychoice;
6611fc
 	
6611fc
-	GSS_LOCK_MUTEX(params->utils);
6611fc
+	GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 	maj_stat = gss_wrap (&min_stat,
6611fc
 			     text->gss_ctx,
6611fc
 			     0, /* Just integrity checking here */
6611fc
@@ -1929,7 +1956,7 @@ static int gssapi_client_mech_step(void *conn_context,
6611fc
 			     input_token,
6611fc
 			     NULL,
6611fc
 			     output_token);
6611fc
-	GSS_UNLOCK_MUTEX(params->utils);
6611fc
+	GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 	
6611fc
 	params->utils->free(input_token->value);
6611fc
 	input_token->value = NULL;
6611fc
@@ -1937,9 +1964,9 @@ static int gssapi_client_mech_step(void *conn_context,
6611fc
 	if (GSS_ERROR(maj_stat)) {
6611fc
 	    sasl_gss_seterror(text->utils, maj_stat, min_stat);
6611fc
 	    if (output_token->value) {
6611fc
-		GSS_LOCK_MUTEX(params->utils);
6611fc
+		GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 		gss_release_buffer(&min_stat, output_token);
6611fc
-		GSS_UNLOCK_MUTEX(params->utils);
6611fc
+		GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 	    }
6611fc
 	    sasl_gss_free_context_contents(text);
6611fc
 	    return SASL_FAIL;
6611fc
@@ -1955,18 +1982,18 @@ static int gssapi_client_mech_step(void *conn_context,
6611fc
 				      &(text->out_buf_len),
6611fc
 				      *clientoutlen);
6611fc
 		if (ret != SASL_OK) {
6611fc
-		    GSS_LOCK_MUTEX(params->utils);
6611fc
+		    GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 		    gss_release_buffer(&min_stat, output_token);
6611fc
-		    GSS_UNLOCK_MUTEX(params->utils);
6611fc
+		    GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 		    return ret;
6611fc
 		}
6611fc
 		memcpy(text->out_buf, output_token->value, *clientoutlen);
6611fc
 		*clientout = text->out_buf;
6611fc
 	    }
6611fc
 	    
6611fc
-	    GSS_LOCK_MUTEX(params->utils);
6611fc
+	    GSS_LOCK_MUTEX_CTX(params->utils, text);
6611fc
 	    gss_release_buffer(&min_stat, output_token);
6611fc
-	    GSS_UNLOCK_MUTEX(params->utils);
6611fc
+	    GSS_UNLOCK_MUTEX_CTX(params->utils, text);
6611fc
 
6611fc
 	}
6611fc
 	
6611fc
-- 
6611fc
2.4.3
6611fc
6611fc