Better error reporting through com_err
[mech_eap.git] / wrap.c
diff --git a/wrap.c b/wrap.c
index f6542b7..122945e 100644 (file)
--- a/wrap.c
+++ b/wrap.c
@@ -41,12 +41,33 @@ gss_wrap(OM_uint32 *minor,
          int *conf_state,
          gss_buffer_t output_message_buffer)
 {
-    if (!CTX_IS_ESTABLISHED(ctx))
+    OM_uint32 major;
+
+    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;
+    }
+
+    major = gssEapWrap(minor, ctx, conf_req_flag, qop_req,
+                       input_message_buffer,
+                       conf_state, output_message_buffer);
+    if (GSS_ERROR(major))
+        goto cleanup;
+
+cleanup:
+    GSSEAP_MUTEX_UNLOCK(&ctx->mutex);
 
-    return gssEapWrap(minor, ctx, conf_req_flag, qop_req,
-                      input_message_buffer,
-                      conf_state, output_message_buffer);
+    return major;
 }
 
 OM_uint32
@@ -63,7 +84,6 @@ gssEapWrap(OM_uint32 *minor,
     unsigned char *p;
     int i;
 
-
     iov[0].type = GSS_IOV_BUFFER_TYPE_HEADER;
     iov[0].buffer.value = NULL;
     iov[0].buffer.length = 0;