Fixes for Heimdal (macOS) builds from Stefan.
[mech_eap.git] / mech_eap / util_saml.cpp
index 494aeb9..71ad9bd 100644 (file)
@@ -46,6 +46,7 @@
 #include <xmltooling/util/DateTime.h>
 
 #include <saml/exceptions.h>
+#include <saml/SAMLConfig.h>
 #include <saml/saml1/core/Assertions.h>
 #include <saml/saml2/core/Assertions.h>
 #include <saml/saml2/metadata/Metadata.h>
@@ -82,7 +83,7 @@ gss_eap_saml_assertion_provider::initWithExistingContext(const gss_eap_attr_ctx
     /* Then we may be creating from an existing attribute context */
     const gss_eap_saml_assertion_provider *saml;
 
-    assert(m_assertion == NULL);
+    GSSEAP_ASSERT(m_assertion == NULL);
 
     if (!gss_eap_attr_provider::initWithExistingContext(manager, ctx))
         return false;
@@ -102,8 +103,9 @@ gss_eap_saml_assertion_provider::initWithGssContext(const gss_eap_attr_ctx *mana
     gss_buffer_desc value = GSS_C_EMPTY_BUFFER;
     int authenticated, complete;
     OM_uint32 minor;
+    gss_eap_attrid attrid(VENDORPEC_UKERNA, PW_SAML_AAA_ASSERTION);
 
-    assert(m_assertion == NULL);
+    GSSEAP_ASSERT(m_assertion == NULL);
 
     if (!gss_eap_attr_provider::initWithGssContext(manager, gssCred, gssCtx))
         return false;
@@ -114,9 +116,7 @@ gss_eap_saml_assertion_provider::initWithGssContext(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->getFragmentedAttribute(PW_SAML_AAA_ASSERTION,
-                                       VENDORPEC_UKERNA,
-                                       &authenticated, &complete, &value)) {
+        radius->getFragmentedAttribute(attrid, &authenticated, &complete, &value)) {
         setAssertion(&value, authenticated);
         gss_release_buffer(&minor, &value);
     } else {
@@ -316,14 +316,23 @@ gss_eap_saml_assertion_provider::releaseAnyNameMapping(gss_buffer_t type_id GSSE
 const char *
 gss_eap_saml_assertion_provider::prefix(void) const
 {
-    return "urn:ietf:params:gss-eap:saml-aaa-assertion";
+    return "urn:ietf:params:gss:federated-saml-assertion";
 }
 
 bool
 gss_eap_saml_assertion_provider::init(void)
 {
-    gss_eap_attr_ctx::registerProvider(ATTR_TYPE_SAML_ASSERTION, createAttrContext);
-    return true;
+    bool ret = false;
+
+    try {
+        ret = SAMLConfig::getConfig().init();
+    } catch (exception &e) {
+    }
+
+    if (ret)
+        gss_eap_attr_ctx::registerProvider(ATTR_TYPE_SAML_ASSERTION, createAttrContext);
+
+    return ret;
 }
 
 void
@@ -363,7 +372,7 @@ gss_eap_saml_attr_provider::getAssertion(int *authenticated,
     if (pAssertion != NULL)
         *pAssertion = NULL;
 
-    saml = static_cast<const gss_eap_saml_assertion_provider *>
+    saml = static_cast<gss_eap_saml_assertion_provider *>
         (m_manager->getProvider(ATTR_TYPE_SAML_ASSERTION));
     if (saml == NULL)
         return false;
@@ -404,7 +413,7 @@ gss_eap_saml_attr_provider::getAttributeTypes(gss_eap_attr_enumeration_cb addAtt
      *   Each attribute carried in the assertion SHOULD also be a GSS name
      *   attribute.  The name of this attribute has three parts, all separated
      *   by an ASCII space character.  The first part is
-     *   urn:ietf:params:gss-eap:saml-attr.  The second part is the URI for
+     *   urn:ietf:params:gss:federated-saml-attribute.  The second part is the URI for
      *   the SAML attribute name format.  The final part is the name of the
      *   SAML attribute.  If the mechanism performs an additional attribute
      *   query, the retrieved attributes SHOULD be GSS-API name attributes
@@ -499,7 +508,7 @@ gss_eap_saml_attr_provider::setAttribute(int complete GSSEAP_UNUSED,
 
     attribute->getAttributeValues().push_back(attributeValue);
 
-    assert(attributeStatement != NULL);
+    GSSEAP_ASSERT(attributeStatement != NULL);
     attributeStatement->getAttributes().push_back(attribute);
 
     delete components;
@@ -694,7 +703,7 @@ gss_eap_saml_attr_provider::getAttribute(const gss_buffer_t attr,
         }
         if (display_value != NULL && base64Encoded == false) {
             display_value->value = toUTF8(av->getTextContent(), true);
-            display_value->length = strlen((char *)value->value);
+            display_value->length = strlen((char *)display_value->value);
         }
     }
 
@@ -720,7 +729,7 @@ gss_eap_saml_attr_provider::releaseAnyNameMapping(gss_buffer_t type_id GSSEAP_UN
 const char *
 gss_eap_saml_attr_provider::prefix(void) const
 {
-    return "urn:ietf:params:gss-eap:saml-attr";
+    return "urn:ietf:params:gss:federated-saml-attribute";
 }
 
 bool