some fixes for attribute handling
authorLuke Howard <lukeh@padl.com>
Tue, 21 Sep 2010 16:09:59 +0000 (18:09 +0200)
committerLuke Howard <lukeh@padl.com>
Tue, 21 Sep 2010 16:09:59 +0000 (18:09 +0200)
mech_eap/util_radius.cpp
mech_eap/util_radius.h
mech_eap/util_saml.cpp

index 8769650..5543973 100644 (file)
@@ -134,7 +134,7 @@ alreadyAddedAttributeP(std::vector <std::string> &attrs, VALUE_PAIR *vp)
 }
 
 static bool
-isSecretAttributeP(int attrid, int vendor)
+isHiddenAttributeP(int attrid, int vendor)
 {
     bool ret = false;
 
@@ -148,6 +148,9 @@ isSecretAttributeP(int attrid, int vendor)
         default:
             break;
         }
+    case RADIUS_VENDOR_ID_GSS_EAP:
+        ret = true;
+        break;
     default:
         break;
     }
@@ -164,7 +167,7 @@ gss_eap_radius_attr_provider::getAttributeTypes(gss_eap_attr_enumeration_cb addA
     for (vp = m_avps; vp != NULL; vp = vp->next) {
         gss_buffer_desc attribute;
 
-        if (isSecretAttributeP(ATTRID(vp->attribute), VENDOR(vp->attribute)))
+        if (isHiddenAttributeP(ATTRID(vp->attribute), VENDOR(vp->attribute)))
             continue;
 
         if (alreadyAddedAttributeP(seen, vp))
@@ -261,8 +264,7 @@ gss_eap_radius_attr_provider::getAttribute(int attrid,
 {
     OM_uint32 tmpMinor;
     VALUE_PAIR *vp;
-    int i = *more;
-    int max = 0;
+    int i = *more, count = 0;
     char name[NAME_LENGTH + 1];
     char displayString[AUTH_STRING_LEN + 1];
     gss_buffer_desc valueBuf = GSS_C_EMPTY_BUFFER;
@@ -270,24 +272,23 @@ gss_eap_radius_attr_provider::getAttribute(int attrid,
 
     *more = 0;
 
-    if (isSecretAttributeP(attrid, vendor))
-        return false;
-
-    vp = rc_avpair_get(m_avps, attrid, vendor);
-    if (vp == NULL)
+    if (isHiddenAttributeP(attrid, vendor))
         return false;
 
     if (i == -1)
         i = 0;
 
-    do {
-        if (i == max)
+    for (vp = rc_avpair_get(m_avps, attrid, vendor);
+         vp != NULL;
+         vp = rc_avpair_get(vp->next, attrid, vendor)) {
+        if (count++ == i) {
+            if (rc_avpair_get(vp->next, attrid, vendor) != NULL)
+                *more = count;
             break;
+        }
+    }
 
-        max++;
-    } while ((vp = rc_avpair_get(vp->next, attrid, vendor)) != NULL);
-
-    if (i > max)
+    if (vp == NULL && *more == 0)
         return false;
 
     if (vp->type == PW_TYPE_STRING) {
@@ -320,13 +321,29 @@ gss_eap_radius_attr_provider::getAttribute(int attrid,
     if (complete != NULL)
         *complete = true;
 
-    if (max > i)
-        *more = i;
-
     return true;
 }
 
 bool
+gss_eap_radius_attr_provider::getFragmentedAttribute(int attribute,
+                                                     int vendor,
+                                                     int *authenticated,
+                                                     int *complete,
+                                                     gss_buffer_t value) const
+{
+    OM_uint32 major, minor;
+
+    major = getBufferFromAvps(&minor, m_avps, attribute, vendor, value, TRUE);
+
+    if (authenticated != NULL)
+        *authenticated = m_authenticated;
+    if (complete != NULL)
+        *complete = true;
+
+    return !GSS_ERROR(major);
+}
+
+bool
 gss_eap_radius_attr_provider::getAttribute(int attrid,
                                            int *authenticated,
                                            int *complete,
index 4c10291..6829db0 100644 (file)
@@ -80,6 +80,12 @@ public:
                       gss_buffer_t display_value,
                       int *more) const;
 
+    bool getFragmentedAttribute(int attribute,
+                                int vendor,
+                                int *authenticated,
+                                int *complete,
+                                gss_buffer_t value) const;
+
     bool authenticated() const { return m_authenticated; }
 
     static bool init();
@@ -100,8 +106,6 @@ private:
 };
 
 /* For now */
-#define PW_SAML_ASSERTION           1936
-
 extern "C" {
 #endif
 
@@ -143,7 +147,9 @@ enum { RADIUS_VENDOR_ATTR_MS_MPPE_SEND_KEY = 16,
 
 enum { RADIUS_VENDOR_ATTR_GSS_EAP_ACCEPTOR_SERVICE_NAME = 1,
        RADIUS_VENDOR_ATTR_GSS_EAP_ACCEPTOR_HOST_NAME,
-       RADIUS_VENDOR_ATTR_GSS_EAP_ACCEPTOR_REALM_NAME };
+       RADIUS_VENDOR_ATTR_GSS_EAP_ACCEPTOR_REALM_NAME,
+       RADIUS_VENDOR_ATTR_GSS_EAP_SAML_AAA_ASSERTION
+};
 
 #ifdef __cplusplus
 }
index 0d4d893..ce704de 100644 (file)
@@ -88,7 +88,7 @@ gss_eap_saml_assertion_provider::initFromGssContext(const gss_eap_attr_ctx *mana
 {
     const gss_eap_radius_attr_provider *radius;
     gss_buffer_desc value = GSS_C_EMPTY_BUFFER;
-    int authenticated, complete, more = -1;
+    int authenticated, complete;
     OM_uint32 minor;
 
     assert(m_assertion == NULL);
@@ -99,8 +99,9 @@ gss_eap_saml_assertion_provider::initFromGssContext(const gss_eap_attr_ctx *mana
     radius = static_cast<const gss_eap_radius_attr_provider *>
         (m_manager->getProvider(ATTR_TYPE_RADIUS));
     if (radius != NULL &&
-        radius->getAttribute(PW_SAML_ASSERTION, &authenticated, &complete,
-                             &value, NULL, &more)) {
+        radius->getFragmentedAttribute(RADIUS_VENDOR_ATTR_GSS_EAP_SAML_AAA_ASSERTION,
+                                       RADIUS_VENDOR_ID_GSS_EAP,
+                                       &authenticated, &complete, &value)) {
         setAssertion(&value, authenticated);
         gss_release_buffer(&minor, &value);
     } else {
@@ -118,7 +119,11 @@ gss_eap_saml_assertion_provider::setAssertion(const saml2::Assertion *assertion,
     delete m_assertion;
 
     if (assertion != NULL) {
+#if 0
         m_assertion = dynamic_cast<saml2::Assertion *>(assertion->clone());
+#else
+        m_assertion = (saml2::Assertion *)((void *)assertion->clone());
+#endif
         m_authenticated = authenticated;
     } else {
         m_assertion = NULL;
@@ -145,9 +150,16 @@ gss_eap_saml_assertion_provider::parseAssertion(const gss_buffer_t buffer)
     const XMLObjectBuilder *b;
 
     doc = XMLToolingConfig::getConfig().getParser().parse(istream);
+    if (doc == NULL)
+        return NULL;
+
     b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
 
+#if 0
     return dynamic_cast<saml2::Assertion *>(b->buildFromDocument(doc));
+#else
+    return (saml2::Assertion *)((void *)b->buildFromDocument(doc));
+#endif
 }
 
 bool
@@ -210,7 +222,7 @@ gss_eap_saml_assertion_provider::getAttribute(const gss_buffer_t attr,
 {
     string str;
 
-    if (attr != GSS_C_NO_BUFFER || attr->length != 0)
+    if (attr != GSS_C_NO_BUFFER && attr->length != 0)
         return false;
 
     if (m_assertion == NULL)
@@ -370,11 +382,11 @@ gss_eap_saml_attr_provider::getAttributeTypes(gss_eap_attr_enumeration_cb addAtt
         XMLCh space[2] = { ' ', 0 };
         gss_buffer_desc utf8;
 
-        qualifiedName = new XMLCh[XMLString::stringLen(attributeName) + 1 +
-                                  XMLString::stringLen(attributeNameFormat) + 1];
-        XMLString::copyString(qualifiedName, attributeName);
+        qualifiedName = new XMLCh[XMLString::stringLen(attributeNameFormat) + 1 +
+                                  XMLString::stringLen(attributeName) + 1];
+        XMLString::copyString(qualifiedName, attributeNameFormat);
         XMLString::catString(qualifiedName, space);
-        XMLString::catString(qualifiedName, attributeNameFormat);
+        XMLString::catString(qualifiedName, attributeName);
 
         utf8.value = (void *)toUTF8(qualifiedName);
         utf8.length = strlen((char *)utf8.value);
@@ -493,8 +505,11 @@ gss_eap_saml_attr_provider::getAttribute(const gss_buffer_t attr,
         i = 0;
     else if (i >= nvalues)
         return false;
-    av = dynamic_cast<const saml2::AttributeValue *>(a->getAttributeValues().at(i)
-);
+#if 0
+    av = dynamic_cast<const saml2::AttributeValue *>(a->getAttributeValues().at(i));
+#else
+    av = (const saml2::AttributeValue *)((void *)(a->getAttributeValues().at(i)));
+#endif
     if (av != NULL) {
         if (value != NULL) {
             value->value = toUTF8(av->getTextContent(), true);