some cleanup work on marshalling provider
authorLuke Howard <lukeh@padl.com>
Sat, 18 Sep 2010 10:03:14 +0000 (12:03 +0200)
committerLuke Howard <lukeh@padl.com>
Sat, 18 Sep 2010 10:03:14 +0000 (12:03 +0200)
mech_eap/util_attr.cpp
mech_eap/util_attr.h
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 74cf43b..28a9161 100644 (file)
@@ -44,22 +44,15 @@ gss_eap_attr_factories[ATTR_TYPE_MAX] = {
     gss_eap_shib_attr_provider::createAttrContext
 };
 
-gss_eap_attr_ctx *
-gss_eap_attr_ctx::createAttrContext(void)
+gss_eap_attr_ctx::gss_eap_attr_ctx(void)
 {
-    gss_eap_attr_ctx *ctx;
-
-    ctx = new gss_eap_attr_ctx;
-
     for (unsigned int i = 0; i < ATTR_TYPE_MAX; i++) {
         gss_eap_attr_provider *provider;
 
         provider = (gss_eap_attr_factories[i])();
         if (provider != NULL)
-            ctx->m_providers[i] = provider;
+            m_providers[i] = provider;
     }
-
-    return ctx;
 }
 
 bool
@@ -304,22 +297,32 @@ gss_eap_attr_ctx::releaseAnyNameMapping(gss_buffer_t type_id,
 }
 
 void
-gss_eap_attr_ctx::marshall(gss_buffer_t buffer) const
+gss_eap_attr_ctx::exportToBuffer(gss_buffer_t buffer) const
 {
-    /* For now, just marshall the RADIUS context. */
+    m_providers[ATTR_TYPE_RADIUS]->exportToBuffer(buffer);
 }
 
 bool
-gss_eap_attr_ctx::unmarshall(const gss_eap_attr_ctx *ctx,
-                             const gss_buffer_t buffer)
+gss_eap_attr_ctx::initFromBuffer(const gss_eap_attr_ctx *ctx,
+                                 const gss_buffer_t buffer)
 {
     unsigned int i;
+    bool ret;
 
-    for (i = 0; i < ATTR_TYPE_MAX; i++) {
+    ret = m_providers[ATTR_TYPE_RADIUS]->initFromBuffer(this, buffer);
+    if (!ret)
+        return false;
+
+    for (i = ATTR_TYPE_RADIUS + 1; i < ATTR_TYPE_MAX; i++) {
         gss_eap_attr_provider *provider = m_providers[i];
+
+        ret = provider->initFromGssContext(
+            this, GSS_C_NO_CREDENTIAL, GSS_C_NO_CONTEXT);
+        if (!ret)
+            break;
     }
 
-    return false;
+    return ret;
 }
 
 
@@ -574,7 +577,7 @@ gssEapExportAttrContext(OM_uint32 *minor,
     };
 
     try {
-        name->attrCtx->marshall(buffer);
+        name->attrCtx->exportToBuffer(buffer);
     } catch (std::exception &e) {
         return mapException(minor, e);
     }
@@ -587,8 +590,20 @@ gssEapImportAttrContext(OM_uint32 *minor,
                         gss_buffer_t buffer,
                         gss_name_t name)
 {
-    if (buffer->length)
-        GSSEAP_NOT_IMPLEMENTED;
+    if (buffer->length != 0) {
+        gss_eap_attr_ctx *ctx = new gss_eap_attr_ctx;
+
+        try {
+            if (!ctx->initFromBuffer(NULL, buffer)) {
+                delete ctx;
+                return GSS_S_DEFECTIVE_TOKEN;
+            }
+            name->attrCtx = ctx;
+        } catch (std::exception &e) {
+            delete ctx;
+            return mapException(minor, e);
+        }
+    }
 
     return GSS_S_COMPLETE;
 }
@@ -598,19 +613,20 @@ gssEapDuplicateAttrContext(OM_uint32 *minor,
                            gss_name_t in,
                            gss_name_t out)
 {
+    gss_eap_attr_ctx *ctx = NULL;
+
+    assert(out->attrCtx == NULL);
+
     try {
         if (in->attrCtx != NULL) {
-            gss_eap_attr_ctx *ctx = new gss_eap_attr_ctx;
-
-            out->attrCtx = new gss_eap_attr_ctx;
             if (!ctx->initFromExistingContext(NULL, in->attrCtx)) {
                 delete ctx;
                 return GSS_S_FAILURE;
             }
             out->attrCtx = ctx;
-        } else
-            out->attrCtx = NULL;
+        }
     } catch (std::exception &e) {
+        delete ctx;
         return mapException(minor, e);
     }
 
@@ -693,7 +709,7 @@ gssEapCreateAttrContext(gss_cred_id_t gssCred,
 {
     gss_eap_attr_ctx *ctx;
 
-    ctx = gss_eap_attr_ctx::createAttrContext();
+    ctx = new gss_eap_attr_ctx;
     if (!ctx->initFromGssContext(NULL, gssCred, gssCtx)) {
         delete ctx;
         return NULL;
index 43a5c88..6141658 100644 (file)
@@ -92,9 +92,9 @@ public:
     virtual void releaseAnyNameMapping(gss_buffer_t type_id,
                                        gss_any_t input) const {}
 
-    virtual void marshall(gss_buffer_t buffer) const {}
-    virtual bool unmarshall(const gss_eap_attr_ctx *ctx,
-                            const gss_buffer_t buffer) { return false; }
+    virtual void exportToBuffer(gss_buffer_t buffer) const {}
+    virtual bool initFromBuffer(const gss_eap_attr_ctx *ctx,
+                                const gss_buffer_t buffer) { return false; }
 
     static bool init() { return true; }
     static void finalize() {}
@@ -110,7 +110,7 @@ typedef gss_eap_attr_provider *(*gss_eap_attr_create_factory)(void);
 struct gss_eap_attr_ctx : gss_eap_attr_provider
 {
 public:
-    gss_eap_attr_ctx(void) {}
+    gss_eap_attr_ctx(void);
     ~gss_eap_attr_ctx(void);
 
     bool initFromExistingContext(const gss_eap_attr_ctx *source,
@@ -119,8 +119,6 @@ public:
                             const gss_cred_id_t cred,
                             const gss_ctx_id_t ctx);
 
-    static gss_eap_attr_ctx *createAttrContext(void);
-
     bool getAttributeTypes(gss_eap_attr_enumeration_cb, void *data) const;
     bool getAttributeTypes(gss_buffer_set_t *attrs);
 
@@ -139,9 +137,9 @@ public:
     void releaseAnyNameMapping(gss_buffer_t type_id,
                                gss_any_t input) const;
 
-    void marshall(gss_buffer_t buffer) const;
-    bool unmarshall(const gss_eap_attr_ctx *ctx,
-                    const gss_buffer_t buffer);
+    void exportToBuffer(gss_buffer_t buffer) const;
+    bool initFromBuffer(const gss_eap_attr_ctx *ctx,
+                        const gss_buffer_t buffer);
     static bool init();
     static void finalize();
 
index 7fe84a4..1440d4c 100644 (file)
@@ -111,13 +111,13 @@ gss_eap_radius_attr_provider::releaseAnyNameMapping(gss_buffer_t type_id,
 }
 
 void
-gss_eap_radius_attr_provider::marshall(gss_buffer_t buffer) const
+gss_eap_radius_attr_provider::exportToBuffer(gss_buffer_t buffer) const
 {
 }
 
 bool
-gss_eap_radius_attr_provider::unmarshall(const gss_eap_attr_ctx *ctx,
-                                         const gss_buffer_t buffer)
+gss_eap_radius_attr_provider::initFromBuffer(const gss_eap_attr_ctx *ctx,
+                                             const gss_buffer_t buffer)
 {
     return false;
 }
index 8d91a9c..3265fa8 100644 (file)
@@ -60,9 +60,9 @@ public:
     void releaseAnyNameMapping(gss_buffer_t type_id,
                                gss_any_t input) const;
 
-    void marshall(gss_buffer_t buffer) const;
-    bool unmarshall(const gss_eap_attr_ctx *ctx,
-                    const gss_buffer_t buffer);
+    void exportToBuffer(gss_buffer_t buffer) const;
+    bool initFromBuffer(const gss_eap_attr_ctx *ctx,
+                        const gss_buffer_t buffer);
 
     bool getAttribute(unsigned int attribute,
                       int *authenticated,
index 2a9e650..03ccb4e 100644 (file)
@@ -225,7 +225,7 @@ gss_eap_saml_assertion_provider::releaseAnyNameMapping(gss_buffer_t type_id,
 }
 
 void
-gss_eap_saml_assertion_provider::marshall(gss_buffer_t buffer) const
+gss_eap_saml_assertion_provider::exportToBuffer(gss_buffer_t buffer) const
 {
     ostringstream sink;
     string str;
@@ -243,8 +243,8 @@ gss_eap_saml_assertion_provider::marshall(gss_buffer_t buffer) const
 }
 
 bool
-gss_eap_saml_assertion_provider::unmarshall(const gss_eap_attr_ctx *ctx,
-                                            const gss_buffer_t buffer)
+gss_eap_saml_assertion_provider::initFromBuffer(const gss_eap_attr_ctx *ctx,
+                                                const gss_buffer_t buffer)
 {
     assert(m_assertion == NULL);
 
@@ -418,15 +418,15 @@ gss_eap_saml_attr_provider::releaseAnyNameMapping(gss_buffer_t type_id,
 }
 
 void
-gss_eap_saml_attr_provider::marshall(gss_buffer_t buffer) const
+gss_eap_saml_attr_provider::exportToBuffer(gss_buffer_t buffer) const
 {
     buffer->length = 0;
     buffer->value = NULL;
 }
 
 bool
-gss_eap_saml_attr_provider::unmarshall(const gss_eap_attr_ctx *ctx,
-                                       const gss_buffer_t buffer)
+gss_eap_saml_attr_provider::initFromBuffer(const gss_eap_attr_ctx *ctx,
+                                           const gss_buffer_t buffer)
 {
     return true;
 }
index c380803..730ebd4 100644 (file)
@@ -68,9 +68,9 @@ public:
     void releaseAnyNameMapping(gss_buffer_t type_id,
                                gss_any_t input) const;
 
-    void marshall(gss_buffer_t buffer) const;
-    bool unmarshall(const gss_eap_attr_ctx *ctx,
-                    const gss_buffer_t buffer);
+    void exportToBuffer(gss_buffer_t buffer) const;
+    bool initFromBuffer(const gss_eap_attr_ctx *ctx,
+                        const gss_buffer_t buffer);
 
     void setAssertion(const opensaml::saml2::Assertion *assertion);
 
@@ -111,9 +111,9 @@ public:
     void releaseAnyNameMapping(gss_buffer_t type_id,
                                gss_any_t input) const;
 
-    void marshall(gss_buffer_t buffer) const;
-    bool unmarshall(const gss_eap_attr_ctx *ctx,
-                    const gss_buffer_t buffer);
+    void exportToBuffer(gss_buffer_t buffer) const;
+    bool initFromBuffer(const gss_eap_attr_ctx *ctx,
+                        const gss_buffer_t buffer);
 
     const opensaml::saml2::Attribute *
         getAttribute(const gss_buffer_t attr) const;
index 352fbed..596521b 100644 (file)
@@ -338,15 +338,15 @@ gss_eap_shib_attr_provider::releaseAnyNameMapping(gss_buffer_t type_id,
 }
 
 void
-gss_eap_shib_attr_provider::marshall(gss_buffer_t buffer) const
+gss_eap_shib_attr_provider::exportToBuffer(gss_buffer_t buffer) const
 {
     buffer->length = 0;
     buffer->value = NULL;
 }
 
 bool
-gss_eap_shib_attr_provider::unmarshall(const gss_eap_attr_ctx *ctx,
-                                       const gss_buffer_t buffer)
+gss_eap_shib_attr_provider::initFromBuffer(const gss_eap_attr_ctx *ctx,
+                                           const gss_buffer_t buffer)
 {
     return true;
 }
index 0d61fa2..a97bb75 100644 (file)
@@ -70,9 +70,9 @@ public:
     void releaseAnyNameMapping(gss_buffer_t type_id,
                                gss_any_t input) const;
 
-    void marshall(gss_buffer_t buffer) const;
-    bool unmarshall(const gss_eap_attr_ctx *ctx,
-                    const gss_buffer_t buffer);
+    void exportToBuffer(gss_buffer_t buffer) const;
+    bool initFromBuffer(const gss_eap_attr_ctx *ctx,
+                        const gss_buffer_t buffer);
 
 
     static bool init();