xref: /titanic_41/usr/src/lib/libgss/g_inquire_names.c (revision aff4bce51ecc47df7e5a6351b7cee6bc20408c63)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  *  glue routine for gss_inquire_context
28  */
29 
30 #include <mechglueP.h>
31 
32 #define	MAX_MECH_OID_PAIRS 32
33 
34 /* Last argument new for V2 */
35 OM_uint32
36 gss_inquire_names_for_mech(minor_status, mechanism, name_types)
37 
38 OM_uint32 *		minor_status;
39 const gss_OID 		mechanism;
40 gss_OID_set *		name_types;
41 
42 {
43 	OM_uint32		status;
44 	gss_mechanism		mech;
45 
46 	/* Initialize outputs. */
47 
48 	if (minor_status != NULL)
49 		*minor_status = 0;
50 
51 	if (name_types != NULL)
52 		*name_types = GSS_C_NO_OID_SET;
53 
54 	/* Validate arguments. */
55 
56 	if (minor_status == NULL)
57 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
58 
59 	if (name_types == NULL)
60 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
61 
62 	/*
63 	 * select the approprate underlying mechanism routine and
64 	 * call it.
65 	 */
66 
67 	mech = __gss_get_mechanism(mechanism);
68 
69 	if (mech) {
70 
71 		if (mech->gss_inquire_names_for_mech)
72 			status = mech->gss_inquire_names_for_mech(
73 					mech->context,
74 					minor_status,
75 					mechanism,
76 					name_types);
77 		else
78 			status = GSS_S_UNAVAILABLE;
79 
80 		return (status);
81 	}
82 
83 	return (GSS_S_BAD_MECH);
84 }
85 
86 static OM_uint32 val_inq_mechs4name_args(
87 	OM_uint32 *minor_status,
88 	const gss_name_t input_name,
89 	gss_OID_set *mech_set)
90 {
91 
92 	/* Initialize outputs. */
93 	if (minor_status != NULL)
94 		*minor_status = 0;
95 
96 	if (mech_set != NULL)
97 		*mech_set = GSS_C_NO_OID_SET;
98 
99 	/* Validate arguments. */
100 
101 	if (minor_status == NULL)
102 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
103 
104 	if (input_name == GSS_C_NO_NAME)
105 		return (GSS_S_BAD_NAME);
106 
107 	return (GSS_S_COMPLETE);
108 }
109 
110 OM_uint32
111 gss_inquire_mechs_for_name(minor_status, input_name, mech_set)
112 
113 OM_uint32 *		minor_status;
114 const gss_name_t	input_name;
115 gss_OID_set *		mech_set;
116 
117 {
118 	OM_uint32		status;
119 	static char		*mech_list[MAX_MECH_OID_PAIRS+1];
120 	gss_OID_set		mech_name_types;
121 	int			present;
122 	char 			*mechanism;
123 	gss_OID 		mechOid;
124 	gss_OID 		name_type;
125 	gss_buffer_desc		name_buffer;
126 	int			i;
127 
128 	status = val_inq_mechs4name_args(minor_status, input_name, mech_set);
129 	if (status != GSS_S_COMPLETE)
130 		return (status);
131 
132 	status = gss_create_empty_oid_set(minor_status, mech_set);
133 	if (status != GSS_S_COMPLETE)
134 		return (status);
135 	*mech_list = NULL;
136 	status = __gss_get_mechanisms(mech_list, MAX_MECH_OID_PAIRS+1);
137 	if (status != GSS_S_COMPLETE)
138 		return (status);
139 	for (i = 0; i < MAX_MECH_OID_PAIRS && mech_list[i] != NULL; i++) {
140 		mechanism = mech_list[i];
141 		if (__gss_mech_to_oid(mechanism, &mechOid) == GSS_S_COMPLETE) {
142 			status = gss_inquire_names_for_mech(
143 					minor_status,
144 					mechOid,
145 					&mech_name_types);
146 			if (status == GSS_S_COMPLETE) {
147 				status = gss_display_name(minor_status,
148 							input_name,
149 							&name_buffer,
150 							&name_type);
151 
152 				(void) gss_release_buffer(NULL, &name_buffer);
153 
154 				if (status == GSS_S_COMPLETE && name_type) {
155 					status = gss_test_oid_set_member(
156 							minor_status,
157 							name_type,
158 							mech_name_types,
159 							&present);
160 					if (status == GSS_S_COMPLETE &&
161 						present) {
162 						status = gss_add_oid_set_member(
163 							minor_status,
164 							mechOid,
165 							mech_set);
166 						if (status != GSS_S_COMPLETE) {
167 						(void) gss_release_oid_set(
168 							    minor_status,
169 							    &mech_name_types);
170 						(void) gss_release_oid_set(
171 							    minor_status,
172 							    mech_set);
173 							return (status);
174 						}
175 					}
176 				}
177 				(void) gss_release_oid_set(
178 					minor_status,
179 					&mech_name_types);
180 			}
181 		} else {
182 			(void) gss_release_oid_set(
183 				minor_status,
184 				mech_set);
185 			return (GSS_S_FAILURE);
186 		}
187 	}
188 	return (GSS_S_COMPLETE);
189 }
190