From 9c0b7be87de83493ca1d5a01326982ce5c8c131b Mon Sep 17 00:00:00 2001 From: Heimdal Developers Date: Mon, 2 Jul 2012 15:00:30 +0100 Subject: [PATCH] Import of code from heimdal This commit updates the code imported from heimdal to 3fe55728404c602884f16126e9cc60fc5a3d8f20 (switch-from-svn-to-git-2993-g3fe5572) Upstream changes are: Andrew Bartlett (1): Revert "make paranoia check less paranoid" - check that key types strictly match Jeffrey Altman (3): do not include stdint.h unprotected Windows EAFNOSUPPORT defined by VS2010 roken: Use a common allocator for all windows Love Hornquist Astrand (2): add rk_getpwnam_r move windows compat errno constants to after is included Nicolas Williams (7): Fixes to make Heimdal -Wall -Werror clean Make krb5_kuserok() pluggable and add features (including MIT config compat) Generalize token expansion to allow for context-specific tokens Address code review comments (use krb5_enomem()) Make master build on Windows Fix a compiler warning in lib/roken/snprintf.c on 32-bit Ubuntu Move base into lib Roland C. Dowdeswell (3): Turn on -Wextra -Wno-sign-compare -Wno-unused-paramter and fix issues. Provide support for enctype aliases for ease of use. Additional changes to make -Wshadow build on Ubuntu 10.04. Simon Wilkinson (1): hcrypto: Use correct size for memset in md2 New files are: roken/realloc.c roken/win32_alloc.c Change-Id: I8129ad5677fd7e3a3d3daa78eadf436bbc63adc2 Reviewed-on: http://gerrit.openafs.org/7612 Tested-by: Jeffrey Altman Reviewed-by: Jeffrey Altman --- src/external/heimdal-last | 2 +- src/external/heimdal/hcrypto/md2.c | 2 +- src/external/heimdal/krb5/config_file.c | 6 +- src/external/heimdal/krb5/crypto-aes.c | 2 + src/external/heimdal/krb5/crypto.c | 12 +- src/external/heimdal/krb5/crypto.h | 1 + src/external/heimdal/krb5/expand_path.c | 179 +++++++++++++++++------ src/external/heimdal/roken/base64.c | 2 +- src/external/heimdal/roken/realloc.c | 47 ++++++ src/external/heimdal/roken/roken.h.in | 89 ++++++++--- src/external/heimdal/roken/snprintf.c | 6 +- src/external/heimdal/roken/win32_alloc.c | 62 ++++++++ src/external/heimdal/roken/write_pid.c | 8 +- 13 files changed, 344 insertions(+), 74 deletions(-) create mode 100644 src/external/heimdal/roken/realloc.c create mode 100644 src/external/heimdal/roken/win32_alloc.c diff --git a/src/external/heimdal-last b/src/external/heimdal-last index 629da3b3f..647676d48 100644 --- a/src/external/heimdal-last +++ b/src/external/heimdal-last @@ -1 +1 @@ -ee7340860a22f81fb869cc431efc1fd4e5c77d34 +3fe55728404c602884f16126e9cc60fc5a3d8f20 diff --git a/src/external/heimdal/hcrypto/md2.c b/src/external/heimdal/hcrypto/md2.c index 26254acee..b6517a631 100644 --- a/src/external/heimdal/hcrypto/md2.c +++ b/src/external/heimdal/hcrypto/md2.c @@ -130,5 +130,5 @@ MD2_Final (void *res, struct md2 *m) MD2_Update(m, pad, 16); memcpy(res, m->state, MD2_DIGEST_LENGTH); - memset(m, 0, sizeof(m)); + memset(m, 0, sizeof(*m)); } diff --git a/src/external/heimdal/krb5/config_file.c b/src/external/heimdal/krb5/config_file.c index 4ac25ae28..00b3d6d58 100644 --- a/src/external/heimdal/krb5/config_file.c +++ b/src/external/heimdal/krb5/config_file.c @@ -444,8 +444,10 @@ krb5_config_parse_file_multi (krb5_context context, home = pw->pw_dir; } if (home) { - asprintf(&newfname, "%s%s", home, &fname[1]); - if (newfname == NULL) { + int aret; + + aret = asprintf(&newfname, "%s%s", home, &fname[1]); + if (aret == -1 || newfname == NULL) { krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", "")); return ENOMEM; diff --git a/src/external/heimdal/krb5/crypto-aes.c b/src/external/heimdal/krb5/crypto-aes.c index 783372b39..6465e4255 100644 --- a/src/external/heimdal/krb5/crypto-aes.c +++ b/src/external/heimdal/krb5/crypto-aes.c @@ -142,6 +142,7 @@ AES_PRF(krb5_context context, struct _krb5_encryption_type _krb5_enctype_aes128_cts_hmac_sha1 = { ETYPE_AES128_CTS_HMAC_SHA1_96, "aes128-cts-hmac-sha1-96", + "aes128-cts", 16, 1, 16, @@ -157,6 +158,7 @@ struct _krb5_encryption_type _krb5_enctype_aes128_cts_hmac_sha1 = { struct _krb5_encryption_type _krb5_enctype_aes256_cts_hmac_sha1 = { ETYPE_AES256_CTS_HMAC_SHA1_96, "aes256-cts-hmac-sha1-96", + "aes256-cts", 16, 1, 16, diff --git a/src/external/heimdal/krb5/crypto.c b/src/external/heimdal/krb5/crypto.c index d43b70418..ae7aa21a8 100644 --- a/src/external/heimdal/krb5/crypto.c +++ b/src/external/heimdal/krb5/crypto.c @@ -467,7 +467,7 @@ verify_checksum(krb5_context context, return KRB5_PROG_SUMTYPE_NOSUPP; /* XXX */ } kct = crypto->et->keyed_checksum; - if (kct != NULL && kct->type != ct->type) { + if (kct == NULL || kct->type != ct->type) { krb5_set_error_message(context, KRB5_PROG_SUMTYPE_NOSUPP, N_("Checksum type %s is keyed, but " "the key type %s passed didnt have that checksum " @@ -679,11 +679,17 @@ krb5_string_to_enctype(krb5_context context, krb5_enctype *etype) { int i; - for(i = 0; i < _krb5_num_etypes; i++) + for(i = 0; i < _krb5_num_etypes; i++) { if(strcasecmp(_krb5_etypes[i]->name, string) == 0){ *etype = _krb5_etypes[i]->type; return 0; } + if(_krb5_etypes[i]->alias != NULL && + strcasecmp(_krb5_etypes[i]->alias, string) == 0){ + *etype = _krb5_etypes[i]->type; + return 0; + } + } krb5_set_error_message (context, KRB5_PROG_ETYPE_NOSUPP, N_("encryption type %s not supported", ""), string); @@ -2033,7 +2039,7 @@ krb5_crypto_init(krb5_context context, krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", "")); return ENOMEM; } - if(etype == ETYPE_NULL) + if(etype == (krb5_enctype)ETYPE_NULL) etype = key->keytype; (*crypto)->et = _krb5_find_enctype(etype); if((*crypto)->et == NULL || ((*crypto)->et->flags & F_DISABLED)) { diff --git a/src/external/heimdal/krb5/crypto.h b/src/external/heimdal/krb5/crypto.h index 9b95b8f0c..201a1d3ee 100644 --- a/src/external/heimdal/krb5/crypto.h +++ b/src/external/heimdal/krb5/crypto.h @@ -103,6 +103,7 @@ struct _krb5_checksum_type { struct _krb5_encryption_type { krb5_enctype type; const char *name; + const char *alias; size_t blocksize; size_t padsize; size_t confoundersize; diff --git a/src/external/heimdal/krb5/expand_path.c b/src/external/heimdal/krb5/expand_path.c index 4c4898a79..456ba305c 100644 --- a/src/external/heimdal/krb5/expand_path.c +++ b/src/external/heimdal/krb5/expand_path.c @@ -32,6 +32,8 @@ #include "krb5_locl.h" +#include + typedef int PTYPE; #ifdef _WIN32 @@ -49,7 +51,7 @@ typedef int PTYPE; * temporary directory until the user profile is loaded. In addition, * the returned path may or may not exist. */ -static int +static krb5_error_code _expand_temp_folder(krb5_context context, PTYPE param, const char *postfix, char **ret) { TCHAR tpath[MAX_PATH]; @@ -70,11 +72,8 @@ _expand_temp_folder(krb5_context context, PTYPE param, const char *postfix, char *ret = strdup(tpath); - if (*ret == NULL) { - if (context) - krb5_set_error_message(context, ENOMEM, "strdup - Out of memory"); - return ENOMEM; - } + if (*ret == NULL) + return krb5_enomem(context); return 0; } @@ -89,7 +88,7 @@ extern HINSTANCE _krb5_hInstance; * "bin" directory is considered to be the directory in which the * krb5.dll is located. */ -static int +static krb5_error_code _expand_bin_dir(krb5_context context, PTYPE param, const char *postfix, char **ret) { TCHAR path[MAX_PATH]; @@ -119,7 +118,7 @@ _expand_bin_dir(krb5_context context, PTYPE param, const char *postfix, char **r *ret = strdup(path); if (*ret == NULL) - return ENOMEM; + return krb5_enomem(context); return 0; } @@ -139,7 +138,7 @@ _expand_bin_dir(krb5_context context, PTYPE param, const char *postfix, char **r * SecurityIdentification level the call will fail. * */ -static int +static krb5_error_code _expand_userid(krb5_context context, PTYPE param, const char *postfix, char **ret) { int rv = EINVAL; @@ -237,7 +236,7 @@ _expand_userid(krb5_context context, PTYPE param, const char *postfix, char **re * Expand a folder identified by a CSIDL */ -static int +static krb5_error_code _expand_csidl(krb5_context context, PTYPE folder, const char *postfix, char **ret) { TCHAR path[MAX_PATH]; @@ -255,33 +254,27 @@ _expand_csidl(krb5_context context, PTYPE folder, const char *postfix, char **re path[len - 1] = '\0'; if (postfix && - strlcat(path, postfix, sizeof(path)/sizeof(path[0])) >= sizeof(path)/sizeof(path[0])) { - return ENOMEM; - } + strlcat(path, postfix, sizeof(path)/sizeof(path[0])) >= sizeof(path)/sizeof(path[0])) + return krb5_enomem(context); *ret = strdup(path); - if (*ret == NULL) { - if (context) - krb5_set_error_message(context, ENOMEM, "Out of memory"); - return ENOMEM; - } + if (*ret == NULL) + return krb5_enomem(context); return 0; } #else -static int +static krb5_error_code _expand_path(krb5_context context, PTYPE param, const char *postfix, char **ret) { *ret = strdup(postfix); - if (*ret == NULL) { - krb5_set_error_message(context, ENOMEM, "malloc - out of memory"); - return ENOMEM; - } + if (*ret == NULL) + return krb5_enomem(context); return 0; } -static int +static krb5_error_code _expand_temp_folder(krb5_context context, PTYPE param, const char *postfix, char **ret) { const char *p = NULL; @@ -293,37 +286,47 @@ _expand_temp_folder(krb5_context context, PTYPE param, const char *postfix, char else *ret = strdup("/tmp"); if (*ret == NULL) - return ENOMEM; + return krb5_enomem(context); return 0; } -static int +static krb5_error_code _expand_userid(krb5_context context, PTYPE param, const char *postfix, char **str) { int ret = asprintf(str, "%ld", (unsigned long)getuid()); if (ret < 0 || *str == NULL) - return ENOMEM; + return krb5_enomem(context); return 0; } #endif /* _WIN32 */ +/** + * Expand an extra token + */ + +static krb5_error_code +_expand_extra_token(krb5_context context, const char *value, char **ret) +{ + *ret = strdup(value); + if (*ret == NULL) + return krb5_enomem(context); + return 0; +} + /** * Expand a %{null} token * * The expansion of a %{null} token is always the empty string. */ -static int +static krb5_error_code _expand_null(krb5_context context, PTYPE param, const char *postfix, char **ret) { *ret = strdup(""); - if (*ret == NULL) { - if (context) - krb5_set_error_message(context, ENOMEM, "Out of memory"); - return ENOMEM; - } + if (*ret == NULL) + return krb5_enomem(context); return 0; } @@ -370,13 +373,15 @@ static const struct token { {"null", SPECIAL(_expand_null)} }; -static int +static krb5_error_code _expand_token(krb5_context context, const char *token, const char *token_end, + char **extra_tokens, char **ret) { size_t i; + char **p; *ret = NULL; @@ -387,6 +392,11 @@ _expand_token(krb5_context context, return EINVAL; } + for (p = extra_tokens; p && p[0]; p += 2) { + if (strncmp(token+2, p[0], (token_end - token) - 2) == 0) + return _expand_extra_token(context, p[1], ret); + } + for (i = 0; i < sizeof(tokens)/sizeof(tokens[0]); i++) { if (!strncmp(token+2, tokens[i].tok, (token_end - token) - 2)) return tokens[i].exp_func(context, tokens[i].param, @@ -398,14 +408,63 @@ _expand_token(krb5_context context, return EINVAL; } +/** + * Internal function to expand tokens in paths. + * + * Inputs: + * + * @context A krb5_context + * @path_in The path to expand tokens from + * + * Outputs: + * + * @ppath_out Path with expanded tokens (caller must free() this) + */ KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL _krb5_expand_path_tokens(krb5_context context, const char *path_in, char **ppath_out) +{ + return _krb5_expand_path_tokensv(context, path_in, ppath_out, NULL); +} + +static void +free_extra_tokens(char **extra_tokens) +{ + char **p; + + for (p = extra_tokens; p && *p; p++) + free(*p); + free(extra_tokens); +} + +/** + * Internal function to expand tokens in paths. + * + * Inputs: + * + * @context A krb5_context + * @path_in The path to expand tokens from + * @token Variable number of pairs of strings, the first of each + * being a token (e.g., "luser") and the second a string to + * replace it with. The list is terminated by a NULL. + * + * Outputs: + * + * @ppath_out Path with expanded tokens (caller must free() this) + */ +KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL +_krb5_expand_path_tokensv(krb5_context context, + const char *path_in, + char **ppath_out, ...) { char *tok_begin, *tok_end, *append; + char **extra_tokens = NULL; const char *path_left; + const char *s; + size_t nextra_tokens = 0; size_t len = 0; + va_list ap; if (path_in == NULL || *path_in == '\0') { *ppath_out = strdup(""); @@ -414,6 +473,42 @@ _krb5_expand_path_tokens(krb5_context context, *ppath_out = NULL; + va_start(ap, ppath_out); + while ((s = va_arg(ap, const char *))) { + nextra_tokens++; + s = va_arg(ap, const char *); + } + va_end(ap); + + /* Get extra tokens */ + if (nextra_tokens) { + size_t i; + + extra_tokens = calloc(nextra_tokens + 2, sizeof (*extra_tokens)); + if (extra_tokens == NULL) + return krb5_enomem(context); + va_start(ap, ppath_out); + for (i = 0; i < nextra_tokens; i++) { + s = va_arg(ap, const char *); + if (s == NULL) + break; + extra_tokens[i] = strdup(s); + if (extra_tokens[i++] == NULL) { + free_extra_tokens(extra_tokens); + return krb5_enomem(context); + } + s = va_arg(ap, const char *); + if (s == NULL) + break; + extra_tokens[i] = strdup(s); + if (extra_tokens[i] == NULL) { + free_extra_tokens(extra_tokens); + return krb5_enomem(context); + } + } + va_end(ap); + } + for (path_left = path_in; path_left && *path_left; ) { tok_begin = strstr(path_left, "%{"); @@ -431,6 +526,7 @@ _krb5_expand_path_tokens(krb5_context context, tok_end = strchr(tok_begin, '}'); if (tok_end == NULL) { + free_extra_tokens(extra_tokens); if (*ppath_out) free(*ppath_out); *ppath_out = NULL; @@ -439,7 +535,9 @@ _krb5_expand_path_tokens(krb5_context context, return EINVAL; } - if (_expand_token(context, tok_begin, tok_end, &append)) { + if (_expand_token(context, tok_begin, tok_end, extra_tokens, + &append)) { + free_extra_tokens(extra_tokens); if (*ppath_out) free(*ppath_out); *ppath_out = NULL; @@ -456,12 +554,11 @@ _krb5_expand_path_tokens(krb5_context context, if (append == NULL) { + free_extra_tokens(extra_tokens); if (*ppath_out) free(*ppath_out); *ppath_out = NULL; - if (context) - krb5_set_error_message(context, ENOMEM, "malloc - out of memory"); - return ENOMEM; + return krb5_enomem(context); } @@ -470,13 +567,12 @@ _krb5_expand_path_tokens(krb5_context context, char * new_str = realloc(*ppath_out, len + append_len + 1); if (new_str == NULL) { + free_extra_tokens(extra_tokens); free(append); if (*ppath_out) free(*ppath_out); *ppath_out = NULL; - if (context) - krb5_set_error_message(context, ENOMEM, "malloc - out of memory"); - return ENOMEM; + return krb5_enomem(context); } *ppath_out = new_str; @@ -496,5 +592,6 @@ _krb5_expand_path_tokens(krb5_context context, } #endif + free_extra_tokens(extra_tokens); return 0; } diff --git a/src/external/heimdal/roken/base64.c b/src/external/heimdal/roken/base64.c index 22c01e3b8..394e9841c 100644 --- a/src/external/heimdal/roken/base64.c +++ b/src/external/heimdal/roken/base64.c @@ -64,7 +64,7 @@ base64_encode(const void *data, int size, char **str) return -1; } - p = s = malloc(size * 4 / 3 + 4); + p = s = (char *) malloc(size * 4 / 3 + 4); if (p == NULL) { *str = NULL; return -1; diff --git a/src/external/heimdal/roken/realloc.c b/src/external/heimdal/roken/realloc.c new file mode 100644 index 000000000..fefa90d62 --- /dev/null +++ b/src/external/heimdal/roken/realloc.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2005 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#undef realloc + +#include +#include "roken.h" +#undef realloc + +ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL +rk_realloc(void *ptr, size_t size) +{ + if (ptr == NULL) + return malloc(size); + return realloc(ptr, size); +} diff --git a/src/external/heimdal/roken/roken.h.in b/src/external/heimdal/roken/roken.h.in index d6985d5b9..7194edf97 100644 --- a/src/external/heimdal/roken/roken.h.in +++ b/src/external/heimdal/roken/roken.h.in @@ -67,8 +67,6 @@ /* * error codes for inet_ntop/inet_pton */ -#define EAFNOSUPPORT WSAEAFNOSUPPORT - typedef SOCKET rk_socket_t; #define rk_closesocket(x) closesocket(x) @@ -79,23 +77,6 @@ typedef SOCKET rk_socket_t; ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_SOCK_IOCTL(SOCKET s, long cmd, int * argp); -/* Microsoft VC 2010 POSIX definitions */ -#ifndef ENOTSOCK -#define ENOTSOCK 128 -#endif -#ifndef ENOTSUP -#define ENOTSUP 129 -#endif -#ifndef EOVERFLOW -#define EOVERFLOW 132 -#endif -#ifndef ETIMEDOUT -#define ETIMEDOUT 138 -#endif -#ifndef EWOULDBLOCK -#define EWOULDBLOCK 140 -#endif - #define rk_SOCK_INIT() rk_WSAStartup() #define rk_SOCK_EXIT() rk_WSACleanup() @@ -116,13 +97,17 @@ typedef int rk_socket_t; #define rk_SOCK_INIT() 0 #define rk_SOCK_EXIT() do { } while(0) -#endif +#endif /* WinSock */ #ifndef IN_LOOPBACKNET #define IN_LOOPBACKNET 127 #endif #ifdef _MSC_VER +#ifndef HAVE_STDINT_H +#include +#endif + /* Declarations for Microsoft Visual C runtime on Windows */ #include @@ -367,6 +352,26 @@ rk_vsnprintf (char *str, size_t sz, const char *format, va_list args); S_ISBLK(m) */ +#if !defined(ROKEN_NO_DEFINE_ALLOCATORS) +/* Ensure that a common memory allocator is used by all */ +#define calloc rk_calloc +#define free rk_free +#define malloc rk_malloc +#define realloc rk_realloc +#endif + +ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL +rk_calloc(size_t, size_t); + +ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL +rk_free(void *); + +ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL +rk_malloc(size_t); + +ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL +rk_realloc(void *, size_t); + #endif /* _MSC_VER */ #ifdef HAVE_WINSOCK @@ -601,6 +606,13 @@ ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL k_getpwnam (const char *); ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL k_getpwuid (uid_t); #endif +#ifdef POSIX_GETPWNAM_R +#define rk_getpwnam_r(_n, _pw, _b, _sz, _pwd) getpwnam_r(_n, _pw, _b, _sz, _pwd) +#else +ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL +rk_getpwnam_r(const char *, struct passwd *, char *, size_t, struct passwd **); +#endif + ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL get_default_username (void); #ifndef HAVE_SETEUID @@ -1026,6 +1038,22 @@ ROKEN_LIB_FUNCTION struct tm * ROKEN_LIB_CALL localtime_r(const time_t *, struct tm *); #endif +#if !defined(HAVE_STRTOLL) || defined(NEED_STRTOLL_PROTO) +#ifndef HAVE_STRTOLL +#define strtoll rk_strtoll +#endif +ROKEN_LIB_FUNCTION long long ROKEN_LIB_CALL +strtoll(const char * __restrict nptr, char ** __restrict endptr, int base); +#endif + +#if !defined(HAVE_STRTOULL) || defined(NEED_STRTOULL_PROTO) +#ifndef HAVE_STRTOULL +#define strtoull rk_strtoull +#endif +ROKEN_LIB_FUNCTION unsigned long long ROKEN_LIB_CALL +strtoull(const char * __restrict nptr, char ** __restrict endptr, int base); +#endif + #if !defined(HAVE_STRSVIS) || defined(NEED_STRSVIS_PROTO) #ifndef HAVE_STRSVIS #define strsvis rk_strsvis @@ -1135,6 +1163,27 @@ rk_qsort(void *, size_t, size_t, int (*)(const void *, const void *)); int ROKEN_LIB_FUNCTION rk_socket(int, int, int); #endif +/* Microsoft VC 2010 POSIX definitions */ +#ifndef EAFNOSUPPORT +#define EAFNOSUPPORT 102 +#endif +#ifndef ENOTSOCK +#define ENOTSOCK 128 +#endif +#ifndef ENOTSUP +#define ENOTSUP 129 +#endif +#ifndef EOVERFLOW +#define EOVERFLOW 132 +#endif +#ifndef ETIMEDOUT +#define ETIMEDOUT 138 +#endif +#ifndef EWOULDBLOCK +#define EWOULDBLOCK 140 +#endif + + #ifdef SOCKET_WRAPPER_REPLACE #include #endif diff --git a/src/external/heimdal/roken/snprintf.c b/src/external/heimdal/roken/snprintf.c index 88e996c67..022118e53 100644 --- a/src/external/heimdal/roken/snprintf.c +++ b/src/external/heimdal/roken/snprintf.c @@ -117,6 +117,10 @@ typedef unsigned long u_longest; typedef long longest; #endif +#ifndef HAVE_UINTPTR_T +typedef u_longest uintptr_t; +#endif + static size_t @@ -498,7 +502,7 @@ xyzprintf (struct snprintf_state *state, const char *char_format, va_list ap) break; } case 'p' : { - u_longest arg = (u_longest)va_arg(ap, void*); + uintptr_t arg = (uintptr_t)va_arg(ap, void*); len += append_number (state, arg, 0x10, "0123456789ABCDEF", width, prec, flags, 0); diff --git a/src/external/heimdal/roken/win32_alloc.c b/src/external/heimdal/roken/win32_alloc.c new file mode 100644 index 000000000..42ebbf7be --- /dev/null +++ b/src/external/heimdal/roken/win32_alloc.c @@ -0,0 +1,62 @@ +/*********************************************************************** + * Copyright (c) 2012, Secure Endpoints Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ +#include +#include "roken.h" +#undef calloc +#undef malloc +#undef free + +/* + * Windows executables and dlls suffer when memory is + * allocated with one allocator and deallocated with + * another because each allocator is backed by a separate + * heap. Reduce the exposure by ensuring that all + * binaries that are built using roken will build against + * same allocator. + */ + +ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL +rk_calloc(size_t elements, size_t size) +{ + return calloc( elements, size); +} + +ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL +rk_free(void * ptr) +{ + free( ptr); +} + +ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL +rk_malloc(size_t size) +{ + return malloc( size); +} diff --git a/src/external/heimdal/roken/write_pid.c b/src/external/heimdal/roken/write_pid.c index 505936984..6d83d87af 100644 --- a/src/external/heimdal/roken/write_pid.c +++ b/src/external/heimdal/roken/write_pid.c @@ -74,13 +74,13 @@ pidfile_cleanup(void) } ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL -pidfile(const char *basename) +pidfile(const char *bname) { if(pidfile_path != NULL) return; - if(basename == NULL) - basename = getprogname(); - pidfile_path = pid_file_write(basename); + if(bname == NULL) + bname = getprogname(); + pidfile_path = pid_file_write(bname); #if defined(HAVE_ATEXIT) atexit(pidfile_cleanup); #elif defined(HAVE_ON_EXIT) -- 2.39.5