1*7f2fe78bSCy Schubert /* #pragma ident "@(#)g_inquire_names.c 1.16 04/02/23 SMI" */
2*7f2fe78bSCy Schubert
3*7f2fe78bSCy Schubert /*
4*7f2fe78bSCy Schubert * Copyright 1996 by Sun Microsystems, Inc.
5*7f2fe78bSCy Schubert *
6*7f2fe78bSCy Schubert * Permission to use, copy, modify, distribute, and sell this software
7*7f2fe78bSCy Schubert * and its documentation for any purpose is hereby granted without fee,
8*7f2fe78bSCy Schubert * provided that the above copyright notice appears in all copies and
9*7f2fe78bSCy Schubert * that both that copyright notice and this permission notice appear in
10*7f2fe78bSCy Schubert * supporting documentation, and that the name of Sun Microsystems not be used
11*7f2fe78bSCy Schubert * in advertising or publicity pertaining to distribution of the software
12*7f2fe78bSCy Schubert * without specific, written prior permission. Sun Microsystems makes no
13*7f2fe78bSCy Schubert * representations about the suitability of this software for any
14*7f2fe78bSCy Schubert * purpose. It is provided "as is" without express or implied warranty.
15*7f2fe78bSCy Schubert *
16*7f2fe78bSCy Schubert * SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17*7f2fe78bSCy Schubert * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18*7f2fe78bSCy Schubert * EVENT SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19*7f2fe78bSCy Schubert * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
20*7f2fe78bSCy Schubert * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
21*7f2fe78bSCy Schubert * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22*7f2fe78bSCy Schubert * PERFORMANCE OF THIS SOFTWARE.
23*7f2fe78bSCy Schubert */
24*7f2fe78bSCy Schubert
25*7f2fe78bSCy Schubert /*
26*7f2fe78bSCy Schubert * glue routine for gss_inquire_context
27*7f2fe78bSCy Schubert */
28*7f2fe78bSCy Schubert
29*7f2fe78bSCy Schubert #include "mglueP.h"
30*7f2fe78bSCy Schubert
31*7f2fe78bSCy Schubert #define MAX_MECH_OID_PAIRS 32
32*7f2fe78bSCy Schubert
33*7f2fe78bSCy Schubert /* Last argument new for V2 */
34*7f2fe78bSCy Schubert OM_uint32 KRB5_CALLCONV
gss_inquire_names_for_mech(minor_status,mechanism,name_types)35*7f2fe78bSCy Schubert gss_inquire_names_for_mech(minor_status, mechanism, name_types)
36*7f2fe78bSCy Schubert
37*7f2fe78bSCy Schubert OM_uint32 * minor_status;
38*7f2fe78bSCy Schubert gss_OID mechanism;
39*7f2fe78bSCy Schubert gss_OID_set * name_types;
40*7f2fe78bSCy Schubert
41*7f2fe78bSCy Schubert {
42*7f2fe78bSCy Schubert OM_uint32 status;
43*7f2fe78bSCy Schubert gss_OID selected_mech = GSS_C_NO_OID, public_mech;
44*7f2fe78bSCy Schubert gss_mechanism mech;
45*7f2fe78bSCy Schubert
46*7f2fe78bSCy Schubert /* Initialize outputs. */
47*7f2fe78bSCy Schubert
48*7f2fe78bSCy Schubert if (minor_status != NULL)
49*7f2fe78bSCy Schubert *minor_status = 0;
50*7f2fe78bSCy Schubert
51*7f2fe78bSCy Schubert if (name_types != NULL)
52*7f2fe78bSCy Schubert *name_types = GSS_C_NO_OID_SET;
53*7f2fe78bSCy Schubert
54*7f2fe78bSCy Schubert /* Validate arguments. */
55*7f2fe78bSCy Schubert
56*7f2fe78bSCy Schubert if (minor_status == NULL)
57*7f2fe78bSCy Schubert return (GSS_S_CALL_INACCESSIBLE_WRITE);
58*7f2fe78bSCy Schubert
59*7f2fe78bSCy Schubert if (name_types == NULL)
60*7f2fe78bSCy Schubert return (GSS_S_CALL_INACCESSIBLE_WRITE);
61*7f2fe78bSCy Schubert
62*7f2fe78bSCy Schubert /*
63*7f2fe78bSCy Schubert * select the approprate underlying mechanism routine and
64*7f2fe78bSCy Schubert * call it.
65*7f2fe78bSCy Schubert */
66*7f2fe78bSCy Schubert
67*7f2fe78bSCy Schubert status = gssint_select_mech_type(minor_status, mechanism,
68*7f2fe78bSCy Schubert &selected_mech);
69*7f2fe78bSCy Schubert if (status != GSS_S_COMPLETE)
70*7f2fe78bSCy Schubert return (status);
71*7f2fe78bSCy Schubert
72*7f2fe78bSCy Schubert mech = gssint_get_mechanism(selected_mech);
73*7f2fe78bSCy Schubert if (mech == NULL)
74*7f2fe78bSCy Schubert return GSS_S_BAD_MECH;
75*7f2fe78bSCy Schubert else if (mech->gss_inquire_names_for_mech == NULL)
76*7f2fe78bSCy Schubert return GSS_S_UNAVAILABLE;
77*7f2fe78bSCy Schubert public_mech = gssint_get_public_oid(selected_mech);
78*7f2fe78bSCy Schubert status = mech->gss_inquire_names_for_mech(minor_status, public_mech,
79*7f2fe78bSCy Schubert name_types);
80*7f2fe78bSCy Schubert if (status != GSS_S_COMPLETE)
81*7f2fe78bSCy Schubert map_error(minor_status, mech);
82*7f2fe78bSCy Schubert
83*7f2fe78bSCy Schubert return status;
84*7f2fe78bSCy Schubert }
85*7f2fe78bSCy Schubert
86*7f2fe78bSCy Schubert static OM_uint32
val_inq_mechs4name_args(OM_uint32 * minor_status,const gss_name_t input_name,gss_OID_set * mech_set)87*7f2fe78bSCy Schubert val_inq_mechs4name_args(
88*7f2fe78bSCy Schubert OM_uint32 *minor_status,
89*7f2fe78bSCy Schubert const gss_name_t input_name,
90*7f2fe78bSCy Schubert gss_OID_set *mech_set)
91*7f2fe78bSCy Schubert {
92*7f2fe78bSCy Schubert
93*7f2fe78bSCy Schubert /* Initialize outputs. */
94*7f2fe78bSCy Schubert if (minor_status != NULL)
95*7f2fe78bSCy Schubert *minor_status = 0;
96*7f2fe78bSCy Schubert
97*7f2fe78bSCy Schubert if (mech_set != NULL)
98*7f2fe78bSCy Schubert *mech_set = GSS_C_NO_OID_SET;
99*7f2fe78bSCy Schubert
100*7f2fe78bSCy Schubert /* Validate arguments.e
101*7f2fe78bSCy Schubert */
102*7f2fe78bSCy Schubert if (minor_status == NULL)
103*7f2fe78bSCy Schubert return (GSS_S_CALL_INACCESSIBLE_WRITE);
104*7f2fe78bSCy Schubert
105*7f2fe78bSCy Schubert if (input_name == GSS_C_NO_NAME)
106*7f2fe78bSCy Schubert return (GSS_S_BAD_NAME);
107*7f2fe78bSCy Schubert
108*7f2fe78bSCy Schubert return (GSS_S_COMPLETE);
109*7f2fe78bSCy Schubert }
110*7f2fe78bSCy Schubert
111*7f2fe78bSCy Schubert static int
mech_supports_nametype(gss_OID mech_oid,gss_OID name_type)112*7f2fe78bSCy Schubert mech_supports_nametype(gss_OID mech_oid, gss_OID name_type)
113*7f2fe78bSCy Schubert {
114*7f2fe78bSCy Schubert OM_uint32 status, minor;
115*7f2fe78bSCy Schubert gss_OID_set types = GSS_C_NO_OID_SET;
116*7f2fe78bSCy Schubert int present;
117*7f2fe78bSCy Schubert
118*7f2fe78bSCy Schubert status = gss_inquire_names_for_mech(&minor, mech_oid, &types);
119*7f2fe78bSCy Schubert if (status != GSS_S_COMPLETE)
120*7f2fe78bSCy Schubert return (0);
121*7f2fe78bSCy Schubert status = gss_test_oid_set_member(&minor, name_type, types, &present);
122*7f2fe78bSCy Schubert (void) gss_release_oid_set(&minor, &types);
123*7f2fe78bSCy Schubert return (status == GSS_S_COMPLETE && present);
124*7f2fe78bSCy Schubert }
125*7f2fe78bSCy Schubert
126*7f2fe78bSCy Schubert OM_uint32 KRB5_CALLCONV
gss_inquire_mechs_for_name(OM_uint32 * minor_status,const gss_name_t input_name,gss_OID_set * mech_set)127*7f2fe78bSCy Schubert gss_inquire_mechs_for_name(OM_uint32 *minor_status,
128*7f2fe78bSCy Schubert const gss_name_t input_name, gss_OID_set *mech_set)
129*7f2fe78bSCy Schubert {
130*7f2fe78bSCy Schubert OM_uint32 status, tmpmin;
131*7f2fe78bSCy Schubert gss_OID_set all_mechs = GSS_C_NO_OID_SET;
132*7f2fe78bSCy Schubert gss_OID_set mechs = GSS_C_NO_OID_SET;
133*7f2fe78bSCy Schubert gss_OID mech_oid, name_type;
134*7f2fe78bSCy Schubert gss_buffer_desc name_buffer = GSS_C_EMPTY_BUFFER;
135*7f2fe78bSCy Schubert size_t i;
136*7f2fe78bSCy Schubert
137*7f2fe78bSCy Schubert status = val_inq_mechs4name_args(minor_status, input_name, mech_set);
138*7f2fe78bSCy Schubert if (status != GSS_S_COMPLETE)
139*7f2fe78bSCy Schubert return (status);
140*7f2fe78bSCy Schubert
141*7f2fe78bSCy Schubert status = gss_display_name(minor_status, input_name, &name_buffer,
142*7f2fe78bSCy Schubert &name_type);
143*7f2fe78bSCy Schubert if (status != GSS_S_COMPLETE)
144*7f2fe78bSCy Schubert goto cleanup;
145*7f2fe78bSCy Schubert status = gss_indicate_mechs(minor_status, &all_mechs);
146*7f2fe78bSCy Schubert if (status != GSS_S_COMPLETE)
147*7f2fe78bSCy Schubert goto cleanup;
148*7f2fe78bSCy Schubert status = gss_create_empty_oid_set(minor_status, &mechs);
149*7f2fe78bSCy Schubert if (status != GSS_S_COMPLETE)
150*7f2fe78bSCy Schubert goto cleanup;
151*7f2fe78bSCy Schubert for (i = 0; i < all_mechs->count; i++) {
152*7f2fe78bSCy Schubert mech_oid = &all_mechs->elements[i];
153*7f2fe78bSCy Schubert if (mech_supports_nametype(mech_oid, name_type)) {
154*7f2fe78bSCy Schubert status = gss_add_oid_set_member(minor_status, mech_oid, &mechs);
155*7f2fe78bSCy Schubert if (status != GSS_S_COMPLETE)
156*7f2fe78bSCy Schubert goto cleanup;
157*7f2fe78bSCy Schubert }
158*7f2fe78bSCy Schubert }
159*7f2fe78bSCy Schubert
160*7f2fe78bSCy Schubert *mech_set = mechs;
161*7f2fe78bSCy Schubert mechs = GSS_C_NO_OID_SET;
162*7f2fe78bSCy Schubert
163*7f2fe78bSCy Schubert cleanup:
164*7f2fe78bSCy Schubert (void) gss_release_buffer(&tmpmin, &name_buffer);
165*7f2fe78bSCy Schubert (void) gss_release_oid_set(&tmpmin, &all_mechs);
166*7f2fe78bSCy Schubert (void) gss_release_oid_set(&tmpmin, &mechs);
167*7f2fe78bSCy Schubert return (status);
168*7f2fe78bSCy Schubert }
169