refactor OID interning code
[mech_eap.orig] / util_attr.cpp
index e5fb568..a24064a 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)
 {
@@ -764,6 +764,18 @@ gssEapInquireName(OM_uint32 *minor,
                   gss_OID *MN_mech,
                   gss_buffer_set_t *attrs)
 {
+    OM_uint32 major;
+
+    if (name_is_MN != NULL)
+        *name_is_MN = (name->mechanismUsed != GSS_C_NULL_OID);
+
+    if (MN_mech != NULL) {
+        major = gssEapCanonicalizeOid(minor, name->mechanismUsed,
+                                      OID_FLAG_NULL_VALID, MN_mech);
+        if (GSS_ERROR(major))
+            return major;
+    }
+
     if (name->attrCtx == NULL) {
         *minor = GSSEAP_NO_ATTR_CONTEXT;
         return GSS_S_UNAVAILABLE;
@@ -1029,6 +1041,7 @@ gssEapReleaseAttrContext(OM_uint32 *minor,
     if (name->attrCtx != NULL)
         delete name->attrCtx;
 
+    *minor = 0;
     return GSS_S_COMPLETE;
 }
 
@@ -1040,36 +1053,38 @@ OM_uint32
 gssEapCreateAttrContext(OM_uint32 *minor,
                         gss_cred_id_t gssCred,
                         gss_ctx_id_t gssCtx,
-                        struct gss_eap_attr_ctx **pAttrContext)
+                        struct gss_eap_attr_ctx **pAttrContext,
+                        time_t *pExpiryTime)
 {
-    gss_eap_attr_ctx *ctx;
+    gss_eap_attr_ctx *ctx = NULL;
     OM_uint32 major;
 
     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 {
         ctx = new gss_eap_attr_ctx();
-        if (!ctx->initFromGssContext(gssCred, gssCtx)) {
+        if (ctx->initFromGssContext(gssCred, gssCtx)) {
+            *minor = 0;
+            major = GSS_S_COMPLETE;
+        } else {
             delete ctx;
-            *minor = GSSEAP_ATTR_CONTEXT_FAILURE;
-            return GSS_S_FAILURE;
         }
     } catch (std::exception &e) {
-        major = ctx->mapException(minor, e);
-        delete ctx;
-        return major;
+        if (ctx != NULL)
+            major = ctx->mapException(minor, e);
     }
 
-    gssCtx->expiryTime = ctx->getExpiryTime();
-
-    *pAttrContext = ctx;
+    if (major == GSS_S_COMPLETE) {
+        *pAttrContext = ctx;
+        *pExpiryTime = ctx->getExpiryTime();
+    }
 
-    *minor = 0;
-    return GSS_S_COMPLETE;
+    return major;
 }