diff options
author | Andrew Bartlett <abartlet@samba.org> | 2010-11-29 11:24:08 +1100 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2010-12-01 17:00:47 +1100 |
commit | c5bea98ddb2f7967df572160f639da3cba381a87 (patch) | |
tree | e5ca502195932ea7674f03a732fc26dd5427553d /source4/heimdal/lib/roken | |
parent | 9c84f987acb5ffc97a612839e13e8b8042e6120e (diff) | |
download | samba-c5bea98ddb2f7967df572160f639da3cba381a87.tar.gz samba-c5bea98ddb2f7967df572160f639da3cba381a87.tar.bz2 samba-c5bea98ddb2f7967df572160f639da3cba381a87.zip |
s4:heimdal: import lorikeet-heimdal-201012010201 (commit 81fe27bcc0148d410ca4617f8759b9df1a5e935c)
Diffstat (limited to 'source4/heimdal/lib/roken')
-rw-r--r-- | source4/heimdal/lib/roken/getarg.c | 14 | ||||
-rw-r--r-- | source4/heimdal/lib/roken/rand.c | 48 | ||||
-rw-r--r-- | source4/heimdal/lib/roken/resolve.c | 8 | ||||
-rw-r--r-- | source4/heimdal/lib/roken/roken-common.h | 12 | ||||
-rw-r--r-- | source4/heimdal/lib/roken/roken.h.in | 43 | ||||
-rw-r--r-- | source4/heimdal/lib/roken/setprogname.c | 33 | ||||
-rw-r--r-- | source4/heimdal/lib/roken/socket.c | 39 |
7 files changed, 142 insertions, 55 deletions
diff --git a/source4/heimdal/lib/roken/getarg.c b/source4/heimdal/lib/roken/getarg.c index e7dc74b7bc..a96e5c85bf 100644 --- a/source4/heimdal/lib/roken/getarg.c +++ b/source4/heimdal/lib/roken/getarg.c @@ -435,11 +435,7 @@ arg_match_long(struct getargs *args, size_t num_args, *flag = !negate; return 0; } else if (*goptarg && strcmp(goptarg + 1, "maybe") == 0) { -#ifdef HAVE_RANDOM - *flag = random() & 1; -#else - *flag = rand() & 1; -#endif + *flag = rk_random() & 1; } else { *flag = negate; return 0; @@ -554,13 +550,7 @@ getarg(struct getargs *args, size_t num_args, int i; int ret = 0; -#if defined(HAVE_SRANDOMDEV) - srandomdev(); -#elif defined(HAVE_RANDOM) - srandom(time(NULL)); -#else - srand ((int) time(NULL)); -#endif + rk_random_init(); (*goptind)++; for(i = *goptind; i < argc; i++) { if(argv[i][0] != '-') diff --git a/source4/heimdal/lib/roken/rand.c b/source4/heimdal/lib/roken/rand.c new file mode 100644 index 0000000000..ef92c2052b --- /dev/null +++ b/source4/heimdal/lib/roken/rand.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 1997 - 2002 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 "roken.h" + +void ROKEN_LIB_FUNCTION +rk_random_init(void) +{ +#if defined(HAVE_ARC4RANDOM) + arc4random_stir(); +#elif defined(HAVE_SRANDOMDEV) + srandomdev(); +#elif defined(HAVE_RANDOM) + srandom(time(NULL)); +#else + srand (time(NULL)); +#endif +} diff --git a/source4/heimdal/lib/roken/resolve.c b/source4/heimdal/lib/roken/resolve.c index 97edda471b..03715e5ffd 100644 --- a/source4/heimdal/lib/roken/resolve.c +++ b/source4/heimdal/lib/roken/resolve.c @@ -619,10 +619,6 @@ compare_srv(const void *a, const void *b) return ((*aa)->u.srv->priority - (*bb)->u.srv->priority); } -#ifndef HAVE_RANDOM -#define random() rand() -#endif - /* try to rearrange the srv-records by the algorithm in RFC2782 */ ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL rk_dns_srv_order(struct rk_dns_reply *r) @@ -636,6 +632,8 @@ rk_dns_srv_order(struct rk_dns_reply *r) char *oldstate; #endif + rk_random_init(); + for(rr = r->head; rr; rr = rr->next) if(rr->type == rk_ns_t_srv) num_srv++; @@ -682,7 +680,7 @@ rk_dns_srv_order(struct rk_dns_reply *r) /* ss is now the first record of this priority and ee is the first of the next */ while(ss < ee) { - rnd = random() % (sum + 1); + rnd = rk_random() % (sum + 1); for(count = 0, tt = ss; ; tt++) { if(*tt == NULL) continue; diff --git a/source4/heimdal/lib/roken/roken-common.h b/source4/heimdal/lib/roken/roken-common.h index a437d8a346..d9369a3e15 100644 --- a/source4/heimdal/lib/roken/roken-common.h +++ b/source4/heimdal/lib/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/source4/heimdal/lib/roken/roken.h.in b/source4/heimdal/lib/roken/roken.h.in index 0c0dd20035..e7cb1598fb 100644 --- a/source4/heimdal/lib/roken/roken.h.in +++ b/source4/heimdal/lib/roken/roken.h.in @@ -43,18 +43,26 @@ #ifndef ROKEN_LIB_FUNCTION #ifdef _WIN32 -#define ROKEN_LIB_FUNCTION -#define ROKEN_LIB_CALL __cdecl +# define ROKEN_LIB_CALL __cdecl +# ifdef ROKEN_LIB_DYNAMIC +# define ROKEN_LIB_FUNCTION __declspec(dllimport) +# define ROKEN_LIB_VARIABLE __declspec(dllimport) +# else +# define ROKEN_LIB_FUNCTION +# define ROKEN_LIB_VARIABLE +# endif #else #define ROKEN_LIB_FUNCTION #define ROKEN_LIB_CALL +#define ROKEN_LIB_VARIABLE #endif #endif #ifdef HAVE_WINSOCK /* Declarations for Microsoft Windows */ -#include<ws2tcpip.h> +#include <winsock2.h> +#include <ws2tcpip.h> /* * error codes for inet_ntop/inet_pton @@ -241,10 +249,6 @@ struct sockaddr_dl; #include <time.h> #endif -#ifdef HAVE_WS2TCPIP_H -#include <ws2tcpip.h> -#endif - #ifdef HAVE_PATHS_H #include <paths.h> #endif @@ -536,7 +540,6 @@ int ROKEN_LIB_FUNCTION rk_strerror_r(int, char *, size_t); #endif /* This causes a fatal error under Psoriasis */ #ifndef SunOS -const char * ROKEN_LIB_FUNCTION hstrerror(int); ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL hstrerror(int); #endif #endif @@ -757,14 +760,23 @@ ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL get_window_size(int fd, struct winsize *); ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL vsyslog(int, const char *, va_list); #endif +#ifndef HAVE_GETOPT +#define getopt rk_getopt +#define optarg rk_optarg +#define optind rk_optind +#define opterr rk_opterr +ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL +getopt(int nargc, char * const *nargv, const char *ostr); +#endif + #if !HAVE_DECL_OPTARG -extern char *optarg; +ROKEN_LIB_VARIABLE extern char *optarg; #endif #if !HAVE_DECL_OPTIND -extern int optind; +ROKEN_LIB_VARIABLE extern int optind; #endif #if !HAVE_DECL_OPTERR -extern int opterr; +ROKEN_LIB_VARIABLE extern int opterr; #endif #ifndef HAVE_GETIPNODEBYNAME @@ -1072,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/source4/heimdal/lib/roken/setprogname.c b/source4/heimdal/lib/roken/setprogname.c index 115af77b88..88a5f9bb44 100644 --- a/source4/heimdal/lib/roken/setprogname.c +++ b/source4/heimdal/lib/roken/setprogname.c @@ -40,19 +40,52 @@ extern const char *__progname; #endif #ifndef HAVE_SETPROGNAME + ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL setprogname(const char *argv0) { + #ifndef HAVE___PROGNAME + const char *p; if(argv0 == NULL) return; p = strrchr(argv0, '/'); + +#ifdef BACKSLASH_PATH_DELIM + { + const char * pb; + + pb = strrchr((p != NULL)? p : argv0, '\\'); + if (pb != NULL) + p = pb; + } +#endif + if(p == NULL) p = argv0; else p++; + +#ifdef _WIN32 + { + char * fn = strdup(p); + char * ext; + + strlwr(fn); + ext = strrchr(fn, '.'); + if (ext != NULL && !strcmp(ext, ".exe")) + *ext = '\0'; + + __progname = fn; + } +#else + __progname = p; + #endif + +#endif /* HAVE___PROGNAME */ } + #endif /* HAVE_SETPROGNAME */ diff --git a/source4/heimdal/lib/roken/socket.c b/source4/heimdal/lib/roken/socket.c index ef594ffd0d..8797f95772 100644 --- a/source4/heimdal/lib/roken/socket.c +++ b/source4/heimdal/lib/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 } |