From d154a0d74b23b4a1fbd921f17dec3e0e3506eeab Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 6 Oct 2007 23:07:33 +0000 Subject: r25557: merge libreplace fixes from samba4 (This used to be commit 8c1669997c53f0f7bfb9a794083afd01b131f676) --- source3/configure.in | 38 -------- source3/lib/replace/README | 6 ++ source3/lib/replace/getaddrinfo.h | 158 +++++++++++++++++++++++++++++++ source3/lib/replace/libreplace.m4 | 39 ++++++++ source3/lib/replace/replace.h | 7 +- source3/lib/replace/system/getaddrinfo.h | 158 ------------------------------- 6 files changed, 204 insertions(+), 202 deletions(-) create mode 100644 source3/lib/replace/getaddrinfo.h delete mode 100644 source3/lib/replace/system/getaddrinfo.h diff --git a/source3/configure.in b/source3/configure.in index c36b430fcc..e73edb418f 100644 --- a/source3/configure.in +++ b/source3/configure.in @@ -3222,44 +3222,6 @@ if test x"$samba_cv_HAVE_STRUCT_SOCKADDR_IN6" = x"yes"; then AC_DEFINE(HAVE_STRUCT_SOCKADDR_IN6,1,[Whether the system has struct sockaddr_in6]) fi -dnl test for struct addrinfo -AC_CACHE_CHECK([for struct addrinfo],samba_cv_HAVE_STRUCT_ADDRINFO,[ -AC_TRY_COMPILE([ -#include -#include -#include ], -[ -struct addrinfo ai; -], -samba_cv_HAVE_STRUCT_ADDRINFO=yes,samba_cv_HAVE_STRUCT_ADDRINFO=no)]) -if test x"$samba_cv_HAVE_STRUCT_ADDRINFO" = x"yes"; then - AC_DEFINE(HAVE_STRUCT_ADDRINFO,1,[Whether the system has struct addrinfo]) -fi - -dnl test for getaddrinfo/getnameinfo -AC_CACHE_CHECK([for getaddrinfo],samba_cv_HAVE_GETADDRINFO,[ -AC_TRY_COMPILE([ -#include -#include -#include ], -[ -struct sockaddr sa; -struct addrinfo *ai = NULL; -int ret = getaddrinfo(NULL, NULL, NULL, &ai); -if (ret != 0) { - const char *es = gai_strerror(ret); -} -freeaddrinfo(ai); -ret = getnameinfo(&sa, sizeof(sa), - NULL, 0, - NULL, 0, 0); - -], -samba_cv_HAVE_GETADDRINFO=yes,samba_cv_HAVE_GETADDRINFO=no)]) -if test x"$samba_cv_HAVE_GETADDRINFO" = x"yes"; then - AC_DEFINE(HAVE_GETADDRINFO,1,[Whether the system has getaddrinfo and getnameinfo]) -fi - ################################################ # look for a method of setting the effective uid seteuid=no; diff --git a/source3/lib/replace/README b/source3/lib/replace/README index 77558b2ca9..c61f78a951 100644 --- a/source3/lib/replace/README +++ b/source3/lib/replace/README @@ -50,10 +50,16 @@ pwrite getpass readline (the library) inet_ntoa +inet_ntop +inet_pton strtoll strtoull socketpair strptime +getaddrinfo +freeaddrinfo +getnameinfo +gai_strerror Types: bool diff --git a/source3/lib/replace/getaddrinfo.h b/source3/lib/replace/getaddrinfo.h new file mode 100644 index 0000000000..ed678bd065 --- /dev/null +++ b/source3/lib/replace/getaddrinfo.h @@ -0,0 +1,158 @@ +/* +PostgreSQL Database Management System +(formerly known as Postgres, then as Postgres95) + +Portions Copyright (c) 1996-2005, The PostgreSQL Global Development Group + +Portions Copyright (c) 1994, The Regents of the University of California + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose, without fee, and without a written agreement +is hereby granted, provided that the above copyright notice and this paragraph +and the following two paragraphs appear in all copies. + +IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR +DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING +LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, +EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. + +THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS +ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS +TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + +*/ + +/*------------------------------------------------------------------------- + * + * getaddrinfo.h + * Support getaddrinfo() on platforms that don't have it. + * + * Note: we use our own routines on platforms that don't HAVE_STRUCT_ADDRINFO, + * whether or not the library routine getaddrinfo() can be found. This + * policy is needed because on some platforms a manually installed libbind.a + * may provide getaddrinfo(), yet the system headers may not provide the + * struct definitions needed to call it. To avoid conflict with the libbind + * definition in such cases, we rename our routines to pg_xxx() via macros. + * + * This code will also work on platforms where struct addrinfo is defined + * in the system headers but no getaddrinfo() can be located. + * + * Copyright (c) 2003-2007, PostgreSQL Global Development Group + * + *------------------------------------------------------------------------- + */ +#ifndef GETADDRINFO_H +#define GETADDRINFO_H + + +/* Various macros that ought to be in , but might not be */ + +#ifndef EAI_FAIL +#define EAI_BADFLAGS (-1) +#define EAI_NONAME (-2) +#define EAI_AGAIN (-3) +#define EAI_FAIL (-4) +#define EAI_FAMILY (-6) +#define EAI_SOCKTYPE (-7) +#define EAI_SERVICE (-8) +#define EAI_MEMORY (-10) +#define EAI_SYSTEM (-11) +#endif /* !EAI_FAIL */ + +#ifndef AI_PASSIVE +#define AI_PASSIVE 0x0001 +#endif + +#ifndef AI_NUMERICHOST +/* + * some platforms don't support AI_NUMERICHOST; define as zero if using + * the system version of getaddrinfo... + */ +#if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO) +#define AI_NUMERICHOST 0 +#else +#define AI_NUMERICHOST 0x0004 +#endif +#endif + +#ifndef NI_NUMERICHOST +#define NI_NUMERICHOST 1 +#endif + +#ifndef NI_NUMERICSERV +#define NI_NUMERICSERV 2 +#endif + +#ifndef NI_NOFQDN +#define NI_NOFQDN 4 +#endif + +#ifndef NI_NAMEREQD +#define NI_NAMEREQD 8 +#endif + +#ifndef NI_DGRAM +#define NI_DGRAM 16 +#endif + + +#ifndef NI_MAXHOST +#define NI_MAXHOST 1025 +#endif + +#ifndef NI_MAXSERV +#define NI_MAXSERV 32 +#endif + +#ifndef HAVE_STRUCT_ADDRINFO + +struct addrinfo +{ + int ai_flags; + int ai_family; + int ai_socktype; + int ai_protocol; + size_t ai_addrlen; + struct sockaddr *ai_addr; + char *ai_canonname; + struct addrinfo *ai_next; +}; +#endif /* HAVE_STRUCT_ADDRINFO */ + + +#ifndef HAVE_GETADDRINFO + +/* Rename private copies per comments above */ +#ifdef getaddrinfo +#undef getaddrinfo +#endif +#define getaddrinfo pg_getaddrinfo + +#ifdef freeaddrinfo +#undef freeaddrinfo +#endif +#define freeaddrinfo pg_freeaddrinfo + +#ifdef gai_strerror +#undef gai_strerror +#endif +#define gai_strerror pg_gai_strerror + +#ifdef getnameinfo +#undef getnameinfo +#endif +#define getnameinfo pg_getnameinfo + +extern int getaddrinfo(const char *node, const char *service, + const struct addrinfo * hints, struct addrinfo ** res); +extern void freeaddrinfo(struct addrinfo * res); +extern const char *gai_strerror(int errcode); +extern int getnameinfo(const struct sockaddr * sa, socklen_t salen, + char *node, size_t nodelen, + char *service, size_t servicelen, int flags); +#endif /* HAVE_GETADDRINFO */ + +#endif /* GETADDRINFO_H */ diff --git a/source3/lib/replace/libreplace.m4 b/source3/lib/replace/libreplace.m4 index 354349187e..29ec2acdab 100644 --- a/source3/lib/replace/libreplace.m4 +++ b/source3/lib/replace/libreplace.m4 @@ -137,6 +137,45 @@ if test x"$samba_cv_REPLACE_INET_NTOA" = x"yes"; then AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced]) fi +dnl test for struct addrinfo +AC_CACHE_CHECK([for struct addrinfo],samba_cv_HAVE_STRUCT_ADDRINFO,[ +AC_TRY_COMPILE([ +#include +#include +#include ], +[ +struct addrinfo ai; +], +samba_cv_HAVE_STRUCT_ADDRINFO=yes,samba_cv_HAVE_STRUCT_ADDRINFO=no)]) +if test x"$samba_cv_HAVE_STRUCT_ADDRINFO" = x"yes"; then + AC_DEFINE(HAVE_STRUCT_ADDRINFO,1,[Whether the system has struct addrinfo]) +fi + +dnl test for getaddrinfo/getnameinfo +AC_CACHE_CHECK([for getaddrinfo],samba_cv_HAVE_GETADDRINFO,[ +AC_TRY_COMPILE([ +#include +#include +#include ], +[ +struct sockaddr sa; +struct addrinfo *ai = NULL; +int ret = getaddrinfo(NULL, NULL, NULL, &ai); +if (ret != 0) { + const char *es = gai_strerror(ret); +} +freeaddrinfo(ai); +ret = getnameinfo(&sa, sizeof(sa), + NULL, 0, + NULL, 0, 0); + +], +samba_cv_HAVE_GETADDRINFO=yes,samba_cv_HAVE_GETADDRINFO=no)]) +if test x"$samba_cv_HAVE_GETADDRINFO" = x"yes"; then + AC_DEFINE(HAVE_GETADDRINFO,1,[Whether the system has getaddrinfo and getnameinfo]) +fi + + dnl Provided by replace.c: AC_TRY_COMPILE([ #include diff --git a/source3/lib/replace/replace.h b/source3/lib/replace/replace.h index ca4becaa70..26e39ac603 100644 --- a/source3/lib/replace/replace.h +++ b/source3/lib/replace/replace.h @@ -330,22 +330,17 @@ ssize_t rep_pread(int __fd, void *__buf, size_t __nbytes, off_t __offset); ssize_t rep_pwrite(int __fd, const void *__buf, size_t __nbytes, off_t __offset); #endif -#include "system/network.h" - #ifndef HAVE_INET_PTON int rep_inet_pton(int af, const char *src, void *dst); #define inet_pton rep_inet_pton #endif #ifndef HAVE_INET_NTOP +#include "system/network.h" const char *rep_inet_ntop(int af, const void *src, char *dst, socklen_t size); #define inet_ntop rep_inet_ntop #endif -#if !defined(HAVE_GETADDRINFO) -#include "system/getaddrinfo.h" -#endif - #ifdef HAVE_LIMITS_H #include #endif diff --git a/source3/lib/replace/system/getaddrinfo.h b/source3/lib/replace/system/getaddrinfo.h deleted file mode 100644 index ed678bd065..0000000000 --- a/source3/lib/replace/system/getaddrinfo.h +++ /dev/null @@ -1,158 +0,0 @@ -/* -PostgreSQL Database Management System -(formerly known as Postgres, then as Postgres95) - -Portions Copyright (c) 1996-2005, The PostgreSQL Global Development Group - -Portions Copyright (c) 1994, The Regents of the University of California - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose, without fee, and without a written agreement -is hereby granted, provided that the above copyright notice and this paragraph -and the following two paragraphs appear in all copies. - -IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR -DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING -LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, -EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGE. - -THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS -ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS -TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - -*/ - -/*------------------------------------------------------------------------- - * - * getaddrinfo.h - * Support getaddrinfo() on platforms that don't have it. - * - * Note: we use our own routines on platforms that don't HAVE_STRUCT_ADDRINFO, - * whether or not the library routine getaddrinfo() can be found. This - * policy is needed because on some platforms a manually installed libbind.a - * may provide getaddrinfo(), yet the system headers may not provide the - * struct definitions needed to call it. To avoid conflict with the libbind - * definition in such cases, we rename our routines to pg_xxx() via macros. - * - * This code will also work on platforms where struct addrinfo is defined - * in the system headers but no getaddrinfo() can be located. - * - * Copyright (c) 2003-2007, PostgreSQL Global Development Group - * - *------------------------------------------------------------------------- - */ -#ifndef GETADDRINFO_H -#define GETADDRINFO_H - - -/* Various macros that ought to be in , but might not be */ - -#ifndef EAI_FAIL -#define EAI_BADFLAGS (-1) -#define EAI_NONAME (-2) -#define EAI_AGAIN (-3) -#define EAI_FAIL (-4) -#define EAI_FAMILY (-6) -#define EAI_SOCKTYPE (-7) -#define EAI_SERVICE (-8) -#define EAI_MEMORY (-10) -#define EAI_SYSTEM (-11) -#endif /* !EAI_FAIL */ - -#ifndef AI_PASSIVE -#define AI_PASSIVE 0x0001 -#endif - -#ifndef AI_NUMERICHOST -/* - * some platforms don't support AI_NUMERICHOST; define as zero if using - * the system version of getaddrinfo... - */ -#if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO) -#define AI_NUMERICHOST 0 -#else -#define AI_NUMERICHOST 0x0004 -#endif -#endif - -#ifndef NI_NUMERICHOST -#define NI_NUMERICHOST 1 -#endif - -#ifndef NI_NUMERICSERV -#define NI_NUMERICSERV 2 -#endif - -#ifndef NI_NOFQDN -#define NI_NOFQDN 4 -#endif - -#ifndef NI_NAMEREQD -#define NI_NAMEREQD 8 -#endif - -#ifndef NI_DGRAM -#define NI_DGRAM 16 -#endif - - -#ifndef NI_MAXHOST -#define NI_MAXHOST 1025 -#endif - -#ifndef NI_MAXSERV -#define NI_MAXSERV 32 -#endif - -#ifndef HAVE_STRUCT_ADDRINFO - -struct addrinfo -{ - int ai_flags; - int ai_family; - int ai_socktype; - int ai_protocol; - size_t ai_addrlen; - struct sockaddr *ai_addr; - char *ai_canonname; - struct addrinfo *ai_next; -}; -#endif /* HAVE_STRUCT_ADDRINFO */ - - -#ifndef HAVE_GETADDRINFO - -/* Rename private copies per comments above */ -#ifdef getaddrinfo -#undef getaddrinfo -#endif -#define getaddrinfo pg_getaddrinfo - -#ifdef freeaddrinfo -#undef freeaddrinfo -#endif -#define freeaddrinfo pg_freeaddrinfo - -#ifdef gai_strerror -#undef gai_strerror -#endif -#define gai_strerror pg_gai_strerror - -#ifdef getnameinfo -#undef getnameinfo -#endif -#define getnameinfo pg_getnameinfo - -extern int getaddrinfo(const char *node, const char *service, - const struct addrinfo * hints, struct addrinfo ** res); -extern void freeaddrinfo(struct addrinfo * res); -extern const char *gai_strerror(int errcode); -extern int getnameinfo(const struct sockaddr * sa, socklen_t salen, - char *node, size_t nodelen, - char *service, size_t servicelen, int flags); -#endif /* HAVE_GETADDRINFO */ - -#endif /* GETADDRINFO_H */ -- cgit