1 /* 2 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 3 * Use is subject to license terms. 4 */ 5 6 | #pragma ident "@(#)g_exp_sec_context.c 1.15 04/09/08 SMI" 6 | #pragma ident "@(#)g_exp_sec_context.c 1.14 04/02/23 SMI" 7 8 /* 9 * glue routine for gss_export_sec_context 10 */ 11 12 #include <mechglueP.h> 13 #include <stdio.h> 14 #include <errno.h> 15 #ifdef HAVE_STDLIB_H 16 #include <stdlib.h> 17 #endif 18 #include <string.h> 19 20 OM_uint32 21 gss_export_sec_context(minor_status, 22 context_handle, 23 interprocess_token) 24 25 OM_uint32 *minor_status; 26 gss_ctx_id_t *context_handle; 27 gss_buffer_t interprocess_token; 28 29 { 30 OM_uint32 status; 31 | size_t length; 31 | OM_uint32 length; 32 gss_union_ctx_id_t ctx; 33 gss_mechanism mech; 34 gss_buffer_desc token; 35 char *buf; 36 37 | gss_initialize(); 37 | if (minor_status == NULL) 38 + return (GSS_S_CALL_INACCESSIBLE_WRITE); 39 + *minor_status = 0; 40 41 if (context_handle == NULL || *context_handle == GSS_C_NO_CONTEXT) 40 | return (GSS_S_NO_CONTEXT); 42 | return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_NO_CONTEXT); 43 44 + if (interprocess_token == NULL) 45 + return (GSS_S_CALL_INACCESSIBLE_READ); 46 + 47 /* 48 * select the approprate underlying mechanism routine and 49 * call it. 50 */ 51 52 ctx = (gss_union_ctx_id_t)*context_handle; 53 mech = __gss_get_mechanism(ctx->mech_type); 54 if (!mech) 55 return (GSS_S_BAD_MECH); 56 if (!mech->gss_export_sec_context) 52 | return (GSS_S_BAD_BINDINGS); 57 | return (GSS_S_UNAVAILABLE); 58 59 status = mech->gss_export_sec_context(mech->context, minor_status, 60 &ctx->internal_ctx_id, &token); 61 if (status != GSS_S_COMPLETE) 62 return (status); 63 64 length = token.length + 4 + ctx->mech_type->length; 65 interprocess_token->length = length; 66 interprocess_token->value = malloc(length); 67 if (interprocess_token->value == 0) { 64 - *minor_status = ENOMEM; 68 (void) gss_release_buffer(minor_status, &token); 69 return (GSS_S_FAILURE); 70 } 71 buf = interprocess_token->value; 72 length = ctx->mech_type->length; 73 buf[3] = (unsigned char) (length & 0xFF); 74 length >>= 8; 75 buf[2] = (unsigned char) (length & 0xFF); 76 length >>= 8; 77 buf[1] = (unsigned char) (length & 0xFF); 78 length >>= 8; 79 buf[0] = (unsigned char) (length & 0xFF); 80 (void) memcpy(buf+4, ctx->mech_type->elements, 81 (size_t)ctx->mech_type->length); 82 (void) memcpy(buf+4+ctx->mech_type->length, token.value, token.length); 83 84 (void) gss_release_buffer(minor_status, &token); 85 86 free(ctx->mech_type->elements); 87 free(ctx->mech_type); 88 free(ctx); 89 *context_handle = 0; 90 91 return (GSS_S_COMPLETE); 92 } ----Unchanged portion omitted----