From 5ece0443a85a0c6339c5fed6b7d1e2f6a214356f Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 30 Jan 2012 14:53:16 -0500 Subject: Add helper to convert OID sets --- proxy/src/gp_conv.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++ proxy/src/gp_conv.h | 3 +++ 2 files changed, 76 insertions(+) diff --git a/proxy/src/gp_conv.c b/proxy/src/gp_conv.c index 06e0042..c5a96dc 100644 --- a/proxy/src/gp_conv.c +++ b/proxy/src/gp_conv.c @@ -543,3 +543,76 @@ done: return ret; } +int gp_conv_gssx_to_oid_set(gssx_OID_set *in, gss_OID_set *out) +{ + gss_OID_set o; + int i; + + if (in->gssx_OID_set_len == 0) { + *out = GSS_C_NO_OID_SET; + return 0; + } + + o = malloc(sizeof(gss_OID_set_desc)); + if (!o) { + return ENOMEM; + } + + o->count = in->gssx_OID_set_len; + o->elements = calloc(o->count, sizeof(gss_OID_desc)); + if (!o->elements) { + free(o); + return ENOMEM; + } + + for (i = 0; i < o->count; i++) { + o->elements[i].elements = + gp_memdup(in->gssx_OID_set_val[i].octet_string_val, + in->gssx_OID_set_val[i].octet_string_len); + if (!o->elements[i].elements) { + while (i > 0) { + i--; + free(o->elements[i].elements); + } + free(o->elements); + free(o); + return ENOMEM; + } + o->elements[i].length = in->gssx_OID_set_val[i].octet_string_len; + } + + *out = o; + return 0; +} + +int gp_conv_oid_set_to_gssx(gss_OID_set in, gssx_OID_set *out) +{ + int ret; + int i; + + if (in->count == 0) { + return 0; + } + + out->gssx_OID_set_len = in->count; + out->gssx_OID_set_val = calloc(in->count, sizeof(gssx_OID)); + if (!out->gssx_OID_set_val) { + return ENOMEM; + } + + for (i = 0; i < in->count; i++) { + ret = gp_conv_octet_string(in->elements[i].length, + in->elements[i].elements, + &out->gssx_OID_set_val[i]); + if (ret) { + while (i > 0) { + i--; + free(out->gssx_OID_set_val[i].octet_string_val); + } + free(out->gssx_OID_set_val); + return ENOMEM; + } + } + + return 0; +} diff --git a/proxy/src/gp_conv.h b/proxy/src/gp_conv.h index 20c18d5..110970a 100644 --- a/proxy/src/gp_conv.h +++ b/proxy/src/gp_conv.h @@ -65,4 +65,7 @@ int gp_conv_status_to_gssx(struct gssx_call_ctx *call_ctx, int gp_copy_utf8string(utf8string *in, utf8string *out); int gp_copy_gssx_status_alloc(gssx_status *in, gssx_status **out); +int gp_conv_gssx_to_oid_set(gssx_OID_set *in, gss_OID_set *out); +int gp_conv_oid_set_to_gssx(gss_OID_set in, gssx_OID_set *out); + #endif /* _GSS_CONV_H_ */ -- cgit