Path: blob/main/crypto/krb5/src/lib/gssapi/mechglue/g_mechname.c
39586 views
/*1* g_mechname.c --- registry of mechanism-specific name types2*3* This file contains a registry of mechanism-specific name types. It4* is used to determine which name types not should be lazy evaluated,5* but rather evaluated on the spot.6*/78#include "mglueP.h"9#ifdef HAVE_STDLIB_H10#include <stdlib.h>11#endif1213#include <stdio.h>14#include <string.h>15#include <errno.h>1617static gss_mech_spec_name name_list = NULL;1819/*20* generic searching helper function.21*/22static gss_mech_spec_name23search_mech_spec(gss_OID name_type)24{25gss_mech_spec_name p;2627for (p = name_list; p; p = p->next) {28if (g_OID_equal(name_type, p->name_type))29return p;30}31return NULL;32}3334/*35* Given a name_type, if it is specific to a mechanism, return the36* mechanism OID. Otherwise, return NULL.37*/38gss_OID39gss_find_mechanism_from_name_type(gss_OID name_type)40{41gss_mech_spec_name p;4243p = search_mech_spec(name_type);44if (!p)45return NULL;46return p->mech;47}4849/*50* This function adds a (name_type, mechanism) pair to the51* mechanism-specific name type registry. If an entry for the52* name_type already exists, then zero out the mechanism entry.53* Otherwise, enter the pair into the registry.54*/55OM_uint3256gss_add_mech_name_type(OM_uint32 *minor_status, gss_OID name_type,57gss_OID mech)58{59OM_uint32 major_status, tmp;60gss_mech_spec_name p;6162p = search_mech_spec(name_type);63if (p) {64/*65* We found an entry for this name type; mark it as not being66* a mechanism-specific name type.67*/68if (p->mech) {69if (!g_OID_equal(mech, p->mech)) {70generic_gss_release_oid(minor_status, &p->mech);71p->mech = 0;72}73}74return GSS_S_COMPLETE;75}76p = malloc(sizeof(gss_mech_spec_name_desc));77if (!p) {78*minor_status = ENOMEM;79map_errcode(minor_status);80goto allocation_failure;81}82p->name_type = 0;83p->mech = 0;8485major_status = generic_gss_copy_oid(minor_status, name_type,86&p->name_type);87if (major_status) {88map_errcode(minor_status);89goto allocation_failure;90}91major_status = generic_gss_copy_oid(minor_status, mech,92&p->mech);93if (major_status) {94map_errcode(minor_status);95goto allocation_failure;96}9798p->next = name_list;99p->prev = 0;100name_list = p;101102return GSS_S_COMPLETE;103104allocation_failure:105if (p) {106if (p->mech)107generic_gss_release_oid(&tmp, &p->mech);108if (p->name_type)109generic_gss_release_oid(&tmp, &p->name_type);110free(p);111}112return GSS_S_FAILURE;113}114115116