2N/A/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2N/A/*
2N/A * lib/gssapi/krb5/export_sec_context.c
2N/A *
2N/A * Copyright 1995, 2008 by the Massachusetts Institute of Technology.
2N/A * All Rights Reserved.
2N/A *
2N/A * Export of this software from the United States of America may
2N/A * require a specific license from the United States Government.
2N/A * It is the responsibility of any person or organization contemplating
2N/A * export to obtain such a license before exporting.
2N/A *
2N/A * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
2N/A * distribute this software and its documentation for any purpose and
2N/A * without fee is hereby granted, provided that the above copyright
2N/A * notice appear in all copies and that both that copyright notice and
2N/A * this permission notice appear in supporting documentation, and that
2N/A * the name of M.I.T. not be used in advertising or publicity pertaining
2N/A * to distribution of the software without specific, written prior
2N/A * permission. Furthermore if you modify this software you must label
2N/A * your software as modified software and not distribute it in such a
2N/A * fashion that it might be confused with the original M.I.T. software.
2N/A * M.I.T. makes no representations about the suitability of
2N/A * this software for any purpose. It is provided "as is" without express
2N/A * or implied warranty.
2N/A *
2N/A */
2N/A
2N/A/*
2N/A * export_sec_context.c - Externalize the security context.
2N/A */
2N/A#include "gssapiP_krb5.h"
2N/A#ifndef LEAN_CLIENT
2N/AOM_uint32
2N/Akrb5_gss_export_sec_context(minor_status, context_handle, interprocess_token)
2N/A OM_uint32 *minor_status;
2N/A gss_ctx_id_t *context_handle;
2N/A gss_buffer_t interprocess_token;
2N/A{
2N/A krb5_context context = NULL;
2N/A krb5_error_code kret;
2N/A OM_uint32 retval;
2N/A size_t bufsize, blen;
2N/A krb5_gss_ctx_id_t ctx;
2N/A krb5_octet *obuffer, *obp;
2N/A
2N/A /* Assume a tragic failure */
2N/A obuffer = (krb5_octet *) NULL;
2N/A retval = GSS_S_FAILURE;
2N/A *minor_status = 0;
2N/A
2N/A if (!kg_validate_ctx_id(*context_handle)) {
2N/A kret = (OM_uint32) G_VALIDATE_FAILED;
2N/A retval = GSS_S_NO_CONTEXT;
2N/A goto error_out;
2N/A }
2N/A
2N/A ctx = (krb5_gss_ctx_id_t) *context_handle;
2N/A context = ctx->k5_context;
2N/A kret = krb5_gss_ser_init(context);
2N/A if (kret)
2N/A goto error_out;
2N/A
2N/A /* Determine size needed for externalization of context */
2N/A bufsize = 0;
2N/A if ((kret = kg_ctx_size(context, (krb5_pointer) ctx,
2N/A &bufsize)))
2N/A goto error_out;
2N/A
2N/A /* Allocate the buffer */
2N/A if ((obuffer = (krb5_octet *) xmalloc(bufsize)) == NULL) {
2N/A kret = ENOMEM;
2N/A goto error_out;
2N/A }
2N/A
2N/A obp = obuffer;
2N/A blen = bufsize;
2N/A /* Externalize the context */
2N/A if ((kret = kg_ctx_externalize(context,
2N/A (krb5_pointer) ctx, &obp, &blen)))
2N/A goto error_out;
2N/A
2N/A /* Success! Return the buffer */
2N/A interprocess_token->length = bufsize - blen;
2N/A interprocess_token->value = obuffer;
2N/A *minor_status = 0;
2N/A retval = GSS_S_COMPLETE;
2N/A
2N/A /* Now, clean up the context state */
2N/A (void)krb5_gss_delete_sec_context(minor_status, context_handle, NULL);
2N/A *context_handle = GSS_C_NO_CONTEXT;
2N/A
2N/A return (GSS_S_COMPLETE);
2N/A
2N/Aerror_out:
2N/A if (retval != GSS_S_COMPLETE)
2N/A if (kret != 0 && context != 0)
2N/A save_error_info((OM_uint32)kret, context);
2N/A if (obuffer && bufsize) {
2N/A memset(obuffer, 0, bufsize);
2N/A xfree(obuffer);
2N/A }
2N/A if (*minor_status == 0)
2N/A *minor_status = (OM_uint32) kret;
2N/A return(retval);
2N/A}
2N/A#endif /* LEAN_CLIENT */