Cleanup
[mech_eap.orig] / util.h
diff --git a/util.h b/util.h
index 972f721..cdcabd3 100644 (file)
--- a/util.h
+++ b/util.h
@@ -59,6 +59,9 @@
 
 #include <krb5.h>
 
+#include "util_saml.h"
+#include "util_radius.h"
+
 #define KRB_KEYTYPE(key)        ((key)->enctype)
 
 int
@@ -122,6 +125,24 @@ gssEapIsIntegrityOnly(gss_iov_buffer_desc *iov, int iov_count);
 int
 gssEapAllocIov(gss_iov_buffer_t iov, size_t size);
 
+OM_uint32
+gssEapDeriveRFC3961Key(OM_uint32 *minor,
+                       gss_buffer_t msk,
+                       krb5_enctype enctype,
+                       krb5_keyblock *pKey);
+
+/* util_krb.c */
+OM_uint32
+gssEapKerberosInit(OM_uint32 *minor, krb5_context *context);
+
+#define GSSEAP_KRB_INIT(ctx) do {                   \
+        OM_uint32 tmpMajor;                         \
+        tmpMajor  = gssEapKerberosInit(minor, ctx); \
+        if (GSS_ERROR(tmpMajor)) {                  \
+            return tmpMajor;                        \
+        }                                           \
+    } while (0)
+
 /* util_mech.c */
 void
 gssEapInternalizeOid(const gss_OID oid,
@@ -151,6 +172,14 @@ gssEapIsMechanismOid(const gss_OID oid);
 /* util_name.c */
 OM_uint32 gssEapAllocName(OM_uint32 *minor, gss_name_t *pName);
 OM_uint32 gssEapReleaseName(OM_uint32 *minor, gss_name_t *pName);
+OM_uint32 gssEapExportName(OM_uint32 *minor,
+                           const gss_name_t name,
+                           gss_buffer_t exportedName,
+                           int composite);
+OM_uint32 gssEapImportName(OM_uint32 *minor,
+                           const gss_buffer_t input_name_buffer,
+                           gss_OID input_name_type,
+                           gss_name_t *output_name);
 
 /* util_oid.c */
 OM_uint32
@@ -168,10 +197,15 @@ decomposeOid(OM_uint32 *minor_status,
              int *suffix) ;
 
 static inline int
-oidEqual(const gss_OID_desc *o1, const gss_OID_desc  *o2)
+oidEqual(const gss_OID_desc *o1, const gss_OID_desc *o2)
 {
-    return (o1->length == o2->length &&
-            memcmp(o1->elements, o2->elements, o1->length) == 0);
+    if (o1 == GSS_C_NO_OID)
+        return (o2 == GSS_C_NO_OID);
+    else if (o2 == GSS_C_NO_OID)
+        return (o1 == GSS_C_NO_OID);
+    else
+        return (o1->length == o2->length &&
+                memcmp(o1->elements, o2->elements, o1->length) == 0);
 }
 
 /* util_ordering.c */
@@ -196,13 +230,15 @@ sequenceInit(void **vqueue, uint64_t seqnum,
 
 /* 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
+    TOK_TYPE_NONE                    = 0x0000,
+    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_EXPORT_NAME             = 0x0401,
+    TOK_TYPE_EXPORT_NAME_COMPOSITE   = 0x0402,
+    TOK_TYPE_DELETE                  = 0x0405,
 };
 
 size_t
@@ -236,11 +272,22 @@ verifyTokenHeader(const gss_OID_desc * mech,
 #include <pthread.h>
 
 #define GSSEAP_MUTEX                    pthread_mutex_t
+#define GSSEAP_MUTEX_INITIALIZER        PTHREAD_MUTEX_INITIALIZER
+
 #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))
 
+#define GSSEAP_THREAD_KEY               pthread_key_t
+#define GSSEAP_KEY_CREATE(k, d)         pthread_key_create((k), (d))
+#define GSSEAP_GETSPECIFIC(k)           pthread_getspecific((k))
+#define GSSEAP_SETSPECIFIC(k, d)        pthread_setspecific((k), (d))
+
+#define GSSEAP_THREAD_ONCE              pthread_once_t
+#define GSSEAP_ONCE(o, i)               pthread_once((o), (i))
+#define GSSEAP_ONCE_INITIALIZER         PTHREAD_ONCE_INIT
+
 /* Helper functions */
 static inline void
 store_uint16_be(uint16_t val, void *vp)
@@ -303,4 +350,43 @@ load_uint64_be(const void *cvp)
     return ((uint64_t)load_uint32_be(p) << 32) | load_uint32_be(p + 4);
 }
 
+static OM_uint32
+makeStringBuffer(OM_uint32 *minor,
+                 const char *string,
+                 gss_buffer_t buffer)
+{
+    size_t len = strlen(string);
+
+    buffer->value = GSSEAP_MALLOC(len + 1);
+    if (buffer->value == NULL) {
+        *minor = ENOMEM;
+        return GSS_S_FAILURE;
+    }
+    memcpy(buffer->value, string, len + 1);
+    buffer->length = len;
+
+    *minor = 0;
+    return GSS_S_COMPLETE;
+}
+
+static OM_uint32
+bufferToString(OM_uint32 *minor,
+               const gss_buffer_t buffer,
+               char **pString)
+{
+    char *s;
+
+    s = GSSEAP_MALLOC(buffer->length + 1);
+    if (s == NULL) {
+        *minor = ENOMEM;
+        return GSS_S_FAILURE;
+    }
+    memcpy(s, buffer->value, buffer->length);
+    s[buffer->length] = '\0';
+
+    *pString = s;
+
+    *minor = 0;
+    return GSS_S_COMPLETE;
+}
 #endif /* _UTIL_H_ */