gethostby{name,addr}_r functions.
Contributed by Juan Carlos Gomes IT#68 (apparently).
Also includes support for detecting ssleay in configure.in.
/* define this to the number of arguments ctime_r() expects */
#undef CTIME_R_NARGS
+/* define this to the number of arguments gethostbyaddr_r expects */
+#undef GETHOSTBYADDR_R_NARGS
+
+/* define this to the number of arguments gethostbyname_r expects */
+#undef GETHOSTBYNAME_R_NARGS
+
/* define this if sys_errlist is not defined in stdio.h or errno.h */
#undef DECL_SYS_ERRLIST
AC_DEFINE_UNQUOTED(CTIME_R_NARGS, $ol_cv_func_ctime_r_nargs)
fi
])dnl
+dnl ====================================================================
+dnl check no of arguments for gethostbyname_r
+AC_DEFUN(OL_FUNC_GETHOSTBYNAME_R_NARGS,
+ [AC_CACHE_CHECK(number of arguments of gethostbyname_r, ol_cv_func_gethostbyname_r_nargs,
+ [AC_TRY_COMPILE([#include <sys/types.h>
+ #include <sys/socket.h>
+ #include <netinet/in.h>
+ #include <netdb.h>
+ #define BUFSIZE (sizeof(struct hostent)+10)],
+ [struct hostent hent; char buffer[BUFSIZE];
+ int bufsize=BUFSIZE;int h_errno;
+ (void)gethostbyname_r( "segovia.cs.purdue.edu", &hent, buffer, bufsize, &h_errno);
+ return 0;],
+ ol_cv_func_gethostbyname_r_nargs=5, ol_cv_func_gethostbyname_r_nargs=0)
+ if test $ol_cv_func_gethostbyname_r_nargs = 0 ; then
+ AC_TRY_COMPILE([#include <sys/types.h>
+ #include <sys/socket.h>
+ #include <netinet/in.h>
+ #include <netdb.h>
+ #define BUFSIZE (sizeof(struct hostent)+10)],
+ [struct hostent hent;struct hostent *rhent;
+ char buffer[BUFSIZE];
+ int bufsize=BUFSIZE;int h_errno;
+ (void)gethostbyname_r( "segovia.cs.purdue.edu", &hent, buffer, bufsize, &rhent, &h_errno);
+ return 0;],
+ ol_cv_func_gethostbyname_r_nargs=6, ol_cv_func_gethostbyname_r_nargs=0)
+ fi
+ ])
+ if test $ol_cv_func_gethostbyname_r_nargs -gt 1 ; then
+ AC_DEFINE_UNQUOTED(GETHOSTBYNAME_R_NARGS, $ol_cv_func_gethostbyname_r_nargs)
+ fi
+])dnl
+dnl check no of arguments for gethostbyaddr_r
+AC_DEFUN(OL_FUNC_GETHOSTBYADDR_R_NARGS,
+ [AC_CACHE_CHECK(number of arguments of gethostbyaddr_r, ol_cv_func_gethostbyaddr_r_nargs,
+ [AC_TRY_COMPILE([#include <sys/types.h>
+ #include <sys/socket.h>
+ #include <netinet/in.h>
+ #include <netdb.h>
+ #define BUFSIZE (sizeof(struct hostent)+10)],
+ [struct hostent hent; char buffer[BUFSIZE];
+ struct in_addr add={0x70707070};
+ size_t alen=sizeof(struct in_addr);
+ int bufsize=BUFSIZE;int h_errno;
+ (void)gethostbyaddr_r( (void *)&(add.s_addr),
+ alen, AF_INET, &hent, buffer, bufsize, &h_errno);
+ return 0;],
+ ol_cv_func_gethostbyaddr_r_nargs=7,
+ ol_cv_func_gethostbyaddr_r_nargs=0)
+ if test $ol_cv_func_gethostbyaddr_r_nargs = 0 ; then
+ AC_TRY_COMPILE([#include <sys/types.h>
+ #include <sys/socket.h>
+ #include <netinet/in.h>
+ #include <netdb.h>
+ #define BUFSIZE (sizeof(struct hostent)+10)],
+ [struct hostent hent; struct hostent *rhent; char buffer[BUFSIZE];
+ struct in_addr add={0x70707070};
+ size_t alen=sizeof(struct in_addr);
+ int bufsize=BUFSIZE;int h_errno;
+ (void)gethostbyaddr_r( (void *)&(add.s_addr),
+ alen, AF_INET, &hent, buffer, bufsize,
+ &rhent, &h_errno);
+ return 0;],
+ ol_cv_func_gethostbyaddr_r_nargs=8,
+ ol_cv_func_gethostbyaddr_r_nargs=0)
+ fi
+ ])
+ if test $ol_cv_func_gethostbyaddr_r_nargs -gt 1 ; then
+ AC_DEFINE_UNQUOTED(GETHOSTBYADDR_R_NARGS, $ol_cv_func_gethostbyaddr_r_nargs)
+ fi
+])dnl
OL_ARG_ENABLE(x_compile,[ --enable-x-compile enable cross compiling],
no, [yes no])dnl
-
dnl General "with" options
OL_ARG_ENABLE(dmalloc,[ --enable-dmalloc enable debug malloc support], no)dnl
auto, [auto posix mach lwp yes no manual] )
OL_ARG_WITH(yielding_select,[ --with-yielding-select with implicitly yielding select],
auto, [auto yes no manual] )
+OL_ARG_WITH(tls,[ --with-tls use tls/ssl],
+ auto, [auto ssleay openssl yes no] )
dnl Server options
KRB_LIBS=
TERMCAP_LIBS=
+TLS_LIBS=
dnl ----------------------------------------------------------------
dnl Checks for programs
AC_DEFINE(HAVE_KERBEROS, 1, [define if you have Kerberos])
fi
+dnl
+dnl Check for SSL/TLS
+dnl
+ol_link_tls=no
+if test $ol_with_tls = auto -o $ol_with_tls = ssleay \
+ -o $ol_with_tls = openssl ; then
+
+ AC_CHECK_HEADERS(ssl.h)
+
+ if test $ac_cv_header_ssl_h = yes ; then
+ AC_CHECK_LIB( ssl, SSLeay_add_ssl_algorithms,
+ [have_ssleay=yes], [have_ssleay=no], [-lcrypto])
+
+ if test $have_ssleay = yes ; then
+ ol_with_tls=found
+ ol_link_tls=yes
+
+ AC_DEFINE( HAVE_SSLEAY, 1,
+ [define if you have SSLeay] )
+
+ TLS_LIBS="-lssl -lcrypto"
+ fi
+ fi
+fi
+
+if test $ol_link_tls = yes ; then
+ AC_DEFINE( HAVE_TLS, 1, [define if you have TLS] )
+fi
+
ol_link_threads=no
if test $ol_with_threads = auto -o $ol_with_threads = yes \
-o $ol_with_threads = posix ; then
ol_cv_func_ctime_r=0
fi
+if test "$ac_cv_func_gethostbyname_r" = yes ; then
+ OL_FUNC_GETHOSTBYNAME_R_NARGS
+else
+ ol_cv_func_gethostbyname_r=0
+fi
+
+if test "$ac_cv_func_gethostbyaddr_r" = yes ; then
+ OL_FUNC_GETHOSTBYADDR_R_NARGS
+else
+ ol_cv_func_gethostbyaddr_r=0
+fi
+
if test "$ac_cv_func_ctime_r" = yes \
-a "$ol_cv_func_ctime_r_nargs" -ge 2 -a "$ol_cv_func_ctime_r_nargs" -le 3 \
+ -a "$ol_cv_func_gethostbyname_r_nargs" -ge 5 -a "$ol_cv_func_gethostbyname_r_nargs" -le 6 \
+ -a "$ol_cv_func_gethostbyaddr_r_nargs" -ge 5 -a "$ol_cv_func_gethostbyaddr_r_nargs" -le 6 \
-a "$ac_cv_func_gethostbyaddr_r" = yes \
-a "$ac_cv_func_gethostbyname_r" = yes \
; then
AC_SUBST(KRB_LIBS)
AC_SUBST(TERMCAP_LIBS)
+AC_SUBST(TLS_LIBS)
dnl ----------------------------------------------------------------
dnl final output
*/
/*
* util-int.c Various functions to replace missing threadsafe ones.
- * Without the real *_r funcs, things will work, but won't be
- * threadsafe.
+ * Without the real *_r funcs, things will
+ * work, but might not be threadsafe.
*
* Written by Bart Hartgers.
*
* in file LICENSE in the top-level directory of the distribution.
*/
+
#include "portable.h"
#include <stdlib.h>
int *herrno_ptr )
{
#if defined( HAVE_GETHOSTBYNAME_R )
+
+# if (GETHOSTBYNAME_R_NARGS > 6) || (GETHOSTBYNAME_R_NARGS < 5)
+ Ouch! gethostbyname_r() must have either 5 or 6 args
+#endif
+
# define NEED_SAFE_REALLOC 1
int r=-1;
int buflen=BUFSTART;
for(;buflen<BUFMAX;) {
if (safe_realloc( buf, buflen )==NULL)
return r;
+
+#if (GETHOSTBYNAME_R_NARGS < 6)
+ r = ((*result=gethostbyname_r( name, resbuf, *buf,\
+ buflen, herrno_ptr ))== NULL) ?\
+ -1 : 0;
+#else
r = gethostbyname_r( name, resbuf, *buf,
buflen, result, herrno_ptr );
+#endif
+
+ Debug( LDAP_DEBUG_TRACE, "ldap_pvt_gethostbyname_a: host=%s, r=%d\n",\
+ name, r, 0 );
+
#ifdef NETDB_INTERNAL
if ((r<0) &&
(*herrno_ptr==NETDB_INTERNAL) &&
int *herrno_ptr )
{
#if defined( HAVE_GETHOSTBYADDR_R )
+
+#if (GETHOSTBYADDR_R_NARGS > 8) || (GETHOSTBYADDR_R_NARGS < 7)
+ Ouch! gethostbyaddr_r() must have either 7 or 8 args
+#endif
+
# undef NEED_SAFE_REALLOC
# define NEED_SAFE_REALLOC
int r=-1;
for(;buflen<BUFMAX;) {
if (safe_realloc( buf, buflen )==NULL)
return r;
+#if (GETHOSTBYADDR_R_NARGS < 8)
+ r = ((*result=gethostbyaddr_r( addr, len, type,
+ resbuf, *buf, buflen,
+ herrno_ptr )) == NULL) ?\
+ -1 : 0;
+#else
r = gethostbyaddr_r( addr, len, type,
resbuf, *buf, buflen,
result, herrno_ptr );
+#endif
+
#ifdef NETDB_INTERNAL
if ((r<0) &&
(*herrno_ptr==NETDB_INTERNAL) &&
for( n_alias=total_alias_len=0, p=src->h_aliases; (*p) ; p++ ) {
total_alias_len += strlen( *p ) + 1;
- n_alias++;
+ n_alias++;
}
for( n_addr=0, p=src->h_addr_list; (*p) ; p++ ) {