send a composite name token instead of a sec context to shib
[mech_eap.orig] / util_radius.cpp
index 09f4559..5462acc 100644 (file)
@@ -63,12 +63,12 @@ gss_eap_radius_attr_provider::~gss_eap_radius_attr_provider(void)
 }
 
 bool
-gss_eap_radius_attr_provider::initFromExistingContext(const gss_eap_attr_ctx *manager,
+gss_eap_radius_attr_provider::initWithExistingContext(const gss_eap_attr_ctx *manager,
                                                       const gss_eap_attr_provider *ctx)
 {
     const gss_eap_radius_attr_provider *radius;
 
-    if (!gss_eap_attr_provider::initFromExistingContext(manager, ctx))
+    if (!gss_eap_attr_provider::initWithExistingContext(manager, ctx))
         return false;
 
     radius = static_cast<const gss_eap_radius_attr_provider *>(ctx);
@@ -82,11 +82,11 @@ gss_eap_radius_attr_provider::initFromExistingContext(const gss_eap_attr_ctx *ma
 }
 
 bool
-gss_eap_radius_attr_provider::initFromGssContext(const gss_eap_attr_ctx *manager,
+gss_eap_radius_attr_provider::initWithGssContext(const gss_eap_attr_ctx *manager,
                                                  const gss_cred_id_t gssCred,
                                                  const gss_ctx_id_t gssCtx)
 {
-    if (!gss_eap_attr_provider::initFromGssContext(manager, gssCred, gssCtx))
+    if (!gss_eap_attr_provider::initWithGssContext(manager, gssCred, gssCtx))
         return false;
 
     if (gssCtx != GSS_C_NO_CONTEXT) {
@@ -190,7 +190,6 @@ copyAvps(const VALUE_PAIR *src)
         if (vpcopy == NULL) {
             pairfree(&dst);
             throw std::bad_alloc();
-            return NULL;
         }
         *pDst = vpcopy;
         pDst = &vpcopy->next;
@@ -670,13 +669,12 @@ jsonToAvp(VALUE_PAIR **pVp, JSONObject &obj)
     if (da != NULL) {
         vp = pairalloc(da);
     } else {
-        /* Assume unknown attributes are octet strings */
-        vp = paircreate(attrid, PW_TYPE_OCTETS);
+        int type = base64Valid(value.string()) ?
+            PW_TYPE_OCTETS : PW_TYPE_STRING;
+        vp = paircreate(attrid, type);
     }
-    if (vp == NULL) {
+    if (vp == NULL)
         throw std::bad_alloc();
-        goto fail;
-    }
 
     switch (vp->type) {
     case PW_TYPE_INTEGER:
@@ -708,29 +706,17 @@ jsonToAvp(VALUE_PAIR **pVp, JSONObject &obj)
             goto fail;
 
         const char *str = value.string();
-        size_t stringLen = strlen(str);
+        ssize_t len = strlen(str);
 
         /* this optimization requires base64Decode only understand packed encoding */
-        if (stringLen >= BASE64_EXPAND(MAX_STRING_LEN))
+        if (len >= BASE64_EXPAND(MAX_STRING_LEN))
             goto fail;
 
-        /*
-         * If the attribute is unknown, we don't know its syntax; assume
-         * it is an octet string and, if that fails to decode and will
-         * fit, a string.
-         */
-        size_t valueLen = base64Decode(str, vp->vp_octets);
-        if (valueLen < 0) {
-            if (da == NULL && stringLen < MAX_STRING_LEN) {
-                vp->type = PW_TYPE_STRING;
-                vp->length = stringLen;
-                memcpy(vp->vp_strvalue, str, stringLen + 1);
-            } else
-                goto fail;
-        } else {
-            vp->length = valueLen;
-            vp->vp_octets[valueLen] = '\0';
-        }
+        len = base64Decode(str, vp->vp_octets);
+        if (len < 0)
+            goto fail;
+
+        vp->length = len;
         break;
     }
     }