17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * lib/krb5/krb/copy_tick.c
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * Copyright 1990,1991 by the Massachusetts Institute of Technology.
57c478bd9Sstevel@tonic-gate  * All Rights Reserved.
67c478bd9Sstevel@tonic-gate  *
77c478bd9Sstevel@tonic-gate  * Export of this software from the United States of America may
87c478bd9Sstevel@tonic-gate  *   require a specific license from the United States Government.
97c478bd9Sstevel@tonic-gate  *   It is the responsibility of any person or organization contemplating
107c478bd9Sstevel@tonic-gate  *   export to obtain such a license before exporting.
11*55fea89dSDan Cross  *
127c478bd9Sstevel@tonic-gate  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
137c478bd9Sstevel@tonic-gate  * distribute this software and its documentation for any purpose and
147c478bd9Sstevel@tonic-gate  * without fee is hereby granted, provided that the above copyright
157c478bd9Sstevel@tonic-gate  * notice appear in all copies and that both that copyright notice and
167c478bd9Sstevel@tonic-gate  * this permission notice appear in supporting documentation, and that
177c478bd9Sstevel@tonic-gate  * the name of M.I.T. not be used in advertising or publicity pertaining
187c478bd9Sstevel@tonic-gate  * to distribution of the software without specific, written prior
197c478bd9Sstevel@tonic-gate  * permission.  Furthermore if you modify this software you must label
207c478bd9Sstevel@tonic-gate  * your software as modified software and not distribute it in such a
217c478bd9Sstevel@tonic-gate  * fashion that it might be confused with the original M.I.T. software.
227c478bd9Sstevel@tonic-gate  * M.I.T. makes no representations about the suitability of
237c478bd9Sstevel@tonic-gate  * this software for any purpose.  It is provided "as is" without express
247c478bd9Sstevel@tonic-gate  * or implied warranty.
25*55fea89dSDan Cross  *
267c478bd9Sstevel@tonic-gate  *
277c478bd9Sstevel@tonic-gate  * krb5_copy_ticket()
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
30159d09a2SMark Phalan #include "k5-int.h"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate static krb5_error_code
krb5_copy_enc_tkt_part(krb5_context context,const krb5_enc_tkt_part * partfrom,krb5_enc_tkt_part ** partto)33505d05c7Sgtb krb5_copy_enc_tkt_part(krb5_context context, const krb5_enc_tkt_part *partfrom, krb5_enc_tkt_part **partto)
347c478bd9Sstevel@tonic-gate {
357c478bd9Sstevel@tonic-gate     krb5_error_code retval;
367c478bd9Sstevel@tonic-gate     krb5_enc_tkt_part *tempto;
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate     if (!(tempto = (krb5_enc_tkt_part *)malloc(sizeof(*tempto))))
397c478bd9Sstevel@tonic-gate 	return ENOMEM;
407c478bd9Sstevel@tonic-gate     *tempto = *partfrom;
417c478bd9Sstevel@tonic-gate     retval = krb5_copy_keyblock(context, partfrom->session,
427c478bd9Sstevel@tonic-gate 				&tempto->session);
437c478bd9Sstevel@tonic-gate     if (retval) {
447c478bd9Sstevel@tonic-gate 	krb5_xfree(tempto);
457c478bd9Sstevel@tonic-gate 	return retval;
467c478bd9Sstevel@tonic-gate     }
477c478bd9Sstevel@tonic-gate     retval = krb5_copy_principal(context, partfrom->client, &tempto->client);
487c478bd9Sstevel@tonic-gate     if (retval) {
497c478bd9Sstevel@tonic-gate 	krb5_free_keyblock(context, tempto->session);
507c478bd9Sstevel@tonic-gate 	krb5_xfree(tempto);
517c478bd9Sstevel@tonic-gate 	return retval;
527c478bd9Sstevel@tonic-gate     }
537c478bd9Sstevel@tonic-gate     tempto->transited = partfrom->transited;
547c478bd9Sstevel@tonic-gate     if (tempto->transited.tr_contents.length == 0) {
557c478bd9Sstevel@tonic-gate 	tempto->transited.tr_contents.data = 0;
567c478bd9Sstevel@tonic-gate     } else {
577c478bd9Sstevel@tonic-gate 	tempto->transited.tr_contents.data =
587c478bd9Sstevel@tonic-gate 	  malloc(partfrom->transited.tr_contents.length);
597c478bd9Sstevel@tonic-gate 	if (!tempto->transited.tr_contents.data) {
607c478bd9Sstevel@tonic-gate 	    krb5_free_principal(context, tempto->client);
617c478bd9Sstevel@tonic-gate 	    krb5_free_keyblock(context, tempto->session);
627c478bd9Sstevel@tonic-gate 	    krb5_xfree(tempto);
637c478bd9Sstevel@tonic-gate 	    return ENOMEM;
647c478bd9Sstevel@tonic-gate 	}
657c478bd9Sstevel@tonic-gate 	memcpy((char *)tempto->transited.tr_contents.data,
667c478bd9Sstevel@tonic-gate 	       (char *)partfrom->transited.tr_contents.data,
677c478bd9Sstevel@tonic-gate 	       partfrom->transited.tr_contents.length);
687c478bd9Sstevel@tonic-gate     }
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate     retval = krb5_copy_addresses(context, partfrom->caddrs, &tempto->caddrs);
717c478bd9Sstevel@tonic-gate     if (retval) {
727c478bd9Sstevel@tonic-gate 	krb5_xfree(tempto->transited.tr_contents.data);
737c478bd9Sstevel@tonic-gate 	krb5_free_principal(context, tempto->client);
747c478bd9Sstevel@tonic-gate 	krb5_free_keyblock(context, tempto->session);
757c478bd9Sstevel@tonic-gate 	krb5_xfree(tempto);
767c478bd9Sstevel@tonic-gate 	return retval;
777c478bd9Sstevel@tonic-gate     }
787c478bd9Sstevel@tonic-gate     if (partfrom->authorization_data) {
797c478bd9Sstevel@tonic-gate 	retval = krb5_copy_authdata(context, partfrom->authorization_data,
807c478bd9Sstevel@tonic-gate 				    &tempto->authorization_data);
817c478bd9Sstevel@tonic-gate 	if (retval) {
827c478bd9Sstevel@tonic-gate 	    krb5_free_addresses(context, tempto->caddrs);
837c478bd9Sstevel@tonic-gate 	    krb5_xfree(tempto->transited.tr_contents.data);
847c478bd9Sstevel@tonic-gate 	    krb5_free_principal(context, tempto->client);
857c478bd9Sstevel@tonic-gate 	    krb5_free_keyblock(context, tempto->session);
867c478bd9Sstevel@tonic-gate 	    krb5_xfree(tempto);
877c478bd9Sstevel@tonic-gate 	    return retval;
887c478bd9Sstevel@tonic-gate 	}
897c478bd9Sstevel@tonic-gate     }
907c478bd9Sstevel@tonic-gate     *partto = tempto;
917c478bd9Sstevel@tonic-gate     return 0;
927c478bd9Sstevel@tonic-gate }
937c478bd9Sstevel@tonic-gate 
94505d05c7Sgtb krb5_error_code KRB5_CALLCONV
krb5_copy_ticket(krb5_context context,const krb5_ticket * from,krb5_ticket ** pto)95505d05c7Sgtb krb5_copy_ticket(krb5_context context, const krb5_ticket *from, krb5_ticket **pto)
967c478bd9Sstevel@tonic-gate {
977c478bd9Sstevel@tonic-gate     krb5_error_code retval;
987c478bd9Sstevel@tonic-gate     krb5_ticket *tempto;
997c478bd9Sstevel@tonic-gate     krb5_data *scratch;
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate     if (!(tempto = (krb5_ticket *)malloc(sizeof(*tempto))))
1027c478bd9Sstevel@tonic-gate 	return ENOMEM;
1037c478bd9Sstevel@tonic-gate     *tempto = *from;
1047c478bd9Sstevel@tonic-gate     retval = krb5_copy_principal(context, from->server, &tempto->server);
1057c478bd9Sstevel@tonic-gate     if (retval) {
1067c478bd9Sstevel@tonic-gate 	krb5_xfree(tempto);
1077c478bd9Sstevel@tonic-gate 	return retval;
1087c478bd9Sstevel@tonic-gate     }
1097c478bd9Sstevel@tonic-gate     retval = krb5_copy_data(context, &from->enc_part.ciphertext, &scratch);
1107c478bd9Sstevel@tonic-gate     if (retval) {
1117c478bd9Sstevel@tonic-gate 	krb5_free_principal(context, tempto->server);
1127c478bd9Sstevel@tonic-gate 	krb5_xfree(tempto);
1137c478bd9Sstevel@tonic-gate 	return retval;
1147c478bd9Sstevel@tonic-gate     }
1157c478bd9Sstevel@tonic-gate     tempto->enc_part.ciphertext = *scratch;
1167c478bd9Sstevel@tonic-gate     krb5_xfree(scratch);
1177c478bd9Sstevel@tonic-gate     retval = krb5_copy_enc_tkt_part(context, from->enc_part2, &tempto->enc_part2);
1187c478bd9Sstevel@tonic-gate     if (retval) {
1197c478bd9Sstevel@tonic-gate 	krb5_xfree(tempto->enc_part.ciphertext.data);
1207c478bd9Sstevel@tonic-gate 	krb5_free_principal(context, tempto->server);
1217c478bd9Sstevel@tonic-gate 	krb5_xfree(tempto);
1227c478bd9Sstevel@tonic-gate 	return retval;
123*55fea89dSDan Cross     }
1247c478bd9Sstevel@tonic-gate     *pto = tempto;
1257c478bd9Sstevel@tonic-gate     return 0;
1267c478bd9Sstevel@tonic-gate }
127