|
Packit |
fd8b60 |
/* #pragma ident "@(#)g_exp_sec_context.c 1.14 04/02/23 SMI" */
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/*
|
|
Packit |
fd8b60 |
* Copyright 1996 by Sun Microsystems, Inc.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* Permission to use, copy, modify, distribute, and sell this software
|
|
Packit |
fd8b60 |
* and its documentation for any purpose is hereby granted without fee,
|
|
Packit |
fd8b60 |
* provided that the above copyright notice appears in all copies and
|
|
Packit |
fd8b60 |
* that both that copyright notice and this permission notice appear in
|
|
Packit |
fd8b60 |
* supporting documentation, and that the name of Sun Microsystems not be used
|
|
Packit |
fd8b60 |
* in advertising or publicity pertaining to distribution of the software
|
|
Packit |
fd8b60 |
* without specific, written prior permission. Sun Microsystems makes no
|
|
Packit |
fd8b60 |
* representations about the suitability of this software for any
|
|
Packit |
fd8b60 |
* purpose. It is provided "as is" without express or implied warranty.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
Packit |
fd8b60 |
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
|
Packit |
fd8b60 |
* EVENT SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
Packit |
fd8b60 |
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
|
|
Packit |
fd8b60 |
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
Packit |
fd8b60 |
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
Packit |
fd8b60 |
* PERFORMANCE OF THIS SOFTWARE.
|
|
Packit |
fd8b60 |
*/
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/*
|
|
Packit |
fd8b60 |
* glue routine for gss_export_sec_context
|
|
Packit |
fd8b60 |
*/
|
|
Packit |
fd8b60 |
#ifndef LEAN_CLIENT
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#include "mglueP.h"
|
|
Packit |
fd8b60 |
#include <stdio.h>
|
|
Packit |
fd8b60 |
#include <errno.h>
|
|
Packit |
fd8b60 |
#ifdef HAVE_STDLIB_H
|
|
Packit |
fd8b60 |
#include <stdlib.h>
|
|
Packit |
fd8b60 |
#endif
|
|
Packit |
fd8b60 |
#include <string.h>
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
static OM_uint32
|
|
Packit |
fd8b60 |
val_exp_sec_ctx_args(
|
|
Packit |
fd8b60 |
OM_uint32 *minor_status,
|
|
Packit |
fd8b60 |
gss_ctx_id_t *context_handle,
|
|
Packit |
fd8b60 |
gss_buffer_t interprocess_token)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Initialize outputs. */
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (minor_status != NULL)
|
|
Packit |
fd8b60 |
*minor_status = 0;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (interprocess_token != GSS_C_NO_BUFFER) {
|
|
Packit |
fd8b60 |
interprocess_token->length = 0;
|
|
Packit |
fd8b60 |
interprocess_token->value = NULL;
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Validate arguments. */
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (minor_status == NULL)
|
|
Packit |
fd8b60 |
return (GSS_S_CALL_INACCESSIBLE_WRITE);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (context_handle == NULL || *context_handle == GSS_C_NO_CONTEXT)
|
|
Packit |
fd8b60 |
return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_NO_CONTEXT);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (interprocess_token == GSS_C_NO_BUFFER)
|
|
Packit |
fd8b60 |
return (GSS_S_CALL_INACCESSIBLE_WRITE);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
return (GSS_S_COMPLETE);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
OM_uint32 KRB5_CALLCONV
|
|
Packit |
fd8b60 |
gss_export_sec_context(minor_status,
|
|
Packit |
fd8b60 |
context_handle,
|
|
Packit |
fd8b60 |
interprocess_token)
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
OM_uint32 * minor_status;
|
|
Packit |
fd8b60 |
gss_ctx_id_t * context_handle;
|
|
Packit |
fd8b60 |
gss_buffer_t interprocess_token;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
OM_uint32 status;
|
|
Packit |
fd8b60 |
OM_uint32 length;
|
|
Packit |
fd8b60 |
gss_union_ctx_id_t ctx = NULL;
|
|
Packit |
fd8b60 |
gss_mechanism mech;
|
|
Packit |
fd8b60 |
gss_buffer_desc token = GSS_C_EMPTY_BUFFER;
|
|
Packit |
fd8b60 |
char *buf;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
status = val_exp_sec_ctx_args(minor_status,
|
|
Packit |
fd8b60 |
context_handle, interprocess_token);
|
|
Packit |
fd8b60 |
if (status != GSS_S_COMPLETE)
|
|
Packit |
fd8b60 |
return (status);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/*
|
|
Packit |
fd8b60 |
* select the approprate underlying mechanism routine and
|
|
Packit |
fd8b60 |
* call it.
|
|
Packit |
fd8b60 |
*/
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
ctx = (gss_union_ctx_id_t) *context_handle;
|
|
Packit |
fd8b60 |
if (ctx->internal_ctx_id == GSS_C_NO_CONTEXT)
|
|
Packit |
fd8b60 |
return (GSS_S_NO_CONTEXT);
|
|
Packit |
fd8b60 |
mech = gssint_get_mechanism (ctx->mech_type);
|
|
Packit |
fd8b60 |
if (!mech)
|
|
Packit |
fd8b60 |
return GSS_S_BAD_MECH;
|
|
Packit |
fd8b60 |
if (!mech->gss_export_sec_context)
|
|
Packit |
fd8b60 |
return (GSS_S_UNAVAILABLE);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
status = mech->gss_export_sec_context(minor_status,
|
|
Packit |
fd8b60 |
&ctx->internal_ctx_id, &token);
|
|
Packit |
fd8b60 |
if (status != GSS_S_COMPLETE) {
|
|
Packit |
fd8b60 |
map_error(minor_status, mech);
|
|
Packit |
fd8b60 |
goto cleanup;
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
length = token.length + 4 + ctx->mech_type->length;
|
|
Packit |
fd8b60 |
interprocess_token->length = length;
|
|
Packit |
fd8b60 |
interprocess_token->value = gssalloc_malloc(length);
|
|
Packit |
fd8b60 |
if (interprocess_token->value == 0) {
|
|
Packit |
fd8b60 |
*minor_status = ENOMEM;
|
|
Packit |
fd8b60 |
status = GSS_S_FAILURE;
|
|
Packit |
fd8b60 |
goto cleanup;
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
buf = interprocess_token->value;
|
|
Packit |
fd8b60 |
length = ctx->mech_type->length;
|
|
Packit |
fd8b60 |
buf[3] = (unsigned char) (length & 0xFF);
|
|
Packit |
fd8b60 |
length >>= 8;
|
|
Packit |
fd8b60 |
buf[2] = (unsigned char) (length & 0xFF);
|
|
Packit |
fd8b60 |
length >>= 8;
|
|
Packit |
fd8b60 |
buf[1] = (unsigned char) (length & 0xFF);
|
|
Packit |
fd8b60 |
length >>= 8;
|
|
Packit |
fd8b60 |
buf[0] = (unsigned char) (length & 0xFF);
|
|
Packit |
fd8b60 |
memcpy(buf+4, ctx->mech_type->elements, (size_t) ctx->mech_type->length);
|
|
Packit |
fd8b60 |
memcpy(buf+4+ctx->mech_type->length, token.value, token.length);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
status = GSS_S_COMPLETE;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
cleanup:
|
|
Packit |
fd8b60 |
(void) gss_release_buffer(minor_status, &token);
|
|
Packit |
fd8b60 |
if (ctx != NULL && ctx->internal_ctx_id == GSS_C_NO_CONTEXT) {
|
|
Packit |
fd8b60 |
/* If the mech deleted its context, delete the union context. */
|
|
Packit |
fd8b60 |
free(ctx->mech_type->elements);
|
|
Packit |
fd8b60 |
free(ctx->mech_type);
|
|
Packit |
fd8b60 |
free(ctx);
|
|
Packit |
fd8b60 |
*context_handle = GSS_C_NO_CONTEXT;
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
return status;
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
#endif /*LEAN_CLIENT */
|