1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate /*
30*0Sstevel@tonic-gate  *  glue routine for gss_compare_name
31*0Sstevel@tonic-gate  *
32*0Sstevel@tonic-gate  */
33*0Sstevel@tonic-gate 
34*0Sstevel@tonic-gate #include <mechglueP.h>
35*0Sstevel@tonic-gate #ifdef HAVE_STDLIB_H
36*0Sstevel@tonic-gate #include <stdlib.h>
37*0Sstevel@tonic-gate #endif
38*0Sstevel@tonic-gate #include <string.h>
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate OM_uint32
41*0Sstevel@tonic-gate gss_compare_name(minor_status,
42*0Sstevel@tonic-gate 			name1,
43*0Sstevel@tonic-gate 			name2,
44*0Sstevel@tonic-gate 			name_equal)
45*0Sstevel@tonic-gate 
46*0Sstevel@tonic-gate OM_uint32 *minor_status;
47*0Sstevel@tonic-gate const gss_name_t name1;
48*0Sstevel@tonic-gate const gss_name_t name2;
49*0Sstevel@tonic-gate int *name_equal;
50*0Sstevel@tonic-gate 
51*0Sstevel@tonic-gate {
52*0Sstevel@tonic-gate 	OM_uint32		major_status, temp_minor;
53*0Sstevel@tonic-gate 	gss_union_name_t	union_name1, union_name2;
54*0Sstevel@tonic-gate 	gss_mechanism		mech;
55*0Sstevel@tonic-gate 	gss_name_t		internal_name;
56*0Sstevel@tonic-gate 
57*0Sstevel@tonic-gate 	if (minor_status == NULL)
58*0Sstevel@tonic-gate 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
59*0Sstevel@tonic-gate 	*minor_status = 0;
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate 	if (name1 == 0 || name2 == 0)
62*0Sstevel@tonic-gate 		return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_BAD_NAME);
63*0Sstevel@tonic-gate 
64*0Sstevel@tonic-gate 	if (name_equal == NULL)
65*0Sstevel@tonic-gate 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
66*0Sstevel@tonic-gate 
67*0Sstevel@tonic-gate 	union_name1 = (gss_union_name_t)name1;
68*0Sstevel@tonic-gate 	union_name2 = (gss_union_name_t)name2;
69*0Sstevel@tonic-gate 	/*
70*0Sstevel@tonic-gate 	 * Try our hardest to make union_name1 be the mechanism-specific
71*0Sstevel@tonic-gate 	 * name.  (Of course we can't if both names aren't
72*0Sstevel@tonic-gate 	 * mechanism-specific.)
73*0Sstevel@tonic-gate 	 */
74*0Sstevel@tonic-gate 	if (union_name1->mech_type == 0) {
75*0Sstevel@tonic-gate 		union_name1 = (gss_union_name_t)name2;
76*0Sstevel@tonic-gate 		union_name2 = (gss_union_name_t)name1;
77*0Sstevel@tonic-gate 	}
78*0Sstevel@tonic-gate 	/*
79*0Sstevel@tonic-gate 	 * If union_name1 is mechanism specific, then fetch its mechanism
80*0Sstevel@tonic-gate 	 * information.
81*0Sstevel@tonic-gate 	 */
82*0Sstevel@tonic-gate 	if (union_name1->mech_type) {
83*0Sstevel@tonic-gate 		mech = __gss_get_mechanism(union_name1->mech_type);
84*0Sstevel@tonic-gate 		if (!mech)
85*0Sstevel@tonic-gate 			return (GSS_S_BAD_MECH);
86*0Sstevel@tonic-gate 		if (!mech->gss_compare_name)
87*0Sstevel@tonic-gate 			return (GSS_S_UNAVAILABLE);
88*0Sstevel@tonic-gate 	}
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate 	*name_equal = 0;	/* Default to *not* equal.... */
91*0Sstevel@tonic-gate 
92*0Sstevel@tonic-gate 	/*
93*0Sstevel@tonic-gate 	 * First case... both names are mechanism-specific
94*0Sstevel@tonic-gate 	 */
95*0Sstevel@tonic-gate 	if (union_name1->mech_type && union_name2->mech_type) {
96*0Sstevel@tonic-gate 		if (!g_OID_equal(union_name1->mech_type,
97*0Sstevel@tonic-gate 					union_name2->mech_type))
98*0Sstevel@tonic-gate 			return (GSS_S_COMPLETE);
99*0Sstevel@tonic-gate 		if ((union_name1->mech_name == 0) ||
100*0Sstevel@tonic-gate 			(union_name2->mech_name == 0))
101*0Sstevel@tonic-gate 			/* should never happen */
102*0Sstevel@tonic-gate 			return (GSS_S_BAD_NAME);
103*0Sstevel@tonic-gate 		return (mech->gss_compare_name(mech->context, minor_status,
104*0Sstevel@tonic-gate 							union_name1->mech_name,
105*0Sstevel@tonic-gate 							union_name2->mech_name,
106*0Sstevel@tonic-gate 							name_equal));
107*0Sstevel@tonic-gate 	}
108*0Sstevel@tonic-gate 
109*0Sstevel@tonic-gate 	/*
110*0Sstevel@tonic-gate 	 * Second case... both names are NOT mechanism specific.
111*0Sstevel@tonic-gate 	 *
112*0Sstevel@tonic-gate 	 * All we do here is make sure the two name_types are equal and then
113*0Sstevel@tonic-gate 	 * that the external_names are equal. Note the we do not take care
114*0Sstevel@tonic-gate 	 * of the case where two different external names map to the same
115*0Sstevel@tonic-gate 	 * internal name. We cannot determine this, since we as yet do not
116*0Sstevel@tonic-gate 	 * know what mechanism to use for calling the underlying
117*0Sstevel@tonic-gate 	 * gss_import_name().
118*0Sstevel@tonic-gate 	 */
119*0Sstevel@tonic-gate 	if (!union_name1->mech_type && !union_name2->mech_type) {
120*0Sstevel@tonic-gate 		/*
121*0Sstevel@tonic-gate 		 * Second case, first sub-case... one name has null
122*0Sstevel@tonic-gate 		 * name_type, the other doesn't.
123*0Sstevel@tonic-gate 		 *
124*0Sstevel@tonic-gate 		 * Not knowing a mech_type we can't import the name with
125*0Sstevel@tonic-gate 		 * null name_type so we can't compare.
126*0Sstevel@tonic-gate 		 */
127*0Sstevel@tonic-gate 		if ((union_name1->name_type == GSS_C_NULL_OID &&
128*0Sstevel@tonic-gate 		    union_name2->name_type != GSS_C_NULL_OID) ||
129*0Sstevel@tonic-gate 		    (union_name1->name_type != GSS_C_NULL_OID &&
130*0Sstevel@tonic-gate 		    union_name2->name_type == GSS_C_NULL_OID))
131*0Sstevel@tonic-gate 			return (GSS_S_COMPLETE);
132*0Sstevel@tonic-gate 		/*
133*0Sstevel@tonic-gate 		 * Second case, second sub-case... both names have
134*0Sstevel@tonic-gate 		 * name_types, but they are different.
135*0Sstevel@tonic-gate 		 */
136*0Sstevel@tonic-gate 		if ((union_name1->name_type != GSS_C_NULL_OID &&
137*0Sstevel@tonic-gate 		    union_name2->name_type != GSS_C_NULL_OID) &&
138*0Sstevel@tonic-gate 		    !g_OID_equal(union_name1->name_type,
139*0Sstevel@tonic-gate 					union_name2->name_type))
140*0Sstevel@tonic-gate 			return (GSS_S_COMPLETE);
141*0Sstevel@tonic-gate 		/*
142*0Sstevel@tonic-gate 		 * Second case, third sub-case... both names have equal
143*0Sstevel@tonic-gate 		 * name_types (and both have no mech_types) so we just
144*0Sstevel@tonic-gate 		 * compare the external_names.
145*0Sstevel@tonic-gate 		 */
146*0Sstevel@tonic-gate 		if ((union_name1->external_name->length !=
147*0Sstevel@tonic-gate 			union_name2->external_name->length) ||
148*0Sstevel@tonic-gate 			(memcmp(union_name1->external_name->value,
149*0Sstevel@tonic-gate 				union_name2->external_name->value,
150*0Sstevel@tonic-gate 				union_name1->external_name->length) != 0))
151*0Sstevel@tonic-gate 			return (GSS_S_COMPLETE);
152*0Sstevel@tonic-gate 		*name_equal = 1;
153*0Sstevel@tonic-gate 		return (GSS_S_COMPLETE);
154*0Sstevel@tonic-gate 	}
155*0Sstevel@tonic-gate 
156*0Sstevel@tonic-gate 	/*
157*0Sstevel@tonic-gate 	 * Final case... one name is mechanism specific, the other isn't.
158*0Sstevel@tonic-gate 	 *
159*0Sstevel@tonic-gate 	 * We attempt to convert the general name to the mechanism type of
160*0Sstevel@tonic-gate 	 * the mechanism-specific name, and then do the compare.  If we
161*0Sstevel@tonic-gate 	 * can't import the general name, then we return that the name is
162*0Sstevel@tonic-gate 	 * _NOT_ equal.
163*0Sstevel@tonic-gate 	 */
164*0Sstevel@tonic-gate 	if (union_name2->mech_type) {
165*0Sstevel@tonic-gate 		/* We make union_name1 the mechanism specific name. */
166*0Sstevel@tonic-gate 		union_name1 = (gss_union_name_t)name2;
167*0Sstevel@tonic-gate 		union_name2 = (gss_union_name_t)name1;
168*0Sstevel@tonic-gate 	}
169*0Sstevel@tonic-gate 	major_status = __gss_import_internal_name(minor_status,
170*0Sstevel@tonic-gate 							union_name1->mech_type,
171*0Sstevel@tonic-gate 							union_name2,
172*0Sstevel@tonic-gate 							&internal_name);
173*0Sstevel@tonic-gate 	if (major_status != GSS_S_COMPLETE)
174*0Sstevel@tonic-gate 		return (GSS_S_COMPLETE); /* return complete, but not equal */
175*0Sstevel@tonic-gate 
176*0Sstevel@tonic-gate 	major_status = mech->gss_compare_name(mech->context, minor_status,
177*0Sstevel@tonic-gate 							union_name1->mech_name,
178*0Sstevel@tonic-gate 							internal_name,
179*0Sstevel@tonic-gate 							name_equal);
180*0Sstevel@tonic-gate 	(void) __gss_release_internal_name(&temp_minor, union_name1->mech_type,
181*0Sstevel@tonic-gate 					&internal_name);
182*0Sstevel@tonic-gate 	return (major_status);
183*0Sstevel@tonic-gate }
184