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
|
/* Copyright (C) 2012 the GSS-PROXY contributors, see COPYING for license */
#include "gss_plugin.h"
static OM_uint32 init_ctx_local(OM_uint32 *minor_status,
struct gpp_cred_handle *cred_handle,
struct gpp_context_handle *ctx_handle,
struct gpp_name_handle *name,
gss_OID mech_type,
OM_uint32 req_flags,
OM_uint32 time_req,
gss_channel_bindings_t input_cb,
gss_buffer_t input_token,
gss_OID *actual_mech_type,
gss_buffer_t output_token,
OM_uint32 *ret_flags,
OM_uint32 *time_rec)
{
OM_uint32 maj, min;
if (name->remote && !name->local) {
maj = gpp_name_to_local(&min, name->remote,
mech_type, &name->local);
if (maj) {
goto done;
}
}
maj = gss_init_sec_context(&min,
cred_handle->local,
&ctx_handle->local,
name->local,
gpp_special_mech(mech_type),
req_flags,
time_req,
input_cb,
input_token,
actual_mech_type,
output_token,
ret_flags,
time_rec);
done:
*minor_status = min;
return maj;
}
OM_uint32 gssi_init_sec_context(OM_uint32 *minor_status,
gss_cred_id_t claimant_cred_handle,
gss_ctx_id_t *context_handle,
gss_name_t target_name,
gss_OID mech_type,
OM_uint32 req_flags,
OM_uint32 time_req,
gss_channel_bindings_t input_cb,
gss_buffer_t input_token,
gss_OID *actual_mech_type,
gss_buffer_t output_token,
OM_uint32 *ret_flags,
OM_uint32 *time_rec)
{
enum gpp_behavior behavior = GPP_UNINITIALIZED;
struct gpp_context_handle *ctx_handle = NULL;
struct gpp_cred_handle *cred_handle = NULL;
struct gpp_name_handle *name;
OM_uint32 tmaj, tmin;
OM_uint32 maj, min;
GSSI_TRACE();
*minor_status = 0;
if (target_name == GSS_C_NO_NAME) {
return GSS_S_CALL_INACCESSIBLE_READ;
}
if (mech_type == GSS_C_NO_OID || gpp_is_special_oid(mech_type)) {
return GSS_S_BAD_MECH;
}
tmaj = GSS_S_COMPLETE;
tmin = 0;
if (*context_handle) {
ctx_handle = (struct gpp_context_handle *)*context_handle;
if (ctx_handle->local) {
/* ok this means a previous call decided to use the local mech,
* so let's just re-enter the mechglue here and keep at it */
behavior = GPP_LOCAL_ONLY;
}
} else {
ctx_handle = calloc(1, sizeof(struct gpp_context_handle));
if (!ctx_handle) {
maj = GSS_S_FAILURE;
min = ENOMEM;
goto done;
}
}
if (claimant_cred_handle != GSS_C_NO_CREDENTIAL) {
cred_handle = (struct gpp_cred_handle *)claimant_cred_handle;
if (cred_handle->local) {
/* ok this means a previous call decided to short circuit to the
* local mech, so let's just re-enter the mechglue here, as we
* have no way to export creds yet. */
behavior = GPP_LOCAL_ONLY;
} else if (behavior == GPP_LOCAL_ONLY) {
maj = GSS_S_DEFECTIVE_CREDENTIAL;
min = 0;
goto done;
}
} else {
cred_handle = calloc(1, sizeof(struct gpp_cred_handle));
if (!cred_handle) {
maj = GSS_S_FAILURE;
min = ENOMEM;
goto done;
}
}
name = (struct gpp_name_handle *)target_name;
if (behavior == GPP_UNINITIALIZED) {
behavior = gpp_get_behavior();
}
/* See if we should try local first */
if (behavior == GPP_LOCAL_ONLY || behavior == GPP_LOCAL_FIRST) {
maj = init_ctx_local(&min, cred_handle, ctx_handle, name,
mech_type, req_flags, time_req, input_cb,
input_token, actual_mech_type, output_token,
ret_flags, time_rec);
if (maj == GSS_S_COMPLETE || maj == GSS_S_CONTINUE_NEEDED ||
behavior == GPP_LOCAL_ONLY) {
goto done;
}
/* not successful, save actual local error if remote fallback fails */
tmaj = maj;
tmin = min;
}
/* Then try with remote */
if (behavior != GPP_LOCAL_ONLY) {
if (name->local && !name->remote) {
maj = gpp_local_to_name(&min, name->local, &name->remote);
if (maj) {
goto done;
}
}
if (!cred_handle->remote) {
struct gpp_cred_handle *r_creds;
maj = gppint_get_def_creds(&min,
GPP_REMOTE_ONLY,
GSS_C_NO_NAME,
GSS_C_INITIATE,
&r_creds);
if (maj == GSS_S_COMPLETE) {
/* steal result */
cred_handle->remote = r_creds->remote;
free(r_creds);
}
}
maj = gpm_init_sec_context(&min,
cred_handle->remote,
&ctx_handle->remote,
name->remote,
mech_type,
req_flags,
time_req,
input_cb,
input_token,
actual_mech_type,
output_token,
ret_flags,
time_rec);
if (maj == GSS_S_COMPLETE || maj == GSS_S_CONTINUE_NEEDED ||
behavior == GPP_REMOTE_ONLY) {
goto done;
}
/* So remote failed, but we can fallback to local, try that */
maj = init_ctx_local(&min, cred_handle, ctx_handle, name,
mech_type, req_flags, time_req, input_cb,
input_token, actual_mech_type, output_token,
ret_flags, time_rec);
}
done:
if (maj != GSS_S_COMPLETE &&
maj != GSS_S_CONTINUE_NEEDED &&
tmaj != GSS_S_COMPLETE) {
maj = tmaj;
min = tmin;
}
if (maj != GSS_S_COMPLETE && maj != GSS_S_CONTINUE_NEEDED) {
if (ctx_handle &&
ctx_handle->local == GSS_C_NO_CONTEXT &&
ctx_handle->remote == NULL) {
free(ctx_handle);
ctx_handle = NULL;
}
*minor_status = gpp_map_error(min);
}
/* always replace the provided context handle to avoid
* dangling pointers when a context has been passed in */
*context_handle = (gss_ctx_id_t)ctx_handle;
if (claimant_cred_handle == GSS_C_NO_CREDENTIAL) {
free(cred_handle);
}
return maj;
}
|