attribute composition helpers
authorLuke Howard <lukeh@padl.com>
Wed, 8 Sep 2010 18:43:33 +0000 (20:43 +0200)
committerLuke Howard <lukeh@padl.com>
Wed, 8 Sep 2010 18:43:33 +0000 (20:43 +0200)
mech_eap/get_name_attribute.c
mech_eap/util.h
mech_eap/util_name.c

index 400ee9c..f2ea472 100644 (file)
@@ -42,5 +42,17 @@ gss_get_name_attribute(OM_uint32 *minor,
                        gss_buffer_t display_value,
                        int *more)
 {
-    GSSEAP_NOT_IMPLEMENTED;
+    OM_uint32 major, tmpMinor;
+
+    if (name == GSS_C_NO_NAME) {
+        *minor = EINVAL;
+        return GSS_S_CALL_INACCESSIBLE_READ | GSS_S_BAD_NAME;
+    }
+
+    GSSEAP_MUTEX_LOCK(&name->mutex);
+
+cleanup:
+    GSSEAP_MUTEX_UNLOCK(&name->mutex);
+
+    return major;
 }
index 0388a30..9b7d51e 100644 (file)
@@ -185,6 +185,13 @@ gssEapValidateMechs(OM_uint32 *minor,
                    const gss_OID_set mechs);
 
 /* util_name.c */
+enum gss_eap_attribute_type {
+    ATTR_TYPE_NONE                  = 0,
+    ATTR_TYPE_SAML_AAA_ASSERTION    = 1,
+    ATTR_TYPE_SAML_ATTR             = 2,
+    ATTR_TYPE_RADIUS_AVP            = 3
+};
+
 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,
@@ -196,6 +203,21 @@ OM_uint32 gssEapImportName(OM_uint32 *minor,
                            gss_OID input_name_type,
                            gss_name_t *output_name);
 
+enum gss_eap_attribute_type
+gssEapAttributePrefixToType(const gss_buffer_t prefix);
+gss_buffer_t
+gssEapAttributeTypeToPrefix(enum gss_eap_attribute_type type);
+OM_uint32
+decomposeAttributeName(OM_uint32 *minor,
+                       const gss_buffer_t attribute,
+                       gss_buffer_t prefix,
+                       gss_buffer_t suffix);
+OM_uint32
+composeAttributeName(OM_uint32 *minor,
+                       const gss_buffer_t prefix,
+                       const gss_buffer_t suffix,
+                       gss_buffer_t attribute);
+
 /* util_oid.c */
 OM_uint32
 composeOid(OM_uint32 *minor_status,
index 9f0e219..f1655cc 100644 (file)
@@ -386,3 +386,126 @@ cleanup:
 
     return major;
 }
+
+static gss_buffer_desc attributePrefixes[] = {
+    {
+        /* ATTR_TYPE_NONE */
+        0,
+        NULL,
+    },
+    {
+        /* ATTR_TYPE_SAML_AAA_ASSERTION */
+        sizeof("urn:ietf:params:gss-eap:saml-aaa-assertion"),
+        "urn:ietf:params:gss-eap:saml-aaa-assertion"
+    },
+    {
+        /* ATTR_TYPE_SAML_ATTR */
+        sizeof("urn:ietf:params:gss-eap:saml-attr"),
+        "urn:ietf:params:gss-eap:saml-attr"
+    },
+    {
+        /* ATTR_TYPE_RADIUS_AVP */
+        sizeof("urn:ietf:params:gss-eap:radius-avp"),
+        "urn:ietf:params:gss-eap:radius-avp",
+    }
+};
+
+enum gss_eap_attribute_type
+gssEapAttributePrefixToType(const gss_buffer_t prefix)
+{
+    enum gss_eap_attribute_type i;
+
+    for (i = ATTR_TYPE_SAML_AAA_ASSERTION;
+         i < sizeof(attributePrefixes) / sizeof(attributePrefixes[0]);
+         i++)
+    {
+        gss_buffer_t p = &attributePrefixes[i];
+
+        if (p->length == prefix->length &&
+            memcmp(p->value, prefix->value, prefix->length) == 0) {
+            return i;
+        }
+    }
+
+    return ATTR_TYPE_NONE;
+}
+
+gss_buffer_t
+gssEapAttributeTypeToPrefix(enum gss_eap_attribute_type type)
+{
+    if (type <= ATTR_TYPE_NONE ||
+        type > ATTR_TYPE_RADIUS_AVP)
+        return GSS_C_NO_BUFFER;
+
+    return &attributePrefixes[type];
+}
+
+OM_uint32
+decomposeAttributeName(OM_uint32 *minor,
+                       const gss_buffer_t attribute,
+                       gss_buffer_t prefix,
+                       gss_buffer_t suffix)
+{
+    char *p = NULL;
+    int i;
+
+    for (i = 0; i < attribute->length; i++) {
+        if (((char *)attribute->value)[i] == ' ') {
+            p = (char *)attribute->value + i + 1;
+            break;
+        }
+    }
+
+    prefix->value = attribute->value;
+    prefix->length = i;
+
+    if (p != NULL && *p != '\0')  {
+        suffix->length = attribute->length - 1 - prefix->length;
+        suffix->value = p;
+    } else {
+        suffix->length = 0;
+        suffix->value = NULL;
+    }
+
+    *minor = 0;
+    return GSS_S_COMPLETE;
+}
+
+OM_uint32
+composeAttributeName(OM_uint32 *minor,
+                       const gss_buffer_t prefix,
+                       const gss_buffer_t suffix,
+                       gss_buffer_t attribute)
+{
+    size_t len = 0;
+    char *p;
+
+    attribute->length = 0;
+    attribute->value = NULL;
+
+    if (prefix == GSS_C_NO_BUFFER || prefix->length == 0)
+        return GSS_S_COMPLETE;
+
+    len = prefix->length;
+    if (suffix != NULL) {
+        len += 1 + suffix->length;
+    }
+
+    p = attribute->value = GSSEAP_MALLOC(len + 1);
+    if (attribute->value == NULL) {
+        *minor = ENOMEM;
+        return GSS_S_FAILURE;
+    }
+    attribute->length = len;
+
+    memcpy(p, prefix->value, prefix->length);
+    if (suffix != NULL) {
+        p[prefix->length] = ' ';
+        memcpy(p + prefix->length + 1, suffix->value, suffix->length);
+    }
+
+    p[attribute->length] = '\0';
+
+    *minor = 0;
+    return GSS_S_COMPLETE;
+}