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
|
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* #pragma ident "@(#)g_store_cred.c 1.2 04/04/05 SMI" */
/*
* glue routine for gss_store_cred
*/
#include <mglueP.h>
static OM_uint32
val_store_cred_args(
OM_uint32 *minor_status,
const gss_cred_id_t input_cred_handle,
gss_cred_usage_t cred_usage,
const gss_OID desired_mech,
OM_uint32 overwrite_cred,
OM_uint32 default_cred,
gss_OID_set *elements_stored,
gss_cred_usage_t *cred_usage_stored)
{
/* Initialize outputs. */
if (minor_status != NULL)
*minor_status = 0;
if (elements_stored != NULL)
*elements_stored = GSS_C_NULL_OID_SET;
/* Validate arguments. */
if (minor_status == NULL)
return (GSS_S_CALL_INACCESSIBLE_WRITE);
if (input_cred_handle == GSS_C_NO_CREDENTIAL)
return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_NO_CRED);
if (cred_usage != GSS_C_ACCEPT
&& cred_usage != GSS_C_INITIATE
&& cred_usage != GSS_C_BOTH) {
if (minor_status) {
*minor_status = EINVAL;
map_errcode(minor_status);
}
return GSS_S_FAILURE;
}
return (GSS_S_COMPLETE);
}
OM_uint32 gss_store_cred(minor_status,
input_cred_handle,
cred_usage,
desired_mech,
overwrite_cred,
default_cred,
elements_stored,
cred_usage_stored)
OM_uint32 *minor_status;
const gss_cred_id_t input_cred_handle;
gss_cred_usage_t cred_usage;
const gss_OID desired_mech;
OM_uint32 overwrite_cred;
OM_uint32 default_cred;
gss_OID_set *elements_stored;
gss_cred_usage_t *cred_usage_stored;
{
OM_uint32 major_status = GSS_S_FAILURE;
gss_union_cred_t union_cred;
gss_cred_id_t mech_cred;
gss_mechanism mech;
gss_OID dmech;
int i;
major_status = val_store_cred_args(minor_status,
input_cred_handle,
cred_usage,
desired_mech,
overwrite_cred,
default_cred,
elements_stored,
cred_usage_stored);
if (major_status != GSS_S_COMPLETE)
return (major_status);
/* Initial value needed below. */
major_status = GSS_S_FAILURE;
if (cred_usage_stored != NULL)
*cred_usage_stored = GSS_C_BOTH; /* there's no GSS_C_NEITHER */
union_cred = (gss_union_cred_t)input_cred_handle;
/* desired_mech != GSS_C_NULL_OID -> store one element */
if (desired_mech != GSS_C_NULL_OID) {
mech = gssint_get_mechanism(desired_mech);
if (mech == NULL)
return (GSS_S_BAD_MECH);
if (mech->gss_store_cred == NULL)
return (major_status);
mech_cred = gssint_get_mechanism_cred(union_cred, desired_mech);
if (mech_cred == GSS_C_NO_CREDENTIAL)
return (GSS_S_NO_CRED);
major_status = mech->gss_store_cred(
minor_status,
(gss_cred_id_t)mech_cred,
cred_usage,
desired_mech,
overwrite_cred,
default_cred,
elements_stored,
cred_usage_stored);
if (major_status != GSS_S_COMPLETE)
map_error(minor_status, mech);
return major_status;
}
/* desired_mech == GSS_C_NULL_OID -> store all elements */
*minor_status = 0;
for (i = 0; i < union_cred->count; i++) {
/* Get mech and cred element */
dmech = &union_cred->mechs_array[i];
mech = gssint_get_mechanism(dmech);
if (mech == NULL)
continue;
if (mech->gss_store_cred == NULL)
continue;
mech_cred = gssint_get_mechanism_cred(union_cred, dmech);
if (mech_cred == GSS_C_NO_CREDENTIAL)
continue; /* can't happen, but safe to ignore */
major_status = mech->gss_store_cred(
minor_status,
(gss_cred_id_t)mech_cred,
cred_usage,
dmech,
overwrite_cred,
default_cred,
NULL,
cred_usage_stored);
if (major_status != GSS_S_COMPLETE) {
map_error(minor_status, mech);
continue;
}
/* Succeeded for at least one mech */
if (elements_stored == NULL)
continue;
if (*elements_stored == GSS_C_NULL_OID_SET) {
major_status = gss_create_empty_oid_set(minor_status,
elements_stored);
if (GSS_ERROR(major_status))
return (major_status);
}
major_status = gss_add_oid_set_member(minor_status, dmech,
elements_stored);
/* The caller should clean up elements_stored */
if (GSS_ERROR(major_status))
return (major_status);
}
/*
* Success with some mechs may mask failure with others, but
* that's what elements_stored is for.
*/
return (major_status);
}
|