* k5seal.c (kg_seal): Extract the krb5 context from the security context
authorKen Raeburn <raeburn@mit.edu>
Mon, 15 Mar 2004 17:45:01 +0000 (17:45 +0000)
committerKen Raeburn <raeburn@mit.edu>
Mon, 15 Mar 2004 17:45:01 +0000 (17:45 +0000)
instead of requiring it be passed in as an argument.
* k5unseal.c (kg_unseal): Likewise.
* gssapiP_krb5.h (kg_seal, kg_unseal): Declarations updated.
* delete_sec_context.c, process_context_token.c, seal.c, sign.c, unseal.c,
verify.c: Callers changed.
* inq_context.c (krb5_gss_inquire_context): Use krb5 context contained in
security context instead of calling kg_get_context.
* wrap_size_limit.c (krb5_gss_wrap_size_limit): Likewise.

* import_sec_context.c (krb5_gss_ser_init): New function.
(krb5_gss_import_sec_context): Create a krb5 context locally to use for the
import.
* export_sec_context.c (krb5_gss_export_sec_context): Use the krb5 context in
the security context.
* gssapiP_krb5.h (krb5_gss_ser_init): Declare.
* gssapi_krb5.c (kg_get_context): Don't call krb5 serialization initialization
code here.

* accept_sec_context.c (krb5_gss_accept_sec_context): Free the new krb5 context
in an error case not caught before.

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16171 dc483132-0cff-0310-8789-dd5450dbe970

17 files changed:
src/lib/gssapi/krb5/ChangeLog
src/lib/gssapi/krb5/accept_sec_context.c
src/lib/gssapi/krb5/delete_sec_context.c
src/lib/gssapi/krb5/export_sec_context.c
src/lib/gssapi/krb5/gssapiP_krb5.h
src/lib/gssapi/krb5/gssapi_krb5.c
src/lib/gssapi/krb5/import_sec_context.c
src/lib/gssapi/krb5/inq_context.c
src/lib/gssapi/krb5/k5seal.c
src/lib/gssapi/krb5/k5unseal.c
src/lib/gssapi/krb5/process_context_token.c
src/lib/gssapi/krb5/seal.c
src/lib/gssapi/krb5/ser_sctx.c
src/lib/gssapi/krb5/sign.c
src/lib/gssapi/krb5/unseal.c
src/lib/gssapi/krb5/verify.c
src/lib/gssapi/krb5/wrap_size_limit.c

index a3704fa97ac12faf5b90330c9c2c87c801cefccf..ae317482fe843a0bd2445c8c1421fb518267cd96 100644 (file)
@@ -1,3 +1,27 @@
+2004-03-15  Ken Raeburn  <raeburn@mit.edu>
+
+       * k5seal.c (kg_seal): Extract the krb5 context from the security
+       context instead of requiring it be passed in as an argument.
+       * k5unseal.c (kg_unseal): Likewise.
+       * gssapiP_krb5.h (kg_seal, kg_unseal): Declarations updated.
+       * delete_sec_context.c, process_context_token.c, seal.c, sign.c,
+       unseal.c, verify.c: Callers changed.
+       * inq_context.c (krb5_gss_inquire_context): Use krb5 context
+       contained in security context instead of calling kg_get_context.
+       * wrap_size_limit.c (krb5_gss_wrap_size_limit): Likewise.
+
+       * import_sec_context.c (krb5_gss_ser_init): New function.
+       (krb5_gss_import_sec_context): Create a krb5 context locally to
+       use for the import.
+       * export_sec_context.c (krb5_gss_export_sec_context): Use the
+       krb5 context in the security context.
+       * gssapiP_krb5.h (krb5_gss_ser_init): Declare.
+       * gssapi_krb5.c (kg_get_context): Don't call krb5 serialization
+       initialization code here.
+
+       * accept_sec_context.c (krb5_gss_accept_sec_context): Free the
+       new krb5 context in an error case not caught before.
+
 2004-03-14  Ken Raeburn  <raeburn@mit.edu>
 
        * gssapiP_krb5.h (struct _krb5_gss_ctx_id_rec): Add a krb5
index 021866ab3de11f42c2e4a17ea1d08aee282d9873..731cc476021a770c0dbe283dda19fee2ec84454d 100644 (file)
@@ -287,6 +287,7 @@ krb5_gss_accept_sec_context(minor_status, context_handle,
    /*SUPPRESS 29*/
    if (*context_handle != GSS_C_NO_CONTEXT) {
       *minor_status = 0;
+      krb5_free_context(context);
       return(GSS_S_FAILURE);
    }
 
index 70a79f5e938632182c5a60dd233c8143d5afc569..3d4706808c08fcba82d15e809f4f1d103638d03e 100644 (file)
@@ -63,7 +63,7 @@ krb5_gss_delete_sec_context(minor_status, context_handle, output_token)
       gss_buffer_desc empty;
       empty.length = 0; empty.value = NULL;
 
-      if ((major = kg_seal(context, minor_status, *context_handle, 0,
+      if ((major = kg_seal(minor_status, *context_handle, 0,
                           GSS_C_QOP_DEFAULT,
                           &empty, NULL, output_token, KG_TOK_DEL_CTX)))
         return(major);
index fc4b0ace2565d6ba01ff139274662c129bcf87bc..fb57b882a275061717f46486655829cedb9fff02 100644 (file)
@@ -43,9 +43,6 @@ krb5_gss_export_sec_context(minor_status, context_handle, interprocess_token)
     krb5_gss_ctx_id_t  ctx;
     krb5_octet         *obuffer, *obp;
 
-    if (GSS_ERROR(kg_get_context(minor_status, &context)))
-       return(GSS_S_FAILURE);
-
     /* Assume a tragic failure */
     obuffer = (krb5_octet *) NULL;
     retval = GSS_S_FAILURE;
@@ -58,6 +55,10 @@ krb5_gss_export_sec_context(minor_status, context_handle, interprocess_token)
     }
 
     ctx = (krb5_gss_ctx_id_t) *context_handle;
+    context = ctx->k5_context;
+    kret = krb5_gss_ser_init(context);
+    if (kret)
+       goto error_out;
 
     /* Determine size needed for externalization of context */
     bufsize = 0;
index 7c58c9a8596849c682fb19eac5e4893a25330d2c..d207010c1f544229c96bce3b42120898f8dbd4f0 100644 (file)
@@ -258,8 +258,7 @@ krb5_error_code kg_decrypt (krb5_context context,
                                      krb5_pointer out,
                                      unsigned int length);
 
-OM_uint32 kg_seal (krb5_context context,
-                 OM_uint32 *minor_status,
+OM_uint32 kg_seal (OM_uint32 *minor_status,
                  gss_ctx_id_t context_handle,
                  int conf_req_flag,
                  int qop_req,
@@ -268,8 +267,7 @@ OM_uint32 kg_seal (krb5_context context,
                  gss_buffer_t output_message_buffer,
                  int toktype);
 
-OM_uint32 kg_unseal (krb5_context context,
-                   OM_uint32 *minor_status,
+OM_uint32 kg_unseal (OM_uint32 *minor_status,
                    gss_ctx_id_t context_handle,
                    gss_buffer_t input_token_buffer,
                    gss_buffer_t message_buffer,
@@ -277,8 +275,7 @@ OM_uint32 kg_unseal (krb5_context context,
                    int *qop_state,
                    int toktype);
 
-OM_uint32 kg_seal_size (krb5_context context,
-                                 OM_uint32 *minor_status,
+OM_uint32 kg_seal_size (OM_uint32 *minor_status,
                                  gss_ctx_id_t context_handle,
                                  int conf_req_flag,
                                  gss_qop_t qop_req,
@@ -569,6 +566,8 @@ OM_uint32 krb5_gss_import_sec_context
            gss_ctx_id_t *              /* context_handle */
            );
 
+krb5_error_code krb5_gss_ser_init(krb5_context);
+
 OM_uint32 krb5_gss_release_oid
 (OM_uint32 *,          /* minor_status */
            gss_OID *                   /* oid */
index de85a3a7b90be463e66e73e17f1ac23325ea85b3..a77b9541d21fa31dc87b489e5a27fc9fe90ed9a1 100644 (file)
@@ -161,18 +161,6 @@ kg_get_context(minor_status, context)
    if (!kg_context) {
           if ((code = krb5_init_context(&kg_context)))
                   goto fail;
-          if ((code = krb5_ser_context_init(kg_context)))
-                  goto fail;
-          if ((code = krb5_ser_auth_context_init(kg_context)))
-                  goto fail;
-          if ((code = krb5_ser_ccache_init(kg_context)))
-                  goto fail;
-          if ((code = krb5_ser_rcache_init(kg_context)))
-                  goto fail;
-          if ((code = krb5_ser_keytab_init(kg_context)))
-                  goto fail;
-          if ((code = krb5_ser_auth_context_init(kg_context)))
-              goto fail;
    }
    *context = kg_context;
    *minor_status = 0;
index 3745a7c235e87e568d3ca30322cf7076393350eb..19ddb09d3793c246180b2f9ff5a217e42bb648d5 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * lib/gssapi/krb5/import_sec_context.c
  *
- * Copyright 1995 by the Massachusetts Institute of Technology.
+ * Copyright 1995,2004 by the Massachusetts Institute of Technology.
  * All Rights Reserved.
  *
  * Export of this software from the United States of America may
@@ -29,6 +29,8 @@
  * import_sec_context.c        - Internalize the security context.
  */
 #include "gssapiP_krb5.h"
+/* for serialization initialization functions */
+#include "k5-int.h"
 
 /*
  * Fix up the OID of the mechanism so that uses the static version of
@@ -50,6 +52,22 @@ gss_OID krb5_gss_convert_static_mech_oid(oid)
        return oid;
 }
 
+krb5_error_code
+krb5_gss_ser_init (krb5_context context)
+{
+    krb5_error_code code;
+    static krb5_error_code (*const fns[])(krb5_context) = {
+       krb5_ser_context_init, krb5_ser_auth_context_init,
+       krb5_ser_ccache_init, krb5_ser_rcache_init, krb5_ser_keytab_init,
+    };
+    int i;
+
+    for (i = 0; i < sizeof(fns)/sizeof(fns[0]); i++)
+       if ((code = (fns[i])(context)) != 0)
+           return code;
+    return 0;
+}
+
 OM_uint32
 krb5_gss_import_sec_context(minor_status, interprocess_token, context_handle)
     OM_uint32          *minor_status;
@@ -62,8 +80,21 @@ krb5_gss_import_sec_context(minor_status, interprocess_token, context_handle)
     krb5_gss_ctx_id_t  ctx;
     krb5_octet         *ibp;
 
-    if (GSS_ERROR(kg_get_context(minor_status, &context)))
-       return(GSS_S_FAILURE);
+    /* This is a bit screwy.  We create a krb5 context because we need
+       one when calling the serialization code.  However, one of the
+       objects we're unpacking is a krb5 context, so when we finish,
+       we can throw this one away.  */
+    kret = krb5_init_context(&context);
+    if (kret) {
+       *minor_status = kret;
+       return GSS_S_FAILURE;
+    }
+    kret = krb5_gss_ser_init(context);
+    if (kret) {
+       krb5_free_context(context);
+       *minor_status = kret;
+       return GSS_S_FAILURE;
+    }
 
     /* Assume a tragic failure */
     ctx = (krb5_gss_ctx_id_t) NULL;
@@ -72,9 +103,9 @@ krb5_gss_import_sec_context(minor_status, interprocess_token, context_handle)
     /* Internalize the context */
     ibp = (krb5_octet *) interprocess_token->value;
     blen = (size_t) interprocess_token->length;
-    if ((kret = kg_ctx_internalize(context,
-                                  (krb5_pointer *) &ctx,
-                                  &ibp, &blen))) {
+    kret = kg_ctx_internalize(context, (krb5_pointer *) &ctx, &ibp, &blen);
+    krb5_free_context(context);
+    if (kret) {
        *minor_status = (OM_uint32) kret;
        return(GSS_S_FAILURE);
     }
index 5c156f86d66aa16dd991983bc5486781da9e053a..0954ddc5dd4b0d3126a57a9ff1852b3db187380d 100644 (file)
@@ -43,9 +43,6 @@ krb5_gss_inquire_context(minor_status, context_handle, initiator_name,
    krb5_timestamp now;
    krb5_deltat lifetime;
 
-   if (GSS_ERROR(kg_get_context(minor_status, &context)))
-      return(GSS_S_FAILURE);
-
    if (initiator_name)
       *initiator_name = (gss_name_t) NULL;
    if (acceptor_name)
@@ -66,6 +63,7 @@ krb5_gss_inquire_context(minor_status, context_handle, initiator_name,
 
    init = NULL;
    accept = NULL;
+   context = ctx->k5_context;
 
    if ((code = krb5_timeofday(context, &now))) {
       *minor_status = code;
index 7999a3e1580af757fb959169683c35e881e630cf..30dbcab64cf6e1e3b246efb5827e641ba6c9d795 100644 (file)
@@ -316,9 +316,8 @@ make_seal_token_v1 (krb5_context context,
    and do not encode the ENC_TYPE, MSG_LENGTH, or MSG_TEXT fields */
 
 OM_uint32
-kg_seal(context, minor_status, context_handle, conf_req_flag, qop_req,
+kg_seal(minor_status, context_handle, conf_req_flag, qop_req,
        input_message_buffer, conf_state, output_message_buffer, toktype)
-    krb5_context context;
     OM_uint32 *minor_status;
     gss_ctx_id_t context_handle;
     int conf_req_flag;
@@ -331,6 +330,7 @@ kg_seal(context, minor_status, context_handle, conf_req_flag, qop_req,
     krb5_gss_ctx_id_rec *ctx;
     krb5_error_code code;
     krb5_timestamp now;
+    krb5_context context;
 
     output_message_buffer->length = 0;
     output_message_buffer->value = NULL;
@@ -359,6 +359,7 @@ kg_seal(context, minor_status, context_handle, conf_req_flag, qop_req,
        return(GSS_S_NO_CONTEXT);
     }
 
+    context = ctx->k5_context;
     if ((code = krb5_timeofday(context, &now))) {
        *minor_status = code;
        return(GSS_S_FAILURE);
index 6851352eee927d43eebda6651d46fbeae51b2a59..714610102b5289bc9dfe703f409048a25e640c45 100644 (file)
@@ -475,9 +475,8 @@ kg_unseal_v1(context, minor_status, ctx, ptr, bodysize, message_buffer,
    conf_state is only valid if SEAL. */
 
 OM_uint32
-kg_unseal(context, minor_status, context_handle, input_token_buffer,
+kg_unseal(minor_status, context_handle, input_token_buffer,
          message_buffer, conf_state, qop_state, toktype)
-    krb5_context context;
     OM_uint32 *minor_status;
     gss_ctx_id_t context_handle;
     gss_buffer_t input_token_buffer;
@@ -538,11 +537,11 @@ kg_unseal(context, minor_status, context_handle, input_token_buffer,
     }
 
     if (ctx->proto == 0)
-       return kg_unseal_v1(context, minor_status, ctx, ptr, bodysize,
+       return kg_unseal_v1(ctx->k5_context, minor_status, ctx, ptr, bodysize,
                            message_buffer, conf_state, qop_state,
                            toktype);
     else
-       return gss_krb5int_unseal_token_v3(context, minor_status, ctx,
+       return gss_krb5int_unseal_token_v3(ctx->k5_context, minor_status, ctx,
                                           ptr, bodysize, message_buffer,
                                           conf_state, qop_state, toktype);
 }
index 4639108d512239421d14005b9922af3eb1aa2dfe..f1bf5c53797d6ef2a3ed86df06ca7a7f69f14d5a 100644 (file)
@@ -33,13 +33,9 @@ krb5_gss_process_context_token(minor_status, context_handle,
      gss_ctx_id_t context_handle;
      gss_buffer_t token_buffer;
 {
-   krb5_context context;
    krb5_gss_ctx_id_rec *ctx;
    OM_uint32 majerr;
 
-   if (GSS_ERROR(kg_get_context(minor_status, &context)))
-      return(GSS_S_FAILURE);
-
    /* validate the context handle */
    if (! kg_validate_ctx_id(context_handle)) {
       *minor_status = (OM_uint32) G_VALIDATE_FAILED;
@@ -55,7 +51,7 @@ krb5_gss_process_context_token(minor_status, context_handle,
 
    /* "unseal" the token */
 
-   if (GSS_ERROR(majerr = kg_unseal(context, minor_status, ctx, token_buffer,
+   if (GSS_ERROR(majerr = kg_unseal(minor_status, ctx, token_buffer,
                                    GSS_C_NO_BUFFER, NULL, NULL,
                                    KG_TOK_DEL_CTX)))
       return(majerr);
index 818de191f20a342a6a226046f192f34afe825fc0..63d3dabe0673423e5dcc44211d871e66ee9fb4e5 100644 (file)
@@ -38,12 +38,7 @@ krb5_gss_seal(minor_status, context_handle, conf_req_flag,
      int *conf_state;
      gss_buffer_t output_message_buffer;
 {
-   krb5_context context;
-
-   if (GSS_ERROR(kg_get_context(minor_status, &context)))
-      return(GSS_S_FAILURE);
-
-   return(kg_seal(context, minor_status, context_handle, conf_req_flag,
+   return(kg_seal(minor_status, context_handle, conf_req_flag,
                  qop_req, input_message_buffer, conf_state,
                  output_message_buffer, KG_TOK_SEAL_MSG));
 }
@@ -61,12 +56,7 @@ krb5_gss_wrap(minor_status, context_handle, conf_req_flag,
     int                        *conf_state;
     gss_buffer_t       output_message_buffer;
 {
-    krb5_context       context;
-    
-    if (GSS_ERROR(kg_get_context(minor_status, &context)))
-       return(GSS_S_FAILURE);
-
-    return(kg_seal(context, minor_status, context_handle, conf_req_flag,
+    return(kg_seal(minor_status, context_handle, conf_req_flag,
                   (int) qop_req, input_message_buffer, conf_state,
                   output_message_buffer, KG_TOK_WRAP_MSG));
 }
index e0d0ee0afc8545b3e46b8f12e8178d115b867ded..452ffbf43d0a05f084d020642f28f477df7b900d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * lib/gssapi/krb5/ser_sctx.c
  *
- * Copyright 1995 by the Massachusetts Institute of Technology.
+ * Copyright 1995, 2004 by the Massachusetts Institute of Technology.
  * All Rights Reserved.
  *
  * Export of this software from the United States of America may
@@ -320,6 +320,11 @@ kg_ctx_size(kcontext, arg, sizep)
        if (!kret && ctx->seqstate)
            kret = kg_queue_size(kcontext, ctx->seqstate, &required);
 
+       if (!kret)
+           kret = krb5_size_opaque(kcontext,
+                                   KV5M_CONTEXT,
+                                   (krb5_pointer) ctx->k5_context,
+                                   &required);
        if (!kret)
            kret = krb5_size_opaque(kcontext,
                                    KV5M_AUTH_CONTEXT,
@@ -440,6 +445,12 @@ kg_ctx_externalize(kcontext, arg, buffer, lenremain)
                kret = kg_queue_externalize(kcontext,
                                            ctx->seqstate, &bp, &remain);
 
+           if (!kret)
+               kret = krb5_externalize_opaque(kcontext,
+                                              KV5M_CONTEXT,
+                                              (krb5_pointer) ctx->k5_context,
+                                              &bp, &remain);
+
            if (!kret)
                kret = krb5_externalize_opaque(kcontext,
                                               KV5M_AUTH_CONTEXT,
@@ -511,6 +522,8 @@ kg_ctx_internalize(kcontext, argp, buffer, lenremain)
             xmalloc(sizeof(krb5_gss_ctx_id_rec)))) {
            memset(ctx, 0, sizeof(krb5_gss_ctx_id_rec));
 
+           ctx->k5_context = kcontext;
+
            /* Get static data */
            (void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
            ctx->initiate = (int) ibuf;
@@ -597,6 +610,12 @@ kg_ctx_internalize(kcontext, argp, buffer, lenremain)
                    kret = 0;
            }
                
+           if (!kret)
+               kret = krb5_internalize_opaque(kcontext,
+                                              KV5M_CONTEXT,
+                                              (krb5_pointer *) &ctx->k5_context,
+                                              &bp, &remain);
+
            if (!kret)
                kret = krb5_internalize_opaque(kcontext,
                                               KV5M_AUTH_CONTEXT,
index 0177f40d4883982750e1a066a6da70fd832aa045..2d192c9bb178b08af12824c7c13b1c0ee284168d 100644 (file)
@@ -36,12 +36,7 @@ krb5_gss_sign(minor_status, context_handle,
      gss_buffer_t message_buffer;
      gss_buffer_t message_token;
 {
-   krb5_context context;
-   
-   if (GSS_ERROR(kg_get_context(minor_status, &context)))
-      return(GSS_S_FAILURE);
-
-   return(kg_seal(context, minor_status, context_handle, 0,
+   return(kg_seal(minor_status, context_handle, 0,
                  qop_req, message_buffer, NULL,
                  message_token, KG_TOK_SIGN_MSG));
 }
@@ -56,12 +51,7 @@ krb5_gss_get_mic(minor_status, context_handle, qop_req,
     gss_buffer_t       message_buffer;
     gss_buffer_t       message_token;
 {
-    krb5_context context;
-    
-    if (GSS_ERROR(kg_get_context(minor_status, &context)))
-       return(GSS_S_FAILURE);
-
-    return(kg_seal(context, minor_status, context_handle, 0,
+    return(kg_seal(minor_status, context_handle, 0,
                   (int) qop_req, message_buffer, NULL,
                   message_token, KG_TOK_MIC_MSG));
 }
index 546521e1bf4a816766efe7ac64ac75d8862f4fbe..71dc110486b819932fe112262f891f2d6bb199da 100644 (file)
@@ -37,12 +37,7 @@ krb5_gss_unseal(minor_status, context_handle,
      int *conf_state;
      int *qop_state;
 {
-   krb5_context context;
-
-   if (GSS_ERROR(kg_get_context(minor_status, &context)))
-      return(GSS_S_FAILURE);
-
-   return(kg_unseal(context, minor_status, context_handle,
+   return(kg_unseal(minor_status, context_handle,
                    input_message_buffer, output_message_buffer,
                    conf_state, qop_state, KG_TOK_SEAL_MSG));
 }
@@ -59,14 +54,10 @@ krb5_gss_unwrap(minor_status, context_handle,
     int                        *conf_state;
     gss_qop_t          *qop_state;
 {
-    krb5_context       context;
     OM_uint32          rstat;
     int                        qstate;
 
-    if (GSS_ERROR(kg_get_context(minor_status, &context)))
-       return(GSS_S_FAILURE);
-
-    rstat = kg_unseal(context, minor_status, context_handle,
+    rstat = kg_unseal(minor_status, context_handle,
                      input_message_buffer, output_message_buffer,
                      conf_state, &qstate, KG_TOK_WRAP_MSG);
     if (!rstat && qop_state)
index 0e73056404420b8bed7c29c4e059f3cef264eba4..833697b19e913370c9bc593036662112e15eb80a 100644 (file)
@@ -36,13 +36,7 @@ krb5_gss_verify(minor_status, context_handle,
      gss_buffer_t token_buffer;
      int *qop_state;
 {
-     krb5_context context;
-
-     if (GSS_ERROR(kg_get_context(minor_status, &context)))
-       return(GSS_S_FAILURE);
-
-
-     return(kg_unseal(context, minor_status, context_handle,
+     return(kg_unseal(minor_status, context_handle,
                      token_buffer, message_buffer,
                      NULL, qop_state, KG_TOK_SIGN_MSG));
 }
@@ -58,15 +52,10 @@ krb5_gss_verify_mic(minor_status, context_handle,
     gss_buffer_t       token_buffer;
     gss_qop_t          *qop_state;
 {
-    krb5_context       context;
     OM_uint32          rstat;
     int                        qstate;
 
-    if (GSS_ERROR(kg_get_context(minor_status, &context)))
-       return(GSS_S_FAILURE);
-
-
-    rstat = kg_unseal(context, minor_status, context_handle,
+    rstat = kg_unseal(minor_status, context_handle,
                      token_buffer, message_buffer,
                      NULL, &qstate, KG_TOK_MIC_MSG);
     if (!rstat && qop_state)
index b91c7f7593a399e872e12f98119298cb9258996f..46007063773f6a1efe5bdcb885c48177d67561b3 100644 (file)
@@ -83,15 +83,11 @@ krb5_gss_wrap_size_limit(minor_status, context_handle, conf_req_flag,
     OM_uint32          req_output_size;
     OM_uint32          *max_input_size;
 {
-    krb5_context       context;
     krb5_gss_ctx_id_rec        *ctx;
     OM_uint32          data_size, conflen;
     OM_uint32          ohlen;
     int                        overhead;
 
-    if (GSS_ERROR(kg_get_context(minor_status, &context)))
-       return(GSS_S_FAILURE);
-
     /* only default qop is allowed */
     if (qop_req != GSS_C_QOP_DEFAULT) {
        *minor_status = (OM_uint32) G_UNKNOWN_QOP;
@@ -147,7 +143,7 @@ krb5_gss_wrap_size_limit(minor_status, context_handle, conf_req_flag,
     /* Calculate the token size and subtract that from the output size */
     overhead = 7 + ctx->mech_used->length;
     data_size = req_output_size;
-    conflen = kg_confounder_size(context, ctx->enc);
+    conflen = kg_confounder_size(ctx->k5_context, ctx->enc);
     data_size = (conflen + data_size + 8) & (~(OM_uint32)7);
     ohlen = g_token_size((gss_OID) ctx->mech_used,
                         (unsigned int) (data_size + ctx->cksum_size + 14))