cleanup unused parameter warnings
[mech_eap.git] / util_attr.cpp
index 3d7d1f6..28065ac 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, JANET(UK)
+ * Copyright (c) 2011, JANET(UK)
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -425,7 +425,7 @@ struct eap_gss_get_attr_types_args {
 };
 
 static bool
-addAttribute(const gss_eap_attr_provider *provider,
+addAttribute(const gss_eap_attr_provider *provider GSSEAP_UNUSED,
              const gss_buffer_t attribute,
              void *data)
 {
@@ -601,25 +601,47 @@ gss_eap_attr_ctx::getExpiryTime(void) const
     return expiryTime;
 }
 
-/*
- * Map C++ exception to GSS status
- */
-static OM_uint32
-mapException(OM_uint32 *minor, std::exception &e)
+OM_uint32
+gss_eap_attr_ctx::mapException(OM_uint32 *minor, std::exception &e) const
 {
-    OM_uint32 major = GSS_S_FAILURE;
+    unsigned int i;
+    OM_uint32 major;
 
-    /* XXX TODO implement other mappings */
-    if (typeid(e) == typeid(std::bad_alloc))
+    /* Errors we handle ourselves */
+    major = GSS_S_FAILURE;
+
+    if (typeid(e) == typeid(std::bad_alloc)) {
         *minor = ENOMEM;
-    else
-        *minor = 0;
+        goto cleanup;
+    }
 
-#ifdef GSSEAP_DEBUG
+    /* Errors we delegate to providers */
+    major = GSS_S_CONTINUE_NEEDED;
+
+    for (i = ATTR_TYPE_MIN; i <= ATTR_TYPE_MAX; i++) {
+        gss_eap_attr_provider *provider = m_providers[i];
+
+        if (provider == NULL)
+            continue;
+
+        major = provider->mapException(minor, e);
+        if (major != GSS_S_CONTINUE_NEEDED)
+            break;
+    }
+
+    if (major == GSS_S_CONTINUE_NEEDED) {
+        *minor = GSSEAP_ATTR_CONTEXT_FAILURE;
+        major = GSS_S_FAILURE;
+    }
+
+cleanup:
+#if 0
     /* rethrow for now for debugging */
     throw e;
 #endif
 
+    assert(GSS_ERROR(major));
+
     return major;
 }
 
@@ -738,8 +760,8 @@ gss_eap_attr_ctx::composeAttributeName(unsigned int type,
 OM_uint32
 gssEapInquireName(OM_uint32 *minor,
                   gss_name_t name,
-                  int *name_is_MN,
-                  gss_OID *MN_mech,
+                  int *name_is_MN GSSEAP_UNUSED,
+                  gss_OID *MN_mech GSSEAP_UNUSED,
                   gss_buffer_set_t *attrs)
 {
     if (name->attrCtx == NULL) {
@@ -757,7 +779,7 @@ gssEapInquireName(OM_uint32 *minor,
             return GSS_S_UNAVAILABLE;
         }
     } catch (std::exception &e) {
-        return mapException(minor, e);
+        return name->attrCtx->mapException(minor, e);
     }
 
     return GSS_S_COMPLETE;
@@ -804,7 +826,7 @@ gssEapGetNameAttribute(OM_uint32 *minor,
             return GSS_S_UNAVAILABLE;
         }
     } catch (std::exception &e) {
-        return mapException(minor, e);
+        return name->attrCtx->mapException(minor, e);
     }
 
     return GSS_S_COMPLETE;
@@ -830,8 +852,8 @@ gssEapDeleteNameAttribute(OM_uint32 *minor,
                                  (int)attr->length, (char *)attr->value);
             return GSS_S_UNAVAILABLE;
         }
-    } catch (std::exception &ex) {
-        return mapException(minor, ex);
+    } catch (std::exception &e) {
+        return name->attrCtx->mapException(minor, e);
     }
 
     return GSS_S_COMPLETE;
@@ -859,8 +881,8 @@ gssEapSetNameAttribute(OM_uint32 *minor,
                                  (int)attr->length, (char *)attr->value);
             return GSS_S_UNAVAILABLE;
         }
-    } catch (std::exception &ex) {
-        return mapException(minor, ex);
+    } catch (std::exception &e) {
+        return name->attrCtx->mapException(minor, e);
     }
 
     return GSS_S_COMPLETE;
@@ -884,7 +906,7 @@ gssEapExportAttrContext(OM_uint32 *minor,
     try {
         name->attrCtx->exportToBuffer(buffer);
     } catch (std::exception &e) {
-        return mapException(minor, e);
+        return name->attrCtx->mapException(minor, e);
     }
 
     return GSS_S_COMPLETE;
@@ -914,7 +936,7 @@ gssEapImportAttrContext(OM_uint32 *minor,
             name->attrCtx = ctx;
         } catch (std::exception &e) {
             delete ctx;
-            return mapException(minor, e);
+            return name->attrCtx->mapException(minor, e);
         }
     }
 
@@ -945,7 +967,7 @@ gssEapDuplicateAttrContext(OM_uint32 *minor,
         }
     } catch (std::exception &e) {
         delete ctx;
-        return mapException(minor, e);
+        return in->attrCtx->mapException(minor, e);
     }
 
     return GSS_S_COMPLETE;
@@ -969,7 +991,7 @@ gssEapMapNameToAny(OM_uint32 *minor,
     try {
         *output = name->attrCtx->mapToAny(authenticated, type_id);
     } catch (std::exception &e) {
-        return mapException(minor, e);
+        return name->attrCtx->mapException(minor, e);
     }
 
     return GSS_S_COMPLETE;
@@ -994,7 +1016,7 @@ gssEapReleaseAnyNameMapping(OM_uint32 *minor,
             name->attrCtx->releaseAnyNameMapping(type_id, *input);
         *input = NULL;
     } catch (std::exception &e) {
-        return mapException(minor, e);
+        return name->attrCtx->mapException(minor, e);
     }
 
     return GSS_S_COMPLETE;
@@ -1007,6 +1029,7 @@ gssEapReleaseAttrContext(OM_uint32 *minor,
     if (name->attrCtx != NULL)
         delete name->attrCtx;
 
+    *minor = 0;
     return GSS_S_COMPLETE;
 }
 
@@ -1014,25 +1037,42 @@ gssEapReleaseAttrContext(OM_uint32 *minor,
  * Public accessor for initialisng a context from a GSS context. Also
  * sets expiry time on GSS context as a side-effect.
  */
-struct gss_eap_attr_ctx *
-gssEapCreateAttrContext(gss_cred_id_t gssCred,
-                        gss_ctx_id_t gssCtx)
+OM_uint32
+gssEapCreateAttrContext(OM_uint32 *minor,
+                        gss_cred_id_t gssCred,
+                        gss_ctx_id_t gssCtx,
+                        struct gss_eap_attr_ctx **pAttrContext,
+                        time_t *pExpiryTime)
 {
-    gss_eap_attr_ctx *ctx;
-    OM_uint32 tmpMinor;
+    gss_eap_attr_ctx *ctx = NULL;
+    OM_uint32 major;
 
     assert(gssCtx != GSS_C_NO_CONTEXT);
 
-    if (GSS_ERROR(gssEapAttrProvidersInit(&tmpMinor)))
-        return NULL;
+    major = gssEapAttrProvidersInit(minor);
+    if (GSS_ERROR(major))
+        return major;
 
-    ctx = new gss_eap_attr_ctx();
-    if (!ctx->initFromGssContext(gssCred, gssCtx)) {
-        delete ctx;
-        return NULL;
+    *minor = GSSEAP_ATTR_CONTEXT_FAILURE;
+    major = GSS_S_FAILURE;
+
+    try {
+        ctx = new gss_eap_attr_ctx();
+        if (ctx->initFromGssContext(gssCred, gssCtx)) {
+            *minor = 0;
+            major = GSS_S_COMPLETE;
+        } else {
+            delete ctx;
+        }
+    } catch (std::exception &e) {
+        if (ctx != NULL)
+            major = ctx->mapException(minor, e);
     }
 
-    gssCtx->expiryTime = ctx->getExpiryTime();
+    if (major == GSS_S_COMPLETE) {
+        *pAttrContext = ctx;
+        *pExpiryTime = ctx->getExpiryTime();
+    }
 
-    return ctx;
+    return major;
 }