* acquire_cred.c (krb5_gss_acquire_cred): Create and destroy a local krb5
authorKen Raeburn <raeburn@mit.edu>
Fri, 19 Mar 2004 09:33:57 +0000 (09:33 +0000)
committerKen Raeburn <raeburn@mit.edu>
Fri, 19 Mar 2004 09:33:57 +0000 (09:33 +0000)
context.
* add_cred.c (krb5_gss_add_cred): Likewise.
* compare_name.c (krb5_gss_compare_name): Likewise.
* copy_ccache.c (gss_krb5_copy_ccache): Likewise.
* disp_name.c (krb5_gss_display_name): Likewise.
* duplicate_name.c (krb5_gss_duplicate_name): Likewise.
* inq_cred.c (krb5_gss_inquire_cred): Likewise.

* context_time.c (krb5_gss_context_time): Use the krb5 context in the GSS
security context.

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

src/lib/gssapi/krb5/ChangeLog
src/lib/gssapi/krb5/acquire_cred.c
src/lib/gssapi/krb5/add_cred.c
src/lib/gssapi/krb5/compare_name.c
src/lib/gssapi/krb5/context_time.c
src/lib/gssapi/krb5/copy_ccache.c
src/lib/gssapi/krb5/disp_name.c
src/lib/gssapi/krb5/duplicate_name.c
src/lib/gssapi/krb5/inq_cred.c

index ae317482fe843a0bd2445c8c1421fb518267cd96..d4106013236ed9a301623ba45da5f15c46c77d23 100644 (file)
@@ -1,3 +1,17 @@
+2004-03-19  Ken Raeburn  <raeburn@mit.edu>
+
+       * acquire_cred.c (krb5_gss_acquire_cred): Create and destroy a
+       local krb5 context.
+       * add_cred.c (krb5_gss_add_cred): Likewise.
+       * compare_name.c (krb5_gss_compare_name): Likewise.
+       * copy_ccache.c (gss_krb5_copy_ccache): Likewise.
+       * disp_name.c (krb5_gss_display_name): Likewise.
+       * duplicate_name.c (krb5_gss_duplicate_name): Likewise.
+       * inq_cred.c (krb5_gss_inquire_cred): Likewise.
+
+       * context_time.c (krb5_gss_context_time): Use the krb5 context in
+       the GSS security context.
+
 2004-03-15  Ken Raeburn  <raeburn@mit.edu>
 
        * k5seal.c (kg_seal): Extract the krb5 context from the security
index 0a0de14b99a87d5dc1ff6d20094a318d8b9651f9..e652c664c117e9f7bf81d7dcebb74196af2432c8 100644 (file)
@@ -331,9 +331,6 @@ krb5_gss_acquire_cred(minor_status, desired_name, time_req,
    OM_uint32 ret;
    krb5_error_code code;
 
-   if (GSS_ERROR(kg_get_context(minor_status, &context)))
-      return(GSS_S_FAILURE);
-
    /* make sure all outputs are valid */
 
    *output_cred_handle = NULL;
@@ -402,6 +399,13 @@ krb5_gss_acquire_cred(minor_status, desired_name, time_req,
    /* if requested, acquire credentials for accepting */
    /* this will fill in cred->princ if the desired_name is not specified */
 
+   code = krb5_init_context(&context);
+   if (code) {
+       xfree(cred);
+       *minor_status = (OM_uint32) code;
+       return GSS_S_FAILURE;
+   }
+
    if ((cred_usage == GSS_C_ACCEPT) ||
        (cred_usage == GSS_C_BOTH))
       if ((ret = acquire_accept_cred(context, minor_status, desired_name,
@@ -410,6 +414,7 @@ krb5_gss_acquire_cred(minor_status, desired_name, time_req,
         if (cred->princ)
            krb5_free_principal(context, cred->princ);
         xfree(cred);
+        krb5_free_context(context);
         /* minor_status set by acquire_accept_cred() */
         return(ret);
       }
@@ -430,6 +435,7 @@ krb5_gss_acquire_cred(minor_status, desired_name, time_req,
         if (cred->princ)
            krb5_free_principal(context, cred->princ);
         xfree(cred);
+        krb5_free_context(context);
         /* minor_status set by acquire_init_cred() */
         return(ret);
       }
@@ -444,6 +450,7 @@ krb5_gss_acquire_cred(minor_status, desired_name, time_req,
         if (cred->keytab)
            (void)krb5_kt_close(context, cred->keytab);
         xfree(cred);
+        krb5_free_context(context);
         *minor_status = code;
         return(GSS_S_FAILURE);
       }
@@ -466,6 +473,7 @@ krb5_gss_acquire_cred(minor_status, desired_name, time_req,
         if (cred->princ)
            krb5_free_principal(context, cred->princ);
         xfree(cred);
+        krb5_free_context(context);
         *minor_status = code;
         return(GSS_S_FAILURE);
       }
@@ -494,6 +502,7 @@ krb5_gss_acquire_cred(minor_status, desired_name, time_req,
           if (cred->princ)
               krb5_free_principal(context, cred->princ);
           xfree(cred);
+          krb5_free_context(context);
           /* *minor_status set above */
           return(ret);
        }
@@ -511,6 +520,7 @@ krb5_gss_acquire_cred(minor_status, desired_name, time_req,
       if (cred->princ)
         krb5_free_principal(context, cred->princ);
       xfree(cred);
+      krb5_free_context(context);
       *minor_status = (OM_uint32) G_VALIDATE_FAILED;
       return(GSS_S_FAILURE);
    }
@@ -522,5 +532,6 @@ krb5_gss_acquire_cred(minor_status, desired_name, time_req,
    if (actual_mechs)
       *actual_mechs = ret_mechs;
 
+   krb5_free_context(context);
    return(GSS_S_COMPLETE);
 }
index 254abfe06828fc455c447264f17240af2d460554..085b96d31b9c8d98f7000a6d319d85cea8b71fe5 100644 (file)
@@ -138,8 +138,11 @@ krb5_gss_add_cred(minor_status, input_cred_handle,
        return(GSS_S_DUPLICATE_ELEMENT);
     }
 
-    if (GSS_ERROR(kg_get_context(minor_status, &context)))
-       return(GSS_S_FAILURE);
+    code = krb5_init_context(&context);
+    if (code) {
+       *minor_status = code;
+       return GSS_S_FAILURE;
+    }
 
     /* verify the desired_name */
 
@@ -147,6 +150,7 @@ krb5_gss_add_cred(minor_status, input_cred_handle,
     if ((desired_name != (gss_name_t) NULL) &&
        (! kg_validate_name(desired_name))) {
        *minor_status = (OM_uint32) G_VALIDATE_FAILED;
+       krb5_free_context(context);
        return(GSS_S_CALL_BAD_STRUCTURE|GSS_S_BAD_NAME);
     }
 
@@ -156,6 +160,7 @@ krb5_gss_add_cred(minor_status, input_cred_handle,
        !krb5_principal_compare(context, (krb5_principal) desired_name,
                                cred->princ)) {
        *minor_status = 0;
+       krb5_free_context(context);
        return(GSS_S_BAD_NAME);
     }
 
@@ -172,6 +177,7 @@ krb5_gss_add_cred(minor_status, input_cred_handle,
             (krb5_gss_cred_id_t) xmalloc(sizeof(krb5_gss_cred_id_rec)))
            == NULL) {
            *minor_status = ENOMEM;
+           krb5_free_context(context);
            return(GSS_S_FAILURE);
        }
        memset(new_cred, 0, sizeof(krb5_gss_cred_id_rec));
@@ -187,6 +193,7 @@ krb5_gss_add_cred(minor_status, input_cred_handle,
            xfree(new_cred);
 
            *minor_status = code;
+           krb5_free_context(context);
            return(GSS_S_FAILURE);
        }
            
@@ -198,6 +205,7 @@ krb5_gss_add_cred(minor_status, input_cred_handle,
                xfree(new_cred);
 
                *minor_status = ENOMEM;
+               krb5_free_context(context);
                return(GSS_S_FAILURE);
            }
 
@@ -214,6 +222,7 @@ krb5_gss_add_cred(minor_status, input_cred_handle,
                xfree(new_cred);
 
                *minor_status = code;
+               krb5_free_context(context);
                return(GSS_S_FAILURE);
            }
 
@@ -224,6 +233,7 @@ krb5_gss_add_cred(minor_status, input_cred_handle,
                xfree(new_cred);
 
                *minor_status = code;
+               krb5_free_context(context);
                return(GSS_S_FAILURE);
            }
        } else {
@@ -241,6 +251,7 @@ krb5_gss_add_cred(minor_status, input_cred_handle,
                    krb5_free_principal(context, new_cred->princ);
                xfree(new_cred);
 
+               krb5_free_context(context);
                *minor_status = code;
                return(GSS_S_FAILURE);
            }
@@ -261,6 +272,7 @@ krb5_gss_add_cred(minor_status, input_cred_handle,
                krb5_free_principal(context, new_cred->princ);
                xfree(new_cred);
 
+               krb5_free_context(context);
                *minor_status = ENOMEM;
                return(GSS_S_FAILURE);
            }
@@ -279,6 +291,7 @@ krb5_gss_add_cred(minor_status, input_cred_handle,
                if (new_cred->princ)
                    krb5_free_principal(context, new_cred->princ);
                xfree(new_cred);
+               krb5_free_context(context);
 
                *minor_status = code;
                return(GSS_S_FAILURE);
@@ -299,6 +312,7 @@ krb5_gss_add_cred(minor_status, input_cred_handle,
            if (new_cred->princ)
            krb5_free_principal(context, new_cred->princ);
            xfree(new_cred);
+           krb5_free_context(context);
 
            *minor_status = (OM_uint32) G_VALIDATE_FAILED;
            return(GSS_S_FAILURE);
@@ -325,6 +339,7 @@ krb5_gss_add_cred(minor_status, input_cred_handle,
        
        if (output_cred_handle)
            (void) krb5_gss_release_cred(&dummy, (gss_cred_id_t *) &cred);
+       krb5_free_context(context);
 
        return(major_status);
     }
@@ -337,6 +352,7 @@ krb5_gss_add_cred(minor_status, input_cred_handle,
     if (output_cred_handle)
        *output_cred_handle = cred;
 
+    krb5_free_context(context);
     *minor_status = 0;
     return(GSS_S_COMPLETE);
 }
index 75a534220da16553293b4f74cf03c67d617c9dc0..12201bf0017137bffdc7201de105d11d5a5adeab 100644 (file)
@@ -34,9 +34,7 @@ krb5_gss_compare_name(minor_status, name1, name2, name_equal)
      int *name_equal;
 { 
    krb5_context context;
-
-   if (GSS_ERROR(kg_get_context(minor_status, &context)))
-      return(GSS_S_FAILURE);
+   krb5_error_code code;
 
    if (! kg_validate_name(name1)) {
       *minor_status = (OM_uint32) G_VALIDATE_FAILED;
@@ -48,8 +46,15 @@ krb5_gss_compare_name(minor_status, name1, name2, name_equal)
       return(GSS_S_CALL_BAD_STRUCTURE|GSS_S_BAD_NAME);
    }
 
+   code = krb5_init_context(&context);
+   if (code) {
+       *minor_status = code;
+       return GSS_S_FAILURE;
+   }
+
    *minor_status = 0;
    *name_equal = krb5_principal_compare(context, (krb5_principal) name1,
                                        (krb5_principal) name2);
+   krb5_free_context(context);
    return(GSS_S_COMPLETE);
 }
index 8b94ee587d362886e1453bed8ef855c38851edc6..8b7930ffd96f12d8b07e9e6fe502727bb9d7d423 100644 (file)
@@ -32,15 +32,11 @@ krb5_gss_context_time(minor_status, context_handle, time_rec)
      gss_ctx_id_t context_handle;
      OM_uint32 *time_rec;
 {
-   krb5_context context;
    krb5_error_code code;
    krb5_gss_ctx_id_rec *ctx;
    krb5_timestamp now;
    krb5_deltat lifetime;
 
-   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;
@@ -54,7 +50,7 @@ krb5_gss_context_time(minor_status, context_handle, time_rec)
       return(GSS_S_NO_CONTEXT);
    }
 
-   if ((code = krb5_timeofday(context, &now))) {
+   if ((code = krb5_timeofday(ctx->k5_context, &now))) {
       *minor_status = code;
       return(GSS_S_FAILURE);
    }
index 3770cb7322fc8b75e425ea65dc16143c4f80903d..d20f72c77c1e1608f3d5061456efb75c73a56004 100644 (file)
@@ -24,18 +24,23 @@ gss_krb5_copy_ccache(minor_status, cred_handle, out_ccache)
        return(GSS_S_FAILURE);
    }
 
-   if (GSS_ERROR(kg_get_context(minor_status, &context)))
-       return (GSS_S_FAILURE);
+   code = krb5_init_context(&context);
+   if (code) {
+       *minor_status = code;
+       return GSS_S_FAILURE;
+   }
 
    code = krb5_cc_start_seq_get(context, k5creds->ccache, &cursor);
    if (code) {
        *minor_status = code;
+       krb5_free_context(context);
        return(GSS_S_FAILURE);
    }
    while (!code && !krb5_cc_next_cred(context, k5creds->ccache, &cursor, &creds)) 
        code = krb5_cc_store_cred(context, out_ccache, &creds);
    krb5_cc_end_seq_get(context, k5creds->ccache, &cursor);
 
+   krb5_free_context(context);
    if (code) {
        *minor_status = code;
        return(GSS_S_FAILURE);
index ba01fd4ea7f86d5fd6f12690dc506bb1b28b05fb..419f350b509adf3626138b49c09ac0e5944f03d4 100644 (file)
@@ -34,31 +34,38 @@ krb5_gss_display_name(minor_status, input_name, output_name_buffer,
    krb5_error_code code;
    char *str;
 
-   if (GSS_ERROR(kg_get_context(minor_status, &context)))
-      return(GSS_S_FAILURE);
+   code = krb5_init_context(&context);
+   if (code) {
+       *minor_status = code;
+       return GSS_S_FAILURE;
+   }
 
    output_name_buffer->length = 0;
    output_name_buffer->value = NULL;
 
    if (! kg_validate_name(input_name)) {
       *minor_status = (OM_uint32) G_VALIDATE_FAILED;
+      krb5_free_context(context);
       return(GSS_S_CALL_BAD_STRUCTURE|GSS_S_BAD_NAME);
    }
 
    if ((code = krb5_unparse_name(context,
                                 (krb5_principal) input_name, &str))) {
       *minor_status = code;
+      krb5_free_context(context);
       return(GSS_S_FAILURE);
    }
 
    if (! g_make_string_buffer(str, output_name_buffer)) {
       krb5_free_unparsed_name(context, str);
+      krb5_free_context(context);
 
       *minor_status = (OM_uint32) G_BUFFER_ALLOC;
       return(GSS_S_FAILURE);
    }
 
    krb5_free_unparsed_name(context, str);
+   krb5_free_context(context);
 
    *minor_status = 0;
    if (output_name_type)
index 3b8506cb02761154e340897a960ea53e041cdc29..c186ed4f0f19c7f57ea623877c5624a87765c485 100644 (file)
@@ -35,27 +35,34 @@ OM_uint32 krb5_gss_duplicate_name(OM_uint32  *minor_status,
        krb5_error_code code;
        krb5_principal princ, outprinc;
 
-       if (GSS_ERROR(kg_get_context(minor_status, &context)))
-               return(GSS_S_FAILURE);
+       code = krb5_init_context(&context);
+       if (code) {
+           *minor_status = code;
+           return GSS_S_FAILURE;
+       }
 
        if (! kg_validate_name(input_name)) {
                if (minor_status)
                        *minor_status = (OM_uint32) G_VALIDATE_FAILED;
+               krb5_free_context(context);
                return(GSS_S_CALL_BAD_STRUCTURE|GSS_S_BAD_NAME);
        }
 
        princ = input_name;
        if ((code = krb5_copy_principal(context, princ, &outprinc))) {
                *minor_status = code;
+               krb5_free_context(context);
                return(GSS_S_FAILURE);
        }
 
        if (! kg_save_name((gss_name_t) outprinc)) {
                krb5_free_principal(context, outprinc);
+               krb5_free_context(context);
                *minor_status = (OM_uint32) G_VALIDATE_FAILED;
                return(GSS_S_FAILURE);
        }
        
+       krb5_free_context(context);
        *dest_name = (gss_name_t) outprinc;
        return(GSS_S_COMPLETE);
        
index 14ec0daa10c8eed48fd9d6b7ee6d11797abccf52..b0a426aa54076979bb38630fddfc14f5a2d26135 100644 (file)
@@ -93,8 +93,11 @@ krb5_gss_inquire_cred(minor_status, cred_handle, name, lifetime_ret,
 
    ret = GSS_S_FAILURE;
 
-   if (GSS_ERROR(kg_get_context(minor_status, &context)))
-      return(GSS_S_FAILURE);
+   code = krb5_init_context(&context);
+   if (code) {
+       *minor_status = code;
+       return GSS_S_FAILURE;
+   }
 
    if (name) *name = NULL;
    if (mechanisms) *mechanisms = NULL;
@@ -106,14 +109,17 @@ krb5_gss_inquire_cred(minor_status, cred_handle, name, lifetime_ret,
 
       if ((major = kg_get_defcred(minor_status, (gss_cred_id_t)&cred)) &&
          GSS_ERROR(major)) {
+        krb5_free_context(context);
         return(major);
       }
    } else {
       OM_uint32 major;
           
       major = krb5_gss_validate_cred(minor_status, cred_handle);
-      if (GSS_ERROR(major))
+      if (GSS_ERROR(major)) {
+         krb5_free_context(context);
          return(major);
+      }
       cred = (krb5_gss_cred_id_t) cred_handle;
    }
 
@@ -161,6 +167,7 @@ krb5_gss_inquire_cred(minor_status, cred_handle, name, lifetime_ret,
         (void) gss_release_oid_set(minor_status, &mechs);
         krb5_free_principal(context, ret_name);
         *minor_status = (OM_uint32) G_VALIDATE_FAILED;
+        krb5_free_context(context);
         return(GSS_S_FAILURE);
       }
       *name = (gss_name_t) ret_name;
@@ -178,6 +185,7 @@ krb5_gss_inquire_cred(minor_status, cred_handle, name, lifetime_ret,
    if (cred_handle == GSS_C_NO_CREDENTIAL)
        krb5_gss_release_cred(minor_status, (gss_cred_id_t)cred);
 
+   krb5_free_context(context);
    *minor_status = 0;
    return((lifetime == 0)?GSS_S_CREDENTIALS_EXPIRED:GSS_S_COMPLETE);
 fail:
@@ -186,6 +194,7 @@ fail:
 
        krb5_gss_release_cred(&tmp_min_stat, (gss_cred_id_t)cred);
    }
+   krb5_free_context(context);
    return ret;
 }