1 /* #pragma ident "@(#)g_imp_sec_context.c 1.18 04/02/23 SMI" */
4 * Copyright 1996 by Sun Microsystems, Inc.
6 * Permission to use, copy, modify, distribute, and sell this software
7 * and its documentation for any purpose is hereby granted without fee,
8 * provided that the above copyright notice appears in all copies and
9 * that both that copyright notice and this permission notice appear in
10 * supporting documentation, and that the name of Sun Microsystems not be used
11 * in advertising or publicity pertaining to distribution of the software
12 * without specific, written prior permission. Sun Microsystems makes no
13 * representations about the suitability of this software for any
14 * purpose. It is provided "as is" without express or implied warranty.
16 * SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
20 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
21 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22 * PERFORMANCE OF THIS SOFTWARE.
26 * glue routine gss_export_sec_context
41 OM_uint32 *minor_status,
42 gss_buffer_t interprocess_token,
43 gss_ctx_id_t *context_handle)
46 /* Initialize outputs. */
47 if (minor_status != NULL)
50 if (context_handle != NULL)
51 *context_handle = GSS_C_NO_CONTEXT;
53 /* Validate arguments. */
55 if (minor_status == NULL)
56 return (GSS_S_CALL_INACCESSIBLE_WRITE);
58 if (context_handle == NULL)
59 return (GSS_S_CALL_INACCESSIBLE_WRITE);
61 if (interprocess_token == GSS_C_NO_BUFFER)
62 return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_DEFECTIVE_TOKEN);
64 if (GSS_EMPTY_BUFFER(interprocess_token))
65 return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_DEFECTIVE_TOKEN);
67 return (GSS_S_COMPLETE);
71 OM_uint32 KRB5_CALLCONV
72 gss_import_sec_context(minor_status,
76 OM_uint32 * minor_status;
77 gss_buffer_t interprocess_token;
78 gss_ctx_id_t * context_handle;
84 gss_union_ctx_id_t ctx;
86 gss_buffer_desc token;
87 gss_OID_desc token_mech;
88 gss_OID selected_mech = GSS_C_NO_OID;
92 status = val_imp_sec_ctx_args(minor_status,
93 interprocess_token, context_handle);
94 if (status != GSS_S_COMPLETE)
97 /* Initial value needed below. */
98 status = GSS_S_FAILURE;
100 if (interprocess_token->length >= sizeof (OM_uint32)) {
101 p = interprocess_token->value;
102 length = (OM_uint32)*p++;
103 length = (OM_uint32)(length << 8) + *p++;
104 length = (OM_uint32)(length << 8) + *p++;
105 length = (OM_uint32)(length << 8) + *p++;
109 length > (interprocess_token->length - sizeof (OM_uint32))) {
110 return (GSS_S_CALL_BAD_STRUCTURE | GSS_S_DEFECTIVE_TOKEN);
113 token_mech.length = length;
114 token_mech.elements = p;
118 token.length = interprocess_token->length - sizeof (OM_uint32) - length;
122 * select the approprate underlying mechanism routine and
126 status = gssint_select_mech_type(minor_status, &token_mech,
128 if (status != GSS_S_COMPLETE)
131 mech = gssint_get_mechanism(selected_mech);
133 return GSS_S_BAD_MECH;
134 if (!mech->gssspi_import_sec_context_by_mech &&
135 !mech->gss_import_sec_context)
136 return GSS_S_UNAVAILABLE;
138 status = gssint_create_union_context(minor_status, selected_mech, &ctx);
139 if (status != GSS_S_COMPLETE)
142 if (mech->gssspi_import_sec_context_by_mech) {
143 public_mech = gssint_get_public_oid(selected_mech);
144 status = mech->gssspi_import_sec_context_by_mech(minor_status,
148 status = mech->gss_import_sec_context(minor_status, &token, &mctx);
150 if (status == GSS_S_COMPLETE) {
151 ctx->internal_ctx_id = mctx;
152 *context_handle = (gss_ctx_id_t)ctx;
153 return (GSS_S_COMPLETE);
155 map_error(minor_status, mech);
156 free(ctx->mech_type->elements);
157 free(ctx->mech_type);
161 #endif /* LEAN_CLIENT */