17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5ab9b2e15Sgtb * Common Development and Distribution License (the "License").
6ab9b2e15Sgtb * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
225e01956fSGlenn Barry * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate */
247c478bd9Sstevel@tonic-gate
257c478bd9Sstevel@tonic-gate /*
267c478bd9Sstevel@tonic-gate * routine gss_duplicate_name
277c478bd9Sstevel@tonic-gate *
287c478bd9Sstevel@tonic-gate * This routine does not rely on mechanism implementation of this
297c478bd9Sstevel@tonic-gate * name, but instead uses mechanism specific gss_import_name routine.
307c478bd9Sstevel@tonic-gate */
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate #include <mechglueP.h>
335e01956fSGlenn Barry #include "gssapiP_generic.h"
347c478bd9Sstevel@tonic-gate #ifdef HAVE_STDLIB_H
357c478bd9Sstevel@tonic-gate #include <stdlib.h>
367c478bd9Sstevel@tonic-gate #endif
377c478bd9Sstevel@tonic-gate #include <string.h>
387c478bd9Sstevel@tonic-gate #include <errno.h>
397c478bd9Sstevel@tonic-gate
40503a2b89SPeter Shoults static OM_uint32
val_dup_name_args(OM_uint32 * minor_status,const gss_name_t src_name,gss_name_t * dest_name)41503a2b89SPeter Shoults val_dup_name_args(
42503a2b89SPeter Shoults OM_uint32 *minor_status,
43503a2b89SPeter Shoults const gss_name_t src_name,
44503a2b89SPeter Shoults gss_name_t *dest_name)
45503a2b89SPeter Shoults {
46503a2b89SPeter Shoults
47503a2b89SPeter Shoults /* Initialize outputs. */
48503a2b89SPeter Shoults
49503a2b89SPeter Shoults if (minor_status != NULL)
50503a2b89SPeter Shoults *minor_status = 0;
51503a2b89SPeter Shoults
52503a2b89SPeter Shoults if (dest_name != NULL)
53503a2b89SPeter Shoults *dest_name = GSS_C_NO_NAME;
54503a2b89SPeter Shoults
55503a2b89SPeter Shoults /* Validate arguments. */
56503a2b89SPeter Shoults
57503a2b89SPeter Shoults if (minor_status == NULL)
58503a2b89SPeter Shoults return (GSS_S_CALL_INACCESSIBLE_WRITE);
59503a2b89SPeter Shoults
60503a2b89SPeter Shoults /* if output_name is NULL, simply return */
61503a2b89SPeter Shoults if (dest_name == NULL)
62503a2b89SPeter Shoults return (GSS_S_CALL_INACCESSIBLE_WRITE);
63503a2b89SPeter Shoults
64503a2b89SPeter Shoults if (src_name == GSS_C_NO_NAME)
65503a2b89SPeter Shoults return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_BAD_NAME);
66503a2b89SPeter Shoults
67503a2b89SPeter Shoults return (GSS_S_COMPLETE);
68503a2b89SPeter Shoults }
69503a2b89SPeter Shoults
707c478bd9Sstevel@tonic-gate OM_uint32
gss_duplicate_name(OM_uint32 * minor_status,const gss_name_t src_name,gss_name_t * dest_name)71*dd99db61SToomas Soome gss_duplicate_name(OM_uint32 *minor_status, const gss_name_t src_name,
72*dd99db61SToomas Soome gss_name_t *dest_name)
737c478bd9Sstevel@tonic-gate {
74*dd99db61SToomas Soome gss_union_name_t src_union, dest_union;
75*dd99db61SToomas Soome OM_uint32 major_status = GSS_S_FAILURE;
767c478bd9Sstevel@tonic-gate
77503a2b89SPeter Shoults major_status = val_dup_name_args(minor_status, src_name, dest_name);
78503a2b89SPeter Shoults if (major_status != GSS_S_COMPLETE)
79503a2b89SPeter Shoults return (major_status);
807c478bd9Sstevel@tonic-gate
81503a2b89SPeter Shoults major_status = GSS_S_FAILURE;
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate src_union = (gss_union_name_t)src_name;
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate /*
867c478bd9Sstevel@tonic-gate * First create the union name struct that will hold the external
877c478bd9Sstevel@tonic-gate * name and the name type.
887c478bd9Sstevel@tonic-gate */
897c478bd9Sstevel@tonic-gate dest_union = (gss_union_name_t)malloc(sizeof (gss_union_name_desc));
907c478bd9Sstevel@tonic-gate if (!dest_union)
917c478bd9Sstevel@tonic-gate goto allocation_failure;
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate dest_union->mech_type = 0;
947c478bd9Sstevel@tonic-gate dest_union->mech_name = 0;
957c478bd9Sstevel@tonic-gate dest_union->name_type = 0;
967c478bd9Sstevel@tonic-gate dest_union->external_name = 0;
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate /* Now copy the external representaion */
99ab9b2e15Sgtb if (gssint_create_copy_buffer(src_union->external_name,
100*dd99db61SToomas Soome &dest_union->external_name, 0))
1017c478bd9Sstevel@tonic-gate goto allocation_failure;
1027c478bd9Sstevel@tonic-gate
1037c478bd9Sstevel@tonic-gate if (src_union->name_type != GSS_C_NULL_OID) {
1047c478bd9Sstevel@tonic-gate major_status = generic_gss_copy_oid(minor_status,
105*dd99db61SToomas Soome src_union->name_type, &dest_union->name_type);
1065e01956fSGlenn Barry if (major_status != GSS_S_COMPLETE) {
1075e01956fSGlenn Barry map_errcode(minor_status);
1087c478bd9Sstevel@tonic-gate goto allocation_failure;
1095e01956fSGlenn Barry }
1107c478bd9Sstevel@tonic-gate }
1117c478bd9Sstevel@tonic-gate
1127c478bd9Sstevel@tonic-gate /*
1137c478bd9Sstevel@tonic-gate * See if source name is mechanim specific, if so then need to import it
1147c478bd9Sstevel@tonic-gate */
1157c478bd9Sstevel@tonic-gate if (src_union->mech_type) {
1167c478bd9Sstevel@tonic-gate major_status = generic_gss_copy_oid(minor_status,
117*dd99db61SToomas Soome src_union->mech_type, &dest_union->mech_type);
1185e01956fSGlenn Barry if (major_status != GSS_S_COMPLETE) {
1195e01956fSGlenn Barry map_errcode(minor_status);
1207c478bd9Sstevel@tonic-gate goto allocation_failure;
1215e01956fSGlenn Barry }
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate major_status = __gss_import_internal_name(minor_status,
124*dd99db61SToomas Soome dest_union->mech_type, dest_union, &dest_union->mech_name);
1257c478bd9Sstevel@tonic-gate if (major_status != GSS_S_COMPLETE)
1267c478bd9Sstevel@tonic-gate goto allocation_failure;
1277c478bd9Sstevel@tonic-gate }
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate
1307c478bd9Sstevel@tonic-gate *dest_name = (gss_name_t)dest_union;
1317c478bd9Sstevel@tonic-gate return (GSS_S_COMPLETE);
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate allocation_failure:
1347c478bd9Sstevel@tonic-gate if (dest_union) {
1357c478bd9Sstevel@tonic-gate if (dest_union->external_name) {
136*dd99db61SToomas Soome free(dest_union->external_name->value);
137*dd99db61SToomas Soome free(dest_union->external_name);
1387c478bd9Sstevel@tonic-gate }
139*dd99db61SToomas Soome if (dest_union->name_type) {
1407c478bd9Sstevel@tonic-gate (void) generic_gss_release_oid(minor_status,
141*dd99db61SToomas Soome &dest_union->name_type);
142*dd99db61SToomas Soome }
143*dd99db61SToomas Soome if (dest_union->mech_name) {
1447c478bd9Sstevel@tonic-gate (void) __gss_release_internal_name(minor_status,
145*dd99db61SToomas Soome dest_union->mech_type, &dest_union->mech_name);
146*dd99db61SToomas Soome }
147*dd99db61SToomas Soome if (dest_union->mech_type) {
1487c478bd9Sstevel@tonic-gate (void) generic_gss_release_oid(minor_status,
149*dd99db61SToomas Soome &dest_union->mech_type);
150*dd99db61SToomas Soome }
1517c478bd9Sstevel@tonic-gate free(dest_union);
1527c478bd9Sstevel@tonic-gate }
1537c478bd9Sstevel@tonic-gate return (major_status);
1547c478bd9Sstevel@tonic-gate } /* gss_duplicate_name */
155