Path: blob/main/crypto/heimdal/lib/gssapi/mech/gss_names.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_names.c,v 1.1 2005/12/29 14:40:20 dfr Exp $26*/2728#include "mech_locl.h"2930OM_uint3231_gss_find_mn(OM_uint32 *minor_status, struct _gss_name *name, gss_OID mech,32struct _gss_mechanism_name **output_mn)33{34OM_uint32 major_status;35gssapi_mech_interface m;36struct _gss_mechanism_name *mn;3738*output_mn = NULL;3940HEIM_SLIST_FOREACH(mn, &name->gn_mn, gmn_link) {41if (gss_oid_equal(mech, mn->gmn_mech_oid))42break;43}4445if (!mn) {46/*47* If this name is canonical (i.e. there is only an48* MN but it is from a different mech), give up now.49*/50if (!name->gn_value.value)51return GSS_S_BAD_NAME;5253m = __gss_get_mechanism(mech);54if (!m)55return (GSS_S_BAD_MECH);5657mn = malloc(sizeof(struct _gss_mechanism_name));58if (!mn)59return GSS_S_FAILURE;6061major_status = m->gm_import_name(minor_status,62&name->gn_value,63(name->gn_type.elements64? &name->gn_type : GSS_C_NO_OID),65&mn->gmn_name);66if (major_status != GSS_S_COMPLETE) {67_gss_mg_error(m, major_status, *minor_status);68free(mn);69return major_status;70}7172mn->gmn_mech = m;73mn->gmn_mech_oid = &m->gm_mech_oid;74HEIM_SLIST_INSERT_HEAD(&name->gn_mn, mn, gmn_link);75}76*output_mn = mn;77return 0;78}798081/*82* Make a name from an MN.83*/84struct _gss_name *85_gss_make_name(gssapi_mech_interface m, gss_name_t new_mn)86{87struct _gss_name *name;88struct _gss_mechanism_name *mn;8990name = malloc(sizeof(struct _gss_name));91if (!name)92return (0);93memset(name, 0, sizeof(struct _gss_name));9495mn = malloc(sizeof(struct _gss_mechanism_name));96if (!mn) {97free(name);98return (0);99}100101HEIM_SLIST_INIT(&name->gn_mn);102mn->gmn_mech = m;103mn->gmn_mech_oid = &m->gm_mech_oid;104mn->gmn_name = new_mn;105HEIM_SLIST_INSERT_HEAD(&name->gn_mn, mn, gmn_link);106107return (name);108}109110111112