careful initializing out parameters in gss_inquire_name
[mech_eap.orig] / util_saml.cpp
index 070014e..0733fa9 100644 (file)
@@ -52,6 +52,17 @@ using namespace std;
  * gss_eap_saml_assertion_provider is for retrieving the underlying
  * assertion.
  */
+gss_eap_saml_assertion_provider::gss_eap_saml_assertion_provider(void)
+{
+    m_assertion = NULL;
+    m_authenticated = false;
+}
+
+gss_eap_saml_assertion_provider::~gss_eap_saml_assertion_provider(void)
+{
+    delete m_assertion;
+}
+
 bool
 gss_eap_saml_assertion_provider::initFromExistingContext(const gss_eap_attr_ctx *manager,
                                                          const gss_eap_attr_provider *ctx)
@@ -88,7 +99,7 @@ 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(512 /* XXX */, &authenticated, &complete,
+        radius->getAttribute(PW_SAML_ASSERTION, &authenticated, &complete,
                              &value, NULL, &more)) {
         setAssertion(&value, authenticated);
         gss_release_buffer(&minor, &value);
@@ -99,11 +110,6 @@ gss_eap_saml_assertion_provider::initFromGssContext(const gss_eap_attr_ctx *mana
     return true;
 }
 
-gss_eap_saml_assertion_provider::~gss_eap_saml_assertion_provider(void)
-{
-    delete m_assertion;
-}
-
 void
 gss_eap_saml_assertion_provider::setAssertion(const saml2::Assertion *assertion,
                                               bool authenticated)
@@ -170,6 +176,23 @@ gss_eap_saml_assertion_provider::deleteAttribute(const gss_buffer_t value)
     m_authenticated = false;
 }
 
+time_t
+gss_eap_saml_assertion_provider::getExpiryTime(void) const
+{
+    saml2::Conditions *conditions;
+    time_t expiryTime = 0;
+
+    if (m_assertion == NULL)
+        return 0;
+
+    conditions = m_assertion->getConditions();
+
+    if (conditions != NULL && conditions->getNotOnOrAfter() != NULL)
+        expiryTime = conditions->getNotOnOrAfter()->getEpoch();
+
+    return expiryTime;
+}
+
 bool
 gss_eap_saml_assertion_provider::getAttribute(const gss_buffer_t attr,
                                               int *authenticated,
@@ -189,8 +212,10 @@ gss_eap_saml_assertion_provider::getAttribute(const gss_buffer_t attr,
     if (*more != -1)
         return false;
 
-    *authenticated = m_authenticated;
-    *complete = false;
+    if (authenticated != NULL)
+        *authenticated = m_authenticated;
+    if (complete != NULL)
+        *complete = true;
 
     XMLHelper::serialize(m_assertion->marshall((DOMDocument *)NULL), str);
 
@@ -280,23 +305,22 @@ gss_eap_saml_attr_provider::getAssertion(int *authenticated,
 {
     const gss_eap_saml_assertion_provider *saml;
 
-    *authenticated = false;
-    *pAssertion = NULL;
+    if (authenticated != NULL)
+        *authenticated = false;
+    if (pAssertion != NULL)
+        *pAssertion = NULL;
 
     saml = static_cast<const gss_eap_saml_assertion_provider *>
         (m_manager->getProvider(ATTR_TYPE_SAML_ASSERTION));
     if (saml == NULL)
         return false;
 
-    *authenticated = saml->authenticated();
-    *pAssertion = saml->getAssertion();
+    if (authenticated != NULL)
+        *authenticated = saml->authenticated();
+    if (pAssertion != NULL)
+        *pAssertion = saml->getAssertion();
 
-    return (*pAssertion != NULL);
-}
-
-gss_eap_saml_attr_provider::~gss_eap_saml_attr_provider(void)
-{
-    /* Nothing to do, we're just a wrapper around the assertion provider. */
+    return (saml->getAssertion() != NULL);
 }
 
 bool
@@ -389,8 +413,10 @@ gss_eap_saml_attr_provider::getAttribute(const gss_buffer_t attr,
 {
     const saml2::Assertion *assertion;
 
-    *authenticated = false;
-    *complete = true;
+    if (authenticated != NULL)
+        *authenticated = false;
+    if (complete != NULL)
+        *complete = true;
     *pAttribute = NULL;
 
     if (!getAssertion(authenticated, &assertion) ||
@@ -460,16 +486,19 @@ gss_eap_saml_attr_provider::getAttribute(const gss_buffer_t attr,
     av = dynamic_cast<const saml2::AttributeValue *>(a->getAttributeValues().at(i)
 );
     if (av != NULL) {
-        value->value = toUTF8(av->getTextContent(), true);
-        value->length = strlen((char *)value->value);
-
-        if (display_value != NULL)
-            duplicateBuffer(*value, display_value);
-
-        if (nvalues > ++i)
-            *more = i;
+        if (value != NULL) {
+            value->value = toUTF8(av->getTextContent(), true);
+            value->length = strlen((char *)value->value);
+        }
+        if (display_value != NULL) {
+            display_value->value = toUTF8(av->getTextContent(), true);
+            display_value->length = strlen((char *)value->value);
+        }
     }
 
+    if (nvalues > ++i)
+        *more = i;
+
     return true;
 }