remove debugging statement
[moonshot.git] / mech_eap / inquire_context.c
index d1143e8..0e7b586 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
  * SUCH DAMAGE.
  */
 
+/*
+ * Return context handle properties.
+ */
+
 #include "gssapiP_eap.h"
 
 OM_uint32
@@ -45,40 +49,46 @@ gss_inquire_context(OM_uint32 *minor,
 {
     OM_uint32 major, tmpMinor;
 
-    *minor = 0;
-
     if (ctx == GSS_C_NO_CONTEXT) {
-        major = GSS_S_NO_CONTEXT;
-        goto cleanup;
+        *minor = EINVAL;
+        return GSS_S_CALL_INACCESSIBLE_READ | GSS_S_NO_CONTEXT;
     }
 
+    GSSEAP_MUTEX_LOCK(&ctx->mutex);
+
     if (src_name != NULL) {
-        major = gss_duplicate_name(minor, ctx->initiatorName, src_name);
+        major = gssEapDuplicateName(minor, ctx->initiatorName, src_name);
         if (GSS_ERROR(major))
             goto cleanup;
     }
 
     if (targ_name != NULL) {
-        major = gss_duplicate_name(minor, ctx->acceptorName, targ_name);
+        major = gssEapDuplicateName(minor, ctx->acceptorName, targ_name);
         if (GSS_ERROR(major))
             goto cleanup;
     }
 
     if (lifetime_rec != NULL) {
-        time_t now = time(NULL);
-        time_t lifetime;
+        time_t now, lifetime;
 
-        if (ctx->expiryTime == ~0)
+        if (ctx->expiryTime == 0) {
             lifetime = GSS_C_INDEFINITE;
-        else
+        } else {
+            now = time(NULL);
             lifetime = now - ctx->expiryTime;
-
-        if (lifetime < 0)
-            lifetime = 0;
+            if (lifetime < 0)
+                lifetime = 0;
+        }
 
         *lifetime_rec = lifetime;
     }
 
+    if (mech_type != NULL) {
+        major = gssEapCanonicalizeOid(minor, ctx->mechanismUsed, 0, mech_type);
+        if (GSS_ERROR(major))
+            goto cleanup;
+    }
+
     if (ctx_flags != NULL) {
         *ctx_flags = ctx->gssFlags;
     }
@@ -92,8 +102,11 @@ gss_inquire_context(OM_uint32 *minor,
     }
 
     major = GSS_S_COMPLETE;
+    *minor = 0;
 
 cleanup:
+    GSSEAP_MUTEX_UNLOCK(&ctx->mutex);
+
     if (GSS_ERROR(major)) {
         gssEapReleaseName(&tmpMinor, src_name);
         gssEapReleaseName(&tmpMinor, targ_name);