Skip to content

Commit 9c6e612

Browse files
committed
Move ctx_id function and add export type option
Move the function to export a context to gssx_ctx or import into gp_export.c Add function to check for exported_context_type option in call_ctx
1 parent 781d0f1 commit 9c6e612

File tree

4 files changed

+152
-107
lines changed

4 files changed

+152
-107
lines changed

proxy/src/gp_conv.c

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -462,109 +462,6 @@ uint32_t gp_conv_gssx_to_name(uint32_t *min, gssx_name *in, gss_name_t *out)
462462
return ret_maj;
463463
}
464464

465-
uint32_t gp_conv_ctx_id_to_gssx(uint32_t *min, gss_ctx_id_t *in, gssx_ctx *out)
466-
{
467-
uint32_t ret_maj;
468-
uint32_t ret_min;
469-
gss_name_t src_name = GSS_C_NO_NAME;
470-
gss_name_t targ_name = GSS_C_NO_NAME;
471-
gss_buffer_desc export_buffer = GSS_C_EMPTY_BUFFER;
472-
uint32_t lifetime_rec;
473-
gss_OID mech_type;
474-
uint32_t ctx_flags;
475-
int is_locally_initiated;
476-
int is_open;
477-
int ret;
478-
479-
/* TODO: For mechs that need multiple roundtrips to complete */
480-
/* out->state; */
481-
482-
/* we do not need the client to release anything nutil we handle state */
483-
out->needs_release = false;
484-
485-
ret_maj = gss_inquire_context(&ret_min, *in, &src_name, &targ_name,
486-
&lifetime_rec, &mech_type, &ctx_flags,
487-
&is_locally_initiated, &is_open);
488-
if (ret_maj) {
489-
goto done;
490-
}
491-
492-
ret = gp_conv_oid_to_gssx(mech_type, &out->mech);
493-
if (ret) {
494-
ret_maj = GSS_S_FAILURE;
495-
ret_min = ret;
496-
goto done;
497-
}
498-
499-
ret_maj = gp_conv_name_to_gssx(&ret_min, src_name, &out->src_name);
500-
if (ret_maj) {
501-
goto done;
502-
}
503-
504-
ret_maj = gp_conv_name_to_gssx(&ret_min, targ_name, &out->targ_name);
505-
if (ret_maj) {
506-
goto done;
507-
}
508-
509-
out->lifetime = lifetime_rec;
510-
511-
out->ctx_flags = ctx_flags;
512-
513-
if (is_locally_initiated) {
514-
out->locally_initiated = true;
515-
}
516-
517-
if (is_open) {
518-
out->open = true;
519-
}
520-
521-
/* note: once converted the original context token is not usable anymore,
522-
* so this must be the last call to use it */
523-
ret_maj = gss_export_sec_context(&ret_min, in, &export_buffer);
524-
if (ret_maj) {
525-
ret_maj = GSS_S_FAILURE;
526-
ret_min = ENOMEM;
527-
goto done;
528-
}
529-
ret = gp_conv_buffer_to_gssx(&export_buffer, &out->exported_context_token);
530-
if (ret) {
531-
ret_maj = GSS_S_FAILURE;
532-
ret_min = ret;
533-
goto done;
534-
}
535-
536-
/* Leave this empty, used only on the way in for init_sec_context */
537-
/* out->gssx_option */
538-
539-
done:
540-
*min = ret_min;
541-
gss_release_name(&ret_min, &src_name);
542-
gss_release_name(&ret_min, &targ_name);
543-
gss_release_buffer(&ret_min, &export_buffer);
544-
if (ret_maj) {
545-
xdr_free((xdrproc_t)xdr_gssx_OID, (char *)&out->mech);
546-
xdr_free((xdrproc_t)xdr_gssx_name, (char *)&out->src_name);
547-
xdr_free((xdrproc_t)xdr_gssx_name, (char *)&out->targ_name);
548-
}
549-
return ret_maj;
550-
}
551-
552-
int gp_conv_gssx_to_ctx_id(gssx_ctx *in, gss_ctx_id_t *out)
553-
{
554-
gss_buffer_desc export_buffer = GSS_C_EMPTY_BUFFER;
555-
uint32_t ret_maj;
556-
uint32_t ret_min;
557-
558-
gp_conv_gssx_to_buffer(&in->exported_context_token, &export_buffer);
559-
560-
ret_maj = gss_import_sec_context(&ret_min, &export_buffer, out);
561-
if (ret_maj) {
562-
return EINVAL;
563-
}
564-
565-
return 0;
566-
}
567-
568465
int gp_conv_status_to_gssx(struct gssx_call_ctx *call_ctx,
569466
uint32_t ret_maj, uint32_t ret_min,
570467
gss_OID mech, struct gssx_status *status)

proxy/src/gp_conv.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ uint32_t gp_conv_name_to_gssx_alloc(uint32_t *min,
6060
gss_name_t in, gssx_name **out);
6161
uint32_t gp_conv_gssx_to_name(uint32_t *min, gssx_name *in, gss_name_t *out);
6262

63-
uint32_t gp_conv_ctx_id_to_gssx(uint32_t *min,
64-
gss_ctx_id_t *in, gssx_ctx *out);
65-
int gp_conv_gssx_to_ctx_id(gssx_ctx *in, gss_ctx_id_t *out);
66-
6763
int gp_conv_status_to_gssx(struct gssx_call_ctx *call_ctx,
6864
uint32_t ret_maj, uint32_t ret_min,
6965
gss_OID mech, struct gssx_status *status);

proxy/src/gp_export.c

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,142 @@ int gp_find_cred(gssx_cred *cred, gss_cred_id_t *out)
168168
{
169169
return gp_import_gssx_cred(&cred->cred_handle_reference, out);
170170
}
171+
172+
173+
/* Exported Contexts */
174+
175+
#define EXP_CTX_TYPE_OPTION "exported_contex_type"
176+
#define LINUX_LUCID_V1 "linux_lucid_v1"
177+
178+
enum exp_ctx_types {
179+
EXP_CTX_DEFAULT = 0,
180+
EXP_CTX_LINUX_LUCID_V1 = 1,
181+
};
182+
183+
int gp_get_exported_context_type(struct gssx_call_ctx *ctx)
184+
{
185+
186+
struct gssx_option *val;
187+
int i;
188+
189+
for (i = 0; i < ctx->options.options_len; i++) {
190+
val = &ctx->options.options_val[i];
191+
if (val->option.octet_string_len == sizeof(EXP_CTX_TYPE_OPTION) &&
192+
strncmp(EXP_CTX_TYPE_OPTION,
193+
val->option.octet_string_val,
194+
val->option.octet_string_len) == 0) {
195+
if (strncmp(LINUX_LUCID_V1,
196+
val->value.octet_string_val,
197+
val->value.octet_string_len) == 0) {
198+
return EXP_CTX_LINUX_LUCID_V1;
199+
}
200+
return -1;
201+
}
202+
}
203+
204+
return EXP_CTX_DEFAULT;
205+
}
206+
207+
uint32_t gp_export_ctx_id_to_gssx(uint32_t *min, int type,
208+
gss_ctx_id_t *in, gssx_ctx *out)
209+
{
210+
uint32_t ret_maj;
211+
uint32_t ret_min;
212+
gss_name_t src_name = GSS_C_NO_NAME;
213+
gss_name_t targ_name = GSS_C_NO_NAME;
214+
gss_buffer_desc export_buffer = GSS_C_EMPTY_BUFFER;
215+
uint32_t lifetime_rec;
216+
gss_OID mech_type;
217+
uint32_t ctx_flags;
218+
int is_locally_initiated;
219+
int is_open;
220+
int ret;
221+
222+
/* TODO: For mechs that need multiple roundtrips to complete */
223+
/* out->state; */
224+
225+
/* we do not need the client to release anything until we handle state */
226+
out->needs_release = false;
227+
228+
ret_maj = gss_inquire_context(&ret_min, *in, &src_name, &targ_name,
229+
&lifetime_rec, &mech_type, &ctx_flags,
230+
&is_locally_initiated, &is_open);
231+
if (ret_maj) {
232+
goto done;
233+
}
234+
235+
ret = gp_conv_oid_to_gssx(mech_type, &out->mech);
236+
if (ret) {
237+
ret_maj = GSS_S_FAILURE;
238+
ret_min = ret;
239+
goto done;
240+
}
241+
242+
ret_maj = gp_conv_name_to_gssx(&ret_min, src_name, &out->src_name);
243+
if (ret_maj) {
244+
goto done;
245+
}
246+
247+
ret_maj = gp_conv_name_to_gssx(&ret_min, targ_name, &out->targ_name);
248+
if (ret_maj) {
249+
goto done;
250+
}
251+
252+
out->lifetime = lifetime_rec;
253+
254+
out->ctx_flags = ctx_flags;
255+
256+
if (is_locally_initiated) {
257+
out->locally_initiated = true;
258+
}
259+
260+
if (is_open) {
261+
out->open = true;
262+
}
263+
264+
/* note: once converted the original context token is not usable anymore,
265+
* so this must be the last call to use it */
266+
ret_maj = gss_export_sec_context(&ret_min, in, &export_buffer);
267+
if (ret_maj) {
268+
ret_maj = GSS_S_FAILURE;
269+
ret_min = ENOMEM;
270+
goto done;
271+
}
272+
ret = gp_conv_buffer_to_gssx(&export_buffer, &out->exported_context_token);
273+
if (ret) {
274+
ret_maj = GSS_S_FAILURE;
275+
ret_min = ret;
276+
goto done;
277+
}
278+
279+
/* Leave this empty, used only on the way in for init_sec_context */
280+
/* out->gssx_option */
281+
282+
done:
283+
*min = ret_min;
284+
gss_release_name(&ret_min, &src_name);
285+
gss_release_name(&ret_min, &targ_name);
286+
gss_release_buffer(&ret_min, &export_buffer);
287+
if (ret_maj) {
288+
xdr_free((xdrproc_t)xdr_gssx_OID, (char *)&out->mech);
289+
xdr_free((xdrproc_t)xdr_gssx_name, (char *)&out->src_name);
290+
xdr_free((xdrproc_t)xdr_gssx_name, (char *)&out->targ_name);
291+
}
292+
return ret_maj;
293+
}
294+
295+
uint32_t gp_import_gssx_to_ctx_id(uint32_t *min, int type,
296+
gssx_ctx *in, gss_ctx_id_t *out)
297+
{
298+
gss_buffer_desc export_buffer = GSS_C_EMPTY_BUFFER;
299+
300+
if (type != EXP_CTX_DEFAULT) {
301+
*min = EINVAL;
302+
return GSS_S_FAILURE;
303+
}
304+
305+
gp_conv_gssx_to_buffer(&in->exported_context_token, &export_buffer);
306+
307+
return gss_import_sec_context(min, &export_buffer, out);
308+
}
309+

proxy/src/gp_export.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,17 @@ uint32_t gp_export_gssx_cred(uint32_t *min,
3434
int gp_import_gssx_cred(octet_string *in, gss_cred_id_t *out);
3535
int gp_find_cred(gssx_cred *cred, gss_cred_id_t *out);
3636

37+
int gp_get_exported_context_type(struct gssx_call_ctx *ctx);
38+
uint32_t gp_export_ctx_id_to_gssx(uint32_t *min, int type,
39+
gss_ctx_id_t *in, gssx_ctx *out);
40+
uint32_t gp_import_gssx_to_ctx_id(uint32_t *min, int type,
41+
gssx_ctx *in, gss_ctx_id_t *out);
42+
43+
/* Compat fns */
44+
#define gp_conv_ctx_id_to_gssx(min, in, out) \
45+
gp_export_ctx_id_to_gssx(min, 0, in, out)
46+
static int32_t dummy_min;
47+
#define gp_conv_gssx_to_ctx_id(in, out) \
48+
(uint32_t)gp_import_gssx_to_ctx_id(&dummy_min, 0, in, out)
49+
3750
#endif /* _GSS_EXPORT_H_ */

0 commit comments

Comments
 (0)