Path: blob/main/crypto/krb5/src/lib/gssapi/mechglue/g_dup_name.c
39586 views
/*1* Copyright 2004 Sun Microsystems, Inc. All rights reserved.2* Use is subject to license terms.3*/45/* #pragma ident "@(#)g_dup_name.c 1.14 04/02/23 SMI" */67/*8* routine gss_duplicate_name9*10* This routine does not rely on mechanism implementation of this11* name, but instead uses mechanism specific gss_import_name routine.12*/1314#include <mglueP.h>15#ifdef HAVE_STDLIB_H16#include <stdlib.h>17#endif18#include <string.h>19#include <errno.h>2021static OM_uint3222val_dup_name_args(23OM_uint32 *minor_status,24const gss_name_t src_name,25gss_name_t *dest_name)26{2728/* Initialize outputs. */2930if (minor_status != NULL)31*minor_status = 0;3233if (dest_name != NULL)34*dest_name = GSS_C_NO_NAME;3536/* Validate arguments. */3738if (minor_status == NULL)39return (GSS_S_CALL_INACCESSIBLE_WRITE);4041/* if output_name is NULL, simply return */42if (dest_name == NULL)43return (GSS_S_CALL_INACCESSIBLE_WRITE);4445if (src_name == GSS_C_NO_NAME)46return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_BAD_NAME);4748return (GSS_S_COMPLETE);49}505152OM_uint32 KRB5_CALLCONV53gss_duplicate_name(OM_uint32 *minor_status, const gss_name_t src_name,54gss_name_t *dest_name)55{56gss_union_name_t src_union, dest_union;57OM_uint32 major_status = GSS_S_FAILURE;5859major_status = val_dup_name_args(minor_status, src_name, dest_name);60if (major_status != GSS_S_COMPLETE)61return (major_status);6263src_union = (gss_union_name_t)src_name;6465/*66* First create the union name struct that will hold the external67* name and the name type.68*/69dest_union = (gss_union_name_t)malloc(sizeof (gss_union_name_desc));70if (!dest_union)71goto allocation_failure;7273dest_union->loopback = 0;74dest_union->mech_type = 0;75dest_union->mech_name = 0;76dest_union->name_type = 0;77dest_union->external_name = 0;7879/* Now copy the external representation. */80if (gssint_create_copy_buffer(src_union->external_name,81&dest_union->external_name, 0))82goto allocation_failure;8384if (src_union->name_type != GSS_C_NULL_OID) {85major_status = generic_gss_copy_oid(minor_status,86src_union->name_type,87&dest_union->name_type);88if (major_status != GSS_S_COMPLETE) {89map_errcode(minor_status);90goto allocation_failure;91}92}9394/*95* See if source name is mechanim specific, if so then need to import it96*/97if (src_union->mech_type) {98major_status = generic_gss_copy_oid(minor_status,99src_union->mech_type,100&dest_union->mech_type);101if (major_status != GSS_S_COMPLETE) {102map_errcode(minor_status);103goto allocation_failure;104}105106major_status = gssint_import_internal_name(minor_status,107src_union->mech_type,108src_union,109&dest_union->mech_name);110if (major_status != GSS_S_COMPLETE)111goto allocation_failure;112}113114115dest_union->loopback = dest_union;116*dest_name = (gss_name_t)dest_union;117return (GSS_S_COMPLETE);118119allocation_failure:120if (dest_union) {121if (dest_union->external_name) {122if (dest_union->external_name->value)123free(dest_union->external_name->value);124free(dest_union->external_name);125}126if (dest_union->name_type)127(void) generic_gss_release_oid(minor_status,128&dest_union->name_type);129if (dest_union->mech_name)130(void) gssint_release_internal_name(minor_status,131dest_union->mech_type,132&dest_union->mech_name);133if (dest_union->mech_type)134(void) generic_gss_release_oid(minor_status,135&dest_union->mech_type);136free(dest_union);137}138return (major_status);139} /* gss_duplicate_name */140141142