Path: blob/main/crypto/heimdal/lib/gssapi/mech/gss_duplicate_name.c
34907 views
/*-1* Copyright (c) 2005 Doug Rabson2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*25* $FreeBSD: src/lib/libgssapi/gss_duplicate_name.c,v 1.1 2005/12/29 14:40:20 dfr Exp $26*/2728#include "mech_locl.h"2930GSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL31gss_duplicate_name(OM_uint32 *minor_status,32const gss_name_t src_name,33gss_name_t *dest_name)34{35OM_uint32 major_status;36struct _gss_name *name = (struct _gss_name *) src_name;37struct _gss_name *new_name;38struct _gss_mechanism_name *mn;3940*minor_status = 0;41*dest_name = GSS_C_NO_NAME;4243/*44* If this name has a value (i.e. it didn't come from45* gss_canonicalize_name(), we re-import the thing. Otherwise,46* we make copy of each mech names.47*/48if (name->gn_value.value) {49major_status = gss_import_name(minor_status,50&name->gn_value, &name->gn_type, dest_name);51if (major_status != GSS_S_COMPLETE)52return (major_status);53new_name = (struct _gss_name *) *dest_name;5455HEIM_SLIST_FOREACH(mn, &name->gn_mn, gmn_link) {56struct _gss_mechanism_name *mn2;57_gss_find_mn(minor_status, new_name,58mn->gmn_mech_oid, &mn2);59}60} else {61new_name = malloc(sizeof(struct _gss_name));62if (!new_name) {63*minor_status = ENOMEM;64return (GSS_S_FAILURE);65}66memset(new_name, 0, sizeof(struct _gss_name));67HEIM_SLIST_INIT(&new_name->gn_mn);68*dest_name = (gss_name_t) new_name;6970HEIM_SLIST_FOREACH(mn, &name->gn_mn, gmn_link) {71struct _gss_mechanism_name *new_mn;7273new_mn = malloc(sizeof(*new_mn));74if (!new_mn) {75*minor_status = ENOMEM;76return GSS_S_FAILURE;77}78new_mn->gmn_mech = mn->gmn_mech;79new_mn->gmn_mech_oid = mn->gmn_mech_oid;8081major_status =82mn->gmn_mech->gm_duplicate_name(minor_status,83mn->gmn_name, &new_mn->gmn_name);84if (major_status != GSS_S_COMPLETE) {85free(new_mn);86continue;87}88HEIM_SLIST_INSERT_HEAD(&new_name->gn_mn, new_mn, gmn_link);89}9091}9293return (GSS_S_COMPLETE);94}959697