Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 25 Jun 2004 16:10:30 GMT
From:      Hajimu UMEMOTO <ume@FreeBSD.org>
To:        freebsd-ports-bugs@FreeBSD.org
Subject:   ports/68281: add SPF support for milter-greylist
Message-ID:  <200406251610.i5PGAUIM084961@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR ports/68281; it has been noted by GNATS.

From: Hajimu UMEMOTO <ume@FreeBSD.org>
To: freebsd-gnats-submit@freebsd.org
Cc: Cyril Guibourg <plonk-o-matic@teaser.fr>
Subject: ports/68281: add SPF support for milter-greylist
Date: Sat, 26 Jun 2004 01:05:44 +0900

 Hi,
 
 >>>>> On Fri, 25 Jun 2004 14:21:53 +0200
 >>>>> Cyril Guibourg <plonk-o-matic@teaser.fr> said:
 
 plonk-o-matic> I've been told that libspf_alt needs a reentrant version of libbind in
 plonk-o-matic> order to work fine. Are the available res_* libc routines thread safe ?
 
 Oops, I didn't notice this issue.  The recent 5-CURRENT's resolver is
 thread_safe.  But, 4-STABLE's one is not.  How about adding attached
 patch for now?  It does giant locking around SPF call.
 
 Index: spf.c
 diff -u -p spf.c.orig spf.c
 --- spf.c.orig	Wed May  5 05:50:33 2004
 +++ spf.c	Sat Jun 26 00:27:41 2004
 @@ -52,6 +52,22 @@ __RCSID("$Id: spf.c,v 1.13 2004/05/04 20
  #include "spf.h"
  #include "except.h"
  
 +#if defined(__FreeBSD__)
 +#include <sys/param.h>
 +#if __FreeBSD_version < 502105
 +#define RESOLVER_NEED_LOCK	1
 +#endif
 +#endif
 +
 +#if (defined(HAVE_SPF) || defined(HAVE_SPF_ALT)) && defined(RESOLVER_NEED_LOCK)
 +static pthread_mutex_t spf_mutex_lock = PTHREAD_MUTEX_INITIALIZER;
 +#define RESOLVER_LOCK()		pthread_mutex_lock(&spf_mutex_lock)
 +#define RESOLVER_UNLOCK()	pthread_mutex_unlock(&spf_mutex_lock)
 +#else
 +#define RESOLVER_LOCK()
 +#define RESOLVER_UNLOCK()
 +#endif
 +
  
  #ifdef HAVE_SPF
  #include <spf.h>
 @@ -71,6 +87,7 @@ spf_check(in, helo, from)
  
  	inet_ntop(AF_INET, in, addr, IPADDRLEN);
  
 +	RESOLVER_LOCK();
  	if ((p = SPF_init("milter-greylist", addr, 
  	    NULL, NULL, NULL, FALSE, FALSE)) == NULL) {
  		syslog(LOG_ERR, "SPF_Init failed");
 @@ -89,6 +106,7 @@ spf_check(in, helo, from)
  	SPF_close(p);
  
  out1:
 +	RESOLVER_UNLOCK();
  	if (conf.c_debug) {
  		gettimeofday(&tv2, NULL);
  		timersub(&tv2, &tv1, &tv3);
 @@ -126,6 +144,7 @@ spf_alt_check(in, helo, fromp)
  	if (conf.c_debug)
  		gettimeofday(&tv1, NULL);
  
 +	RESOLVER_LOCK();
  	if ((spfconf = SPF_create_config()) == NULL) {
  		syslog(LOG_ERR, "SPF_create_config failed");
  		goto out1;
 @@ -188,6 +207,7 @@ out3:
  out2:
  	SPF_destroy_config(spfconf);
  out1:
 +	RESOLVER_UNLOCK();
  	if (conf.c_debug) {
  		gettimeofday(&tv2, NULL);
  		timersub(&tv2, &tv1, &tv3);
 
 Sincerely,
 
 --
 Hajimu UMEMOTO @ Internet Mutual Aid Society Yokohama, Japan
 ume@mahoroba.org  ume@{,jp.}FreeBSD.org
 http://www.imasy.org/~ume/



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200406251610.i5PGAUIM084961>