diff options
author | Simo Sorce <simo@redhat.com> | 2012-01-29 14:27:24 -0500 |
---|---|---|
committer | Simo Sorce <simo@redhat.com> | 2012-01-29 22:08:26 -0500 |
commit | 9014d7581a9e1dc431499b91286758de0dcf769b (patch) | |
tree | 64615bca62fbf2cc504816ff23c1a740c53e5534 | |
parent | a56ca2e026f5ee7cb9b09a694cb76fa2a8552ac4 (diff) | |
download | gss-proxy-9014d7581a9e1dc431499b91286758de0dcf769b.tar.gz gss-proxy-9014d7581a9e1dc431499b91286758de0dcf769b.tar.xz gss-proxy-9014d7581a9e1dc431499b91286758de0dcf769b.zip |
gp_conv: Add helpers to alloc data when converting
-rw-r--r-- | proxy/src/gp_conv.c | 85 | ||||
-rw-r--r-- | proxy/src/gp_conv.h | 6 |
2 files changed, 91 insertions, 0 deletions
diff --git a/proxy/src/gp_conv.c b/proxy/src/gp_conv.c index 6354c80..99b1c05 100644 --- a/proxy/src/gp_conv.c +++ b/proxy/src/gp_conv.c @@ -40,23 +40,88 @@ int gp_conv_octet_string(size_t length, void *value, octet_string *out) return 0; } +int gp_conv_octet_string_alloc(size_t length, void *value, + octet_string **out) +{ + octet_string *o; + int ret; + + o = calloc(1, sizeof(octet_string)); + if (!o) { + return ENOMEM; + } + + ret = gp_conv_octet_string(length, value, o); + if (ret) { + free(o); + return ret; + } + + *out = o; + return 0; +} + void gp_conv_gssx_to_oid(gssx_OID *in, gss_OID out) { out->length = in->octet_string_len; out->elements = (void *)in->octet_string_val; } +int gp_conv_gssx_to_oid_alloc(gssx_OID *in, gss_OID *out) +{ + gss_OID o; + + o = calloc(1, sizeof(gss_OID)); + if (!o) { + return ENOMEM; + } + o->length = in->octet_string_len; + o->elements = malloc(o->length); + if (!o->elements) { + free(o); + return ENOMEM; + } + memcpy(o->elements, in->octet_string_val, o->length); + return 0; +} + int gp_conv_oid_to_gssx(gss_OID in, gssx_OID *out) { return gp_conv_octet_string(in->length, in->elements, out); } +int gp_conv_oid_to_gssx_alloc(gss_OID in, gssx_OID **out) +{ + return gp_conv_octet_string_alloc(in->length, in->elements, out); +} + void gp_conv_gssx_to_buffer(gssx_buffer *in, gss_buffer_t out) { out->length = in->octet_string_len; out->value = (void *)in->octet_string_val; } +int gp_conv_gssx_to_buffer_alloc(gssx_buffer *in, gss_buffer_t *out) +{ + gss_buffer_desc *o; + + o = malloc(sizeof(gss_buffer_desc)); + if (!o) { + return ENOMEM; + } + + o->length = in->octet_string_len; + o->value = malloc(o->length); + if (!o->value) { + free(o); + return ENOMEM; + } + memcpy(o->value, in->octet_string_val, o->length); + + *out = o; + return 0; +} + int gp_conv_buffer_to_gssx(gss_buffer_t in, gssx_buffer *out) { return gp_conv_octet_string(in->length, in->value, out); @@ -104,6 +169,26 @@ done: return ret; } +int gp_conv_cb_to_gssx_alloc(gss_channel_bindings_t in, gssx_cb **out) +{ + gssx_cb *o; + int ret; + + o = malloc(sizeof(gssx_cb)); + if (!o) { + return ENOMEM; + } + + ret = gp_conv_cb_to_gssx(in, o); + if (ret) { + free(o); + return ENOMEM; + } + + *out = o; + return 0; +} + gssx_cred_usage gp_conv_cred_usage_to_gssx(gss_cred_usage_t in) { switch (in) { diff --git a/proxy/src/gp_conv.h b/proxy/src/gp_conv.h index 198a5c5..f738ad7 100644 --- a/proxy/src/gp_conv.h +++ b/proxy/src/gp_conv.h @@ -30,15 +30,21 @@ #include "rpcgen/gss_proxy.h" int gp_conv_octet_string(size_t length, void *value, octet_string *out); +int gp_conv_octet_string_alloc(size_t length, void *value, + octet_string **out); void gp_conv_gssx_to_oid(gssx_OID *in, gss_OID out); +int gp_conv_gssx_to_oid_alloc(gssx_OID *in, gss_OID *out); int gp_conv_oid_to_gssx(gss_OID in, gssx_OID *out); +int gp_conv_oid_to_gssx_alloc(gss_OID in, gssx_OID **out); void gp_conv_gssx_to_buffer(gssx_buffer *in, gss_buffer_t out); +int gp_conv_gssx_to_buffer_alloc(gssx_buffer *in, gss_buffer_t *out); int gp_conv_buffer_to_gssx(gss_buffer_t in, gssx_buffer *out); void gp_conv_gssx_to_cb(gssx_cb *in, gss_channel_bindings_t out); int gp_conv_cb_to_gssx(gss_channel_bindings_t in, gssx_cb *out); +int gp_conv_cb_to_gssx_alloc(gss_channel_bindings_t in, gssx_cb **out); gssx_cred_usage gp_conv_cred_usage_to_gssx(gss_cred_usage_t in); gss_cred_usage_t gp_conv_gssx_to_cred_usage(gssx_cred_usage in); |