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
|
/*
* 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.
*
* created andros 2.24.01 from g_compare_name.c
*/
/*
* glue routine for gss_duplicate_name
*
*/
#include <stdio.h>
#include "mglueP.h"
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include <string.h>
#include <errno.h>
OM_uint32 KRB5_CALLCONV
gss_duplicate_name (minor_status,
in_name,
exp_name)
OM_uint32 * minor_status;
const gss_name_t in_name;
gss_name_t *exp_name;
{
OM_uint32 tmp,major_status = GSS_S_COMPLETE;
gss_union_name_t union_in_name, union_exp_name;
gss_mechanism mech;
gss_initialize();
/* if exp_name is NULL, simply return */
if (exp_name == NULL)
return (GSS_S_COMPLETE);
*exp_name = NULL;
if (in_name == 0)
return (GSS_S_BAD_NAME);
union_in_name = (gss_union_name_t) in_name;
/*
* Create the union name struct that will hold the exported
* name and the name type.
*/
union_exp_name = (gss_union_name_t) malloc (sizeof(gss_union_name_desc));
if (!union_exp_name) {
*minor_status = ENOMEM;
goto allocation_failure;
}
#ifdef DEBUG
fprintf(stderr, "gss_duplicate_name: copying *oid %p\n",
union_in_name->mech_type);
#endif
union_exp_name->gss_mech = union_in_name->gss_mech;
union_exp_name->mech_type = GSS_C_NO_OID;
if (union_in_name->mech_type != GSS_C_NO_OID &&
(generic_gss_copy_oid(&tmp, union_in_name->mech_type,
&union_exp_name->mech_type) != GSS_S_COMPLETE)) {
*minor_status = ENOMEM;
goto allocation_failure;
}
union_exp_name->mech_name = NULL;
union_exp_name->name_type = GSS_C_NO_OID;
if (union_in_name->name_type != GSS_C_NO_OID &&
(generic_gss_copy_oid(&tmp, union_in_name->name_type,
&union_exp_name->name_type) != GSS_S_COMPLETE)) {
*minor_status = ENOMEM;
goto allocation_failure;
}
union_exp_name->external_name = NULL;
union_exp_name->external_name =
(gss_buffer_t) malloc(sizeof(gss_buffer_desc));
if (!union_exp_name->external_name) {
*minor_status = ENOMEM;
goto allocation_failure;
}
union_exp_name->external_name->length = union_in_name->external_name->length;
/*
* we malloc length+1 to stick a NULL on the end, just in case
* Note that this NULL is not included in ->length for a reason!
*/
union_exp_name->external_name->value =
(void *) malloc(union_in_name->external_name->length);
if (!union_exp_name->external_name->value) {
*minor_status = ENOMEM;
goto allocation_failure;
}
memcpy(union_exp_name->external_name->value,
union_in_name->external_name->value,
union_exp_name->external_name->length);
/*
* Mechanism specific name
*/
if (union_in_name->mech_type != GSS_C_NO_OID) {
mech = __gss_get_mechanism (union_in_name->mech_type);
if (!mech)
return (GSS_S_BAD_MECH);
if (!mech->gss_duplicate_name)
return (GSS_S_BAD_BINDINGS);
#ifdef USE_MECH_CONTEXT
major_status = mech->gss_duplicate_name(mech->context, minor_status,
#else
major_status = mech->gss_duplicate_name(minor_status,
#endif
union_in_name->mech_name, &union_exp_name->mech_name);
if (major_status != GSS_S_COMPLETE)
return (major_status);
}
#ifdef DEBUG
fprintf(stderr, "gss_duplicate_name: returning union_exp_name %p\n",
union_exp_name);
#endif
*exp_name = union_exp_name;
return (major_status);
allocation_failure:
if (union_exp_name) {
if (union_exp_name->external_name) {
if (union_exp_name->external_name->value)
free(union_exp_name->external_name->value);
free(union_exp_name->external_name);
}
if (union_exp_name->name_type)
generic_gss_release_oid(&tmp, &union_exp_name->name_type);
if (union_exp_name->mech_name)
__gss_release_internal_name(minor_status, union_exp_name->mech_type,
&union_exp_name->mech_name);
if (union_exp_name->mech_type)
generic_gss_release_oid(&tmp, &union_exp_name->mech_type);
free(union_exp_name);
}
return (major_status);
}
|