1 /* #ident "@(#)gss_compare_name.c 1.13 95/08/02 SMI" */
4 * Copyright 1996 by Sun Microsystems, Inc.
6 * Permission to use, copy, modify, distribute, and sell this software
7 * and its documentation for any purpose is hereby granted without fee,
8 * provided that the above copyright notice appears in all copies and
9 * that both that copyright notice and this permission notice appear in
10 * supporting documentation, and that the name of Sun Microsystems not be used
11 * in advertising or publicity pertaining to distribution of the software
12 * without specific, written prior permission. Sun Microsystems makes no
13 * representations about the suitability of this software for any
14 * purpose. It is provided "as is" without express or implied warranty.
16 * SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
20 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
21 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22 * PERFORMANCE OF THIS SOFTWARE.
26 * glue routine for gss_compare_name
36 #define g_OID_equal(o1,o2) \
37 (((o1)->length == (o2)->length) && \
38 (memcmp((o1)->elements,(o2)->elements,(int) (o1)->length) == 0))
40 OM_uint32 KRB5_CALLCONV
41 gss_compare_name (minor_status,
46 OM_uint32 * minor_status;
52 OM_uint32 major_status, temp_minor;
53 gss_union_name_t union_name1, union_name2;
55 gss_name_t internal_name;
59 if (name1 == 0 || name2 == 0) {
62 return GSS_S_BAD_NAME;
65 union_name1 = (gss_union_name_t) name1;
66 union_name2 = (gss_union_name_t) name2;
68 * Try our hardest to make union_name1 be the mechanism-specific
69 * name. (Of course we can't if both names aren't
70 * mechanism-specific.)
72 if (union_name1->mech_type == 0) {
73 union_name1 = (gss_union_name_t) name2;
74 union_name2 = (gss_union_name_t) name1;
77 * If union_name1 is mechanism specific, then fetch its mechanism
80 if (union_name1->mech_type) {
81 mech = __gss_get_mechanism (union_name1->mech_type);
83 return (GSS_S_BAD_MECH);
84 if (!mech->gss_compare_name)
85 return (GSS_S_BAD_BINDINGS);
88 if (name_equal == NULL)
89 return GSS_S_COMPLETE;
91 *name_equal = 0; /* Default to *not* equal.... */
94 * First case... both names are mechanism-specific
96 if (union_name1->mech_type && union_name2->mech_type) {
97 if (!g_OID_equal(union_name1->mech_type, union_name2->mech_type))
98 return (GSS_S_COMPLETE);
99 if ((union_name1->mech_name == 0) || (union_name2->mech_name == 0))
100 /* should never happen */
101 return (GSS_S_BAD_NAME);
102 #ifdef USE_MECH_CONTEXT
103 return (mech->gss_compare_name(mech->context, minor_status,
105 return (mech->gss_compare_name(minor_status,
107 union_name1->mech_name,
108 union_name2->mech_name, name_equal));
113 * Second case... both names are NOT mechanism specific.
115 * All we do here is make sure the two name_types are equal and then
116 * that the external_names are equal. Note the we do not take care
117 * of the case where two different external names map to the same
118 * internal name. We cannot determine this, since we as yet do not
119 * know what mechanism to use for calling the underlying
122 if (!union_name1->mech_type && !union_name2->mech_type) {
123 if (!g_OID_equal(union_name1->name_type, union_name2->name_type))
124 return (GSS_S_COMPLETE);
125 if ((union_name1->external_name->length !=
126 union_name2->external_name->length) ||
127 (memcmp(union_name1->external_name->value,
128 union_name2->external_name->value,
129 union_name1->external_name->length) != 0))
130 return (GSS_S_COMPLETE);
132 return (GSS_S_COMPLETE);
136 * Final case... one name is mechanism specific, the other isn't.
138 * We attempt to convert the general name to the mechanism type of
139 * the mechanism-specific name, and then do the compare. If we
140 * can't import the general name, then we return that the name is
143 if (union_name2->mech_type) {
144 /* We make union_name1 the mechanism specific name. */
145 union_name1 = (gss_union_name_t) name2;
146 union_name2 = (gss_union_name_t) name1;
148 major_status = __gss_import_internal_name(minor_status,
149 union_name1->mech_type,
152 if (major_status != GSS_S_COMPLETE)
153 return (GSS_S_COMPLETE);
154 #ifdef USE_MECH_CONTEXT
155 major_status = mech->gss_compare_name(mech->context, minor_status,
157 major_status = mech->gss_compare_name(minor_status,
159 union_name1->mech_name,
160 internal_name, name_equal);
161 __gss_release_internal_name(&temp_minor, union_name1->mech_type,
163 return (major_status);