gss_compare_name.c revision 178828
1193323Sed/*- 2193323Sed * Copyright (c) 2005 Doug Rabson 3193323Sed * All rights reserved. 4193323Sed * 5193323Sed * Redistribution and use in source and binary forms, with or without 6193323Sed * modification, are permitted provided that the following conditions 7193323Sed * are met: 8193323Sed * 1. Redistributions of source code must retain the above copyright 9193323Sed * notice, this list of conditions and the following disclaimer. 10193323Sed * 2. Redistributions in binary form must reproduce the above copyright 11193323Sed * notice, this list of conditions and the following disclaimer in the 12193323Sed * documentation and/or other materials provided with the distribution. 13193323Sed * 14193323Sed * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15193323Sed * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16193323Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17193323Sed * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18193323Sed * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19193323Sed * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20193323Sed * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21198090Srdivacky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22198090Srdivacky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23198090Srdivacky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24198090Srdivacky * SUCH DAMAGE. 25198090Srdivacky * 26198090Srdivacky * $FreeBSD: head/lib/libgssapi/gss_compare_name.c 178828 2008-05-07 13:53:12Z dfr $ 27193323Sed */ 28193323Sed 29193323Sed#include <gssapi/gssapi.h> 30193323Sed#include <string.h> 31193323Sed 32193323Sed#include "mech_switch.h" 33193323Sed#include "name.h" 34193323Sed#include "utils.h" 35193323Sed 36193323SedOM_uint32 37193323Sedgss_compare_name(OM_uint32 *minor_status, 38193323Sed const gss_name_t name1_arg, 39193323Sed const gss_name_t name2_arg, 40193323Sed int *name_equal) 41193323Sed{ 42193323Sed struct _gss_name *name1 = (struct _gss_name *) name1_arg; 43193323Sed struct _gss_name *name2 = (struct _gss_name *) name2_arg; 44193323Sed 45193323Sed /* 46193323Sed * First check the implementation-independant name if both 47193323Sed * names have one. Otherwise, try to find common mechanism 48193323Sed * names and compare them. 49193323Sed */ 50193323Sed if (name1->gn_value.value && name2->gn_value.value) { 51193323Sed *name_equal = 1; 52193323Sed if (!gss_oid_equal(&name1->gn_type, &name2->gn_type)) { 53193323Sed *name_equal = 0; 54193323Sed } else if (name1->gn_value.length != name2->gn_value.length || 55193323Sed memcmp(name1->gn_value.value, name1->gn_value.value, 56193323Sed name1->gn_value.length)) { 57193323Sed *name_equal = 0; 58193323Sed } 59193323Sed } else { 60193323Sed struct _gss_mechanism_name *mn1; 61193323Sed struct _gss_mechanism_name *mn2; 62193323Sed 63193323Sed SLIST_FOREACH(mn1, &name1->gn_mn, gmn_link) { 64193323Sed OM_uint32 major_status; 65193323Sed 66193323Sed major_status = _gss_find_mn(minor_status, name2, 67193323Sed mn1->gmn_mech_oid, &mn2); 68193323Sed if (major_status == GSS_S_COMPLETE) { 69193323Sed return (mn1->gmn_mech->gm_compare_name( 70193323Sed minor_status, 71193323Sed mn1->gmn_name, 72 mn2->gmn_name, 73 name_equal)); 74 } 75 } 76 *name_equal = 0; 77 } 78 79 *minor_status = 0; 80 return (GSS_S_COMPLETE); 81} 82