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 /* 22*5e01956fSGlenn 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> 33*5e01956fSGlenn 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 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 717c478bd9Sstevel@tonic-gate gss_duplicate_name(minor_status, 727c478bd9Sstevel@tonic-gate src_name, 737c478bd9Sstevel@tonic-gate dest_name) 747c478bd9Sstevel@tonic-gate OM_uint32 *minor_status; 757c478bd9Sstevel@tonic-gate const gss_name_t src_name; 767c478bd9Sstevel@tonic-gate gss_name_t *dest_name; 777c478bd9Sstevel@tonic-gate { 787c478bd9Sstevel@tonic-gate gss_union_name_t src_union, dest_union; 797c478bd9Sstevel@tonic-gate OM_uint32 major_status = GSS_S_FAILURE; 807c478bd9Sstevel@tonic-gate 81503a2b89SPeter Shoults major_status = val_dup_name_args(minor_status, src_name, dest_name); 82503a2b89SPeter Shoults if (major_status != GSS_S_COMPLETE) 83503a2b89SPeter Shoults return (major_status); 847c478bd9Sstevel@tonic-gate 85503a2b89SPeter Shoults major_status = GSS_S_FAILURE; 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate src_union = (gss_union_name_t)src_name; 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate /* 907c478bd9Sstevel@tonic-gate * First create the union name struct that will hold the external 917c478bd9Sstevel@tonic-gate * name and the name type. 927c478bd9Sstevel@tonic-gate */ 937c478bd9Sstevel@tonic-gate dest_union = (gss_union_name_t)malloc(sizeof (gss_union_name_desc)); 947c478bd9Sstevel@tonic-gate if (!dest_union) 957c478bd9Sstevel@tonic-gate goto allocation_failure; 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate dest_union->mech_type = 0; 987c478bd9Sstevel@tonic-gate dest_union->mech_name = 0; 997c478bd9Sstevel@tonic-gate dest_union->name_type = 0; 1007c478bd9Sstevel@tonic-gate dest_union->external_name = 0; 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate /* Now copy the external representaion */ 103ab9b2e15Sgtb if (gssint_create_copy_buffer(src_union->external_name, 1047c478bd9Sstevel@tonic-gate &dest_union->external_name, 0)) 1057c478bd9Sstevel@tonic-gate goto allocation_failure; 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate if (src_union->name_type != GSS_C_NULL_OID) { 1087c478bd9Sstevel@tonic-gate major_status = generic_gss_copy_oid(minor_status, 1097c478bd9Sstevel@tonic-gate src_union->name_type, 1107c478bd9Sstevel@tonic-gate &dest_union->name_type); 111*5e01956fSGlenn Barry if (major_status != GSS_S_COMPLETE) { 112*5e01956fSGlenn Barry map_errcode(minor_status); 1137c478bd9Sstevel@tonic-gate goto allocation_failure; 1147c478bd9Sstevel@tonic-gate } 115*5e01956fSGlenn Barry } 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate /* 1187c478bd9Sstevel@tonic-gate * See if source name is mechanim specific, if so then need to import it 1197c478bd9Sstevel@tonic-gate */ 1207c478bd9Sstevel@tonic-gate if (src_union->mech_type) { 1217c478bd9Sstevel@tonic-gate major_status = generic_gss_copy_oid(minor_status, 1227c478bd9Sstevel@tonic-gate src_union->mech_type, 1237c478bd9Sstevel@tonic-gate &dest_union->mech_type); 124*5e01956fSGlenn Barry if (major_status != GSS_S_COMPLETE) { 125*5e01956fSGlenn Barry map_errcode(minor_status); 1267c478bd9Sstevel@tonic-gate goto allocation_failure; 127*5e01956fSGlenn Barry } 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate major_status = __gss_import_internal_name(minor_status, 1307c478bd9Sstevel@tonic-gate dest_union->mech_type, 1317c478bd9Sstevel@tonic-gate dest_union, 1327c478bd9Sstevel@tonic-gate &dest_union->mech_name); 1337c478bd9Sstevel@tonic-gate if (major_status != GSS_S_COMPLETE) 1347c478bd9Sstevel@tonic-gate goto allocation_failure; 1357c478bd9Sstevel@tonic-gate } 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate *dest_name = (gss_name_t)dest_union; 1397c478bd9Sstevel@tonic-gate return (GSS_S_COMPLETE); 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate allocation_failure: 1427c478bd9Sstevel@tonic-gate if (dest_union) { 1437c478bd9Sstevel@tonic-gate if (dest_union->external_name) { 1447c478bd9Sstevel@tonic-gate if (dest_union->external_name->value) 1457c478bd9Sstevel@tonic-gate free(dest_union->external_name->value); 1467c478bd9Sstevel@tonic-gate free(dest_union->external_name); 1477c478bd9Sstevel@tonic-gate } 1487c478bd9Sstevel@tonic-gate if (dest_union->name_type) 1497c478bd9Sstevel@tonic-gate (void) generic_gss_release_oid(minor_status, 1507c478bd9Sstevel@tonic-gate &dest_union->name_type); 1517c478bd9Sstevel@tonic-gate if (dest_union->mech_name) 1527c478bd9Sstevel@tonic-gate (void) __gss_release_internal_name(minor_status, 1537c478bd9Sstevel@tonic-gate dest_union->mech_type, 1547c478bd9Sstevel@tonic-gate &dest_union->mech_name); 1557c478bd9Sstevel@tonic-gate if (dest_union->mech_type) 1567c478bd9Sstevel@tonic-gate (void) generic_gss_release_oid(minor_status, 1577c478bd9Sstevel@tonic-gate &dest_union->mech_type); 1587c478bd9Sstevel@tonic-gate free(dest_union); 1597c478bd9Sstevel@tonic-gate } 1607c478bd9Sstevel@tonic-gate return (major_status); 1617c478bd9Sstevel@tonic-gate } /* gss_duplicate_name */ 162