From 341d8bf1313434acf3acded90cfcffd575adc4e5 Mon Sep 17 00:00:00 2001 From: Heimdal Developers Date: Wed, 1 Dec 2010 18:02:30 +0000 Subject: [PATCH] Import of code from heimdal This commit updates the code imported from heimdal to 42f9c644cf00be752f09d85a9664bf2e3502101c (switch-from-svn-to-git-1962-g42f9c64) Upstream changes are: Asanka C. Herath (9): Windows: Registry based configuration Rename get_entry() -> _krb5_config_get_entry() Deal with quoted strings when reading lists of config strings Add missing export and calling convention annotations Windows: Build and export localtime_r Windows: Older Windows SDKs need More compatibility macros Increase KBR5_BUFSIZ to 2048 and use it in config_file.c Deal with backslash escaped quotes Love Hornquist Astrand (3): provide symbol renameing for sha512 and sha384 less exit with failures add random abstraction Change-Id: I495fa8e9c1c037d6dee191279c1155a4ec6be945 Reviewed-on: http://gerrit.openafs.org/3400 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- src/external/heimdal-last | 2 +- src/external/heimdal/hcrypto/sha.h | 6 ++ src/external/heimdal/krb5/config_file.c | 73 +++++++++++++++++++---- src/external/heimdal/roken/localtime_r.c | 6 ++ src/external/heimdal/roken/roken-common.h | 12 ++++ src/external/heimdal/roken/roken.h.in | 13 ++-- src/external/heimdal/roken/socket.c | 39 ++++-------- 7 files changed, 107 insertions(+), 44 deletions(-) diff --git a/src/external/heimdal-last b/src/external/heimdal-last index 2aeb3f61a..c1a7d22fe 100644 --- a/src/external/heimdal-last +++ b/src/external/heimdal-last @@ -1 +1 @@ -5b91f58f350c92fb9eacd1ebac558381b0b8deac +42f9c644cf00be752f09d85a9664bf2e3502101c diff --git a/src/external/heimdal/hcrypto/sha.h b/src/external/heimdal/hcrypto/sha.h index a1f5a9931..fbc1810b4 100644 --- a/src/external/heimdal/hcrypto/sha.h +++ b/src/external/heimdal/hcrypto/sha.h @@ -43,6 +43,12 @@ #define SHA256_Init hc_SHA256_Init #define SHA256_Update hc_SHA256_Update #define SHA256_Final hc_SHA256_Final +#define SHA384_Init hc_SHA384_Init +#define SHA384_Update hc_SHA384_Update +#define SHA384_Final hc_SHA384_Final +#define SHA512_Init hc_SHA512_Init +#define SHA512_Update hc_SHA512_Update +#define SHA512_Final hc_SHA512_Final /* * SHA-1 diff --git a/src/external/heimdal/krb5/config_file.c b/src/external/heimdal/krb5/config_file.c index 87280767d..13d07614b 100644 --- a/src/external/heimdal/krb5/config_file.c +++ b/src/external/heimdal/krb5/config_file.c @@ -84,8 +84,8 @@ static krb5_error_code parse_list(struct fileptr *f, unsigned *lineno, krb5_config_binding **parent, const char **err_message); -static krb5_config_section * -get_entry(krb5_config_section **parent, const char *name, int type) +krb5_config_section * +_krb5_config_get_entry(krb5_config_section **parent, const char *name, int type) { krb5_config_section **q; @@ -135,7 +135,7 @@ parse_section(char *p, krb5_config_section **s, krb5_config_section **parent, return KRB5_CONFIG_BADFORMAT; } *p1 = '\0'; - tmp = get_entry(parent, p + 1, krb5_config_list); + tmp = _krb5_config_get_entry(parent, p + 1, krb5_config_list); if(tmp == NULL) { *err_message = "out of memory"; return KRB5_CONFIG_BADFORMAT; @@ -154,7 +154,7 @@ static krb5_error_code parse_list(struct fileptr *f, unsigned *lineno, krb5_config_binding **parent, const char **err_message) { - char buf[BUFSIZ]; + char buf[KRB5_BUFSIZ]; krb5_error_code ret; krb5_config_binding *b = NULL; unsigned beg_lineno = *lineno; @@ -216,14 +216,14 @@ parse_binding(struct fileptr *f, unsigned *lineno, char *p, ++p; *p2 = '\0'; if (*p == '{') { - tmp = get_entry(parent, p1, krb5_config_list); + tmp = _krb5_config_get_entry(parent, p1, krb5_config_list); if (tmp == NULL) { *err_message = "out of memory"; return KRB5_CONFIG_BADFORMAT; } ret = parse_list (f, lineno, &tmp->u.list, err_message); } else { - tmp = get_entry(parent, p1, krb5_config_string); + tmp = _krb5_config_get_entry(parent, p1, krb5_config_string); if (tmp == NULL) { *err_message = "out of memory"; return KRB5_CONFIG_BADFORMAT; @@ -282,10 +282,10 @@ convert_content(const void *key, const void *value, void *context) return; if (CFGetTypeID(value) == CFStringGetTypeID()) { - tmp = get_entry(parent, k, krb5_config_string); + tmp = _krb5_config_get_entry(parent, k, krb5_config_string); tmp->u.string = cfstring2cstring(value); } else if (CFGetTypeID(value) == CFDictionaryGetTypeID()) { - tmp = get_entry(parent, k, krb5_config_list); + tmp = _krb5_config_get_entry(parent, k, krb5_config_list); CFDictionaryApplyFunction(value, convert_content, &tmp->u.list); } else { /* log */ @@ -352,7 +352,7 @@ krb5_config_parse_debug (struct fileptr *f, { krb5_config_section *s = NULL; krb5_config_binding *b = NULL; - char buf[BUFSIZ]; + char buf[KRB5_BUFSIZ]; krb5_error_code ret; while (config_fgets(buf, sizeof(buf), f) != NULL) { @@ -864,6 +864,55 @@ krb5_config_get_string_default (krb5_context context, return ret; } +static char * +next_component_string(char * begin, char * delims, char **state) +{ + char * end; + + if (begin == NULL) + begin = *state; + + if (*begin == '\0') + return NULL; + + end = begin; + while (*end == '"') { + char * t; + while ((t = strchr(end + 1, '"')) != NULL && *(t - 1) == '\\') { + --t; + memmove(t, t + 1, strlen(t)); + end = t; + } + + if (t) + end = ++t; + else + end += strlen(end); + } + + if (*end != '\0') { + size_t pos; + + pos = strcspn(end, delims); + end = end + pos; + } + + if (*end != '\0') { + *end = '\0'; + *state = end + 1; + if (*begin == '"' && *(end - 1) == '"' && begin + 1 < end) { + begin++; *(end - 1) = '\0'; + } + return begin; + } + + *state = end; + if (*begin == '"' && *(end - 1) == '"' && begin + 1 < end) { + begin++; *(end - 1) = '\0'; + } + return begin; +} + /** * Get a list of configuration strings, free the result with * krb5_config_free_strings(). @@ -894,7 +943,7 @@ krb5_config_vget_strings(krb5_context context, char *s; if(tmp == NULL) goto cleanup; - s = strtok_r(tmp, " \t", &pos); + s = next_component_string(tmp, " \t", &pos); while(s){ char **tmp2 = realloc(strings, (nstr + 1) * sizeof(*strings)); if(tmp2 == NULL) @@ -904,7 +953,7 @@ krb5_config_vget_strings(krb5_context context, nstr++; if(strings[nstr-1] == NULL) goto cleanup; - s = strtok_r(NULL, " \t", &pos); + s = next_component_string(NULL, " \t", &pos); } free(tmp); } @@ -1259,7 +1308,7 @@ krb5_config_get_int (krb5_context context, */ KRB5_DEPRECATED -krb5_error_code KRB5_LIB_FUNCTION +KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL krb5_config_parse_string_multi(krb5_context context, const char *string, krb5_config_section **res) diff --git a/src/external/heimdal/roken/localtime_r.c b/src/external/heimdal/roken/localtime_r.c index e7d03ef6d..fa3d1269d 100644 --- a/src/external/heimdal/roken/localtime_r.c +++ b/src/external/heimdal/roken/localtime_r.c @@ -42,6 +42,11 @@ ROKEN_LIB_FUNCTION struct tm * ROKEN_LIB_CALL localtime_r(const time_t *timer, struct tm *result) { +#ifdef _MSC_VER + + return (localtime_s(result, timer) == 0)? result : NULL; + +#else struct tm *tm; tm = localtime((time_t *)timer); @@ -49,6 +54,7 @@ localtime_r(const time_t *timer, struct tm *result) return NULL; *result = *tm; return result; +#endif } #endif diff --git a/src/external/heimdal/roken/roken-common.h b/src/external/heimdal/roken/roken-common.h index a437d8a34..d9369a3e1 100644 --- a/src/external/heimdal/roken/roken-common.h +++ b/src/external/heimdal/roken/roken-common.h @@ -150,6 +150,11 @@ #endif /* !_WIN32 */ +/* Minimize conflict with WinNT.h */ +#ifdef SLIST_ENTRY +#undef SLIST_ENTRY +#endif + #ifndef PATH_MAX #define PATH_MAX MAX_PATH #endif @@ -221,6 +226,10 @@ #define AI_NUMERICHOST 0x04 #endif +#ifndef AI_NUMERICSERV +#define AI_NUMERICSERV 0x08 +#endif + /* flags for getnameinfo() */ #ifndef NI_DGRAM @@ -486,6 +495,9 @@ rk_cloexec_dir(DIR *); ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL ct_memcmp(const void *, const void *, size_t); +void ROKEN_LIB_FUNCTION +rk_random_init(void); + ROKEN_CPP_END #endif /* __ROKEN_COMMON_H__ */ diff --git a/src/external/heimdal/roken/roken.h.in b/src/external/heimdal/roken/roken.h.in index 41e33f043..6ecdf1c8d 100644 --- a/src/external/heimdal/roken/roken.h.in +++ b/src/external/heimdal/roken/roken.h.in @@ -249,10 +249,6 @@ struct sockaddr_dl; #include #endif -#ifdef HAVE_WS2TCPIP_H -#include -#endif - #ifdef HAVE_PATHS_H #include #endif @@ -1088,6 +1084,15 @@ void rk_qsort(void *, size_t, size_t, int (*)(const void *, const void *)); #endif +#if defined(HAVE_ARC4RANDOM) +#define rk_random() arc4random() +#elif defined(HAVE_RANDOM) +#define rk_random() random() +#else +#define rk_random() rand() +#endif + + #if defined(__linux__) && defined(SOCK_CLOEXEC) && !defined(SOCKET_WRAPPER_REPLACE) && !defined(__SOCKET_WRAPPER_H__) #undef socket #define socket(_fam,_type,_prot) rk_socket(_fam,_type,_prot) diff --git a/src/external/heimdal/roken/socket.c b/src/external/heimdal/roken/socket.c index 6baa0f986..017d6252e 100644 --- a/src/external/heimdal/roken/socket.c +++ b/src/external/heimdal/roken/socket.c @@ -119,8 +119,7 @@ socket_addr_size (const struct sockaddr *sa) return sizeof(struct in6_addr); #endif default : - errx (1, "unknown address family %d", sa->sa_family); - UNREACHABLE(return 0); + return 0; } } @@ -138,9 +137,8 @@ socket_sockaddr_size (const struct sockaddr *sa) case AF_INET6 : return sizeof(struct sockaddr_in6); #endif - default : - errx (1, "unknown address family %d", sa->sa_family); - UNREACHABLE(return 0); + default: + return 0; } } @@ -162,9 +160,8 @@ socket_get_address (const struct sockaddr *sa) return rk_UNCONST(&sin6->sin6_addr); } #endif - default : - errx (1, "unknown address family %d", sa->sa_family); - UNREACHABLE(return NULL); + default: + return NULL; } } @@ -187,8 +184,7 @@ socket_get_port (const struct sockaddr *sa) } #endif default : - errx (1, "unknown address family %d", sa->sa_family); - UNREACHABLE(return 0); + return 0; } } @@ -227,18 +223,13 @@ socket_set_portrange (rk_socket_t sock, int restr, int af) #if defined(IP_PORTRANGE) if (af == AF_INET) { int on = restr ? IP_PORTRANGE_HIGH : IP_PORTRANGE_DEFAULT; - if (setsockopt (sock, IPPROTO_IP, IP_PORTRANGE, &on, - sizeof(on)) < 0) - warn ("setsockopt IP_PORTRANGE (ignored)"); + setsockopt (sock, IPPROTO_IP, IP_PORTRANGE, &on, sizeof(on)); } #endif #if defined(IPV6_PORTRANGE) if (af == AF_INET6) { - int on = restr ? IPV6_PORTRANGE_HIGH : - IPV6_PORTRANGE_DEFAULT; - if (setsockopt (sock, IPPROTO_IPV6, IPV6_PORTRANGE, &on, - sizeof(on)) < 0) - warn ("setsockopt IPV6_PORTRANGE (ignored)"); + int on = restr ? IPV6_PORTRANGE_HIGH : IPV6_PORTRANGE_DEFAULT; + setsockopt (sock, IPPROTO_IPV6, IPV6_PORTRANGE, &on, sizeof(on)); } #endif } @@ -252,9 +243,7 @@ socket_set_debug (rk_socket_t sock) { #if defined(SO_DEBUG) && defined(HAVE_SETSOCKOPT) int on = 1; - - if (setsockopt (sock, SOL_SOCKET, SO_DEBUG, (void *) &on, sizeof (on)) < 0) - warn ("setsockopt SO_DEBUG (ignored)"); + setsockopt (sock, SOL_SOCKET, SO_DEBUG, (void *) &on, sizeof (on)); #endif } @@ -266,9 +255,7 @@ ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL socket_set_tos (rk_socket_t sock, int tos) { #if defined(IP_TOS) && defined(HAVE_SETSOCKOPT) - if (setsockopt (sock, IPPROTO_IP, IP_TOS, (void *) &tos, sizeof (int)) < 0) - if (errno != EINVAL) - warn ("setsockopt TOS (ignored)"); + setsockopt (sock, IPPROTO_IP, IP_TOS, (void *) &tos, sizeof(int)); #endif } @@ -280,9 +267,7 @@ ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL socket_set_reuseaddr (rk_socket_t sock, int val) { #if defined(SO_REUSEADDR) && defined(HAVE_SETSOCKOPT) - if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&val, - sizeof(val)) < 0) - err (1, "setsockopt SO_REUSEADDR"); + setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&val, sizeof(val)); #endif } -- 2.39.5