Path: blob/main/crypto/krb5/src/lib/gssapi/mechglue/g_compare_name.c
39586 views
/* #pragma ident "@(#)g_compare_name.c 1.16 04/02/23 SMI" */12/*3* Copyright 1996 by Sun Microsystems, Inc.4*5* Permission to use, copy, modify, distribute, and sell this software6* and its documentation for any purpose is hereby granted without fee,7* provided that the above copyright notice appears in all copies and8* that both that copyright notice and this permission notice appear in9* supporting documentation, and that the name of Sun Microsystems not be used10* in advertising or publicity pertaining to distribution of the software11* without specific, written prior permission. Sun Microsystems makes no12* representations about the suitability of this software for any13* purpose. It is provided "as is" without express or implied warranty.14*15* SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,16* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO17* EVENT SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR18* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF19* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR20* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR21* PERFORMANCE OF THIS SOFTWARE.22*/2324/*25* glue routine for gss_compare_name26*27*/2829#include "mglueP.h"30#ifdef HAVE_STDLIB_H31#include <stdlib.h>32#endif33#include <string.h>3435static OM_uint3236val_comp_name_args(37OM_uint32 *minor_status,38gss_name_t name1,39gss_name_t name2,40int *name_equal)41{4243/* Initialize outputs. */4445if (minor_status != NULL)46*minor_status = 0;4748/* Validate arguments. */4950if (name1 == GSS_C_NO_NAME || name2 == GSS_C_NO_NAME)51return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_BAD_NAME);5253if (name_equal == NULL)54return (GSS_S_CALL_INACCESSIBLE_WRITE);5556return (GSS_S_COMPLETE);57}585960OM_uint32 KRB5_CALLCONV61gss_compare_name(OM_uint32 * minor_status, gss_name_t name1, gss_name_t name2,62int * name_equal)63{64OM_uint32 major_status, temp_minor;65gss_union_name_t union_name1, union_name2;66gss_mechanism mech = NULL;67gss_name_t internal_name;6869major_status = val_comp_name_args(minor_status,70name1, name2, name_equal);71if (major_status != GSS_S_COMPLETE)72return (major_status);7374union_name1 = (gss_union_name_t) name1;75union_name2 = (gss_union_name_t) name2;76/*77* Try our hardest to make union_name1 be the mechanism-specific78* name. (Of course we can't if both names aren't79* mechanism-specific.)80*/81if (union_name1->mech_type == 0) {82union_name1 = (gss_union_name_t) name2;83union_name2 = (gss_union_name_t) name1;84}85/*86* If union_name1 is mechanism specific, then fetch its mechanism87* information.88*/89if (union_name1->mech_type) {90mech = gssint_get_mechanism (union_name1->mech_type);91if (!mech)92return (GSS_S_BAD_MECH);93if (!mech->gss_compare_name)94return (GSS_S_UNAVAILABLE);95}9697*name_equal = 0; /* Default to *not* equal.... */9899/*100* First case... both names are mechanism-specific101*/102if (union_name1->mech_type && union_name2->mech_type) {103if (!g_OID_equal(union_name1->mech_type, union_name2->mech_type))104return (GSS_S_COMPLETE);105if ((union_name1->mech_name == 0) || (union_name2->mech_name == 0))106/* should never happen */107return (GSS_S_BAD_NAME);108if (!mech)109return (GSS_S_BAD_MECH);110if (!mech->gss_compare_name)111return (GSS_S_UNAVAILABLE);112major_status = mech->gss_compare_name(minor_status,113union_name1->mech_name,114union_name2->mech_name,115name_equal);116if (major_status != GSS_S_COMPLETE)117map_error(minor_status, mech);118return major_status;119}120121/*122* Second case... both names are NOT mechanism specific.123*124* All we do here is make sure the two name_types are equal and then125* that the external_names are equal. Note the we do not take care126* of the case where two different external names map to the same127* internal name. We cannot determine this, since we as yet do not128* know what mechanism to use for calling the underlying129* gss_import_name().130*/131if (!union_name1->mech_type && !union_name2->mech_type) {132/*133* Second case, first sub-case... one name has null134* name_type, the other doesn't.135*136* Not knowing a mech_type we can't import the name with137* null name_type so we can't compare.138*/139if ((union_name1->name_type == GSS_C_NULL_OID &&140union_name2->name_type != GSS_C_NULL_OID) ||141(union_name1->name_type != GSS_C_NULL_OID &&142union_name2->name_type == GSS_C_NULL_OID))143return (GSS_S_COMPLETE);144/*145* Second case, second sub-case... both names have146* name_types, but they are different.147*/148if ((union_name1->name_type != GSS_C_NULL_OID &&149union_name2->name_type != GSS_C_NULL_OID) &&150!g_OID_equal(union_name1->name_type,151union_name2->name_type))152return (GSS_S_COMPLETE);153/*154* Second case, third sub-case... both names have equal155* name_types (and both have no mech_types) so we just156* compare the external_names.157*/158if ((union_name1->external_name->length !=159union_name2->external_name->length) ||160(memcmp(union_name1->external_name->value,161union_name2->external_name->value,162union_name1->external_name->length) != 0))163return (GSS_S_COMPLETE);164*name_equal = 1;165return (GSS_S_COMPLETE);166}167168/*169* Final case... one name is mechanism specific, the other isn't.170*171* We attempt to convert the general name to the mechanism type of172* the mechanism-specific name, and then do the compare. If we173* can't import the general name, then we return that the name is174* _NOT_ equal.175*/176if (union_name2->mech_type) {177/* We make union_name1 the mechanism specific name. */178union_name1 = (gss_union_name_t) name2;179union_name2 = (gss_union_name_t) name1;180}181major_status = gssint_import_internal_name(minor_status,182union_name1->mech_type,183union_name2,184&internal_name);185if (major_status != GSS_S_COMPLETE)186return (GSS_S_COMPLETE); /* return complete, but not equal */187188if (!mech)189return (GSS_S_BAD_MECH);190if (!mech->gss_compare_name)191return (GSS_S_UNAVAILABLE);192major_status = mech->gss_compare_name(minor_status,193union_name1->mech_name,194internal_name, name_equal);195if (major_status != GSS_S_COMPLETE)196map_error(minor_status, mech);197gssint_release_internal_name(&temp_minor, union_name1->mech_type,198&internal_name);199return (major_status);200201}202203204