1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
|
/* #ident "@(#)g_glue.c 1.1 96/02/06 SMI" */
/*
* Copyright 1996 by Sun Microsystems, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of Sun Microsystems not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. Sun Microsystems makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#include "mglueP.h"
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include <string.h>
#include <errno.h>
#define g_OID_equal(o1,o2) \
(((o1)->length == (o2)->length) && \
(memcmp((o1)->elements,(o2)->elements,(int) (o1)->length) == 0))
extern gss_mechanism *__gss_mechs_array;
/*
* This file contains the support routines for the glue layer.
*/
/*
* given the mechs_array and a mechanism OID, return the
* pointer to the mechanism, or NULL if that mechanism is
* not supported. If the requested OID is NULL, then return
* the first mechanism.
*/
gss_mechanism __gss_get_mechanism (type)
gss_OID type;
{
int i;
if (type == GSS_C_NULL_OID)
return (__gss_mechs_array[0]);
for (i=0; __gss_mechs_array[i]->mech_type.length != 0; i++) {
if ((__gss_mechs_array[i]->mech_type.length == type->length) &&
(memcmp (__gss_mechs_array[i]->mech_type.elements, type->elements,
type->length) == 0)) {
return (__gss_mechs_array[i]);
}
}
return NULL;
}
/*
* glue routine for get_mech_type
*
*/
OM_uint32 __gss_get_mech_type(OID, token)
gss_OID OID;
gss_buffer_t token;
{
unsigned char * buffer_ptr;
int length;
/*
* This routine reads the prefix of "token" in order to determine
* its mechanism type. It assumes the encoding suggested in
* Appendix B of RFC 1508. This format starts out as follows :
*
* tag for APPLICATION 0, Sequence[constructed, definite length]
* length of remainder of token
* tag of OBJECT IDENTIFIER
* length of mechanism OID
* encoding of mechanism OID
* <the rest of the token>
*
* Numerically, this looks like :
*
* 0x60
* <length> - could be multiple bytes
* 0x06
* <length> - assume only one byte, hence OID length < 127
* <mech OID bytes>
*
* The routine fills in the OID value and returns an error as necessary.
*/
if (token == NULL)
return (GSS_S_DEFECTIVE_TOKEN);
/* Skip past the APP/Sequnce byte and the token length */
buffer_ptr = (unsigned char *) token->value;
if (*(buffer_ptr++) != 0x60)
return (GSS_S_DEFECTIVE_TOKEN);
length = *buffer_ptr++;
if (length & 0x80) {
if ((length & 0x7f) > 4)
return (GSS_S_DEFECTIVE_TOKEN);
buffer_ptr += length & 0x7f;
}
if (*(buffer_ptr++) != 0x06)
return (GSS_S_DEFECTIVE_TOKEN);
OID->length = (OM_uint32) *(buffer_ptr++);
OID->elements = (void *) buffer_ptr;
return (GSS_S_COMPLETE);
}
/*
* Internal routines to get and release an internal mechanism name
*/
#include "mglueP.h"
OM_uint32 __gss_import_internal_name (minor_status, mech_type, union_name,
internal_name)
OM_uint32 *minor_status;
gss_OID mech_type;
gss_union_name_t union_name;
gss_name_t *internal_name;
{
OM_uint32 status;
gss_mechanism mech;
mech = __gss_get_mechanism (mech_type);
if (mech) {
if (mech->gss_import_name)
status = mech->gss_import_name (
#ifdef USE_MECH_CONTEXT
mech->context,
#endif
minor_status,
union_name->external_name,
union_name->name_type,
internal_name);
else
status = GSS_S_BAD_BINDINGS;
return (status);
}
return (GSS_S_BAD_MECH);
}
OM_uint32 __gss_display_internal_name (minor_status, mech_type, internal_name,
external_name, name_type)
OM_uint32 *minor_status;
gss_OID mech_type;
gss_name_t internal_name;
gss_buffer_t external_name;
gss_OID *name_type;
{
OM_uint32 status;
gss_mechanism mech;
mech = __gss_get_mechanism (mech_type);
if (mech) {
if (mech->gss_display_name)
status = mech->gss_display_name (
#ifdef USE_MECH_CONTEXT
mech->context,
#endif
minor_status,
internal_name,
external_name,
name_type);
else
status = GSS_S_BAD_BINDINGS;
return (status);
}
return (GSS_S_BAD_MECH);
}
OM_uint32 __gss_release_internal_name (minor_status, mech_type, internal_name)
OM_uint32 *minor_status;
gss_OID mech_type;
gss_name_t *internal_name;
{
OM_uint32 status;
gss_mechanism mech;
mech = __gss_get_mechanism (mech_type);
if (mech) {
if (mech->gss_release_name)
status = mech->gss_release_name (
#ifdef USE_MECH_CONTEXT
mech->context,
#endif
minor_status,
internal_name);
else
status = GSS_S_BAD_BINDINGS;
return (status);
}
return (GSS_S_BAD_MECH);
}
/*
* This function converts an internal gssapi name to a union gssapi
* name. Note that internal_name should be considered "consumed" by
* this call, whether or not we return an error.
*/
OM_uint32 __gss_convert_name_to_union_name(minor_status, mech,
internal_name, external_name)
OM_uint32 *minor_status;
gss_mechanism mech;
gss_name_t internal_name;
gss_name_t *external_name;
{
OM_uint32 major_status,tmp;
gss_union_name_t union_name;
union_name = (gss_union_name_t) malloc (sizeof(gss_union_name_desc));
if (!union_name) {
*minor_status = ENOMEM;
goto allocation_failure;
}
union_name->mech_type = 0;
union_name->mech_name = internal_name;
union_name->name_type = 0;
union_name->external_name = 0;
union_name->gss_mech = mech;
major_status = generic_gss_copy_oid(minor_status, &mech->mech_type,
&union_name->mech_type);
if (major_status != GSS_S_COMPLETE)
goto allocation_failure;
union_name->external_name =
(gss_buffer_t) malloc(sizeof(gss_buffer_desc));
if (!union_name->external_name) {
*minor_status = ENOMEM;
goto allocation_failure;
}
#ifdef USE_MECH_CONTEXT
major_status = mech->gss_display_name(mech->context, minor_status,
#else
major_status = mech->gss_display_name(minor_status,
#endif
internal_name,
union_name->external_name,
&union_name->name_type);
if (major_status != GSS_S_COMPLETE)
goto allocation_failure;
*external_name = union_name;
return (GSS_S_COMPLETE);
allocation_failure:
if (union_name) {
if (union_name->external_name) {
if (union_name->external_name->value)
free(union_name->external_name->value);
free(union_name->external_name);
}
if (union_name->name_type)
generic_gss_release_oid(&tmp, &union_name->name_type);
if (union_name->mech_name)
__gss_release_internal_name(minor_status, union_name->mech_type,
&union_name->mech_name);
if (union_name->mech_type)
mech_gss_release_oid(&tmp, &union_name->mech_type, mech);
free(union_name);
}
return (major_status);
}
/*
* Glue routine for returning the mechanism-specific credential from a
* external union credential.
*/
gss_cred_id_t
__gss_get_mechanism_cred(union_cred, mech_type)
gss_union_cred_t union_cred;
gss_OID mech_type;
{
int i;
if (union_cred == GSS_C_NO_CREDENTIAL)
return GSS_C_NO_CREDENTIAL;
for (i=0; i < union_cred->count; i++) {
if (g_OID_equal(mech_type, &union_cred->mechs_array[i]))
return union_cred->cred_array[i];
}
return GSS_C_NO_CREDENTIAL;
}
/*
* Glue routine to copy an external name buffer (used by gss_duplicate_name)
*/
OM_uint32 __gss_copy_namebuf(src, dest)
gss_buffer_t src;
gss_buffer_t *dest;
{
gss_buffer_t temp = NULL;
if (dest == NULL)
return (GSS_S_BAD_NAME);
temp = (gss_buffer_t) malloc (sizeof(gss_buffer_t));
if (!temp) {
return(GSS_S_FAILURE);
}
temp->value = (void *) malloc (src->length + 1);
if (temp->value == NULL) {
free(temp);
return(GSS_S_FAILURE);
}
memcpy(temp->value, src->value, src->length);
temp->length = src->length;
*dest = temp;
return (GSS_S_COMPLETE);
}
|