Merge branch 'master' of ssh://moonshot.suchdamage.org:822/srv/git/moonshot
[mech_eap.orig] / util_radius.cpp
index 6ab819e..770579c 100644 (file)
  * SUCH DAMAGE.
  */
 
+/*
+ * RADIUS attribute provider implementation.
+ */
+
 #include "gssapiP_eap.h"
 
 /* stuff that should be provided by libradsec/libfreeradius-radius */
@@ -142,7 +146,7 @@ isSecretAttributeP(uint32_t attribute)
 }
 
 static bool
-isHiddenAttributeP(uint16_t attrid, uint16_t vendor)
+isInternalAttributeP(uint16_t attrid, uint16_t vendor)
 {
     bool ret = false;
 
@@ -161,9 +165,9 @@ isHiddenAttributeP(uint16_t attrid, uint16_t vendor)
 }
 
 static bool
-isHiddenAttributeP(uint32_t attribute)
+isInternalAttributeP(uint32_t attribute)
 {
-    return isHiddenAttributeP(ATTRID(attribute), VENDOR(attribute));
+    return isInternalAttributeP(ATTRID(attribute), VENDOR(attribute));
 }
 
 /*
@@ -196,7 +200,8 @@ copyAvps(const VALUE_PAIR *src)
 }
 
 bool
-gss_eap_radius_attr_provider::getAttributeTypes(gss_eap_attr_enumeration_cb addAttribute, void *data) const
+gss_eap_radius_attr_provider::getAttributeTypes(gss_eap_attr_enumeration_cb addAttribute,
+                                                void *data) const
 {
     VALUE_PAIR *vp;
     std::vector <std::string> seen;
@@ -205,7 +210,8 @@ gss_eap_radius_attr_provider::getAttributeTypes(gss_eap_attr_enumeration_cb addA
         gss_buffer_desc attribute;
         char attrid[64];
 
-        if (isHiddenAttributeP(vp->attribute))
+        /* Don't advertise attributes that are internal to the GSS-EAP mechanism */
+        if (isInternalAttributeP(vp->attribute))
             continue;
 
         if (alreadyAddedAttributeP(seen, vp))
@@ -264,7 +270,7 @@ gss_eap_radius_attr_provider::setAttribute(int complete,
     OM_uint32 major = GSS_S_UNAVAILABLE, minor;
 
     if (!isSecretAttributeP(attrid) &&
-        !isHiddenAttributeP(attrid)) {
+        !isInternalAttributeP(attrid)) {
         deleteAttribute(attrid);
 
         major = gssEapRadiusAddAvp(&minor, &m_vps,
@@ -291,11 +297,12 @@ gss_eap_radius_attr_provider::setAttribute(int complete,
 bool
 gss_eap_radius_attr_provider::deleteAttribute(uint32_t attrid)
 {
-    if (isSecretAttributeP(attrid) || isHiddenAttributeP(attrid) ||
+    if (isSecretAttributeP(attrid) || isInternalAttributeP(attrid) ||
         pairfind(m_vps, attrid) == NULL)
         return false;
 
     pairdelete(&m_vps, attrid);
+
     return true;
 }
 
@@ -341,9 +348,6 @@ gss_eap_radius_attr_provider::getAttribute(uint32_t attrid,
 
     *more = 0;
 
-    if (isHiddenAttributeP(attrid))
-        return false;
-
     if (i == -1)
         i = 0;
 
@@ -506,8 +510,12 @@ gssEapRadiusGetRawAvp(OM_uint32 *minor,
     uint32_t attr = VENDORATTR(vendor, attribute);
 
     *vp = pairfind(vps, attr);
+    if (*vp == NULL) {
+        *minor = GSSEAP_NO_SUCH_ATTR;
+        return GSS_S_UNAVAILABLE;
+    }
 
-    return (*vp == NULL) ? GSS_S_UNAVAILABLE : GSS_S_COMPLETE;
+    return GSS_S_COMPLETE;
 }
 
 OM_uint32
@@ -526,8 +534,10 @@ gssEapRadiusGetAvp(OM_uint32 *minor,
     buffer->value = NULL;
 
     vp = pairfind(vps, attr);
-    if (vp == NULL)
+    if (vp == NULL) {
+        *minor = GSSEAP_NO_SUCH_ATTR;
         return GSS_S_UNAVAILABLE;
+    }
 
     do {
         buffer->length += vp->length;