Merge TLD code from Windows port, after cleanup
[moonshot.git] / moonshot / mech_eap / util_krb.c
index 88ad6dd..779c812 100644 (file)
 
 #include "gssapiP_eap.h"
 
-static GSSEAP_THREAD_ONCE krbContextKeyOnce = GSSEAP_ONCE_INITIALIZER;
-static GSSEAP_THREAD_KEY krbContextKey;
-
-static void
-destroyKrbContext(void *arg)
+void
+gssEapDestroyKrbContext(krb5_context context)
 {
-    krb5_context context = (krb5_context)arg;
-
     if (context != NULL)
         krb5_free_context(context);
 }
 
-static void
-createKrbContextKey(void)
-{
-    GSSEAP_KEY_CREATE(&krbContextKey, destroyKrbContext);
-}
-
 static krb5_error_code
 initKrbContext(krb5_context *pKrbContext)
 {
@@ -91,19 +80,17 @@ cleanup:
 OM_uint32
 gssEapKerberosInit(OM_uint32 *minor, krb5_context *context)
 {
+    struct gss_eap_thread_local_data *tld;
+
     *minor = 0;
 
-    GSSEAP_ONCE(&krbContextKeyOnce, createKrbContextKey);
-
-    *context = GSSEAP_GETSPECIFIC(krbContextKey);
-    if (*context == NULL) {
-        *minor = initKrbContext(context);
-        if (*minor == 0) {
-            if (GSSEAP_SETSPECIFIC(krbContextKey, *context) != 0) {
-                *minor = errno;
-                krb5_free_context(*context);
-                *context = NULL;
-            }
+    tld = gssEapGetThreadLocalData();
+    if (tld != NULL) {
+        *context = tld->krbContext;
+        if (*context == NULL) {
+            *minor = initKrbContext(context);
+            if (*minor == 0)
+                tld->krbContext = *context;
         }
     }