Contains allocator methods for use with mechanisms and mechglues for
allocations that must be made in one module but freed in another. On
windows, an allocation made in one module cannot safely be freed in
another using the usual c runtime malloc/free; runtime dll mismatch
will cause heap corruption in that case. But it is safe to instead
directly use HeapAlloc()/HeapFree() specifying the default process
heap. For now, this header is not public. If it becomes public
strncpy will need to be used instead of strlcpy.
Signed-off-by: Kevin Wasserman <kevin.wasserman@painless-security.com>
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@25330
dc483132-0cff-0310-8789-
dd5450dbe970
copy include\profile.h "$(KRB_INSTALL_DIR)\include\."
copy include\com_err.h "$(KRB_INSTALL_DIR)\include\."
copy include\gssapi\gssapi.h "$(KRB_INSTALL_DIR)\include\gssapi\."
+ copy include\gssapi\gssapi_alloc.h "$(KRB_INSTALL_DIR)\include\gssapi\."
copy include\gssapi\gssapi_krb5.h "$(KRB_INSTALL_DIR)\include\gssapi\."
copy include\gssapi\gssapi_ext.h "$(KRB_INSTALL_DIR)\include\gssapi\."
copy lib\$(OUTPRE)*.lib "$(KRB_INSTALL_DIR)\lib\."
clean-windows::
$(RM) com_err.h profile.h
$(RM) gssapi\gssapi.h gssapi\gssapi_generic.h gssapi\gssapi_krb5.h
- $(RM) gssapi\gssapi_ext.h gssapi\timestamp
+ $(RM) gssapi\gssapi_alloc.h gssapi\gssapi_ext.h gssapi\timestamp
if exist gssapi\nul rmdir /s /q gssapi
$(RM) osconf.h autoconf.h autoconf.stamp
@echo Making clean in include
$(EHDRDIR)$(S)gssapi_krb5.h \
$(EHDRDIR)$(S)gssapi_generic.h \
$(EHDRDIR)$(S)gssapi.h \
+ $(EHDRDIR)$(S)gssapi_alloc.h \
$(EHDRDIR)$(S)gssapi_ext.h
merged-gssapi-header.h: $(EXPORTED_HEADERS)
cat $(EXPORTED_HEADERS) > merged.tmp
HDRS= $(EHDRDIR)$(S)gssapi.h \
$(EHDRDIR)$(S)gssapi_generic.h \
+ $(EHDRDIR)$(S)gssapi_alloc.h \
$(EHDRDIR)$(S)gssapi_ext.h
MK_EHDRDIR=if test -d $(EHDRDIR); then :; else (set -x; mkdir $(EHDRDIR)); fi
$(CP) gssapi.h $@
$(EHDRDIR)$(S)gssapi_generic.h: $(EHDRDIR)$(S)timestamp $(srcdir)$(S)gssapi_generic.h
$(CP) $(srcdir)$(S)gssapi_generic.h $@
+$(EHDRDIR)$(S)gssapi_alloc.h: $(EHDRDIR)$(S)timestamp $(srcdir)$(S)gssapi_alloc.h
+ $(CP) $(srcdir)$(S)gssapi_alloc.h $@
$(EHDRDIR)$(S)gssapi_ext.h: $(EHDRDIR)$(S)timestamp $(srcdir)$(S)gssapi_ext.h
$(CP) $(srcdir)$(S)gssapi_ext.h $@
util_token.o \
gssapi_err_generic.o
-EXPORTED_HEADERS= gssapi_generic.h gssapi_ext.h
+EXPORTED_HEADERS= gssapi_generic.h gssapi_ext.h
EXPORTED_BUILT_HEADERS= gssapi.h
$(OBJS): $(EXPORTED_HEADERS) $(ETHDRS)
--- /dev/null
+/* To the extent possible under law, Painless Security, LLC has waived
+ * all copyright and related or neighboring rights to GSS-API Memory
+ * Management Header. This work is published from: United States.
+ */
+
+#ifndef GSSAPI_ALLOC_H
+#define GSSAPI_ALLOC_H
+
+#ifdef _WIN32
+#include "winbase.h"
+#endif
+#include <string.h>
+/*
+ * Note that we'll need to do something else if we decide to install
+ * this header for mechanisms.
+ */
+#include <k5-platform.h>
+
+static inline void
+gssalloc_free(void * value)
+{
+ if (value) {
+#if _WIN32
+ HeapFree(GetProcessHeap(), 0, value);
+#else
+ free(value);
+#endif
+ }
+}
+
+static inline void *
+gssalloc_malloc(size_t size)
+{
+#if _WIN32
+ return HeapAlloc(GetProcessHeap(), 0, size);
+#else
+ return malloc(size);
+#endif
+}
+
+static inline void *
+gssalloc_calloc(size_t count, size_t size)
+{
+#if _WIN32
+ return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, count * size);
+#else
+ return calloc(count, size);
+#endif
+}
+
+static inline char *
+gssalloc_strdup(const char *str)
+{
+ int size = strlen(str)+1;
+ char *copy = gssalloc_malloc(size);
+ if (copy) {
+ strlcpy(copy, str, size);
+ }
+ return copy;
+}
+
+#endif
HEADERS= \
gssapi/gssapi.h \
gssapi/gssapi_krb5.h \
+ gssapi/gssapi_alloc.h \
gssapi/gssapi_ext.h \
gssapi.h \
gssapiP_krb5.h \
$(CP) $(GSS_GENERIC_BUILD)/gssapi.h $@
gssapi/gssapi_krb5.h: gssapi $(GSS_KRB5_BUILD)/gssapi_krb5.h
$(CP) $(GSS_KRB5_BUILD)/gssapi_krb5.h $@
+gssapi/gssapi_alloc.h: gssapi $(GSS_GENERIC)/gssapi_alloc.h
+ $(CP) $(GSS_GENERIC)/gssapi_alloc.h $@
gssapi/gssapi_ext.h: gssapi $(GSS_GENERIC)/gssapi_ext.h
$(CP) $(GSS_GENERIC)/gssapi_ext.h $@
gssapiP_krb5.h: $(GSS_KRB5)/gssapiP_krb5.h
#
$(OUTPRE)k5seal.$(OBJEXT): autoconf.h com_err.h gssapi/gssapi.h \
gssapi/gssapi_ext.h gssapi/gssapi_krb5.h gssapiP_generic.h \
- gssapiP_krb5.h gssapi_err_generic.h gssapi_err_krb5.h \
+ gssapiP_krb5.h gssapi_err_generic.h gssapi_err_krb5.h gssapi/gssapi_alloc.h\
gssapi_generic.h k5-buf.h k5-err.h k5-gmt_mktime.h \
k5-int-pkinit.h k5-int.h k5-platform.h k5-plugin.h \
k5-thread.h k5-trace.h k5seal.c krb5.h krb5/authdata_plugin.h \
gssapi_err_generic.h gssapi_generic.h k5-buf.h k5-platform.h \
k5-thread.h util_ordering.c
$(OUTPRE)kernel_gss.$(OBJEXT): autoconf.h com_err.h \
- gssapi/gssapi.h gssapi/gssapi_ext.h gssapi/gssapi_krb5.h \
+ gssapi/gssapi.h gssapi/gssapi_ext.h gssapi/gssapi_krb5.h gssapi/gssapi_alloc.h\
gssapiP_generic.h gssapiP_krb5.h gssapi_err_generic.h \
gssapi_err_krb5.h gssapi_generic.h k5-buf.h k5-err.h \
k5-gmt_mktime.h k5-int-pkinit.h k5-int.h k5-platform.h \