* SUCH DAMAGE.
*/
+/*
+ * RADIUS attribute provider implementation.
+ */
+
#include "gssapiP_eap.h"
/* stuff that should be provided by libradsec/libfreeradius-radius */
return false;
/* We assume libradsec validated this for us */
- m_authenticated = (pairfind(m_vps, PW_MESSAGE_AUTHENTICATOR) != NULL);
+ assert(pairfind(m_vps, PW_MESSAGE_AUTHENTICATOR) != NULL);
+ m_authenticated = true;
}
}
static bool
isSecretAttributeP(uint16_t attrid, uint16_t vendor)
{
- bool ret = false;
+ bool bSecretAttribute = false;
switch (vendor) {
case VENDORPEC_MS:
switch (attrid) {
case PW_MS_MPPE_SEND_KEY:
case PW_MS_MPPE_RECV_KEY:
- ret = true;
+ bSecretAttribute = true;
break;
default:
break;
break;
}
- return ret;
+ return bSecretAttribute;
}
static bool
}
static bool
-isHiddenAttributeP(uint16_t attrid, uint16_t vendor)
+isInternalAttributeP(uint16_t attrid, uint16_t vendor)
{
- bool ret = false;
+ bool bInternalAttribute = false;
/* should have been filtered */
assert(!isSecretAttributeP(attrid, vendor));
switch (vendor) {
case VENDORPEC_UKERNA:
- ret = true;
+ bInternalAttribute = true;
break;
default:
break;
}
- return ret;
+ return bInternalAttribute;
}
static bool
-isHiddenAttributeP(uint32_t attribute)
+isInternalAttributeP(uint32_t attribute)
{
- return isHiddenAttributeP(ATTRID(attribute), VENDOR(attribute));
+ return isInternalAttributeP(ATTRID(attribute), VENDOR(attribute));
}
/*
}
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;
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))
return true;
}
-void
+uint32_t
+getAttributeId(const gss_buffer_t attr)
+{
+ OM_uint32 tmpMinor;
+ gss_buffer_desc strAttr = GSS_C_EMPTY_BUFFER;
+ DICT_ATTR *da;
+ char *s;
+ uint32_t attrid = 0;
+
+ if (attr->length < radiusUrnPrefix.length ||
+ memcmp(attr->value, radiusUrnPrefix.value, radiusUrnPrefix.length) != 0)
+ return 0;
+
+ /* need to duplicate because attr may not be NUL terminated */
+ duplicateBuffer(*attr, &strAttr);
+ s = (char *)strAttr.value + radiusUrnPrefix.length;
+
+ if (isdigit(*s)) {
+ attrid = strtoul(s, NULL, 10);
+ } else {
+ da = dict_attrbyname(s);
+ if (da != NULL)
+ attrid = da->attr;
+ }
+
+ gss_release_buffer(&tmpMinor, &strAttr);
+
+ return attrid;
+}
+
+bool
+gss_eap_radius_attr_provider::setAttribute(int complete,
+ uint32_t attrid,
+ const gss_buffer_t value)
+{
+ OM_uint32 major = GSS_S_UNAVAILABLE, minor;
+
+ if (!isSecretAttributeP(attrid) &&
+ !isInternalAttributeP(attrid)) {
+ deleteAttribute(attrid);
+
+ major = gssEapRadiusAddAvp(&minor, &m_vps,
+ ATTRID(attrid), VENDOR(attrid),
+ value);
+ }
+
+ return !GSS_ERROR(major);
+}
+
+bool
gss_eap_radius_attr_provider::setAttribute(int complete,
const gss_buffer_t attr,
const gss_buffer_t value)
{
+ uint32_t attrid = getAttributeId(attr);
+
+ if (!attrid)
+ return false;
+
+ return setAttribute(complete, attrid, value);
}
-void
-gss_eap_radius_attr_provider::deleteAttribute(const gss_buffer_t value)
+bool
+gss_eap_radius_attr_provider::deleteAttribute(uint32_t attrid)
{
+ if (isSecretAttributeP(attrid) || isInternalAttributeP(attrid) ||
+ pairfind(m_vps, attrid) == NULL)
+ return false;
+
+ pairdelete(&m_vps, attrid);
+
+ return true;
+}
+
+bool
+gss_eap_radius_attr_provider::deleteAttribute(const gss_buffer_t attr)
+{
+ uint32_t attrid = getAttributeId(attr);
+
+ if (!attrid)
+ return false;
+
+ return deleteAttribute(attrid);
}
bool
gss_buffer_t display_value,
int *more) const
{
- OM_uint32 tmpMinor;
- gss_buffer_desc strAttr = GSS_C_EMPTY_BUFFER;
- DICT_ATTR *da;
uint32_t attrid;
- char *s;
-
- duplicateBuffer(*attr, &strAttr);
- s = (char *)strAttr.value;
- if (attr->length < radiusUrnPrefix.length ||
- memcmp(s, radiusUrnPrefix.value, radiusUrnPrefix.length) != 0)
+ attrid = getAttributeId(attr);
+ if (!attrid)
return false;
- s += radiusUrnPrefix.length;
-
- if (isdigit(*s)) {
- attrid = strtoul(s, NULL, 10);
- } else {
- da = dict_attrbyname(s);
- if (da == NULL) {
- gss_release_buffer(&tmpMinor, &strAttr);
- return false;
- }
- attrid = da->attr;
- }
-
- gss_release_buffer(&tmpMinor, &strAttr);
-
return getAttribute(attrid, authenticated, complete,
value, display_value, more);
}
*more = 0;
- if (isHiddenAttributeP(attrid))
- return false;
-
if (i == -1)
i = 0;
{
gss_eap_attr_ctx::registerProvider(ATTR_TYPE_RADIUS,
"urn:ietf:params:gss-eap:radius-avp",
- gss_eap_radius_attr_provider::createAttrContext);
+ createAttrContext);
return true;
}
VALUE_PAIR **vps,
uint16_t attribute,
uint16_t vendor,
- gss_buffer_t buffer)
+ const gss_buffer_t buffer)
{
uint32_t attrid = VENDORATTR(vendor, attribute);
unsigned char *p = (unsigned char *)buffer->value;
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
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;
OM_uint32
gssEapRadiusAttrProviderInit(OM_uint32 *minor)
{
- return gss_eap_radius_attr_provider::init()
- ? GSS_S_COMPLETE : GSS_S_FAILURE;
-}
+ if (!gss_eap_radius_attr_provider::init()) {
+ *minor = GSSEAP_RADSEC_INIT_FAILURE;
+ return GSS_S_FAILURE;
+ }
-OM_uint32
-gssEapRadiusAttrProviderFinalize(OM_uint32 *minor)
-{
- gss_eap_radius_attr_provider::finalize();
return GSS_S_COMPLETE;
}
-/* partition error namespace so it does not conflict with krb5 */
-#define ERROR_TABLE_BASE_rse (46882560L)
-
-#define RS_TO_COM_ERR(rse) ((rse) == RSE_OK ? 0 : (rse) + ERROR_TABLE_BASE_rse)
-#define COM_TO_RS_ERR(err) ((err) > ERROR_TABLE_BASE_rse && \
- (err) <= (ERROR_TABLE_BASE_rse + RSE_SOME_ERROR) ? \
- (err) - ERROR_TABLE_BASE_rse : RSE_SOME_ERROR)
-
OM_uint32
-gssEapRadiusMapError(OM_uint32 *minor,
- struct rs_error *err)
-{
- int code = RSE_OK;
-
- if (err != NULL)
- code = rs_err_code(err, 0);
- else
- code = RSE_SOME_ERROR;
-
- *minor = RS_TO_COM_ERR(code);
-
- gssEapSaveStatusInfo(*minor, "radsec: %s", rs_err_msg(err, 0));
-
- rs_err_free(err);
- return GSS_S_FAILURE;
-}
-
-OM_uint32
-gssEapRadiusAllocConn(OM_uint32 *minor,
- const gss_cred_id_t cred,
- gss_ctx_id_t ctx)
+gssEapRadiusAttrProviderFinalize(OM_uint32 *minor)
{
- struct gss_eap_acceptor_ctx *actx = &ctx->acceptorCtx;
- const char *configFile = RS_CONFIG_FILE;
- const char *configStanza = "gss-eap";
- struct rs_alloc_scheme ralloc;
- struct rs_error *err;
-
- assert(actx->radHandle == NULL);
- assert(actx->radConn == NULL);
-
- if (rs_context_create(&actx->radHandle, RS_DICT_FILE) != 0)
- return GSS_S_FAILURE;
-
- if (cred != GSS_C_NO_CREDENTIAL) {
- if (cred->radiusConfigFile != NULL)
- configFile = cred->radiusConfigFile;
- if (cred->radiusConfigStanza != NULL)
- configStanza = cred->radiusConfigStanza;
- }
-
- ralloc.calloc = GSSEAP_CALLOC;
- ralloc.malloc = GSSEAP_MALLOC;
- ralloc.free = GSSEAP_FREE;
- ralloc.realloc = GSSEAP_REALLOC;
-
- rs_context_set_alloc_scheme(actx->radHandle, &ralloc);
-
- if (rs_context_read_config(actx->radHandle, configFile) != 0) {
- err = rs_err_ctx_pop(actx->radHandle);
- goto fail;
- }
-
- if (rs_conn_create(actx->radHandle, &actx->radConn, configStanza) != 0) {
- err = rs_err_conn_pop(actx->radConn);
- goto fail;
- }
-
- /* XXX TODO rs_conn_select_server does not exist yet */
-#if 0
- if (actx->radServer != NULL) {
- if (rs_conn_select_server(actx->radConn, actx->radServer) != 0) {
- err = rs_err_conn_pop(actx->radConn);
- goto fail;
- }
- }
-#endif
-
- *minor = 0;
+ gss_eap_radius_attr_provider::finalize();
return GSS_S_COMPLETE;
-
-fail:
- OM_uint32 major = gssEapRadiusMapError(minor, err);
-
- if (actx->radConn != NULL) {
- rs_conn_destroy(actx->radConn);
- actx->radConn = NULL;
- }
-
- if (actx->radHandle != NULL) {
- rs_context_destroy(actx->radHandle);
- actx->radHandle = NULL;
- }
-
- return major;
}
/*
{
unsigned char *p = (unsigned char *)buffer->value;
size_t remain = buffer->length;
- uint32_t count;
VALUE_PAIR **pNext = &m_vps;
if (!gss_eap_attr_provider::initFromBuffer(ctx, buffer))
return false;
- if (remain < 4)
- return false;
-
- count = load_uint32_be(p);
- p += 4;
- remain -= 4;
-
do {
VALUE_PAIR *attr;
*pNext = attr;
pNext = &attr->next;
-
- count--;
} while (remain != 0);
- if (count != 0)
- return false;
-
return true;
}
void
gss_eap_radius_attr_provider::exportToBuffer(gss_buffer_t buffer) const
{
- uint32_t count = 0;
VALUE_PAIR *vp;
unsigned char *p;
- size_t remain = 4;
+ size_t remain = 0;
for (vp = m_vps; vp != NULL; vp = vp->next) {
remain += avpSize(vp);
- count++;
}
buffer->value = GSSEAP_MALLOC(remain);
p = (unsigned char *)buffer->value;
- store_uint32_be(count, p);
- p += 4;
- remain -= 4;
-
for (vp = m_vps; vp != NULL; vp = vp->next) {
avpExport(vp, &p, &remain);
}
return time(NULL) + vp->lvalue;
}
+
+OM_uint32
+gssEapRadiusMapError(OM_uint32 *minor,
+ struct rs_error *err)
+{
+ int code;
+
+ assert(err != NULL);
+
+ code = rs_err_code(err, 0);
+
+ if (code == RSE_OK) {
+ *minor = 0;
+ return GSS_S_COMPLETE;
+ }
+
+ *minor = ERROR_TABLE_BASE_rse + code;
+
+ gssEapSaveStatusInfo(*minor, "%s", rs_err_msg(err, 0));
+ rs_err_free(err);
+
+ return GSS_S_FAILURE;
+}