10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*5053Sgtb  * Common Development and Distribution License (the "License").
6*5053Sgtb  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*5053Sgtb  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate  *  routine gss_duplicate_name
300Sstevel@tonic-gate  *
310Sstevel@tonic-gate  * This routine does not rely on mechanism implementation of this
320Sstevel@tonic-gate  * name, but instead uses mechanism specific gss_import_name routine.
330Sstevel@tonic-gate  */
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #include <mechglueP.h>
360Sstevel@tonic-gate #ifdef HAVE_STDLIB_H
370Sstevel@tonic-gate #include <stdlib.h>
380Sstevel@tonic-gate #endif
390Sstevel@tonic-gate #include <string.h>
400Sstevel@tonic-gate #include <errno.h>
410Sstevel@tonic-gate 
420Sstevel@tonic-gate OM_uint32
430Sstevel@tonic-gate gss_duplicate_name(minor_status,
440Sstevel@tonic-gate 		src_name,
450Sstevel@tonic-gate 		dest_name)
460Sstevel@tonic-gate OM_uint32 *minor_status;
470Sstevel@tonic-gate const gss_name_t src_name;
480Sstevel@tonic-gate gss_name_t *dest_name;
490Sstevel@tonic-gate {
500Sstevel@tonic-gate 		gss_union_name_t src_union, dest_union;
510Sstevel@tonic-gate 		OM_uint32 major_status = GSS_S_FAILURE;
520Sstevel@tonic-gate 
530Sstevel@tonic-gate 
540Sstevel@tonic-gate 	if (!minor_status)
550Sstevel@tonic-gate 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
560Sstevel@tonic-gate 
570Sstevel@tonic-gate 	*minor_status = 0;
580Sstevel@tonic-gate 
590Sstevel@tonic-gate 	/* if output_name is NULL, simply return */
600Sstevel@tonic-gate 	if (dest_name == NULL)
610Sstevel@tonic-gate 		return (GSS_S_CALL_INACCESSIBLE_WRITE | GSS_S_BAD_NAME);
620Sstevel@tonic-gate 
630Sstevel@tonic-gate 	*dest_name = 0;
640Sstevel@tonic-gate 
650Sstevel@tonic-gate 	if (src_name == NULL)
660Sstevel@tonic-gate 		return (GSS_S_CALL_INACCESSIBLE_READ);
670Sstevel@tonic-gate 
680Sstevel@tonic-gate 	src_union = (gss_union_name_t)src_name;
690Sstevel@tonic-gate 
700Sstevel@tonic-gate 	/*
710Sstevel@tonic-gate 	 * First create the union name struct that will hold the external
720Sstevel@tonic-gate 	 * name and the name type.
730Sstevel@tonic-gate 	 */
740Sstevel@tonic-gate 	dest_union = (gss_union_name_t)malloc(sizeof (gss_union_name_desc));
750Sstevel@tonic-gate 	if (!dest_union)
760Sstevel@tonic-gate 		goto allocation_failure;
770Sstevel@tonic-gate 
780Sstevel@tonic-gate 	dest_union->mech_type = 0;
790Sstevel@tonic-gate 	dest_union->mech_name = 0;
800Sstevel@tonic-gate 	dest_union->name_type = 0;
810Sstevel@tonic-gate 	dest_union->external_name = 0;
820Sstevel@tonic-gate 
830Sstevel@tonic-gate 	/* Now copy the external representaion */
84*5053Sgtb 	if (gssint_create_copy_buffer(src_union->external_name,
850Sstevel@tonic-gate 				&dest_union->external_name, 0))
860Sstevel@tonic-gate 		goto allocation_failure;
870Sstevel@tonic-gate 
880Sstevel@tonic-gate 	if (src_union->name_type != GSS_C_NULL_OID) {
890Sstevel@tonic-gate 		major_status = generic_gss_copy_oid(minor_status,
900Sstevel@tonic-gate 						src_union->name_type,
910Sstevel@tonic-gate 						&dest_union->name_type);
920Sstevel@tonic-gate 		if (major_status != GSS_S_COMPLETE)
930Sstevel@tonic-gate 			goto allocation_failure;
940Sstevel@tonic-gate 	}
950Sstevel@tonic-gate 
960Sstevel@tonic-gate 	/*
970Sstevel@tonic-gate 	 * See if source name is mechanim specific, if so then need to import it
980Sstevel@tonic-gate 	 */
990Sstevel@tonic-gate 	if (src_union->mech_type) {
1000Sstevel@tonic-gate 		major_status = generic_gss_copy_oid(minor_status,
1010Sstevel@tonic-gate 							src_union->mech_type,
1020Sstevel@tonic-gate 							&dest_union->mech_type);
1030Sstevel@tonic-gate 		if (major_status != GSS_S_COMPLETE)
1040Sstevel@tonic-gate 			goto allocation_failure;
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate 		major_status = __gss_import_internal_name(minor_status,
1070Sstevel@tonic-gate 							dest_union->mech_type,
1080Sstevel@tonic-gate 							dest_union,
1090Sstevel@tonic-gate 							&dest_union->mech_name);
1100Sstevel@tonic-gate 		if (major_status != GSS_S_COMPLETE)
1110Sstevel@tonic-gate 			goto allocation_failure;
1120Sstevel@tonic-gate 	}
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate 	*dest_name = (gss_name_t)dest_union;
1160Sstevel@tonic-gate 	return (GSS_S_COMPLETE);
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate allocation_failure:
1190Sstevel@tonic-gate 	if (dest_union) {
1200Sstevel@tonic-gate 		if (dest_union->external_name) {
1210Sstevel@tonic-gate 			if (dest_union->external_name->value)
1220Sstevel@tonic-gate 				free(dest_union->external_name->value);
1230Sstevel@tonic-gate 				free(dest_union->external_name);
1240Sstevel@tonic-gate 		}
1250Sstevel@tonic-gate 		if (dest_union->name_type)
1260Sstevel@tonic-gate 			(void) generic_gss_release_oid(minor_status,
1270Sstevel@tonic-gate 							&dest_union->name_type);
1280Sstevel@tonic-gate 		if (dest_union->mech_name)
1290Sstevel@tonic-gate 			(void) __gss_release_internal_name(minor_status,
1300Sstevel@tonic-gate 						dest_union->mech_type,
1310Sstevel@tonic-gate 						&dest_union->mech_name);
1320Sstevel@tonic-gate 		if (dest_union->mech_type)
1330Sstevel@tonic-gate 			(void) generic_gss_release_oid(minor_status,
1340Sstevel@tonic-gate 							&dest_union->mech_type);
1350Sstevel@tonic-gate 		free(dest_union);
1360Sstevel@tonic-gate 	}
1370Sstevel@tonic-gate 	return (major_status);
1380Sstevel@tonic-gate } /*	gss_duplicate_name	*/
139