Add some thread primitives
authorLuke Howard <lukeh@padl.com>
Wed, 8 Sep 2010 12:48:30 +0000 (14:48 +0200)
committerLuke Howard <lukeh@padl.com>
Wed, 8 Sep 2010 12:48:30 +0000 (14:48 +0200)
mech_eap/gssapiP_eap.h
mech_eap/util.h
mech_eap/util_context.c
mech_eap/util_cred.c
mech_eap/util_name.c

index 9bb77d3..bc87bc5 100644 (file)
@@ -42,6 +42,7 @@
 #include <gssapi/gssapi.h>
 #include <gssapi/gssapi_ext.h>
 #include "gssapi_eap.h"
+#include "util.h"
 
 /* EAP includes */
 #define IEEE8021X_EAPOL 1
@@ -55,6 +56,7 @@
 #include <krb5.h>
 
 struct gss_name_struct {
+    GSSEAP_MUTEX mutex;
     OM_uint32 flags;
     krb5_principal kerberosName;
     void *aaa;
@@ -67,6 +69,7 @@ struct gss_name_struct {
 #define CRED_FLAG_PASSWORD                  0x00000008
 
 struct gss_cred_id_struct {
+    GSSEAP_MUTEX mutex;
     OM_uint32 flags;
     gss_name_t name;
     gss_buffer_desc password;
@@ -110,6 +113,7 @@ struct eap_gss_acceptor_ctx {
 };
 
 struct gss_ctx_id_struct {
+    GSSEAP_MUTEX mutex;
     enum eap_gss_state state;
     OM_uint32 flags;
     OM_uint32 gssFlags;
@@ -140,16 +144,6 @@ struct gss_ctx_id_struct {
 #define KEY_USAGE_INITIATOR_SEAL            514
 #define KEY_USAGE_INITIATOR_SIGN            515
 
-enum gss_eap_token_type {
-    TOK_TYPE_EAP_RESP  = 0x0601,
-    TOK_TYPE_EAP_REQ   = 0x0602,
-    TOK_TYPE_GSS_CB    = 0x0603,
-    TOK_TYPE_MIC       = 0x0404,
-    TOK_TYPE_WRAP      = 0x0504,
-    TOK_TYPE_DELETE    = 0x0405,
-    TOK_TYPE_NONE      = 0xFFFF
-};
-
 /* wrap_iov.c */
 OM_uint32
 gssEapWrapOrGetMIC(OM_uint32 *minor,
@@ -170,6 +164,4 @@ gssEapUnwrapOrVerifyMIC(OM_uint32 *minor_status,
                         enum gss_eap_token_type toktype);
 
 
-#include "util.h"
-
 #endif /* _GSSAPIP_EAP_H_ */
index 1c368d4..972f721 100644 (file)
@@ -57,6 +57,8 @@
 #ifndef _UTIL_H_
 #define _UTIL_H_ 1
 
+#include <krb5.h>
+
 #define KRB_KEYTYPE(key)        ((key)->enctype)
 
 int
@@ -193,6 +195,16 @@ sequenceInit(void **vqueue, uint64_t seqnum,
              int do_replay, int do_sequence, int wide_nums);
 
 /* util_token.c */
+enum gss_eap_token_type {
+    TOK_TYPE_EAP_RESP  = 0x0601,
+    TOK_TYPE_EAP_REQ   = 0x0602,
+    TOK_TYPE_GSS_CB    = 0x0603,
+    TOK_TYPE_MIC       = 0x0404,
+    TOK_TYPE_WRAP      = 0x0504,
+    TOK_TYPE_DELETE    = 0x0405,
+    TOK_TYPE_NONE      = 0xFFFF
+};
+
 size_t
 tokenSize(const gss_OID_desc *mech, size_t body_size);
 
@@ -221,6 +233,14 @@ verifyTokenHeader(const gss_OID_desc * mech,
         return GSS_S_FAILURE;                           \
     } while (0)
 
+#include <pthread.h>
+
+#define GSSEAP_MUTEX                    pthread_mutex_t
+#define GSSEAP_MUTEX_INIT(m)            pthread_mutex_init((m), NULL)
+#define GSSEAP_MUTEX_DESTROY(m)         pthread_mutex_destroy((m))
+#define GSSEAP_MUTEX_LOCK(m)            pthread_mutex_lock((m))
+#define GSSEAP_MUTEX_UNLOCK(m)          pthread_mutex_unlock((m))
+
 /* Helper functions */
 static inline void
 store_uint16_be(uint16_t val, void *vp)
index d7a87d3..fab4313 100644 (file)
@@ -47,6 +47,12 @@ gssEapAllocContext(OM_uint32 *minor,
         return GSS_S_FAILURE;
     }
 
+    if (GSSEAP_MUTEX_INIT(&ctx->mutex) != 0) {
+        *minor = errno;
+        gssEapReleaseContext(&tmpMinor, &ctx);
+        return GSS_S_FAILURE;
+    }
+
     *minor = krb5_init_context(&ctx->kerberosCtx);
     if (*minor != 0) {
         gssEapReleaseContext(&tmpMinor, &ctx);
@@ -100,6 +106,8 @@ gssEapReleaseContext(OM_uint32 *minor,
     gss_release_oid(&tmpMinor, &ctx->mechanismUsed);
     sequenceFree(ctx->seqState);
 
+    GSSEAP_MUTEX_DESTROY(&ctx->mutex);
+
     memset(ctx, 0, sizeof(*ctx));
     GSSEAP_FREE(ctx);
     *pCtx = GSS_C_NO_CONTEXT;
index 0db20d9..08ede79 100644 (file)
@@ -35,6 +35,7 @@
 OM_uint32
 gssEapAllocCred(OM_uint32 *minor, gss_cred_id_t *pCred)
 {
+    OM_uint32 tmpMinor;
     gss_cred_id_t cred;
 
     assert(*pCred == GSS_C_NO_CREDENTIAL);
@@ -45,8 +46,15 @@ gssEapAllocCred(OM_uint32 *minor, gss_cred_id_t *pCred)
         return GSS_S_FAILURE;
     }
 
+    if (GSSEAP_MUTEX_INIT(&cred->mutex) != 0) {
+        *minor = errno;
+        gssEapReleaseCred(&tmpMinor, &cred);
+        return GSS_S_FAILURE;
+    }
+
     *pCred = cred;
 
+    *minor = 0;
     return GSS_S_COMPLETE;
 }
 
@@ -68,6 +76,7 @@ gssEapReleaseCred(OM_uint32 *minor, gss_cred_id_t *pCred)
         GSSEAP_FREE(cred->password.value);
     }
 
+    GSSEAP_MUTEX_DESTROY(&cred->mutex);
     memset(cred, 0, sizeof(*cred));
     GSSEAP_FREE(cred);
     *pCred = NULL;
index 580adef..b5c7c72 100644 (file)
@@ -35,6 +35,7 @@
 OM_uint32
 gssEapAllocName(OM_uint32 *minor, gss_name_t *pName)
 {
+    OM_uint32 tmpMinor;
     gss_name_t name;
 
     assert(*pName == GSS_C_NO_NAME);
@@ -45,6 +46,12 @@ gssEapAllocName(OM_uint32 *minor, gss_name_t *pName)
         return GSS_S_FAILURE;
     }
 
+    if (GSSEAP_MUTEX_INIT(&name->mutex) != 0) {
+        *minor = errno;
+        gssEapReleaseName(&tmpMinor, &name);
+        return GSS_S_FAILURE;
+    }
+
     *pName = name;
 
     return GSS_S_COMPLETE;
@@ -71,9 +78,24 @@ gssEapReleaseName(OM_uint32 *minor, gss_name_t *pName)
         krb5_free_context(kerbCtx);
     }
 
+    GSSEAP_MUTEX_DESTROY(&name->mutex);
     GSSEAP_FREE(name);
     *pName = NULL;
 
     *minor = 0;
     return GSS_S_COMPLETE;
 }
+
+OM_uint32
+gssEapDuplicateName(krb5_context context,
+                    const gss_name_t src,
+                    gss_name_t *dst)
+{
+}
+
+krb5_boolean
+gssEapCompareName(krb5_context context,
+                  gss_name_t name1,
+                  gss_name_t name2)
+{
+}