#include <string>
#include <sstream>
#include <exception>
-#include <stdexcept>
#include <new>
/* lazy initialisation */
major = gss_create_empty_buffer_set(&minor, attrs);
if (GSS_ERROR(major))
- throw new std::bad_alloc;
+ throw std::bad_alloc();
args.attrs = *attrs;
s = obj.dump(JSON_COMPACT);
if (GSS_ERROR(makeStringBuffer(&minor, s, buffer)))
- throw new std::bad_alloc;
+ throw std::bad_alloc();
}
/*
major = GSS_S_FAILURE;
*minor = ENOMEM;
goto cleanup;
- } else if (typeid(e) == typeid(std::runtime_error)) {
+ } else if (typeid(e) == typeid(JSONException)) {
major = GSS_S_BAD_NAME;
*minor = GSSEAP_BAD_ATTR_TOKEN;
- goto cleanup;
- } else if (this == NULL) {
- major = GSS_S_FAILURE;
+ gssEapSaveStatusInfo(*minor, "%s", e.what());
goto cleanup;
}
}
cleanup:
-#if 0
- /* rethrow for now for debugging */
- throw e;
-#endif
-
assert(GSS_ERROR(major));
return major;
gss_name_t name)
{
gss_eap_attr_ctx *ctx = NULL;
+ OM_uint32 major = GSS_S_FAILURE;
assert(name->attrCtx == NULL);
if (GSS_ERROR(gssEapAttrProvidersInit(minor)))
return GSS_S_UNAVAILABLE;
- if (buffer->length != 0) {
- try {
- ctx = new gss_eap_attr_ctx();
+ if (buffer->length == 0)
+ return GSS_S_COMPLETE;
- if (!ctx->initFromBuffer(buffer)) {
- delete ctx;
- *minor = GSSEAP_BAD_ATTR_TOKEN;
- return GSS_S_BAD_NAME;
- }
+ try {
+ ctx = new gss_eap_attr_ctx();
+
+ if (ctx->initFromBuffer(buffer)) {
name->attrCtx = ctx;
- } catch (std::exception &e) {
- delete ctx;
- return name->attrCtx->mapException(minor, e);
+ major = GSS_S_COMPLETE;
+ *minor = 0;
+ } else {
+ major = GSS_S_BAD_NAME;
+ *minor = GSSEAP_ATTR_CONTEXT_FAILURE;
}
+ } catch (std::exception &e) {
+ if (ctx != NULL)
+ major = ctx->mapException(minor, e);
}
- return GSS_S_COMPLETE;
+ assert(major == GSS_S_COMPLETE || name->attrCtx == NULL);
+
+ if (GSS_ERROR(major))
+ delete ctx;
+
+ return major;
}
OM_uint32
gss_name_t out)
{
gss_eap_attr_ctx *ctx = NULL;
+ OM_uint32 major = GSS_S_FAILURE;
assert(out->attrCtx == NULL);
+ if (in->attrCtx == NULL) {
+ *minor = 0;
+ return GSS_S_COMPLETE;
+ }
+
if (GSS_ERROR(gssEapAttrProvidersInit(minor)))
return GSS_S_UNAVAILABLE;
try {
- if (in->attrCtx != NULL) {
- ctx = new gss_eap_attr_ctx();
- if (!ctx->initFromExistingContext(in->attrCtx)) {
- delete ctx;
- *minor = GSSEAP_ATTR_CONTEXT_FAILURE;
- return GSS_S_FAILURE;
- }
+ ctx = new gss_eap_attr_ctx();
+
+ if (ctx->initFromExistingContext(in->attrCtx)) {
out->attrCtx = ctx;
+ major = GSS_S_COMPLETE;
+ *minor = 0;
+ } else {
+ major = GSS_S_FAILURE;
+ *minor = GSSEAP_ATTR_CONTEXT_FAILURE;
}
} catch (std::exception &e) {
- delete ctx;
- return in->attrCtx->mapException(minor, e);
+ major = in->attrCtx->mapException(minor, e);
}
+ assert(major == GSS_S_COMPLETE || out->attrCtx == NULL);
+
+ if (GSS_ERROR(major))
+ delete ctx;
+
return GSS_S_COMPLETE;
}
assert(gssCtx != GSS_C_NO_CONTEXT);
+ *pAttrContext = NULL;
+
major = gssEapAttrProvidersInit(minor);
if (GSS_ERROR(major))
return major;
- *minor = GSSEAP_ATTR_CONTEXT_FAILURE;
- major = GSS_S_FAILURE;
-
try {
- *pAttrContext = ctx = new gss_eap_attr_ctx();
+ ctx = new gss_eap_attr_ctx();
+
if (ctx->initFromGssContext(gssCred, gssCtx)) {
- *minor = 0;
major = GSS_S_COMPLETE;
+ *minor = 0;
+ } else {
+ major = GSS_S_FAILURE;
+ *minor = GSSEAP_ATTR_CONTEXT_FAILURE;
}
} catch (std::exception &e) {
if (ctx != NULL)
if (major == GSS_S_COMPLETE) {
*pExpiryTime = ctx->getExpiryTime();
- } else {
- delete ctx;
- *pAttrContext = NULL;
+ *pAttrContext = ctx;
}
+ if (GSS_ERROR(major))
+ delete ctx;
+
return major;
}