1 /* #ident "@(#)g_imp_sec_context.c 1.2 96/01/18 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
37 OM_uint32 KRB5_CALLCONV
38 gss_import_sec_context(minor_status,
42 OM_uint32 * minor_status;
43 gss_buffer_t interprocess_token;
44 gss_ctx_id_t * context_handle;
50 gss_union_ctx_id_t ctx;
51 gss_buffer_desc token;
58 if (interprocess_token->length == 0 || interprocess_token->value == 0)
59 return (GSS_S_DEFECTIVE_TOKEN);
61 status = GSS_S_FAILURE;
63 ctx = (gss_union_ctx_id_t) malloc(sizeof(gss_union_ctx_id_desc));
65 *minor_status = ENOMEM;
68 ctx->mech_type = (gss_OID) malloc(sizeof(gss_OID_desc));
69 if (!ctx->mech_type) {
70 *minor_status = ENOMEM;
73 p = interprocess_token->value;
75 length = (length << 8) + *p++;
76 length = (length << 8) + *p++;
77 length = (length << 8) + *p++;
79 ctx->mech_type->length = length;
80 ctx->mech_type->elements = malloc(length);
81 if (!ctx->mech_type->elements) {
82 *minor_status = ENOMEM;
85 memcpy(ctx->mech_type->elements, p, length);
88 token.length = interprocess_token->length - 4 - length;
92 * select the approprate underlying mechanism routine and
96 mech = __gss_get_mechanism (ctx->mech_type);
98 status = GSS_S_BAD_MECH;
101 if (!mech->gss_import_sec_context) {
102 status = GSS_S_BAD_BINDINGS;
106 #ifdef USE_MECH_CONTEXT
107 status = mech->gss_import_sec_context(mech->context, minor_status,
109 status = mech->gss_import_sec_context(minor_status,
111 &token, &ctx->internal_ctx_id);
113 if (status == GSS_S_COMPLETE) {
114 *context_handle = ctx;
115 return (GSS_S_COMPLETE);
120 if (ctx->mech_type) {
121 if (ctx->mech_type->elements)
122 free(ctx->mech_type->elements);
123 free(ctx->mech_type);