~ubuntu-branches/ubuntu/lucid/nfs-utils/lucid

« back to all changes in this revision

Viewing changes to support/gssapi/g_exp_sec_context.c

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar
  • Date: 2006-07-03 10:36:59 UTC
  • mto: (12.1.1 feisty)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20060703103659-71qzs6f21zzmjmhx
Tags: upstream-1.0.8
ImportĀ upstreamĀ versionĀ 1.0.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* #ident  "@(#)g_exp_sec_context.c 1.2     96/01/18 SMI" */
2
 
 
3
 
/*
4
 
 * Copyright 1996 by Sun Microsystems, Inc.
5
 
 *
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.
15
 
 *
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.
23
 
 */
24
 
 
25
 
/*
26
 
 *  glue routine for gss_export_sec_context
27
 
 */
28
 
 
29
 
#include "mglueP.h"
30
 
#include <stdio.h>
31
 
#include <errno.h>
32
 
#ifdef HAVE_STDLIB_H
33
 
#include <stdlib.h>
34
 
#endif
35
 
#include <string.h>
36
 
 
37
 
OM_uint32 KRB5_CALLCONV
38
 
gss_export_sec_context(minor_status,
39
 
                       context_handle,
40
 
                       interprocess_token)
41
 
 
42
 
OM_uint32 *             minor_status;
43
 
gss_ctx_id_t *          context_handle;
44
 
gss_buffer_t            interprocess_token;
45
 
 
46
 
{
47
 
    OM_uint32           status;
48
 
    size_t              length;
49
 
    gss_union_ctx_id_t  ctx;
50
 
    gss_mechanism       mech;
51
 
    gss_buffer_desc     token;
52
 
    char                *buf;
53
 
 
54
 
    gss_initialize();
55
 
 
56
 
    if (context_handle == NULL || *context_handle == GSS_C_NO_CONTEXT)
57
 
        return GSS_S_NO_CONTEXT;
58
 
 
59
 
    /*
60
 
     * select the approprate underlying mechanism routine and
61
 
     * call it.
62
 
     */
63
 
 
64
 
    ctx = (gss_union_ctx_id_t) *context_handle;
65
 
    mech = __gss_get_mechanism (ctx->mech_type);
66
 
    if (!mech)
67
 
        return GSS_S_BAD_MECH;
68
 
    if (!mech->gss_export_sec_context)
69
 
        return GSS_S_BAD_BINDINGS;
70
 
 
71
 
#ifdef USE_MECH_CONTEXT
72
 
    status = mech->gss_export_sec_context(mech->context, minor_status,
73
 
#else
74
 
    status = mech->gss_export_sec_context(minor_status,
75
 
#endif
76
 
                                          &ctx->internal_ctx_id, &token);
77
 
    if (status != GSS_S_COMPLETE)
78
 
        return (status);
79
 
 
80
 
    length = token.length + 4 + ctx->mech_type->length;
81
 
    interprocess_token->length = length;
82
 
    interprocess_token->value = malloc(length);
83
 
    if (interprocess_token->value == 0) {
84
 
        (void) gss_release_buffer(minor_status, &token);
85
 
        *minor_status = ENOMEM;
86
 
        return (GSS_S_FAILURE);
87
 
    }
88
 
    buf = interprocess_token->value;
89
 
    length = ctx->mech_type->length;
90
 
    buf[3] = (unsigned char) (length & 0xFF);
91
 
    length >>= 8;
92
 
    buf[2] = (unsigned char) (length & 0xFF);
93
 
    length >>= 8;
94
 
    buf[1] = (unsigned char) (length & 0xFF);
95
 
    length >>= 8;
96
 
    buf[0] = (unsigned char) (length & 0xFF);
97
 
    memcpy(buf+4, ctx->mech_type->elements, (size_t) ctx->mech_type->length);
98
 
    memcpy(buf+4+ctx->mech_type->length, token.value, token.length);
99
 
 
100
 
    (void) gss_release_buffer(minor_status, &token);
101
 
 
102
 
    free(ctx->mech_type->elements);
103
 
    free(ctx->mech_type);
104
 
    free(ctx);
105
 
    *context_handle = 0;
106
 
 
107
 
    return(GSS_S_COMPLETE);
108
 
}