cleanup and plugin attr context creation
authorLuke Howard <lukeh@padl.com>
Sun, 19 Sep 2010 20:42:06 +0000 (22:42 +0200)
committerLuke Howard <lukeh@padl.com>
Sun, 19 Sep 2010 20:42:06 +0000 (22:42 +0200)
mech_eap/accept_sec_context.c
mech_eap/export_sec_context.c
mech_eap/import_sec_context.c
mech_eap/util_attr.cpp
mech_eap/util_name.c
mech_eap/util_radius.cpp
mech_eap/util_radius.h
mech_eap/util_saml.cpp
mech_eap/util_saml.h
mech_eap/util_shib.cpp
mech_eap/util_shib.h

index ecd5e1c..6353eea 100644 (file)
@@ -209,13 +209,17 @@ serverGetEapUser(void *ctx,
     /*
      * OK, obviously there is no real security here, this is simply
      * for testing the token exchange; this code will be completely
-     * replaced with libradsec once that library is available.
+     * replaced with libradius once that library is available.
      */
     user->methods[0].vendor = EAP_VENDOR_IETF;
     user->methods[0].method = EAP_TYPE_MSCHAPV2;
     user->password = (unsigned char *)strdup(" ");
     user->password_len = 1;
 
+    gssCtx->initiatorName->attrCtx = gssEapCreateAttrContext(NULL, gssCtx);
+    if (gssCtx->initiatorName->attrCtx != NULL)
+        gssCtx->initiatorName->flags |= NAME_FLAG_COMPOSITE;
+
     return 0;
 }
 
index 54e5781..50d4f5c 100644 (file)
@@ -41,7 +41,7 @@ gssEapExportPartialContext(OM_uint32 *minor,
     token->value = NULL;
 
     /*
-     * The format of this token awaits definition by libradsec.
+     * The format of this token awaits definition by libradius.
      */
     return GSS_S_COMPLETE;
 }
@@ -159,6 +159,9 @@ gss_export_sec_context(OM_uint32 *minor,
     OM_uint32 major, tmpMinor;
     gss_ctx_id_t ctx = *context_handle;
 
+    interprocess_token->length = 0;
+    interprocess_token->value = NULL;
+
     if (ctx == GSS_C_NO_CONTEXT)
         return GSS_S_NO_CONTEXT;
 
index 6ef32b8..28962fb 100644 (file)
@@ -264,7 +264,9 @@ gssEapImportContext(OM_uint32 *minor,
             return major;
     }
 
+#ifdef GSSEAP_DEBUG
     assert(remain == 0);
+#endif
 
     *minor = 0;
     major = GSS_S_COMPLETE;
index 90f8d2b..44e1505 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "gssapiP_eap.h"
 
+#include <typeinfo>
 #include <string>
 #include <exception>
 #include <new>
@@ -390,8 +391,20 @@ gss_eap_attr_ctx::getExpiryTime(void) const
 static OM_uint32
 mapException(OM_uint32 *minor, std::exception &e)
 {
-    *minor = 0;
-    return GSS_S_FAILURE;
+    OM_uint32 major = GSS_S_FAILURE;
+
+    /* XXX TODO implement other mappings */
+    if (typeid(e) == typeid(std::bad_alloc))
+        *minor = ENOMEM;
+    else
+        *minor = 0;
+
+#ifdef GSSEAP_DEBUG
+    /* rethrow for now for debugging */
+    throw e;
+#endif
+
+    return major;
 }
 
 void
@@ -592,8 +605,6 @@ gssEapExportAttrContext(OM_uint32 *minor,
 
     try {
         name->attrCtx->exportToBuffer(buffer);
-        if (buffer->length == 0)
-            return GSS_S_FAILURE;
     } catch (std::exception &e) {
         return mapException(minor, e);
     }
@@ -661,6 +672,9 @@ gssEapMapNameToAny(OM_uint32 *minor,
                    gss_buffer_t type_id,
                    gss_any_t *output)
 {
+    if (name->attrCtx == NULL)
+        return GSS_S_UNAVAILABLE;
+
     try {
         *output = name->attrCtx->mapToAny(authenticated, type_id);
     } catch (std::exception &e) {
index 2c25832..50ff1ec 100644 (file)
@@ -148,7 +148,7 @@ importServiceName(OM_uint32 *minor,
                   const gss_buffer_t nameBuffer,
                   gss_name_t *pName)
 {
-    OM_uint32 major, tmpMinor;
+    OM_uint32 major;
     krb5_context krbContext;
     krb5_principal krbPrinc;
     char *service, *host;
@@ -187,7 +187,7 @@ importUserName(OM_uint32 *minor,
                const gss_buffer_t nameBuffer,
                gss_name_t *pName)
 {
-    OM_uint32 major, tmpMinor;
+    OM_uint32 major;
     krb5_context krbContext;
     krb5_principal krbPrinc;
     char *nameString;
@@ -369,7 +369,7 @@ gssEapExportNameInternal(OM_uint32 *minor,
     OM_uint32 major = GSS_S_FAILURE, tmpMinor;
     krb5_context krbContext;
     char *krbName = NULL;
-    size_t krbNameLen;
+    size_t krbNameLen, exportedNameLen;
     unsigned char *p;
     gss_buffer_desc attrs = GSS_C_EMPTY_BUFFER;
 
@@ -386,24 +386,26 @@ gssEapExportNameInternal(OM_uint32 *minor,
     }
     krbNameLen = strlen(krbName);
 
-    exportedName->length = 0;
+    exportedNameLen = 0;
     if (flags & EXPORT_NAME_FLAG_OID) {
-        exportedName->length += 6 + GSS_EAP_MECHANISM->length;
+        exportedNameLen += 6 + GSS_EAP_MECHANISM->length;
     }
-    exportedName->length += 4 + krbNameLen;
+    exportedNameLen += 4 + krbNameLen;
     if (flags & EXPORT_NAME_FLAG_COMPOSITE) {
         major = gssEapExportAttrContext(minor, name, &attrs);
         if (GSS_ERROR(major))
             goto cleanup;
-        exportedName->length += 4 + attrs.length;
+        exportedNameLen += 4 + attrs.length;
     }
 
-    exportedName->value = GSSEAP_MALLOC(exportedName->length);
+    exportedName->value = GSSEAP_MALLOC(exportedNameLen);
     if (exportedName->value == NULL) {
         major = GSS_S_FAILURE;
         *minor = ENOMEM;
         goto cleanup;
     }
+    exportedName->length = exportedNameLen;
+
     p = (unsigned char *)exportedName->value;
 
     if (flags & EXPORT_NAME_FLAG_OID) {
index 6eed537..c3d07ab 100644 (file)
 
 #include "gssapiP_eap.h"
 
+gss_eap_radius_attr_provider::gss_eap_radius_attr_provider(void)
+{
+    m_authenticated = false;
+}
+
+gss_eap_radius_attr_provider::~gss_eap_radius_attr_provider(void)
+{
+}
+
 bool
 gss_eap_radius_attr_provider::initFromExistingContext(const gss_eap_attr_ctx *manager,
                                                       const gss_eap_attr_provider *ctx)
@@ -53,10 +62,6 @@ gss_eap_radius_attr_provider::initFromGssContext(const gss_eap_attr_ctx *manager
     return true;
 }
 
-gss_eap_radius_attr_provider::~gss_eap_radius_attr_provider(void)
-{
-}
-
 bool
 gss_eap_radius_attr_provider::getAttributeTypes(gss_eap_attr_enumeration_cb addAttribute, void *data) const
 {
@@ -113,6 +118,8 @@ gss_eap_radius_attr_provider::releaseAnyNameMapping(gss_buffer_t type_id,
 void
 gss_eap_radius_attr_provider::exportToBuffer(gss_buffer_t buffer) const
 {
+    buffer->length = 0;
+    buffer->value = NULL;
 }
 
 bool
@@ -122,7 +129,7 @@ gss_eap_radius_attr_provider::initFromBuffer(const gss_eap_attr_ctx *ctx,
     if (!gss_eap_attr_provider::initFromBuffer(ctx, buffer))
         return false;
 
-    return false;
+    return true;
 }
 
 bool
index fff01b4..5ce34fd 100644 (file)
@@ -35,7 +35,7 @@
 
 struct gss_eap_radius_attr_provider : gss_eap_attr_provider {
 public:
-    gss_eap_radius_attr_provider(void) {}
+    gss_eap_radius_attr_provider(void);
     ~gss_eap_radius_attr_provider(void);
 
     bool initFromExistingContext(const gss_eap_attr_ctx *source,
index 5879709..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)
@@ -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)
@@ -317,11 +323,6 @@ gss_eap_saml_attr_provider::getAssertion(int *authenticated,
     return (saml->getAssertion() != NULL);
 }
 
-gss_eap_saml_attr_provider::~gss_eap_saml_attr_provider(void)
-{
-    /* Nothing to do, we're just a wrapper around the assertion provider. */
-}
-
 bool
 gss_eap_saml_attr_provider::getAttributeTypes(gss_eap_attr_enumeration_cb addAttribute,
                                               void *data) const
index 73e64e5..fa8e9e8 100644 (file)
@@ -43,7 +43,7 @@ namespace opensaml {
 
 struct gss_eap_saml_assertion_provider : gss_eap_attr_provider {
 public:
-    gss_eap_saml_assertion_provider(void) {}
+    gss_eap_saml_assertion_provider(void);
     ~gss_eap_saml_assertion_provider(void);
 
     bool initFromExistingContext(const gss_eap_attr_ctx *source,
@@ -102,7 +102,7 @@ private:
 struct gss_eap_saml_attr_provider : gss_eap_attr_provider {
 public:
     gss_eap_saml_attr_provider(void) {}
-    ~gss_eap_saml_attr_provider(void);
+    ~gss_eap_saml_attr_provider(void) {}
 
     bool getAttributeTypes(gss_eap_attr_enumeration_cb, void *data) const;
     void setAttribute(int complete,
index 8a26b1b..9f46ead 100644 (file)
@@ -76,6 +76,19 @@ using namespace xmltooling;
 using namespace xercesc;
 using namespace std;
 
+gss_eap_shib_attr_provider::gss_eap_shib_attr_provider(void)
+{
+    m_authenticated = false;
+}
+
+gss_eap_shib_attr_provider::~gss_eap_shib_attr_provider(void)
+{
+    for_each(m_attributes.begin(),
+             m_attributes.end(),
+             xmltooling::cleanup<Attribute>())
+        ;
+}
+
 bool
 gss_eap_shib_attr_provider::initFromExistingContext(const gss_eap_attr_ctx *manager,
                                                     const gss_eap_attr_provider *ctx)
@@ -189,14 +202,6 @@ gss_eap_shib_attr_provider::initFromGssContext(const gss_eap_attr_ctx *manager,
     return true;
 }
 
-gss_eap_shib_attr_provider::~gss_eap_shib_attr_provider(void)
-{
-    for_each(m_attributes.begin(),
-             m_attributes.end(),
-             xmltooling::cleanup<Attribute>())
-        ;
-}
-
 int
 gss_eap_shib_attr_provider::getAttributeIndex(const gss_buffer_t attr) const
 {
index b575463..2f30228 100644 (file)
@@ -45,7 +45,7 @@ namespace shibresolver {
 
 struct gss_eap_shib_attr_provider : gss_eap_attr_provider {
 public:
-    gss_eap_shib_attr_provider(void) {}
+    gss_eap_shib_attr_provider(void);
     ~gss_eap_shib_attr_provider(void);
 
     bool initFromExistingContext(const gss_eap_attr_ctx *source,