Pass GSS_C_DCE_STYLE to wrap/unwrap
[mech_eap.orig] / util_radius.cpp
index 61b1c9c..ac568a0 100644 (file)
 
 #include "gssapiP_eap.h"
 
+static gss_buffer_desc radiusUrnPrefix = {
+    sizeof("urn:radius:") - 1,
+    (void *)"urn:radius:"
+};
+
 VALUE_PAIR *
 gss_eap_radius_attr_provider::copyAvps(const VALUE_PAIR *src)
 {
@@ -134,20 +139,23 @@ alreadyAddedAttributeP(std::vector <std::string> &attrs, VALUE_PAIR *vp)
 }
 
 static bool
-isSecretAttributeP(int attrid, int vendor)
+isHiddenAttributeP(int attrid, int vendor)
 {
     bool ret = false;
 
     switch (vendor) {
-    case RADIUS_VENDOR_ID_MICROSOFT:
+    case VENDOR_ID_MICROSOFT:
         switch (attrid) {
-        case RADIUS_VENDOR_ATTR_MS_MPPE_SEND_KEY:
-        case RADIUS_VENDOR_ATTR_MS_MPPE_RECV_KEY:
+        case VENDOR_ATTR_MS_MPPE_SEND_KEY:
+        case VENDOR_ATTR_MS_MPPE_RECV_KEY:
             ret = true;
             break;
         default:
             break;
         }
+    case VENDOR_ID_UKERNA:
+        ret = true;
+        break;
     default:
         break;
     }
@@ -163,15 +171,18 @@ gss_eap_radius_attr_provider::getAttributeTypes(gss_eap_attr_enumeration_cb addA
 
     for (vp = m_avps; vp != NULL; vp = vp->next) {
         gss_buffer_desc attribute;
-
-        if (isSecretAttributeP(ATTRID(vp->attribute), VENDOR(vp->attribute)))
+        char attrid[64];
+        if (isHiddenAttributeP(ATTRID(vp->attribute), VENDOR(vp->attribute)))
             continue;
 
         if (alreadyAddedAttributeP(seen, vp))
             continue;
 
-        attribute.value = (void *)vp->name;
-        attribute.length = strlen(vp->name);
+        snprintf(attrid, sizeof(attrid), "%s%d",
+            (char *)radiusUrnPrefix.value, vp->attribute);
+
+        attribute.value = attrid;
+        attribute.length = strlen(attrid);
 
         if (!addAttribute(this, &attribute, data))
             return false;
@@ -209,11 +220,16 @@ gss_eap_radius_attr_provider::getAttribute(const gss_buffer_t attr,
     char *s;
 
     /* XXX vendor */
-
     duplicateBuffer(*attr, &strAttr);
     s = (char *)strAttr.value;
 
-    if (isdigit(((char *)strAttr.value)[0])) {
+    if (attr->length < radiusUrnPrefix.length ||
+        memcmp(s, radiusUrnPrefix.value, radiusUrnPrefix.length) != 0)
+        return false;
+
+    s += radiusUrnPrefix.length;
+
+    if (isdigit(*s)) {
         attrid = strtoul(s, NULL, 10);
     } else {
         d = rc_dict_findattr(m_rh, (char *)s);
@@ -234,10 +250,17 @@ static bool
 isPrintableAttributeP(VALUE_PAIR *vp)
 {
     size_t i;
+    int gotChar = 0;
 
     for (i = 0; i < sizeof(vp->strvalue); i++) {
+        if (gotChar && vp->strvalue[i] == '\0')
+            return true;
+
         if (!isprint(vp->strvalue[i]))
             return false;
+
+        if (!gotChar)
+            gotChar++;
     }
 
     return true;
@@ -254,8 +277,7 @@ gss_eap_radius_attr_provider::getAttribute(int attrid,
 {
     OM_uint32 tmpMinor;
     VALUE_PAIR *vp;
-    int i = *more;
-    int max = 0;
+    int i = *more, count = 0;
     char name[NAME_LENGTH + 1];
     char displayString[AUTH_STRING_LEN + 1];
     gss_buffer_desc valueBuf = GSS_C_EMPTY_BUFFER;
@@ -263,24 +285,23 @@ gss_eap_radius_attr_provider::getAttribute(int attrid,
 
     *more = 0;
 
-    if (isSecretAttributeP(attrid, vendor))
-        return false;
-
-    vp = rc_avpair_get(m_avps, attrid, vendor);
-    if (vp == NULL)
+    if (isHiddenAttributeP(attrid, vendor))
         return false;
 
     if (i == -1)
         i = 0;
 
-    do {
-        if (i == max)
+    for (vp = rc_avpair_get(m_avps, attrid, vendor);
+         vp != NULL;
+         vp = rc_avpair_get(vp->next, attrid, vendor)) {
+        if (count++ == i) {
+            if (rc_avpair_get(vp->next, attrid, vendor) != NULL)
+                *more = count;
             break;
+        }
+    }
 
-        max++;
-    } while ((vp = rc_avpair_get(vp->next, attrid, vendor)) != NULL);
-
-    if (i > max)
+    if (vp == NULL && *more == 0)
         return false;
 
     if (vp->type == PW_TYPE_STRING) {
@@ -313,13 +334,29 @@ gss_eap_radius_attr_provider::getAttribute(int attrid,
     if (complete != NULL)
         *complete = true;
 
-    if (max > i)
-        *more = i;
-
     return true;
 }
 
 bool
+gss_eap_radius_attr_provider::getFragmentedAttribute(int attribute,
+                                                     int vendor,
+                                                     int *authenticated,
+                                                     int *complete,
+                                                     gss_buffer_t value) const
+{
+    OM_uint32 major, minor;
+
+    major = getBufferFromAvps(&minor, m_avps, attribute, vendor, value, TRUE);
+
+    if (authenticated != NULL)
+        *authenticated = m_authenticated;
+    if (complete != NULL)
+        *complete = true;
+
+    return !GSS_ERROR(major);
+}
+
+bool
 gss_eap_radius_attr_provider::getAttribute(int attrid,
                                            int *authenticated,
                                            int *complete,
@@ -376,9 +413,11 @@ addAvpFromBuffer(OM_uint32 *minor,
                  rc_handle *rh,
                  VALUE_PAIR **vp,
                  int type,
+                 int vendor,
                  gss_buffer_t buffer)
 {
-    if (rc_avpair_add(rh, vp, type, buffer->value, buffer->length, 0) == NULL) {
+    if (rc_avpair_add(rh, vp, type,
+                      buffer->value, buffer->length, vendor) == NULL) {
         return GSS_S_FAILURE;
     }
 
@@ -389,6 +428,7 @@ OM_uint32
 getBufferFromAvps(OM_uint32 *minor,
                   VALUE_PAIR *vps,
                   int type,
+                  int vendor,
                   gss_buffer_t buffer,
                   int concat)
 {
@@ -398,13 +438,13 @@ getBufferFromAvps(OM_uint32 *minor,
     buffer->length = 0;
     buffer->value = NULL;
 
-    vp = rc_avpair_get(vps, type, 0);
+    vp = rc_avpair_get(vps, type, vendor);
     if (vp == NULL)
         return GSS_S_UNAVAILABLE;
 
     do {
         buffer->length += vp->lvalue;
-    } while (concat && (vp = rc_avpair_get(vp->next, type, 0)) != NULL);
+    } while (concat && (vp = rc_avpair_get(vp->next, type, vendor)) != NULL);
 
     buffer->value = GSSEAP_MALLOC(buffer->length);
     if (buffer->value == NULL) {
@@ -414,9 +454,9 @@ getBufferFromAvps(OM_uint32 *minor,
 
     p = (unsigned char *)buffer->value;
 
-    for (vp = rc_avpair_get(vps, type, 0);
+    for (vp = rc_avpair_get(vps, type, vendor);
          concat && vp != NULL;
-         vp = rc_avpair_get(vp->next, type, 0)) {
+         vp = rc_avpair_get(vp->next, type, vendor)) {
         memcpy(p, vp->strvalue, vp->lvalue);
         p += vp->lvalue;
     }
@@ -624,3 +664,15 @@ gss_eap_radius_attr_provider::exportToBuffer(gss_buffer_t buffer) const
 
     assert(remain == 0);
 }
+
+time_t
+gss_eap_radius_attr_provider::getExpiryTime(void) const
+{
+    VALUE_PAIR *vp;
+
+    vp = rc_avpair_get(m_avps, PW_SESSION_TIMEOUT, 0);
+    if (vp == NULL || vp->lvalue == 0)
+        return 0;
+
+    return time(NULL) + vp->lvalue;
+}