Hi,
The recent libspf2 chenged their API, and milter-greylist doesn't know
the API of recent libspf2. So, I made a patch to support it.
--with-libspf2 is changed to handle recent API of libspf2. You can
still use old API with --with-libspf2_10.
Index: configure.ac
diff -u configure.ac.orig configure.ac
--- configure.ac.orig Sun Jun 26 00:18:03 2005
+++ configure.ac Fri Sep 30 16:56:32 2005
@@ -76,18 +76,43 @@
[ --with-libspf2=DIR Find libspf2 in DIR],
[LDFLAGS=$LDFLAGS" -L$withval/lib -Wl,$rpath$withval/lib"
CFLAGS=$CFLAGS" -I$withval/include"
- AC_CHECK_LIB(spf2, SPF_create_config, [
+ AC_CHECK_LIB(spf2, SPF_server_new, [
SAVEDLDFLAGS=$LDFLAGS
SAVEDCFLAGS=$CFLAGS
LIBS=$LIBS"-lspf2"
AC_DEFINE([HAVE_SPF2], [], [we use libspf2])
- ],[AC_CHECK_LIB([spf2 -lintl], SPF_create_config, [
+ ],[AC_CHECK_LIB([spf2 -lintl], SPF_server_new, [
SAVEDLDFLAGS=$LDFLAGS
SAVEDCFLAGS=$CFLAGS
LIBS=$LIBS"-lspf2 -lintl"
AC_DEFINE([HAVE_SPF2], [], [we use libspf2])
], [echo "libspf2 not found, check config.log for details"
echo "Remove --with-libspf2 to build without SPF support"
+ exit 1;])
+ ])
+])
+LDFLAGS=$SAVEDLDFLAGS
+CFLAGS=$SAVEDCFLAGS
+
+# Try to configure for libspf2 1.0
+SAVEDLDFLAGS=$LDFLAGS
+SAVEDCFLAGS=$CFLAGS
+AC_ARG_WITH(libspf2_10,
+ [ --with-libspf2_10=DIR Find libspf2 1.0 in DIR],
+ [LDFLAGS=$LDFLAGS" -L$withval/lib -Wl,$rpath$withval/lib"
+ CFLAGS=$CFLAGS" -I$withval/include"
+ AC_CHECK_LIB(spf2, SPF_create_config, [
+ SAVEDLDFLAGS=$LDFLAGS
+ SAVEDCFLAGS=$CFLAGS
+ LIBS=$LIBS"-lspf2"
+ AC_DEFINE([HAVE_SPF2_10], [], [we use libspf2 1.0])
+ ],[AC_CHECK_LIB([spf2 -lintl], SPF_create_config, [
+ SAVEDLDFLAGS=$LDFLAGS
+ SAVEDCFLAGS=$CFLAGS
+ LIBS=$LIBS"-lspf2 -lintl"
+ AC_DEFINE([HAVE_SPF2_10], [], [we use libspf2 1.0])
+ ], [echo "libspf2 1.0 not found, check config.log for details"
+ echo "Remove --with-libspf2_10 to build without SPF support"
exit 1;])
])
])
Index: spf.c
diff -u -p spf.c.orig spf.c
--- spf.c.orig Mon Jun 6 06:42:30 2005
+++ spf.c Fri Sep 30 17:13:19 2005
@@ -110,21 +110,24 @@ out1:
#endif /* HAVE_SPF */
+#if defined(HAVE_SPF_ALT) || defined(HAVE_SPF2_10) || defined(HAVE_SPF2)
+/* SMTP needs at least 64 chars for local part and 255 for doamin... */
+#define NS_MAXDNAME 1025
+#endif
+
#ifdef HAVE_SPF_ALT
#include <spf_alt/spf.h>
#include <spf_alt/spf_dns_resolv.h>
#include <spf_alt/spf_lib_version.h>
#endif
-#ifdef HAVE_SPF2
+#ifdef HAVE_SPF2_10
#include <spf2/spf.h>
#include <spf2/spf_dns_resolv.h>
#include <spf2/spf_lib_version.h>
#endif
-#if defined(HAVE_SPF_ALT) || defined(HAVE_SPF2)
-/* SMTP needs at least 64 chars for local part and 255 for doamin... */
-#define NS_MAXDNAME 1025
+#if defined(HAVE_SPF_ALT) || defined(HAVE_SPF2_10)
int
spf_alt_check(sa, salen, helo, fromp)
struct sockaddr *sa;
@@ -220,3 +223,105 @@ out1:
}
#endif /* HAVE_SPF_ALT */
+
+#ifdef HAVE_SPF2
+#include <spf2/spf.h>
+
+int
+spf2_check(sa, salen, helo, fromp)
+ struct sockaddr *sa;
+ socklen_t salen;
+ char *helo;
+ char *fromp;
+{
+ SPF_server_t *spf_server;
+ SPF_request_t *spf_request;
+ SPF_response_t *spf_response;
+ char from[NS_MAXDNAME + 1];
+ int res, result = EXF_NONE;
+ struct timeval tv1, tv2, tv3;
+ size_t len;
+
+ if (conf.c_debug)
+ gettimeofday(&tv1, NULL);
+
+ if ((spf_server = SPF_server_new(SPF_DNS_CACHE, 0)) == NULL) {
+ syslog(LOG_ERR, "SPF_server_new failed");
+ goto out1;
+ }
+
+ if ((spf_request = SPF_request_new(spf_server)) == NULL) {
+ syslog(LOG_ERR, "SPF_request_new failed");
+ goto out2;
+ }
+
+ /*
+ * Get the IP address
+ */
+ switch (sa->sa_family) {
+ case AF_INET:
+ res = SPF_request_set_ipv4(spf_request, *SADDR4(sa));
+ break;
+#ifdef AF_INET6
+ case AF_INET6:
+ res = SPF_request_set_ipv6(spf_request, *SADDR6(sa));
+ break;
+#endif
+ default:
+ syslog(LOG_ERR, "unknown address family %d", sa->sa_family);
+ goto out3;
+ }
+ if (res != 0) {
+ syslog(LOG_ERR, "SPF_request_set_ip_str failed");
+ goto out3;
+ }
+
+ /* HELO string */
+ if (SPF_request_set_helo_dom(spf_request, helo) != 0) {
+ syslog(LOG_ERR, "SPF_request_set_helo_dom failed");
+ goto out3;
+ }
+
+ /*
+ * And the enveloppe source e-mail
+ */
+ if (fromp[0] == '<')
+ fromp++; /* strip leading < */
+ strncpy(from, fromp, NS_MAXDNAME);
+ from[NS_MAXDNAME] = '\0';
+ len = strlen(from);
+ if (fromp[len - 1] == '>')
+ from[len - 1] = '\0'; /* strip trailing > */
+
+ if (SPF_request_set_env_from(spf_request, from) != 0) {
+ syslog(LOG_ERR, "SPF_request_set_env_from failed");
+ goto out3;
+ }
+
+ /*
+ * Get the SPF result
+ */
+ SPF_request_query_mailfrom(spf_request, &spf_response);
+ if ((res = SPF_response_result(spf_response)) == SPF_RESULT_PASS)
+ result = EXF_SPF;
+
+ if (conf.c_debug)
+ syslog(LOG_DEBUG, "SPF return code %d", res);
+
+ SPF_response_free(spf_response);
+out3:
+ SPF_request_free(spf_request);
+out2:
+ SPF_server_free(spf_server);
+out1:
+ if (conf.c_debug) {
+ gettimeofday(&tv2, NULL);
+ timersub(&tv2, &tv1, &tv3);
+ syslog(LOG_DEBUG, "SPF lookup performed in %ld.%06lds",
+ tv3.tv_sec, tv3.tv_usec);
+ }
+
+ return result;
+}
+
+#endif /* HAVE_SPF2 */
Index: spf.h
diff -u spf.h.orig spf.h
--- spf.h.orig Thu Dec 9 07:23:09 2004
+++ spf.h Fri Sep 30 16:56:32 2005
@@ -39,7 +39,11 @@
#include <arpa/inet.h>
#include <netinet/in.h>
-#if defined(HAVE_SPF_ALT) || defined(HAVE_SPF2)
+#if defined(HAVE_SPF2)
+int spf2_check(struct sockaddr *, socklen_t, char *, char *);
+#define SPF_CHECK(w,x,y,z) spf2_check((w),(x),(y),(z))
+
+#elif defined(HAVE_SPF_ALT) || defined(HAVE_SPF2_10)
int spf_alt_check(struct sockaddr *, socklen_t, char *, char *);
#define SPF_CHECK(w,x,y,z) spf_alt_check((w),(x),(y),(z))
Sincerely,
--
Hajimu UMEMOTO @ Internet Mutual Aid Society Yokohama, Japan
ume@... ume@{,jp.}FreeBSD.org
http://www.imasy.org/~ume/Message
support for libspf2 1.2.5
2005-09-30 by Hajimu UMEMOTO
Attachments
- No local attachments were found for this message.