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; }
struct gssapi_thr_context * _gsskrb5_get_thread_context(int createp) { struct gssapi_thr_context *ctx; int ret; HEIMDAL_MUTEX_lock(&_gsskrb5_context_mutex); if (!created_key) abort(); ctx = HEIMDAL_getspecific(gssapi_context_key); if (ctx == NULL) { if (!createp) goto fail; ctx = malloc(sizeof(*ctx)); if (ctx == NULL) goto fail; ctx->error_string = NULL; HEIMDAL_MUTEX_init(&ctx->mutex); HEIMDAL_setspecific(gssapi_context_key, ctx, ret); if (ret) goto fail; } HEIMDAL_MUTEX_unlock(&_gsskrb5_context_mutex); return ctx; fail: HEIMDAL_MUTEX_unlock(&_gsskrb5_context_mutex); if (ctx) free(ctx); return NULL; }
krb5_error_code _gsskrb5_init (krb5_context *context) { static heim_base_once_t once; krb5_error_code ret = 0; heim_base_once_f(&once, NULL, once_func); *context = HEIMDAL_getspecific(context_key); if (*context == NULL) { ret = krb5_init_context(context); if (ret == 0) { HEIMDAL_setspecific(context_key, *context, ret); if (ret) { krb5_free_context(*context); *context = NULL; } } } else { krb5_reload_config(*context, 0, NULL); } return ret; }
krb5_error_code _gsskrb5_init (krb5_context *context) { krb5_error_code 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 ret; } created_key = 1; } HEIMDAL_MUTEX_unlock(&context_mutex); *context = HEIMDAL_getspecific(context_key); if (*context == NULL) { ret = krb5_init_context(context); if (ret == 0) { HEIMDAL_setspecific(context_key, *context, ret); if (ret) { krb5_free_context(*context); *context = NULL; } } } return ret; }