Glue to catch the error from the lower gss-api layer and save that for
later so gss_display_status() can show the error. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@19924 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
		
							
								
								
									
										141
									
								
								lib/gssapi/mech/context.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										141
									
								
								lib/gssapi/mech/context.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,141 @@ | ||||
| #include "mech/mech_locl.h" | ||||
| #include "heim_threads.h" | ||||
|  | ||||
| RCSID("$Id$"); | ||||
|  | ||||
| struct mg_thread_ctx { | ||||
|     gss_OID mech; | ||||
|     OM_uint32 maj_stat; | ||||
|     OM_uint32 min_stat; | ||||
|     gss_buffer_desc maj_error; | ||||
|     gss_buffer_desc min_error; | ||||
| }; | ||||
|  | ||||
| static HEIMDAL_MUTEX context_mutex = HEIMDAL_MUTEX_INITIALIZER; | ||||
| static int created_key; | ||||
| static HEIMDAL_thread_key context_key; | ||||
|  | ||||
|  | ||||
| static void | ||||
| destroy_context(void *ptr) | ||||
| { | ||||
|     struct mg_thread_ctx *mg = ptr; | ||||
|     OM_uint32 junk; | ||||
|  | ||||
|     if (mg == NULL) | ||||
| 	return; | ||||
|  | ||||
|     gss_release_buffer(&junk, &mg->maj_error); | ||||
|     gss_release_buffer(&junk, &mg->min_error); | ||||
|     free(mg); | ||||
| } | ||||
|  | ||||
|  | ||||
| static struct mg_thread_ctx * | ||||
| _gss_mechglue_thread(void) | ||||
| { | ||||
|     struct mg_thread_ctx *ctx; | ||||
|     int ret = 0; | ||||
|  | ||||
|     HEIMDAL_MUTEX_lock(&context_mutex); | ||||
|  | ||||
|     if (!created_key) { | ||||
| 	HEIMDAL_key_create(&context_key, destroy_context, ret); | ||||
| 	if (ret) { | ||||
| 	    HEIMDAL_MUTEX_unlock(&context_mutex); | ||||
| 	    return NULL; | ||||
| 	} | ||||
| 	created_key = 1; | ||||
|     } | ||||
|     HEIMDAL_MUTEX_unlock(&context_mutex); | ||||
|  | ||||
|     ctx = HEIMDAL_getspecific(context_key); | ||||
|     if (ctx == NULL) { | ||||
|  | ||||
| 	ctx = calloc(1, sizeof(*ctx)); | ||||
| 	if (ctx == NULL) | ||||
| 	    return NULL; | ||||
| 	HEIMDAL_setspecific(context_key, ctx, ret); | ||||
| 	if (ret) { | ||||
| 	    free(ctx); | ||||
| 	    return NULL; | ||||
| 	} | ||||
|     } | ||||
|     return ctx; | ||||
| } | ||||
|  | ||||
| OM_uint32 | ||||
| _gss_mg_get_error(const gss_OID mech, OM_uint32 type, | ||||
| 		  OM_uint32 value, gss_buffer_t string) | ||||
| { | ||||
|     struct mg_thread_ctx *mg; | ||||
|  | ||||
|     mg = _gss_mechglue_thread(); | ||||
|     if (mg == NULL) | ||||
| 	return GSS_S_BAD_STATUS; | ||||
|  | ||||
|     if (mech != NULL && gss_oid_equal(mg->mech, mech) == 0) | ||||
| 	return GSS_S_BAD_STATUS; | ||||
|  | ||||
|     switch (type) { | ||||
|     case GSS_C_GSS_CODE: { | ||||
| 	if (value != mg->maj_stat) | ||||
| 	    break; | ||||
| 	string->value = malloc(mg->maj_error.length); | ||||
| 	string->length = mg->maj_error.length; | ||||
| 	memcpy(string->value, mg->maj_error.value, mg->maj_error.length); | ||||
| 	return GSS_S_COMPLETE; | ||||
|     } | ||||
|     case GSS_C_MECH_CODE: { | ||||
| 	if (value != mg->min_stat) | ||||
| 	    break; | ||||
| 	string->value = malloc(mg->min_error.length); | ||||
| 	string->length = mg->min_error.length; | ||||
| 	memcpy(string->value, mg->min_error.value, mg->min_error.length); | ||||
| 	return GSS_S_COMPLETE; | ||||
|     } | ||||
|     } | ||||
|     string->value = NULL; | ||||
|     string->length = 0; | ||||
|     return GSS_S_BAD_STATUS; | ||||
| } | ||||
|  | ||||
| void | ||||
| _gss_mg_error(gssapi_mech_interface m, OM_uint32 maj, OM_uint32 min) | ||||
| { | ||||
|     OM_uint32 major_status, minor_status; | ||||
|     OM_uint32 message_content; | ||||
|     struct mg_thread_ctx *mg; | ||||
|  | ||||
|     mg = _gss_mechglue_thread(); | ||||
|     if (mg == NULL) | ||||
| 	return; | ||||
|  | ||||
|     gss_release_buffer(&minor_status, &mg->maj_error); | ||||
|     gss_release_buffer(&minor_status, &mg->min_error); | ||||
|  | ||||
|     mg->mech = &m->gm_mech_oid; | ||||
|     mg->maj_stat = maj; | ||||
|     mg->min_stat = min; | ||||
|  | ||||
|     major_status = m->gm_display_status(&minor_status, | ||||
| 					maj,  | ||||
| 					GSS_C_GSS_CODE, | ||||
| 					&m->gm_mech_oid, | ||||
| 					&message_content, | ||||
| 					&mg->maj_error); | ||||
|     if (GSS_ERROR(major_status)) { | ||||
| 	mg->maj_error.value = NULL; | ||||
| 	mg->maj_error.length = 0; | ||||
|     } | ||||
|     major_status = m->gm_display_status(&minor_status, | ||||
| 					min,  | ||||
| 					GSS_C_MECH_CODE, | ||||
| 					&m->gm_mech_oid, | ||||
| 					&message_content, | ||||
| 					&mg->min_error); | ||||
|     if (GSS_ERROR(major_status)) { | ||||
| 	mg->min_error.value = NULL; | ||||
| 	mg->min_error.length = 0; | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Love Hörnquist Åstrand
					Love Hörnquist Åstrand