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 ctx = (gss_union_ctx_id_t) malloc(sizeof(gss_union_ctx_id_desc));
102 return (GSS_S_FAILURE);
104 if (interprocess_token->length >= sizeof (OM_uint32)) {
105 p = interprocess_token->value;
106 length = (OM_uint32)*p++;
107 length = (OM_uint32)(length << 8) + *p++;
108 length = (OM_uint32)(length << 8) + *p++;
109 length = (OM_uint32)(length << 8) + *p++;
113 length > (interprocess_token->length - sizeof (OM_uint32))) {
115 return (GSS_S_CALL_BAD_STRUCTURE | GSS_S_DEFECTIVE_TOKEN);
118 token_mech.length = length;
119 token_mech.elements = p;
123 token.length = interprocess_token->length - sizeof (OM_uint32) - length;
127 * select the approprate underlying mechanism routine and
131 status = gssint_select_mech_type(minor_status, &token_mech,
133 if (status != GSS_S_COMPLETE)
136 mech = gssint_get_mechanism(selected_mech);
138 status = GSS_S_BAD_MECH;
141 if (!mech->gssspi_import_sec_context_by_mech &&
142 !mech->gss_import_sec_context) {
143 status = GSS_S_UNAVAILABLE;
147 if (generic_gss_copy_oid(minor_status, selected_mech,
148 &ctx->mech_type) != GSS_S_COMPLETE) {
149 status = GSS_S_FAILURE;
153 if (mech->gssspi_import_sec_context_by_mech) {
154 public_mech = gssint_get_public_oid(selected_mech);
155 status = mech->gssspi_import_sec_context_by_mech(minor_status,
159 status = mech->gss_import_sec_context(minor_status, &token, &mctx);
161 if (status == GSS_S_COMPLETE) {
162 ctx->internal_ctx_id = mctx;
164 *context_handle = (gss_ctx_id_t)ctx;
165 return (GSS_S_COMPLETE);
167 map_error(minor_status, mech);
168 free(ctx->mech_type->elements);
169 free(ctx->mech_type);
175 #endif /* LEAN_CLIENT */