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
55053Sgtb * Common Development and Distribution License (the "License").
65053Sgtb * 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*13132SGlenn.Barry@oracle.com * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate */
240Sstevel@tonic-gate
250Sstevel@tonic-gate /*
260Sstevel@tonic-gate * routine gss_duplicate_name
270Sstevel@tonic-gate *
280Sstevel@tonic-gate * This routine does not rely on mechanism implementation of this
290Sstevel@tonic-gate * name, but instead uses mechanism specific gss_import_name routine.
300Sstevel@tonic-gate */
310Sstevel@tonic-gate
320Sstevel@tonic-gate #include <mechglueP.h>
33*13132SGlenn.Barry@oracle.com #include "gssapiP_generic.h"
340Sstevel@tonic-gate #ifdef HAVE_STDLIB_H
350Sstevel@tonic-gate #include <stdlib.h>
360Sstevel@tonic-gate #endif
370Sstevel@tonic-gate #include <string.h>
380Sstevel@tonic-gate #include <errno.h>
390Sstevel@tonic-gate
409698SPeter.Shoults@Sun.COM static OM_uint32
val_dup_name_args(OM_uint32 * minor_status,const gss_name_t src_name,gss_name_t * dest_name)419698SPeter.Shoults@Sun.COM val_dup_name_args(
429698SPeter.Shoults@Sun.COM OM_uint32 *minor_status,
439698SPeter.Shoults@Sun.COM const gss_name_t src_name,
449698SPeter.Shoults@Sun.COM gss_name_t *dest_name)
459698SPeter.Shoults@Sun.COM {
469698SPeter.Shoults@Sun.COM
479698SPeter.Shoults@Sun.COM /* Initialize outputs. */
489698SPeter.Shoults@Sun.COM
499698SPeter.Shoults@Sun.COM if (minor_status != NULL)
509698SPeter.Shoults@Sun.COM *minor_status = 0;
519698SPeter.Shoults@Sun.COM
529698SPeter.Shoults@Sun.COM if (dest_name != NULL)
539698SPeter.Shoults@Sun.COM *dest_name = GSS_C_NO_NAME;
549698SPeter.Shoults@Sun.COM
559698SPeter.Shoults@Sun.COM /* Validate arguments. */
569698SPeter.Shoults@Sun.COM
579698SPeter.Shoults@Sun.COM if (minor_status == NULL)
589698SPeter.Shoults@Sun.COM return (GSS_S_CALL_INACCESSIBLE_WRITE);
599698SPeter.Shoults@Sun.COM
609698SPeter.Shoults@Sun.COM /* if output_name is NULL, simply return */
619698SPeter.Shoults@Sun.COM if (dest_name == NULL)
629698SPeter.Shoults@Sun.COM return (GSS_S_CALL_INACCESSIBLE_WRITE);
639698SPeter.Shoults@Sun.COM
649698SPeter.Shoults@Sun.COM if (src_name == GSS_C_NO_NAME)
659698SPeter.Shoults@Sun.COM return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_BAD_NAME);
669698SPeter.Shoults@Sun.COM
679698SPeter.Shoults@Sun.COM return (GSS_S_COMPLETE);
689698SPeter.Shoults@Sun.COM }
699698SPeter.Shoults@Sun.COM
700Sstevel@tonic-gate OM_uint32
gss_duplicate_name(minor_status,src_name,dest_name)710Sstevel@tonic-gate gss_duplicate_name(minor_status,
720Sstevel@tonic-gate src_name,
730Sstevel@tonic-gate dest_name)
740Sstevel@tonic-gate OM_uint32 *minor_status;
750Sstevel@tonic-gate const gss_name_t src_name;
760Sstevel@tonic-gate gss_name_t *dest_name;
770Sstevel@tonic-gate {
780Sstevel@tonic-gate gss_union_name_t src_union, dest_union;
790Sstevel@tonic-gate OM_uint32 major_status = GSS_S_FAILURE;
800Sstevel@tonic-gate
819698SPeter.Shoults@Sun.COM major_status = val_dup_name_args(minor_status, src_name, dest_name);
829698SPeter.Shoults@Sun.COM if (major_status != GSS_S_COMPLETE)
839698SPeter.Shoults@Sun.COM return (major_status);
840Sstevel@tonic-gate
859698SPeter.Shoults@Sun.COM major_status = GSS_S_FAILURE;
860Sstevel@tonic-gate
870Sstevel@tonic-gate src_union = (gss_union_name_t)src_name;
880Sstevel@tonic-gate
890Sstevel@tonic-gate /*
900Sstevel@tonic-gate * First create the union name struct that will hold the external
910Sstevel@tonic-gate * name and the name type.
920Sstevel@tonic-gate */
930Sstevel@tonic-gate dest_union = (gss_union_name_t)malloc(sizeof (gss_union_name_desc));
940Sstevel@tonic-gate if (!dest_union)
950Sstevel@tonic-gate goto allocation_failure;
960Sstevel@tonic-gate
970Sstevel@tonic-gate dest_union->mech_type = 0;
980Sstevel@tonic-gate dest_union->mech_name = 0;
990Sstevel@tonic-gate dest_union->name_type = 0;
1000Sstevel@tonic-gate dest_union->external_name = 0;
1010Sstevel@tonic-gate
1020Sstevel@tonic-gate /* Now copy the external representaion */
1035053Sgtb if (gssint_create_copy_buffer(src_union->external_name,
1040Sstevel@tonic-gate &dest_union->external_name, 0))
1050Sstevel@tonic-gate goto allocation_failure;
1060Sstevel@tonic-gate
1070Sstevel@tonic-gate if (src_union->name_type != GSS_C_NULL_OID) {
1080Sstevel@tonic-gate major_status = generic_gss_copy_oid(minor_status,
1090Sstevel@tonic-gate src_union->name_type,
1100Sstevel@tonic-gate &dest_union->name_type);
111*13132SGlenn.Barry@oracle.com if (major_status != GSS_S_COMPLETE) {
112*13132SGlenn.Barry@oracle.com map_errcode(minor_status);
1130Sstevel@tonic-gate goto allocation_failure;
114*13132SGlenn.Barry@oracle.com }
1150Sstevel@tonic-gate }
1160Sstevel@tonic-gate
1170Sstevel@tonic-gate /*
1180Sstevel@tonic-gate * See if source name is mechanim specific, if so then need to import it
1190Sstevel@tonic-gate */
1200Sstevel@tonic-gate if (src_union->mech_type) {
1210Sstevel@tonic-gate major_status = generic_gss_copy_oid(minor_status,
1220Sstevel@tonic-gate src_union->mech_type,
1230Sstevel@tonic-gate &dest_union->mech_type);
124*13132SGlenn.Barry@oracle.com if (major_status != GSS_S_COMPLETE) {
125*13132SGlenn.Barry@oracle.com map_errcode(minor_status);
1260Sstevel@tonic-gate goto allocation_failure;
127*13132SGlenn.Barry@oracle.com }
1280Sstevel@tonic-gate
1290Sstevel@tonic-gate major_status = __gss_import_internal_name(minor_status,
1300Sstevel@tonic-gate dest_union->mech_type,
1310Sstevel@tonic-gate dest_union,
1320Sstevel@tonic-gate &dest_union->mech_name);
1330Sstevel@tonic-gate if (major_status != GSS_S_COMPLETE)
1340Sstevel@tonic-gate goto allocation_failure;
1350Sstevel@tonic-gate }
1360Sstevel@tonic-gate
1370Sstevel@tonic-gate
1380Sstevel@tonic-gate *dest_name = (gss_name_t)dest_union;
1390Sstevel@tonic-gate return (GSS_S_COMPLETE);
1400Sstevel@tonic-gate
1410Sstevel@tonic-gate allocation_failure:
1420Sstevel@tonic-gate if (dest_union) {
1430Sstevel@tonic-gate if (dest_union->external_name) {
1440Sstevel@tonic-gate if (dest_union->external_name->value)
1450Sstevel@tonic-gate free(dest_union->external_name->value);
1460Sstevel@tonic-gate free(dest_union->external_name);
1470Sstevel@tonic-gate }
1480Sstevel@tonic-gate if (dest_union->name_type)
1490Sstevel@tonic-gate (void) generic_gss_release_oid(minor_status,
1500Sstevel@tonic-gate &dest_union->name_type);
1510Sstevel@tonic-gate if (dest_union->mech_name)
1520Sstevel@tonic-gate (void) __gss_release_internal_name(minor_status,
1530Sstevel@tonic-gate dest_union->mech_type,
1540Sstevel@tonic-gate &dest_union->mech_name);
1550Sstevel@tonic-gate if (dest_union->mech_type)
1560Sstevel@tonic-gate (void) generic_gss_release_oid(minor_status,
1570Sstevel@tonic-gate &dest_union->mech_type);
1580Sstevel@tonic-gate free(dest_union);
1590Sstevel@tonic-gate }
1600Sstevel@tonic-gate return (major_status);
1610Sstevel@tonic-gate } /* gss_duplicate_name */
162