On Sat, Jun 21, 2003 at 02:52:50AM +1000, Paul Hampson wrote:
> > From: Oliver Graf
> > Sent: Saturday, 21 June 2003 12:39 AM
>
> > This patchs enables the detection of the correct
> > gethostby(name|addr)_r command, which is needed by a threaded radiusd.
>
> Which patch?
Hmpf... now its attached...
> Oh, did you have a look at the CVS history for configure.in and
> configure.in? I noticed the other day that gethostbyname_r seems
> to have been in and out (and shaken all about) about a year ago.
Yep, I did.
> I haven't looked at the diffs though, so it may not be relevant.
For me its relevant. Without freeradius is not thread-safe.
Oliver.
--- freeradius-snapshot-20030529/src/include/autoconf.h.in.orig Fri Jun 20 16:24:14
2003
+++ freeradius-snapshot-20030529/src/include/autoconf.h.in Fri Jun 20 16:25:11
2003
@@ -48,7 +48,9 @@
/* style of gethost*_r functions */
#define GNUSTYLE 1
#define SYSVSTYLE 2
+#define BSDSTYLE 3
#undef GETHOSTBYADDRRSTYLE
+#undef GETHOSTBYNAMERSTYLE
/* Do we have the crypt function ? */
#undef HAVE_CRYPT
--- freeradius-snapshot-20030529/src/lib/misc.c.orig Fri Jun 20 16:24:00 2003
+++ freeradius-snapshot-20030529/src/lib/misc.c Fri Jun 20 16:24:20 2003
@@ -83,20 +83,29 @@
{
struct hostent *hp;
uint32_t a;
-#ifdef HAVE_GETHOSTBYNAME_R
+#ifdef GETHOSTBYNAMERSTYLE
+#if (GETHOSTBYNAMERSTYLE == SYSVSTYLE) || (GETHOSTBYNAMERSTYLE == GNUSTYLE)
struct hostent result;
int error;
char buffer[2048];
#endif
+#endif
if ((a = ip_addr(host)) != htonl(INADDR_NONE))
return a;
-#ifndef HAVE_GETHOSTBYNAME_R
+#ifdef GETHOSTBYADDRRSTYLE
+#if GETHOSTBYADDRRSTYLE == SYSVSTYLE
+ hp = gethostbyname_r(host, &result, buffer, sizeof(buffer), &error);
+#elif GETHOSTBYADDRRSTYLE == GNUSTYLE
+ gethostbyname_r(host, &result, buffer, sizeof(buffer), &hp, &error);
+#else
hp = gethostbyname(host);
+#endif
#else
- hp = gethostbyname_r(host, &result, buffer, sizeof(buffer), &error);
+ hp = gethostbyname(host);
#endif
+
if (hp == NULL) {
return htonl((uint32_t) INADDR_NONE);
}
--- freeradius-snapshot-20030529/acconfig.h.orig Fri Jun 20 16:23:44 2003
+++ freeradius-snapshot-20030529/acconfig.h Fri Jun 20 16:24:32 2003
@@ -11,7 +11,9 @@
/* style of gethost*_r functions */
#define GNUSTYLE 1
#define SYSVSTYLE 2
+#define BSDSTYLE 3
#undef GETHOSTBYADDRRSTYLE
+#undef GETHOSTBYNAMERSTYLE
/* Do we have the crypt function ? */
#undef HAVE_CRYPT
--- freeradius-snapshot-20030529/configure.in.orig Fri Jun 20 16:23:50 2003
+++ freeradius-snapshot-20030529/configure.in Fri Jun 20 16:24:20 2003
@@ -648,6 +648,10 @@
gethostbyaddrrstyle=""
AC_MSG_CHECKING([gethostbyaddr_r() syntax])
+AC_TRY_COMPILE([#include <netdb.h>], [ gethostbyaddr(NULL, 0, 0) ], [
+ AC_DEFINE(GETHOSTBYADDRRSTYLE, BSDSTYLE)
+ gethostbyaddrrstyle=BSD
+])
AC_TRY_COMPILE([#include <netdb.h>], [ gethostbyaddr_r(NULL, 0, 0, NULL, NULL, 0,
NULL) ] , [
AC_DEFINE(GETHOSTBYADDRRSTYLE, SYSVSTYLE)
gethostbyaddrrstyle=SYSV
@@ -657,15 +661,38 @@
gethostbyaddrrstyle=GNU
])
-AC_TRY_COMPILE([#include <netdb.h>], [ gethostbyaddr(NULL, 0, 0) ], [
- AC_DEFINE(GETHOSTBYADDRRSTYLE, BSDSTYLE)
- gethostbyaddrrstyle=BSD
-])
-
if test "x$gethostbyaddrrstyle" = "x"; then
AC_MSG_RESULT([none! It must not exist, here.])
else
AC_MSG_RESULT([${gethostbyaddrrstyle}-style])
+ if test "$gethostbyaddrrstyle" = "BSD"; then
+ AC_MSG_WARN([ ****** BSD Style gethostbyaddr might NOT be thread-safe!
****** ])
+ fi
+fi
+
+
+gethostbynamerstyle=""
+AC_MSG_CHECKING([gethostbyname_r() syntax])
+AC_TRY_COMPILE([#include <netdb.h>], [ gethostbyname(NULL) ], [
+ AC_DEFINE(GETHOSTBYNAMERSTYLE, BSDSTYLE)
+ gethostbynamerstyle=BSD
+])
+AC_TRY_COMPILE([#include <netdb.h>], [ gethostbyname_r(NULL, NULL, NULL, 0, NULL) ] ,
[
+ AC_DEFINE(GETHOSTBYNAMERSTYLE, SYSVSTYLE)
+ gethostbyaddrrstyle=SYSV
+])
+AC_TRY_COMPILE([#include <netdb.h>], [ gethostbyname_r(NULL, NULL, NULL, 0, NULL,
NULL) ], [
+ AC_DEFINE(GETHOSTBYNAMERSTYLE, GNUSTYLE)
+ gethostbynamerstyle=GNU
+])
+
+if test "x$gethostbynamerstyle" = "x"; then
+ AC_MSG_RESULT([none! It must not exist, here.])
+else
+ AC_MSG_RESULT([${gethostbynamerstyle}-style])
+ if test "$gethostbynamerstyle" = "BSD"; then
+ AC_MSG_WARN([ ****** BSD Style gethostbyname might NOT be thread-safe!
****** ])
+ fi
fi