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.
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.
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]
22 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
26 * glue routine for gss_accept_sec_context
29 #include <mechglueP.h>
30 #include "gssapiP_generic.h"
41 OM_uint32
*minor_status
,
42 gss_ctx_id_t
*context_handle
,
43 gss_buffer_t input_token_buffer
,
46 gss_buffer_t output_token
,
47 gss_cred_id_t
*d_cred
)
50 /* Initialize outputs. */
52 if (minor_status
!= NULL
)
56 *src_name
= GSS_C_NO_NAME
;
58 if (mech_type
!= NULL
)
59 *mech_type
= GSS_C_NO_OID
;
61 if (output_token
!= GSS_C_NO_BUFFER
) {
62 output_token
->length
= 0;
63 output_token
->value
= NULL
;
67 *d_cred
= GSS_C_NO_CREDENTIAL
;
69 /* Validate arguments. */
71 if (minor_status
== NULL
)
72 return (GSS_S_CALL_INACCESSIBLE_WRITE
);
74 if (context_handle
== NULL
)
75 return (GSS_S_CALL_INACCESSIBLE_WRITE
);
77 if (input_token_buffer
== GSS_C_NO_BUFFER
)
78 return (GSS_S_CALL_INACCESSIBLE_READ
);
80 if (output_token
== GSS_C_NO_BUFFER
)
81 return (GSS_S_CALL_INACCESSIBLE_WRITE
);
83 return (GSS_S_COMPLETE
);
87 gss_accept_sec_context(minor_status
,
99 OM_uint32
*minor_status
;
100 gss_ctx_id_t
*context_handle
;
101 const gss_cred_id_t verifier_cred_handle
;
102 const gss_buffer_t input_token_buffer
;
103 const gss_channel_bindings_t input_chan_bindings
;
104 gss_name_t
*src_name
;
106 gss_buffer_t output_token
;
107 OM_uint32
*ret_flags
;
109 gss_cred_id_t
*d_cred
; /* delegated cred handle */
112 OM_uint32 status
, temp_status
, t_minstat
;
113 gss_union_ctx_id_t union_ctx_id
;
114 gss_union_cred_t union_cred
;
115 gss_cred_id_t input_cred_handle
= GSS_C_NO_CREDENTIAL
;
116 gss_cred_id_t tmp_d_cred
= GSS_C_NO_CREDENTIAL
;
117 gss_name_t internal_name
= GSS_C_NO_NAME
;
118 gss_name_t tmp_src_name
= GSS_C_NO_NAME
;
119 gss_OID_desc token_mech_type_desc
;
120 gss_OID token_mech_type
= &token_mech_type_desc
;
124 status
= val_acc_sec_ctx_args(minor_status
,
131 if (status
!= GSS_S_COMPLETE
)
135 * if context_handle is GSS_C_NO_CONTEXT, allocate a union context
136 * descriptor to hold the mech type information as well as the
137 * underlying mechanism context handle. Otherwise, cast the
138 * value of *context_handle to the union context variable.
141 if (*context_handle
== GSS_C_NO_CONTEXT
) {
143 if (input_token_buffer
== GSS_C_NO_BUFFER
)
144 return (GSS_S_CALL_INACCESSIBLE_READ
);
146 /* Get the token mech type */
147 status
= __gss_get_mech_type(token_mech_type
,
153 status
= GSS_S_FAILURE
;
154 union_ctx_id
= (gss_union_ctx_id_t
)
155 malloc(sizeof (gss_union_ctx_id_desc
));
157 return (GSS_S_FAILURE
);
159 union_ctx_id
->internal_ctx_id
= GSS_C_NO_CONTEXT
;
160 status
= generic_gss_copy_oid(&t_minstat
,
162 &union_ctx_id
->mech_type
);
163 if (status
!= GSS_S_COMPLETE
) {
168 /* set the new context handle to caller's data */
169 *context_handle
= (gss_ctx_id_t
)union_ctx_id
;
171 union_ctx_id
= (gss_union_ctx_id_t
)*context_handle
;
172 token_mech_type
= union_ctx_id
->mech_type
;
176 * get the appropriate cred handle from the union cred struct.
177 * defaults to GSS_C_NO_CREDENTIAL if there is no cred, which will
178 * use the default credential.
180 union_cred
= (gss_union_cred_t
)verifier_cred_handle
;
181 input_cred_handle
= __gss_get_mechanism_cred(union_cred
,
185 * now select the approprate underlying mechanism routine and
189 mech
= __gss_get_mechanism(token_mech_type
);
190 if (mech
&& mech
->gss_accept_sec_context
) {
191 status
= mech
->gss_accept_sec_context(
194 &union_ctx_id
->internal_ctx_id
,
203 d_cred
? &tmp_d_cred
: NULL
);
205 /* If there's more work to do, keep going... */
206 if (status
== GSS_S_CONTINUE_NEEDED
)
207 return (GSS_S_CONTINUE_NEEDED
);
209 /* if the call failed, return with failure */
210 if (status
!= GSS_S_COMPLETE
) {
211 if (mech_type
&& (*mech_type
!= GSS_C_NULL_OID
))
212 map_error_oid(minor_status
, *mech_type
);
214 map_error(minor_status
, mech
);
221 * if src_name is non-NULL,
222 * convert internal_name into a union name equivalent
223 * First call the mechanism specific display_name()
224 * then call gss_import_name() to create
225 * the union name struct cast to src_name
226 * NB: __gss_convert_name_to_union_name will
227 * "consume" (free) the name.
229 if (internal_name
!= NULL
) {
230 temp_status
= __gss_convert_name_to_union_name(
232 internal_name
, &tmp_src_name
);
233 if (temp_status
!= GSS_S_COMPLETE
) {
234 *minor_status
= t_minstat
;
235 map_error(minor_status
, mech
);
236 if (output_token
->length
)
237 (void) gss_release_buffer(
240 return (temp_status
);
242 if (src_name
!= NULL
) {
243 *src_name
= tmp_src_name
;
245 } else if (src_name
!= NULL
) {
246 *src_name
= GSS_C_NO_NAME
;
249 /* Ensure we're returning correct creds format */
250 if ((flags
& GSS_C_DELEG_FLAG
) &&
251 tmp_d_cred
!= GSS_C_NO_CREDENTIAL
) {
253 * If we got back an OID different from the original
254 * token OID, assume the delegated_cred is already
255 * a proper union_cred and just return it. Don't
256 * try to re-wrap it. This is for SPNEGO or other
259 if (*mech_type
!= GSS_C_NO_OID
&&
260 token_mech_type
!= GSS_C_NO_OID
&&
261 !g_OID_equal(*mech_type
, token_mech_type
)) {
262 *d_cred
= tmp_d_cred
;
264 gss_union_cred_t d_u_cred
= NULL
;
266 d_u_cred
= malloc(sizeof (gss_union_cred_desc
));
267 if (d_u_cred
== NULL
) {
268 status
= GSS_S_FAILURE
;
271 (void) memset(d_u_cred
, 0,
272 sizeof (gss_union_cred_desc
));
276 status
= generic_gss_copy_oid(
279 &d_u_cred
->mechs_array
);
281 if (status
!= GSS_S_COMPLETE
) {
286 d_u_cred
->cred_array
= malloc(
287 sizeof (gss_cred_id_t
));
288 if (d_u_cred
->cred_array
!= NULL
) {
289 d_u_cred
->cred_array
[0] = tmp_d_cred
;
292 status
= GSS_S_FAILURE
;
296 if (status
!= GSS_S_COMPLETE
) {
297 free(d_u_cred
->cred_array
);
302 internal_name
= GSS_C_NO_NAME
;
304 d_u_cred
->auxinfo
.creation_time
= time(0);
305 d_u_cred
->auxinfo
.time_rec
= 0;
307 if (mech
->gss_inquire_cred
) {
308 status
= mech
->gss_inquire_cred(
313 &d_u_cred
->auxinfo
.time_rec
,
314 &d_u_cred
->auxinfo
.cred_usage
,
318 if (status
!= GSS_S_COMPLETE
)
319 map_error(minor_status
, mech
);
321 if (internal_name
!= NULL
) {
323 __gss_convert_name_to_union_name(
325 internal_name
, &tmp_src_name
);
326 if (temp_status
!= GSS_S_COMPLETE
) {
327 *minor_status
= t_minstat
;
328 map_error(minor_status
, mech
);
329 if (output_token
->length
)
330 (void) gss_release_buffer(
333 free(d_u_cred
->cred_array
);
335 return (temp_status
);
339 if (tmp_src_name
!= NULL
) {
340 status
= gss_display_name(
343 &d_u_cred
->auxinfo
.name
,
344 &d_u_cred
->auxinfo
.name_type
);
347 *d_cred
= (gss_cred_id_t
)d_u_cred
;
350 if (ret_flags
!= NULL
) {
354 if (src_name
== NULL
&& tmp_src_name
!= NULL
)
355 (void) gss_release_name(&t_minstat
,
360 status
= GSS_S_BAD_MECH
;
365 if (union_ctx_id
->mech_type
) {
366 if (union_ctx_id
->mech_type
->elements
)
367 free(union_ctx_id
->mech_type
->elements
);
368 free(union_ctx_id
->mech_type
);
371 *context_handle
= GSS_C_NO_CONTEXT
;
377 * Don't release, it causes a problem with error token.
379 if (output_token
->length
)
380 (void) gss_release_buffer(&t_minstat
, output_token
);
384 *src_name
= GSS_C_NO_NAME
;
386 if (tmp_src_name
!= GSS_C_NO_NAME
)
387 (void) gss_release_buffer(&t_minstat
,
388 (gss_buffer_t
)tmp_src_name
);
392 #endif /* LEAN_CLIENT */