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