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