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