~ubuntu-branches/ubuntu/maverick/krb5/maverick

« back to all changes in this revision

Viewing changes to src/lib/gssapi/mechglue/g_imp_sec_context.c

  • Committer: Bazaar Package Importer
  • Author(s): Sam Hartman, Russ Allbery, Sam Hartman
  • Date: 2008-08-21 10:41:41 UTC
  • mfrom: (11.1.15 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080821104141-a0f9c4o4cpo8xd0o
Tags: 1.6.dfsg.4~beta1-4
[ Russ Allbery ]
* Translation updates:
  - Swedish, thanks Martin Bagge.  (Closes: #487669, #491774)
  - Italian, thanks Luca Monducci.  (Closes: #493962)

[ Sam Hartman ]
* Translation Updates:
    - Dutch, Thanks Vincent Zweije, Closes: #495733

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* #ident  "@(#)g_imp_sec_context.c 1.2     96/01/18 SMI" */
 
1
/* #pragma ident        "@(#)g_imp_sec_context.c        1.18    04/02/23 SMI" */
2
2
 
3
3
/*
4
4
 * Copyright 1996 by Sun Microsystems, Inc.
34
34
#endif
35
35
#include <string.h>
36
36
 
 
37
static OM_uint32
 
38
val_imp_sec_ctx_args(
 
39
    OM_uint32 *minor_status,
 
40
    gss_buffer_t interprocess_token,
 
41
    gss_ctx_id_t *context_handle)
 
42
{
 
43
 
 
44
    /* Initialize outputs. */
 
45
    if (minor_status != NULL)
 
46
        *minor_status = 0;
 
47
 
 
48
    if (context_handle != NULL)
 
49
        *context_handle = GSS_C_NO_CONTEXT;
 
50
 
 
51
    /* Validate arguments. */
 
52
 
 
53
    if (minor_status == NULL)
 
54
        return (GSS_S_CALL_INACCESSIBLE_WRITE);
 
55
 
 
56
    if (context_handle == NULL)
 
57
        return (GSS_S_CALL_INACCESSIBLE_WRITE);
 
58
 
 
59
    if (interprocess_token == GSS_C_NO_BUFFER)
 
60
        return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_DEFECTIVE_TOKEN);
 
61
 
 
62
    if (GSS_EMPTY_BUFFER(interprocess_token))
 
63
        return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_DEFECTIVE_TOKEN);
 
64
 
 
65
    return (GSS_S_COMPLETE);
 
66
}
 
67
 
 
68
 
37
69
OM_uint32 KRB5_CALLCONV
38
70
gss_import_sec_context(minor_status,
39
71
                       interprocess_token,
44
76
gss_ctx_id_t *          context_handle;
45
77
 
46
78
{
47
 
    size_t              length;
 
79
    OM_uint32           length = 0;
48
80
    OM_uint32           status;
49
81
    char                *p;
50
82
    gss_union_ctx_id_t  ctx;
51
83
    gss_buffer_desc     token;
52
84
    gss_mechanism       mech;
53
 
    
54
 
    gss_initialize();
55
 
 
56
 
    *minor_status = 0;
57
 
    
58
 
    if (interprocess_token->length == 0 || interprocess_token->value == 0)
59
 
        return (GSS_S_DEFECTIVE_TOKEN);
60
 
 
 
85
 
 
86
    status = val_imp_sec_ctx_args(minor_status,
 
87
                                  interprocess_token, context_handle);
 
88
    if (status != GSS_S_COMPLETE)
 
89
        return (status);
 
90
 
 
91
    /* Initial value needed below. */
61
92
    status = GSS_S_FAILURE;
62
93
 
63
94
    ctx = (gss_union_ctx_id_t) malloc(sizeof(gss_union_ctx_id_desc));
64
 
    if (!ctx) {
65
 
        *minor_status = ENOMEM;
66
 
        goto error_out;
67
 
    }
 
95
    if (!ctx)
 
96
        return (GSS_S_FAILURE);
 
97
 
68
98
    ctx->mech_type = (gss_OID) malloc(sizeof(gss_OID_desc));
69
99
    if (!ctx->mech_type) {
70
 
        *minor_status = ENOMEM;
71
 
        goto error_out;
72
 
    }
73
 
    p = interprocess_token->value;
74
 
    length = *p++;
75
 
    length = (length << 8) + *p++;
76
 
    length = (length << 8) + *p++;
77
 
    length = (length << 8) + *p++;
 
100
        free(ctx);
 
101
        return (GSS_S_FAILURE);
 
102
    }
 
103
 
 
104
    if (interprocess_token->length >= sizeof (OM_uint32)) {
 
105
        p = interprocess_token->value;
 
106
        length = (OM_uint32)*p++;
 
107
        length = (OM_uint32)(length << 8) + *p++;
 
108
        length = (OM_uint32)(length << 8) + *p++;
 
109
        length = (OM_uint32)(length << 8) + *p++;
 
110
    }
 
111
 
 
112
    if (length == 0 ||
 
113
        length > (interprocess_token->length - sizeof (OM_uint32))) {
 
114
        free(ctx);
 
115
        return (GSS_S_CALL_BAD_STRUCTURE | GSS_S_DEFECTIVE_TOKEN);
 
116
    }
78
117
 
79
118
    ctx->mech_type->length = length;
80
119
    ctx->mech_type->elements = malloc(length);
81
120
    if (!ctx->mech_type->elements) {
82
 
        *minor_status = ENOMEM;
83
121
        goto error_out;
84
122
    }
85
123
    memcpy(ctx->mech_type->elements, p, length);
86
124
    p += length;
87
125
 
88
 
    token.length = interprocess_token->length - 4 - length;
 
126
    token.length = interprocess_token->length - sizeof (OM_uint32) - length;
89
127
    token.value = p;
90
128
 
91
129
    /*
93
131
     * call it.
94
132
     */
95
133
    
96
 
    mech = __gss_get_mechanism (ctx->mech_type);
 
134
    mech = gssint_get_mechanism (ctx->mech_type);
97
135
    if (!mech) {
98
136
        status = GSS_S_BAD_MECH;
99
137
        goto error_out;
100
138
    }
101
139
    if (!mech->gss_import_sec_context) {
102
 
        status = GSS_S_BAD_BINDINGS;
 
140
        status = GSS_S_UNAVAILABLE;
103
141
        goto error_out;
104
142
    }
105
143
    
107
145
                                          &token, &ctx->internal_ctx_id);
108
146
 
109
147
    if (status == GSS_S_COMPLETE) {
 
148
        ctx->loopback = ctx;
110
149
        *context_handle = ctx;
111
150
        return (GSS_S_COMPLETE);
112
151
    }