Better error reporting through com_err
[mech_eap.git] / wrap_size_limit.c
index 39906dd..8fd9251 100644 (file)
@@ -43,6 +43,21 @@ gss_wrap_size_limit(OM_uint32 *minor,
     gss_iov_buffer_desc iov[4];
     OM_uint32 major, overhead;
 
+    if (ctx == GSS_C_NO_CONTEXT) {
+        *minor = EINVAL;
+        return GSS_S_NO_CONTEXT;
+    }
+
+    *minor = 0;
+
+    GSSEAP_MUTEX_LOCK(&ctx->mutex);
+
+    if (!CTX_IS_ESTABLISHED(ctx)) {
+        *minor = GSSEAP_CONTEXT_INCOMPLETE;
+        major = GSS_S_NO_CONTEXT;
+        goto cleanup;
+    }
+
     iov[0].type = GSS_IOV_BUFFER_TYPE_HEADER;
     iov[0].buffer.value = NULL;
     iov[0].buffer.length = 0;
@@ -59,11 +74,10 @@ gss_wrap_size_limit(OM_uint32 *minor,
     iov[3].buffer.value = NULL;
     iov[3].buffer.length = 0;
 
-    major = gss_wrap_iov_length(minor, ctx, conf_req_flag, qop_req,
+    major = gssEapWrapIovLength(minor, ctx, conf_req_flag, qop_req,
                                 NULL, iov, 4);
-    if (GSS_ERROR(major)) {
-        return major;
-    }
+    if (GSS_ERROR(major))
+        goto cleanup;
 
     overhead = iov[0].buffer.length + iov[3].buffer.length;
 
@@ -72,5 +86,8 @@ gss_wrap_size_limit(OM_uint32 *minor,
     else
         *max_input_size = 0;
 
-    return GSS_S_COMPLETE;
+cleanup:
+    GSSEAP_MUTEX_UNLOCK(&ctx->mutex);
+
+    return major;
 }