use key copy function
authorJohn Kohl <jtkohl@mit.edu>
Mon, 26 Mar 1990 12:04:20 +0000 (12:04 +0000)
committerJohn Kohl <jtkohl@mit.edu>
Mon, 26 Mar 1990 12:04:20 +0000 (12:04 +0000)
add a cleanup_key() #define, and use it

cleanup:

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

src/lib/krb5/krb/get_in_tkt.c

index 4d158713dea82a1424b9812c0202f94e3c95fc78..f8722e17d5d3290c935c21e1b79fae65ad5c08ed 100644 (file)
@@ -144,14 +144,16 @@ OLDDECLARG(krb5_ccache, ccache)
     /* XXX check the contents for sanity... */
 
     /* fill in the credentials */
-    creds->keyblock = *as_reply->enc_part2->session;
-    if (!(creds->keyblock.contents = (krb5_octet *)malloc(creds->keyblock.length))) {
+    if (retval = krb5_copy_keyblock(as_reply->enc_part2->session,
+                                   &creds->keyblock)) {
        krb5_free_kdc_rep(as_reply);
-       return ENOMEM;
+       return retval;
     }
-
-    bcopy((char *)as_reply->enc_part2->session->contents,
-         (char *)creds->keyblock.contents, creds->keyblock.length);
+#define cleanup_key() {bzero((char *)creds->keyblock.contents, \
+                            creds->keyblock.length); \
+                      free((char *)creds->keyblock.contents); \
+                      creds->keyblock.contents = 0; \
+                      creds->keyblock.length = 0;}
 
     creds->times = as_reply->enc_part2->times;
     creds->is_skey = FALSE;            /* this is an AS_REQ, so cannot
@@ -160,11 +162,10 @@ OLDDECLARG(krb5_ccache, ccache)
     creds->second_ticket.length = 0;
     creds->second_ticket.data = 0;
 
-
     retval = encode_krb5_ticket(as_reply->ticket, &packet);
     krb5_free_kdc_rep(as_reply);
     if (retval) {
-       free((char *)creds->keyblock.contents);
+       cleanup_key();
        return retval;
     }  
     creds->ticket = *packet;
@@ -174,7 +175,7 @@ OLDDECLARG(krb5_ccache, ccache)
     if (retval = krb5_cc_store_cred(ccache, creds)) {
        /* clean up the pieces */
        free((char *)creds->ticket.data);
-       free((char *)creds->keyblock.contents);
+       cleanup_key();
        return retval;
     }
     return 0;