[PATCH 3/4] Utility functions to move allocations from k5buf/krb5_data to gss_buffer_t
Sam Hartman
hartmans at painless-security.com
Wed Sep 28 15:50:58 EDT 2011
From: Kevin Wasserman <kevin.wasserman at painless-security.com>
On Unix, these simply move the buffer pointer, but on windows they need to
reallocated with gssalloc_malloc and coied since the gss_buffer_t may need
to be freed in a separate module with potentially mismatched c runtime.
Also fix a mismatched parameter warning in generic_gss_copy_oid_set().
Signed-off-by: Kevin Wasserman <kevin.wasserman at painless-security.com>
---
src/lib/gssapi/generic/gssapiP_generic.h | 21 +++++++++++++++++++--
src/lib/gssapi/krb5/gssapiP_krb5.h | 15 +++++++++++++++
2 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/src/lib/gssapi/generic/gssapiP_generic.h b/src/lib/gssapi/generic/gssapiP_generic.h
index 4b2ce6e..49a1ed1 100644
--- a/src/lib/gssapi/generic/gssapiP_generic.h
+++ b/src/lib/gssapi/generic/gssapiP_generic.h
@@ -41,7 +41,7 @@
#include "gssapi_generic.h"
#include "gssapi_ext.h"
-#include "gssapi_bufferext.h"
+#include "gssapi_alloc.h"
#include "gssapi_err_generic.h"
#include <errno.h>
@@ -265,6 +265,23 @@ int gssint_mecherrmap_get(OM_uint32 minor, gss_OID mech_oid,
OM_uint32 *mech_minor);
OM_uint32 gssint_mecherrmap_map_errcode(OM_uint32 errcode);
+static inline void
+gssint_transfer_k5buf_to_gss_buffer(struct k5buf *input_k5buf,
+ gss_buffer_t output_buffer)
+{
+ char *bp = krb5int_buf_data(input_k5buf);
+ output_buffer->length = krb5int_buf_len(input_k5buf)+1;
+#ifdef _WIN32
+ output_buffer->value = gssalloc_malloc(output_buffer->length);
+ memcpy(output_buffer->value, bp, output_buffer->length);
+ krb5int_free_buf(input_k5buf);
+#else
+ output_buffer->value = bp;
+ input_k5buf->data = NULL;
+ input_k5buf->buftype = BUFTYPE_ERROR;
+#endif
+}
+
OM_uint32 generic_gss_create_empty_buffer_set
(OM_uint32 * /*minor_status*/,
gss_buffer_set_t * /*buffer_set*/);
@@ -280,7 +297,7 @@ OM_uint32 generic_gss_release_buffer_set
OM_uint32 generic_gss_copy_oid_set
(OM_uint32 *, /* minor_status */
- const gss_OID_set_desc *, /* const oidset*/
+ const gss_OID_set_desc * const /*oidset*/,
gss_OID_set * /*new_oidset*/);
extern gss_OID_set gss_ma_known_attrs;
diff --git a/src/lib/gssapi/krb5/gssapiP_krb5.h b/src/lib/gssapi/krb5/gssapiP_krb5.h
index 08155e8..ae7fd86 100644
--- a/src/lib/gssapi/krb5/gssapiP_krb5.h
+++ b/src/lib/gssapi/krb5/gssapiP_krb5.h
@@ -1186,6 +1186,21 @@ iakerb_verify_finished(krb5_context context,
const krb5_data *conv,
const krb5_data *finished);
+static inline void
+gss_krb5int_transfer_krb5_data_to_gss_buffer(krb5_data *input_k5data,
+ gss_buffer_t output_buffer)
+{
+ output_buffer->length = input_k5data->length;
+#ifdef _WIN32
+ output_buffer->value = gssalloc_malloc(output_buffer->length);
+ memcpy(output_buffer->value, input_k5data->data, output_buffer->length);
+ free(input_k5data->data);
+#else
+ output_buffer->value = input_k5data->data;
+#endif
+ input_k5data = NULL;
+}
+
#define KRB5_GSS_EXTS_IAKERB_FINISHED 1
#endif /* _GSSAPIP_KRB5_H_ */
--
1.7.4.1
More information about the krbdev
mailing list