remove debugging statement
[mech_eap.orig] / import_sec_context.c
index 202be3d..df52410 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.
  */
 
+/*
+ * Deserialise a context handle.
+ */
+
 #include "gssapiP_eap.h"
 
-#define UPDATE_REMAIN(n)    do {            \
-        p += (n);                           \
-        remain -= (n);                      \
+#define UPDATE_REMAIN(n)    do {                \
+        p += (n);                               \
+        remain -= (n);                          \
     } while (0)
 
-#define CHECK_REMAIN(n)     do {            \
-        if (remain < (n)) {                 \
-            *minor = ERANGE;                \
-            return GSS_S_DEFECTIVE_TOKEN;   \
-        }                                   \
+#define CHECK_REMAIN(n)     do {                \
+        if (remain < (n)) {                     \
+            *minor = GSSEAP_TOK_TRUNC;          \
+            return GSS_S_DEFECTIVE_TOKEN;       \
+        }                                       \
     } while (0)
 
 static OM_uint32
@@ -111,21 +115,15 @@ importMechanismOid(OM_uint32 *minor,
 
     oidBuf.length = load_uint32_be(p);
     if (remain < 4 + oidBuf.length || oidBuf.length == 0) {
-        *minor = ERANGE;
+        *minor = GSSEAP_TOK_TRUNC;
         return GSS_S_DEFECTIVE_TOKEN;
     }
 
     oidBuf.elements = &p[4];
 
-    if (!gssEapIsConcreteMechanismOid(&oidBuf)) {
-        return GSS_S_BAD_MECH;
-    }
-
-    if (!gssEapInternalizeOid(&oidBuf, pOid)) {
-        major = duplicateOid(minor, &oidBuf, pOid);
-        if (GSS_ERROR(major))
-            return major;
-    }
+    major = gssEapCanonicalizeOid(minor, &oidBuf, 0, pOid);
+    if (GSS_ERROR(major))
+        return major;
 
     *pBuf    += 4 + oidBuf.length;
     *pRemain -= 4 + oidBuf.length;
@@ -149,7 +147,7 @@ importKerberosKey(OM_uint32 *minor,
     gss_buffer_desc tmp;
 
     if (remain < 12) {
-        *minor = ERANGE;
+        *minor = GSSEAP_TOK_TRUNC;
         return GSS_S_DEFECTIVE_TOKEN;
     }
 
@@ -158,12 +156,12 @@ importKerberosKey(OM_uint32 *minor,
     length         = load_uint32_be(&p[8]);
 
     if ((length != 0) != (encryptionType != ENCTYPE_NULL)) {
-        *minor = ERANGE;
+        *minor = GSSEAP_BAD_CONTEXT_TOKEN;
         return GSS_S_DEFECTIVE_TOKEN;
     }
 
     if (remain - 12 < length) {
-        *minor = ERANGE;
+        *minor = GSSEAP_TOK_TRUNC;
         return GSS_S_DEFECTIVE_TOKEN;
     }
 
@@ -196,14 +194,14 @@ importName(OM_uint32 *minor,
     gss_buffer_desc tmp;
 
     if (remain < 4) {
-        *minor = ERANGE;
+        *minor = GSSEAP_TOK_TRUNC;
         return GSS_S_DEFECTIVE_TOKEN;
     }
 
     tmp.length = load_uint32_be(p);
     if (tmp.length != 0) {
         if (remain - 4 < tmp.length) {
-            *minor = ERANGE;
+            *minor = GSSEAP_TOK_TRUNC;
             return GSS_S_DEFECTIVE_TOKEN;
         }
 
@@ -232,11 +230,11 @@ gssEapImportContext(OM_uint32 *minor,
     size_t remain = token->length;
 
     if (remain < 16) {
-        *minor = ERANGE;
+        *minor = GSSEAP_TOK_TRUNC;
         return GSS_S_DEFECTIVE_TOKEN;
     }
     if (load_uint32_be(&p[0]) != EAP_EXPORT_CONTEXT_V1) {
-        *minor = EINVAL;
+        *minor = GSSEAP_BAD_CONTEXT_TOKEN;
         return GSS_S_DEFECTIVE_TOKEN;
     }
     ctx->state      = load_uint32_be(&p[4]);
@@ -246,8 +244,8 @@ gssEapImportContext(OM_uint32 *minor,
     remain -= 16;
 
     /* Validate state */
-    if (ctx->state < EAP_STATE_IDENTITY ||
-        ctx->state > EAP_STATE_ESTABLISHED)
+    if (GSSEAP_SM_STATE(ctx) < GSSEAP_STATE_INITIAL ||
+        GSSEAP_SM_STATE(ctx) > GSSEAP_STATE_ESTABLISHED)
         return GSS_S_DEFECTIVE_TOKEN;
 
     /* Only acceptor can export partial context tokens */
@@ -281,10 +279,10 @@ gssEapImportContext(OM_uint32 *minor,
     }
 
     if (remain < 24 + sequenceSize(ctx->seqState)) {
-        *minor = ERANGE;
+        *minor = GSSEAP_TOK_TRUNC;
         return GSS_S_DEFECTIVE_TOKEN;
     }
-    ctx->expiryTime = (time_t)load_uint64_be(&p[0]); /* XXX */
+    ctx->expiryTime = (time_t)load_uint64_be(&p[0]);
     ctx->sendSeq    = load_uint64_be(&p[8]);
     ctx->recvSeq    = load_uint64_be(&p[16]);
     p      += 24;
@@ -299,7 +297,7 @@ gssEapImportContext(OM_uint32 *minor,
      * acceptor contexts.
      */
     if (!CTX_IS_INITIATOR(ctx) && !CTX_IS_ESTABLISHED(ctx)) {
-        assert((ctx->flags & CTX_FLAG_KRB_REAUTH_GSS) == 0);
+        assert((ctx->flags & CTX_FLAG_KRB_REAUTH) == 0);
 
         major = gssEapImportPartialContext(minor, &p, &remain, ctx);
         if (GSS_ERROR(major))
@@ -310,8 +308,8 @@ gssEapImportContext(OM_uint32 *minor,
     assert(remain == 0);
 #endif
 
-    *minor = 0;
     major = GSS_S_COMPLETE;
+    *minor = 0;
 
     return major;
 }
@@ -324,12 +322,13 @@ gss_import_sec_context(OM_uint32 *minor,
     OM_uint32 major, tmpMinor;
     gss_ctx_id_t ctx = GSS_C_NO_CONTEXT;
 
-    *minor = 0;
     *context_handle = GSS_C_NO_CONTEXT;
 
     if (interprocess_token == GSS_C_NO_BUFFER ||
-        interprocess_token->length == 0)
+        interprocess_token->length == 0) {
+        *minor = GSSEAP_TOK_TRUNC;
         return GSS_S_DEFECTIVE_TOKEN;
+    }
 
     major = gssEapAllocContext(minor, &ctx);
     if (GSS_ERROR(major))