1 /* 2 * Copyright 2004 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 * lib/krb5/krb/copy_auth.c 9 * 10 * Copyright 1990 by the Massachusetts Institute of Technology. 11 * All Rights Reserved. 12 * 13 * Export of this software from the United States of America may 14 * require a specific license from the United States Government. 15 * It is the responsibility of any person or organization contemplating 16 * export to obtain such a license before exporting. 17 * 18 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and 19 * distribute this software and its documentation for any purpose and 20 * without fee is hereby granted, provided that the above copyright 21 * notice appear in all copies and that both that copyright notice and 22 * this permission notice appear in supporting documentation, and that 23 * the name of M.I.T. not be used in advertising or publicity pertaining 24 * to distribution of the software without specific, written prior 25 * permission. Furthermore if you modify this software you must label 26 * your software as modified software and not distribute it in such a 27 * fashion that it might be confused with the original M.I.T. software. 28 * M.I.T. makes no representations about the suitability of 29 * this software for any purpose. It is provided "as is" without express 30 * or implied warranty. 31 * 32 * 33 * krb5_copy_authdata() 34 */ 35 36 #include <k5-int.h> 37 38 /*ARGSUSED*/ 39 static krb5_error_code 40 krb5_copy_authdatum(context, inad, outad) 41 krb5_context context; 42 const krb5_authdata *inad; 43 krb5_authdata **outad; 44 { 45 krb5_authdata *tmpad; 46 47 if (!(tmpad = (krb5_authdata *)MALLOC(sizeof(*tmpad)))) 48 return ENOMEM; 49 #ifdef HAVE_C_STRUCTURE_ASSIGNMENT 50 *tmpad = *inad; 51 #else 52 (void) memcpy(tmpad, inad, sizeof(krb5_authdata)); 53 #endif 54 if (!(tmpad->contents = (krb5_octet *)MALLOC(inad->length))) { 55 krb5_xfree_wrap(tmpad, inad->length); 56 return ENOMEM; 57 } 58 (void) memcpy((char *)tmpad->contents, (char *)inad->contents, 59 inad->length); 60 *outad = tmpad; 61 return 0; 62 } 63 64 /* 65 * Copy an authdata array, with fresh allocation. 66 */ 67 KRB5_DLLIMP krb5_error_code KRB5_CALLCONV 68 krb5_copy_authdata(context, inauthdat, outauthdat) 69 krb5_context context; 70 krb5_authdata FAR * const FAR * inauthdat; 71 krb5_authdata FAR * FAR * FAR *outauthdat; 72 { 73 krb5_error_code retval; 74 krb5_authdata ** tempauthdat; 75 register int nelems = 0; 76 77 if (!inauthdat) { 78 *outauthdat = 0; 79 return 0; 80 } 81 82 while (inauthdat[nelems]) nelems++; 83 84 /* one more for a null terminated list */ 85 if (!(tempauthdat = (krb5_authdata **) CALLOC(nelems+1, 86 sizeof(*tempauthdat)))) 87 return ENOMEM; 88 89 for (nelems = 0; inauthdat[nelems]; nelems++) { 90 retval = krb5_copy_authdatum(context, inauthdat[nelems], 91 &tempauthdat[nelems]); 92 if (retval) { 93 krb5_free_authdata(context, tempauthdat); 94 return retval; 95 } 96 } 97 98 *outauthdat = tempauthdat; 99 return 0; 100 } 101