gss_compare_name.c revision 178828
191094Sdes/*-
292289Sdes * Copyright (c) 2005 Doug Rabson
391094Sdes * All rights reserved.
491094Sdes *
591094Sdes * Redistribution and use in source and binary forms, with or without
691094Sdes * modification, are permitted provided that the following conditions
791094Sdes * are met:
891094Sdes * 1. Redistributions of source code must retain the above copyright
991094Sdes *    notice, this list of conditions and the following disclaimer.
1091094Sdes * 2. Redistributions in binary form must reproduce the above copyright
1191094Sdes *    notice, this list of conditions and the following disclaimer in the
1291094Sdes *    documentation and/or other materials provided with the distribution.
1391094Sdes *
1491094Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1591094Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1691094Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1791094Sdes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1891094Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1991094Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2091094Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2191094Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2291094Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2391094Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2491094Sdes * SUCH DAMAGE.
2591094Sdes *
2691094Sdes *	$FreeBSD: head/lib/libgssapi/gss_compare_name.c 178828 2008-05-07 13:53:12Z dfr $
2791094Sdes */
2891094Sdes
2991094Sdes#include <gssapi/gssapi.h>
3091094Sdes#include <string.h>
3191094Sdes
3291094Sdes#include "mech_switch.h"
3391094Sdes#include "name.h"
3494209Sdes#include "utils.h"
3591094Sdes
3691094SdesOM_uint32
3791094Sdesgss_compare_name(OM_uint32 *minor_status,
3891094Sdes    const gss_name_t name1_arg,
3991094Sdes    const gss_name_t name2_arg,
4091094Sdes    int *name_equal)
4191094Sdes{
4291094Sdes	struct _gss_name *name1 = (struct _gss_name *) name1_arg;
4391094Sdes	struct _gss_name *name2 = (struct _gss_name *) name2_arg;
4491094Sdes
4591094Sdes	/*
4691094Sdes	 * First check the implementation-independant name if both
4791094Sdes	 * names have one. Otherwise, try to find common mechanism
4891094Sdes	 * names and compare them.
4994209Sdes	 */
5094209Sdes	if (name1->gn_value.value && name2->gn_value.value) {
5191094Sdes		*name_equal = 1;
5291094Sdes		if (!gss_oid_equal(&name1->gn_type, &name2->gn_type)) {
5391094Sdes			*name_equal = 0;
5494209Sdes		} else if (name1->gn_value.length != name2->gn_value.length ||
5594209Sdes		    memcmp(name1->gn_value.value, name1->gn_value.value,
5694209Sdes			name1->gn_value.length)) {
5794209Sdes			*name_equal = 0;
5894209Sdes		}
5994209Sdes	} else {
6094209Sdes		struct _gss_mechanism_name *mn1;
6194209Sdes		struct _gss_mechanism_name *mn2;
6294209Sdes
6391100Sdes		SLIST_FOREACH(mn1, &name1->gn_mn, gmn_link) {
6491100Sdes			OM_uint32 major_status;
6591100Sdes
6691100Sdes			major_status = _gss_find_mn(minor_status, name2,
6791094Sdes						    mn1->gmn_mech_oid, &mn2);
6894209Sdes			if (major_status == GSS_S_COMPLETE) {
6994209Sdes				return (mn1->gmn_mech->gm_compare_name(
7094209Sdes						minor_status,
7191100Sdes						mn1->gmn_name,
7291100Sdes						mn2->gmn_name,
7391100Sdes						name_equal));
7491100Sdes			}
7591100Sdes		}
7691094Sdes		*name_equal = 0;
7791094Sdes	}
7891094Sdes
7991094Sdes	*minor_status = 0;
8091094Sdes	return (GSS_S_COMPLETE);
8191094Sdes}
8293982Sdes