1 /* 2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3 * Use is subject to license terms. 4 */ 5 6 #pragma ident "%Z%%M% %I% %E% SMI" 7 8 /* 9 * lib/krb5/krb/copy_athctr.c 10 * 11 * Copyright 1990,1991 by the Massachusetts Institute of Technology. 12 * All Rights Reserved. 13 * 14 * Export of this software from the United States of America may 15 * require a specific license from the United States Government. 16 * It is the responsibility of any person or organization contemplating 17 * export to obtain such a license before exporting. 18 * 19 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and 20 * distribute this software and its documentation for any purpose and 21 * without fee is hereby granted, provided that the above copyright 22 * notice appear in all copies and that both that copyright notice and 23 * this permission notice appear in supporting documentation, and that 24 * the name of M.I.T. not be used in advertising or publicity pertaining 25 * to distribution of the software without specific, written prior 26 * permission. Furthermore if you modify this software you must label 27 * your software as modified software and not distribute it in such a 28 * fashion that it might be confused with the original M.I.T. software. 29 * M.I.T. makes no representations about the suitability of 30 * this software for any purpose. It is provided "as is" without express 31 * or implied warranty. 32 * 33 * 34 * krb5_copy_authenticator() 35 */ 36 37 #include <k5-int.h> 38 39 krb5_error_code KRB5_CALLCONV 40 krb5_copy_authenticator(krb5_context context, const krb5_authenticator *authfrom, krb5_authenticator **authto) 41 { 42 krb5_error_code retval; 43 krb5_authenticator *tempto; 44 45 if (!(tempto = (krb5_authenticator *)MALLOC(sizeof(*tempto)))) 46 return ENOMEM; 47 #ifdef HAVE_C_STRUCTURE_ASSIGNMENT 48 *tempto = *authfrom; 49 #else 50 (void) memcpy(tempto, authfrom, sizeof(krb5_authenticator)); 51 #endif 52 53 retval = krb5_copy_principal(context, authfrom->client, &tempto->client); 54 if (retval) { 55 krb5_xfree_wrap(tempto, sizeof(*tempto)); 56 return retval; 57 } 58 59 if (authfrom->checksum && 60 (retval = krb5_copy_checksum(context, authfrom->checksum, &tempto->checksum))) { 61 krb5_free_principal(context, tempto->client); 62 krb5_xfree_wrap(tempto, sizeof(*tempto)); 63 return retval; 64 } 65 66 if (authfrom->subkey) { 67 retval = krb5_copy_keyblock(context, authfrom->subkey, &tempto->subkey); 68 if (retval) { 69 krb5_xfree_wrap(tempto->subkey, sizeof(krb5_keyblock)); 70 krb5_free_checksum(context, tempto->checksum); 71 krb5_free_principal(context, tempto->client); 72 krb5_xfree_wrap(tempto, sizeof(*tempto)); 73 return retval; 74 } 75 } 76 77 if (authfrom->authorization_data) { 78 retval = krb5_copy_authdata(context, authfrom->authorization_data, 79 &tempto->authorization_data); 80 if (retval) { 81 krb5_xfree_wrap(tempto->subkey, sizeof(krb5_keyblock)); 82 krb5_free_checksum(context, tempto->checksum); 83 krb5_free_principal(context, tempto->client); 84 krb5_free_authdata(context, tempto->authorization_data); 85 krb5_xfree_wrap(tempto, sizeof(*tempto)); 86 return retval; 87 } 88 } 89 90 *authto = tempto; 91 return 0; 92 } 93