10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
59698SPeter.Shoults@Sun.COM * Common Development and Distribution License (the "License").
69698SPeter.Shoults@Sun.COM * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*13132SGlenn.Barry@oracle.com * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate */
240Sstevel@tonic-gate
250Sstevel@tonic-gate /*
260Sstevel@tonic-gate * glue routine for gss_export_sec_context
270Sstevel@tonic-gate */
28*13132SGlenn.Barry@oracle.com #ifndef LEAN_CLIENT
290Sstevel@tonic-gate
300Sstevel@tonic-gate #include <mechglueP.h>
31*13132SGlenn.Barry@oracle.com #include "gssapiP_generic.h"
320Sstevel@tonic-gate #include <stdio.h>
330Sstevel@tonic-gate #include <errno.h>
340Sstevel@tonic-gate #ifdef HAVE_STDLIB_H
350Sstevel@tonic-gate #include <stdlib.h>
360Sstevel@tonic-gate #endif
370Sstevel@tonic-gate #include <string.h>
380Sstevel@tonic-gate
val_exp_sec_ctx_args(OM_uint32 * minor_status,gss_ctx_id_t * context_handle,gss_buffer_t interprocess_token)399698SPeter.Shoults@Sun.COM static OM_uint32 val_exp_sec_ctx_args(
409698SPeter.Shoults@Sun.COM OM_uint32 *minor_status,
419698SPeter.Shoults@Sun.COM gss_ctx_id_t *context_handle,
429698SPeter.Shoults@Sun.COM gss_buffer_t interprocess_token)
439698SPeter.Shoults@Sun.COM {
449698SPeter.Shoults@Sun.COM
459698SPeter.Shoults@Sun.COM /* Initialize outputs. */
469698SPeter.Shoults@Sun.COM
479698SPeter.Shoults@Sun.COM if (minor_status != NULL)
489698SPeter.Shoults@Sun.COM *minor_status = 0;
499698SPeter.Shoults@Sun.COM
509698SPeter.Shoults@Sun.COM if (interprocess_token != GSS_C_NO_BUFFER) {
519698SPeter.Shoults@Sun.COM interprocess_token->length = 0;
529698SPeter.Shoults@Sun.COM interprocess_token->value = NULL;
539698SPeter.Shoults@Sun.COM }
549698SPeter.Shoults@Sun.COM
559698SPeter.Shoults@Sun.COM /* Validate arguments. */
569698SPeter.Shoults@Sun.COM
579698SPeter.Shoults@Sun.COM if (minor_status == NULL)
589698SPeter.Shoults@Sun.COM return (GSS_S_CALL_INACCESSIBLE_WRITE);
599698SPeter.Shoults@Sun.COM
609698SPeter.Shoults@Sun.COM if (context_handle == NULL || *context_handle == GSS_C_NO_CONTEXT)
619698SPeter.Shoults@Sun.COM return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_NO_CONTEXT);
629698SPeter.Shoults@Sun.COM
639698SPeter.Shoults@Sun.COM if (interprocess_token == GSS_C_NO_BUFFER)
649698SPeter.Shoults@Sun.COM return (GSS_S_CALL_INACCESSIBLE_WRITE);
659698SPeter.Shoults@Sun.COM
669698SPeter.Shoults@Sun.COM return (GSS_S_COMPLETE);
679698SPeter.Shoults@Sun.COM }
689698SPeter.Shoults@Sun.COM
690Sstevel@tonic-gate OM_uint32
gss_export_sec_context(minor_status,context_handle,interprocess_token)700Sstevel@tonic-gate gss_export_sec_context(minor_status,
710Sstevel@tonic-gate context_handle,
720Sstevel@tonic-gate interprocess_token)
730Sstevel@tonic-gate
740Sstevel@tonic-gate OM_uint32 *minor_status;
750Sstevel@tonic-gate gss_ctx_id_t *context_handle;
760Sstevel@tonic-gate gss_buffer_t interprocess_token;
770Sstevel@tonic-gate
780Sstevel@tonic-gate {
790Sstevel@tonic-gate OM_uint32 status;
800Sstevel@tonic-gate OM_uint32 length;
810Sstevel@tonic-gate gss_union_ctx_id_t ctx;
820Sstevel@tonic-gate gss_mechanism mech;
830Sstevel@tonic-gate gss_buffer_desc token;
840Sstevel@tonic-gate char *buf;
850Sstevel@tonic-gate
869698SPeter.Shoults@Sun.COM status = val_exp_sec_ctx_args(minor_status,
879698SPeter.Shoults@Sun.COM context_handle, interprocess_token);
889698SPeter.Shoults@Sun.COM if (status != GSS_S_COMPLETE)
899698SPeter.Shoults@Sun.COM return (status);
900Sstevel@tonic-gate
910Sstevel@tonic-gate /*
920Sstevel@tonic-gate * select the approprate underlying mechanism routine and
930Sstevel@tonic-gate * call it.
940Sstevel@tonic-gate */
950Sstevel@tonic-gate
960Sstevel@tonic-gate ctx = (gss_union_ctx_id_t)*context_handle;
970Sstevel@tonic-gate mech = __gss_get_mechanism(ctx->mech_type);
980Sstevel@tonic-gate if (!mech)
990Sstevel@tonic-gate return (GSS_S_BAD_MECH);
1000Sstevel@tonic-gate if (!mech->gss_export_sec_context)
1010Sstevel@tonic-gate return (GSS_S_UNAVAILABLE);
1020Sstevel@tonic-gate
1030Sstevel@tonic-gate status = mech->gss_export_sec_context(mech->context, minor_status,
1040Sstevel@tonic-gate &ctx->internal_ctx_id, &token);
105*13132SGlenn.Barry@oracle.com if (status != GSS_S_COMPLETE) {
106*13132SGlenn.Barry@oracle.com map_error(minor_status, mech);
1070Sstevel@tonic-gate return (status);
108*13132SGlenn.Barry@oracle.com }
1090Sstevel@tonic-gate
1100Sstevel@tonic-gate length = token.length + 4 + ctx->mech_type->length;
1110Sstevel@tonic-gate interprocess_token->length = length;
1120Sstevel@tonic-gate interprocess_token->value = malloc(length);
1130Sstevel@tonic-gate if (interprocess_token->value == 0) {
1140Sstevel@tonic-gate (void) gss_release_buffer(minor_status, &token);
1150Sstevel@tonic-gate return (GSS_S_FAILURE);
1160Sstevel@tonic-gate }
1170Sstevel@tonic-gate buf = interprocess_token->value;
1180Sstevel@tonic-gate length = ctx->mech_type->length;
1190Sstevel@tonic-gate buf[3] = (unsigned char) (length & 0xFF);
1200Sstevel@tonic-gate length >>= 8;
1210Sstevel@tonic-gate buf[2] = (unsigned char) (length & 0xFF);
1220Sstevel@tonic-gate length >>= 8;
1230Sstevel@tonic-gate buf[1] = (unsigned char) (length & 0xFF);
1240Sstevel@tonic-gate length >>= 8;
1250Sstevel@tonic-gate buf[0] = (unsigned char) (length & 0xFF);
1260Sstevel@tonic-gate (void) memcpy(buf+4, ctx->mech_type->elements,
1270Sstevel@tonic-gate (size_t)ctx->mech_type->length);
1280Sstevel@tonic-gate (void) memcpy(buf+4+ctx->mech_type->length, token.value, token.length);
1290Sstevel@tonic-gate
1300Sstevel@tonic-gate (void) gss_release_buffer(minor_status, &token);
1310Sstevel@tonic-gate
1320Sstevel@tonic-gate free(ctx->mech_type->elements);
1330Sstevel@tonic-gate free(ctx->mech_type);
1340Sstevel@tonic-gate free(ctx);
1350Sstevel@tonic-gate *context_handle = 0;
1360Sstevel@tonic-gate
1370Sstevel@tonic-gate return (GSS_S_COMPLETE);
1380Sstevel@tonic-gate }
139*13132SGlenn.Barry@oracle.com #endif /*LEAN_CLIENT */
140