View | Details | Raw Unified | Return to bug 94715
Collapse All | Expand All

(-)spamd_new/Makefile (-2 / +10 lines)
Lines 19-29 Link Here
19
19
20
.include <bsd.port.pre.mk>
20
.include <bsd.port.pre.mk>
21
21
22
.if defined(IPFW)
23
CFLAGS+= -DIPFW
24
.if ${OSVERSION} < 490000
25
IGNORE=		IPFW with Tables is required for this port to function properly
26
.endif
27
.else
22
.if ${OSVERSION} < 502117
28
.if ${OSVERSION} < 502117
23
IGNORE=		OpenBSD 3.5 pf/pfctl is necessary for this port to function properly.
29
IGNORE=		OpenBSD 3.5 pf/pfctl is necessary for this port to function properly.
24
.else
30
.else
25
LOCAL_PFCTL=	/sbin/pfctl
31
LOCAL_PFCTL=	/sbin/pfctl
26
.endif
32
.endif
33
.endif
34
27
35
28
USE_RC_SUBR=	yes
36
USE_RC_SUBR=	yes
29
RC_SCRIPTS_SUB=	PREFIX=${PREFIX} RC_SUBR=${RC_SUBR}
37
RC_SCRIPTS_SUB=	PREFIX=${PREFIX} RC_SUBR=${RC_SUBR}
Lines 46-52 Link Here
46
	@${REINPLACE_CMD} -e 's|/etc/spamd.conf|${PREFIX}/etc/spamd.conf|' \
54
	@${REINPLACE_CMD} -e 's|/etc/spamd.conf|${PREFIX}/etc/spamd.conf|' \
47
	    ${WRKSRC}/spamd/spamd.8 ${WRKSRC}/spamd-setup/spamd-setup.8
55
	    ${WRKSRC}/spamd/spamd.8 ${WRKSRC}/spamd-setup/spamd-setup.8
48
	@${SED} ${RC_SCRIPTS_SUB:S/$/!g/:S/^/ -e s!%%/:S/=/%%!/} \
56
	@${SED} ${RC_SCRIPTS_SUB:S/$/!g/:S/^/ -e s!%%/:S/=/%%!/} \
49
		${FILESDIR}/pfspamd.sh > ${WRKDIR}/pfspamd.sh
57
		${FILESDIR}/pfspamd.sh > ${WRKDIR}/pfspamd.sh 
50
58
51
pre-su-install:
59
pre-su-install:
52
.if !defined(BATCH) && !defined(PACKAGE_BUILDING)
60
.if !defined(BATCH) && !defined(PACKAGE_BUILDING)
Lines 63-73 Link Here
63
	${INSTALL_MAN} ${WRKSRC}/spamd-setup/spamd-setup.8 ${PREFIX}/man/man8
71
	${INSTALL_MAN} ${WRKSRC}/spamd-setup/spamd-setup.8 ${PREFIX}/man/man8
64
	${INSTALL_MAN} ${WRKSRC}/spamdb/spamdb.8 ${PREFIX}/man/man8
72
	${INSTALL_MAN} ${WRKSRC}/spamdb/spamdb.8 ${PREFIX}/man/man8
65
	${INSTALL_MAN} ${WRKSRC}/spamlogd/spamlogd.8 ${PREFIX}/man/man8
73
	${INSTALL_MAN} ${WRKSRC}/spamlogd/spamlogd.8 ${PREFIX}/man/man8
66
	@${INSTALL_SCRIPT} -m 555 ${WRKDIR}/pfspamd.sh ${PREFIX}/etc/rc.d/pfspamd.sh
67
	@if [ ! -f ${SAMPLE_SPAMD_CONF} ]; then			\
74
	@if [ ! -f ${SAMPLE_SPAMD_CONF} ]; then			\
68
		${ECHO_MSG} "Installing ${SAMPLE_SPAMD_CONF} file."; \
75
		${ECHO_MSG} "Installing ${SAMPLE_SPAMD_CONF} file."; \
69
		${INSTALL_DATA} ${WRKSRC}/doc/spamd.conf	\
76
		${INSTALL_DATA} ${WRKSRC}/doc/spamd.conf	\
70
		${SAMPLE_SPAMD_CONF};				\
77
		${SAMPLE_SPAMD_CONF};				\
71
	fi
78
	fi
79
	@${INSTALL_SCRIPT} -m 555 ${WRKDIR}/pfspamd.sh ${PREFIX}/etc/rc.d/pfspamd.sh
72
80
73
.include <bsd.port.post.mk>
81
.include <bsd.port.post.mk>
(-)spamd_new/files/patch-greyc (+131 lines)
Line 0 Link Here
1
--- spamd/grey.c	Wed Apr 13 03:22:17 2005
2
+++ spamd/grey.c	Mon Mar 20 15:26:18 2006
3
@@ -39,6 +39,10 @@
4
 #include <unistd.h>
5
 #include <netdb.h>
6
 
7
+#ifdef IPFW
8
+#include <netinet/ip_fw.h>
9
+#endif
10
+
11
 #include "grey.h"
12
 
13
 extern time_t passtime, greyexp, whiteexp, trapexp;
14
@@ -65,13 +69,17 @@
15
 char *traplist_msg = "\"Your address %A has mailed to spamtraps here\\n\"";
16
 
17
 pid_t db_pid = -1;
18
-int pfdev;
19
 int spamdconf;
20
 
21
+#ifdef IPFW
22
+extern int tabno;
23
+#else
24
+int pfdev;
25
 static char *pargv[11]= {
26
 	"pfctl", "-p", "/dev/pf", "-q", "-t",
27
 	"spamd-white", "-T", "replace", "-f" "-", NULL
28
 };
29
+#endif
30
 
31
 /* If the parent gets a signal, kill off the children and exit */
32
 /* ARGSUSED */
33
@@ -104,6 +112,7 @@
34
 	return(0);
35
 }
36
 
37
+#ifndef IPFW
38
 int
39
 configure_pf(char **addrs, int count)
40
 {
41
@@ -166,11 +175,54 @@
42
 	for (i = 0; i < count; i++)
43
 		if (addrs[i] != NULL)
44
 			fprintf(pf, "%s/32\n", addrs[i]);
45
+
46
 	fclose(pf);
47
 	waitpid(pid, NULL, 0);
48
 	sigaction(SIGCHLD, &sa, NULL);
49
 	return(0);
50
 }
51
+#else
52
+int
53
+configure_pf(char **addrs, int count)
54
+{
55
+	int s = -1;
56
+	ipfw_table_entry ent;
57
+	int i;
58
+
59
+	if (s == -1)
60
+		s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
61
+	if (s < 0)
62
+	{
63
+		syslog_r(LOG_INFO, &sdata, "IPFW socket unavailable (%m)");
64
+		return(-1);
65
+	}
66
+
67
+	/* flush the table */	
68
+	ent.tbl = tabno;
69
+	if (setsockopt(s, IPPROTO_IP, IP_FW_TABLE_FLUSH,  &ent.tbl, sizeof(ent.tbl)) < 0)
70
+	{
71
+		syslog_r(LOG_INFO, &sdata, "IPFW setsockopt(IP_FW_TABLE_FLUSH) (%m)");
72
+		return(-1);
73
+	}
74
+
75
+	for (i = 0; i < count; i++)
76
+		if (addrs[i] != NULL)
77
+	{
78
+		/* add addrs[i] to tabno */
79
+		ent.tbl = tabno;
80
+		ent.masklen = 32;
81
+		ent.value = 0;
82
+		inet_aton(addrs[i], (struct in_addr *)&ent.addr);
83
+		if (setsockopt(s, IPPROTO_IP, IP_FW_TABLE_ADD,  &ent, sizeof(ent)) < 0)
84
+		{
85
+			syslog_r(LOG_INFO, &sdata, "IPFW setsockopt(IP_FW_TABLE_ADD) (%m)");
86
+			return(-1);
87
+		}
88
+	}
89
+
90
+	return(0);
91
+}
92
+#endif
93
 
94
 void
95
 freeaddrlists(void)
96
@@ -590,11 +642,13 @@
97
 	int i;
98
 	struct sigaction sa;
99
 
100
+#ifndef IPFW
101
 	pfdev = open("/dev/pf", O_RDWR);
102
 	if (pfdev == -1) {
103
 		syslog_r(LOG_ERR, &sdata, "open of /dev/pf failed (%m)");
104
 		exit(1);
105
 	}
106
+#endif
107
 
108
 	/* check to see if /var/db/spamd exists, if not, create it */
109
 	if ((i = open(PATH_SPAMD_DB, O_RDWR, 0)) == -1 && errno == ENOENT) {
110
@@ -636,7 +690,9 @@
111
 		 * child, talks to jailed spamd over greypipe,
112
 		 * updates db. has no access to pf.
113
 		 */
114
+#ifndef IPFW
115
 		close(pfdev);
116
+#endif
117
 		setproctitle("(%s update)", PATH_SPAMD_DB);
118
 		greyreader();
119
 		/* NOTREACHED */
120
@@ -655,7 +711,11 @@
121
 	sigaction(SIGCHLD, &sa, NULL);
122
 	sigaction(SIGINT, &sa, NULL);
123
 
124
+#ifndef IPFW
125
 	setproctitle("(pf <spamd-white> update)");
126
+#else
127
+	setproctitle("(ipfw white table update)");
128
+#endif
129
 	greyscanner();
130
 	/* NOTREACHED */
131
 	exit(1);
(-)spamd_new/files/patch-greyh (+10 lines)
Line 0 Link Here
1
--- spamd/grey.h	Thu Mar 16 19:55:33 2006
2
+++ spamd/grey.h	Thu Mar 16 19:55:56 2006
3
@@ -22,6 +22,7 @@
4
 #define WHITEEXP (60 * 60 * 24 * 36) /* remove white entries after 36 days */
5
 #define TRAPEXP (60 * 60 * 24) /* hitting a spamtrap blacklists for a day */
6
 #define PATH_PFCTL "/sbin/pfctl"
7
+#define PATH_IPFW "/sbin/ipfw"
8
 #define DB_SCAN_INTERVAL 60
9
 #define PATH_SPAMD_DB "/var/db/spamd"
10
 
(-)spamd_new/files/patch-spamd (+48 lines)
Line 0 Link Here
1
--- spamd/spamd.c	Thu Mar 16 20:56:45 2006
2
+++ spamd/spamd.c	Thu Mar 16 21:07:11 2006
3
@@ -123,6 +123,10 @@
4
 pid_t jail_pid = -1;
5
 u_short cfg_port;
6
 
7
+#ifdef IPFW
8
+int tabno=1;
9
+#endif
10
+
11
 extern struct sdlist *blacklists;
12
 
13
 int conffd = -1;
14
@@ -153,6 +157,10 @@
15
 	    "             [-G mins:hours:hours] [-n name] [-p port]\n");
16
 	fprintf(stderr,
17
 	    "             [-r reply] [-s secs] [-w window]\n");
18
+#ifdef IPFW
19
+	fprintf(stderr,
20
+	    "             [-t table_no]\n");
21
+#endif
22
 	exit(1);
23
 }
24
 
25
@@ -958,7 +966,11 @@
26
 	if (gethostname(hostname, sizeof hostname) == -1)
27
 		err(1, "gethostname");
28
 
29
+#ifdef IPFW
30
+	while ((ch = getopt(argc, argv, "45b:c:B:p:dgG:r:s:n:vw:t:")) != -1) {
31
+#else
32
 	while ((ch = getopt(argc, argv, "45b:c:B:p:dgG:r:s:n:vw:")) != -1) {
33
+#endif
34
 		switch (ch) {
35
 		case '4':
36
 			nreply = "450";
37
@@ -1015,6 +1027,11 @@
38
 		case 'v':
39
 			verbose = 1;
40
 			break;
41
+#ifdef IPFW
42
+		case 't':
43
+			tabno = atoi(optarg);
44
+			break;
45
+#endif
46
 		case 'w':
47
 			window = atoi(optarg);
48
 			if (window <= 0)
(-)spamd_new/files/patch-spamd-setup (+115 lines)
Line 0 Link Here
1
--- spamd-setup/spamd-setup.c	Wed Apr 13 03:18:59 2005
2
+++ spamd-setup/spamd-setup.c	Fri Mar 17 16:19:25 2006
3
@@ -41,9 +41,14 @@
4
 #include <netdb.h>
5
 #include <zlib.h>
6
 
7
+#ifdef IPFW
8
+#include <net/if.h>
9
+#include <netinet/ip_fw.h>
10
+#endif
11
+
12
 #define PATH_FTP		"/usr/bin/ftp"
13
-#define PATH_PFCTL		"%%LOCAL_PFCTL%%"
14
-#define PATH_SPAMD_CONF		"%%LOCAL_SPAMD_CONF%%"
15
+#define PATH_PFCTL		""
16
+#define PATH_SPAMD_CONF		"/usr/local/etc/spamd.conf"
17
 #define SPAMD_ARG_MAX		256 /* max # of args to an exec */
18
 
19
 struct cidr {
20
@@ -93,6 +98,11 @@
21
 int		debug;
22
 int		dryrun;
23
 
24
+#ifdef IPFW
25
+int tabno=2;
26
+#endif
27
+
28
+
29
 u_int32_t
30
 imask(u_int8_t b)
31
 {
32
@@ -630,6 +640,7 @@
33
 }
34
 
35
 
36
+#ifndef IPFW
37
 int
38
 configure_pf(struct cidr **blacklists)
39
 {
40
@@ -676,6 +687,51 @@
41
 	}
42
 	return(0);
43
 }
44
+#else
45
+int
46
+configure_pf(struct cidr **blacklists)
47
+{
48
+	int s = -1;
49
+	ipfw_table_entry ent;
50
+
51
+	if (s == -1)
52
+		s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
53
+	if (s < 0)
54
+	{
55
+		err(1, "IPFW socket unavailable");
56
+		return(-1);
57
+	}
58
+
59
+	/* flush the table */   
60
+	ent.tbl = tabno;
61
+	if (setsockopt(s, IPPROTO_IP, IP_FW_TABLE_FLUSH,  &ent.tbl, sizeof(ent.tbl)) < 0)
62
+	{
63
+		err(1, "IPFW setsockopt(IP_FW_TABLE_FLUSH)");
64
+		return(-1);
65
+	}
66
+
67
+	while (*blacklists != NULL) {
68
+		struct cidr *b = *blacklists;
69
+
70
+		while (b->addr != 0) {
71
+			/* add b to tabno */
72
+			ent.tbl = tabno;
73
+			ent.masklen = b->bits;
74
+			ent.value = 0;
75
+			inet_aton(atop(b->addr), (struct in_addr *)&ent.addr);
76
+			if (setsockopt(s, IPPROTO_IP, IP_FW_TABLE_ADD,  &ent, sizeof(ent)) < 0)
77
+			{
78
+				err(1, "IPFW setsockopt(IP_FW_TABLE_ADD)");
79
+				return(-1);
80
+			}
81
+			b++;
82
+		}
83
+		blacklists++;
84
+	}
85
+
86
+	return(0);
87
+}
88
+#endif
89
 
90
 int
91
 getlist(char ** db_array, char *name, struct blacklist *blist,
92
@@ -773,7 +829,11 @@
93
 	struct servent *ent;
94
 	int i, ch;
95
 
96
+#ifndef IPFW
97
 	while ((ch = getopt(argc, argv, "nd")) != -1) {
98
+#else
99
+	while ((ch = getopt(argc, argv, "ndt")) != -1) {
100
+#endif
101
 		switch (ch) {
102
 		case 'n':
103
 			dryrun = 1;
104
@@ -781,6 +841,11 @@
105
 		case 'd':
106
 			debug = 1;
107
 			break;
108
+#ifdef IPFW
109
+		case 't':
110
+			tabno = atoi(optarg);
111
+			break;
112
+#endif
113
 		default:
114
 			break;
115
 		}
(-)spamd_new/files/patch-spamdm (+89 lines)
Line 0 Link Here
1
--- spamd/spamd.8	Wed Apr 13 03:21:48 2005
2
+++ spamd/spamd.8	Mon Mar 20 15:12:10 2006
3
@@ -49,6 +49,8 @@
4
 daemon which rejects false mail.
5
 If the
6
 .Xr pf 4
7
+or
8
+.Xr ipfw 4
9
 packet filter is configured to redirect port 25 (SMTP) to this daemon,
10
 it will attempt to waste the time and resources of the spam sender.
11
 .Pp
12
@@ -151,11 +153,15 @@
13
 which processes a list of spammers' addresses, and applies appropriate
14
 .Xr pfctl 8
15
 .Em rdr
16
+or
17
+.Xr ipfw 8
18
+.Em fwd
19
 rules.
20
 .Xr spamd-setup 8
21
 is run from
22
 .Xr cron 8 .
23
 .Sh REDIRECTING SMTP CONNECTIONS
24
+.Ss "When using PF"
25
 With
26
 .Xr pf 4 ,
27
 connections to port 25 (SMTP) can be redirected to another host or port,
28
@@ -189,6 +195,8 @@
29
 can also be used to load addresses into the
30
 .Em <spamd>
31
 table.
32
+
33
+
34
 .Xr spamd-setup 8
35
 also has the added benefit of being able to remove addresses from
36
 blacklists, and will connect to
37
@@ -203,6 +211,52 @@
38
 This is important as it allows legitimate mail
39
 senders to pressure spam sources into behaving properly so that they
40
 may be removed from the relevant blacklists.
41
+
42
+.Ss "If compiled with IPFW"
43
+With
44
+.Xr ipfw 4 ,
45
+the syntax for redirection of TCP sessions is quite different
46
+from that of
47
+.Xr pf 4 .
48
+The
49
+.Em fwd
50
+rule used for this purpose are described in
51
+.Xr ipfw 8 .
52
+The rules should be added to the ruleset called by /etc/rc.firewall
53
+to be present at boot time.
54
+.Bd -literal -offset 4n
55
+fwd 127.0.0.1,8025 tcp from table(2) to me 25 in
56
+allow tcp from table(1) to me 25 in
57
+fwd 127.0.0.1,8025 tcp from any to me 25 in
58
+.Ed
59
+.Pp
60
+Any addresses in the blacklist table
61
+.Em 2
62
+and not in the whitelist table
63
+.Em 1
64
+are then redirected to
65
+.Nm
66
+running on port 8025.
67
+Addresses can be loaded into the blacklist
68
+.Em table ,
69
+like:
70
+.Bd -literal -offset 4n
71
+# ipfw table 1 add a.b.c.d/x
72
+.Ed
73
+.Pp
74
+.Xr spamd-setup 8
75
+can also be used to load addresses into the blacklist table
76
+.Em 2 .
77
+.Pp
78
+The 
79
+.Op Fl t Ar table_no
80
+option to 
81
+.Em spamd 
82
+and 
83
+.Em spamd-setup 
84
+can be used to change the default table
85
+numbers.
86
+
87
 .Sh CONFIGURATION CONNECTIONS
88
 .Nm
89
 listens for configuration connections on the port identified by the
(-)spamd_new/pkg-message (-2 / +11 lines)
Lines 1-9 Link Here
1
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
In order to use spamd greylisting feature you have to have a mounted fdescfs(5)
2
In order to use spamd greylisting feature with pf firewall you have to have a 
3
at /dev/fd.  This is done by adding:
3
mounted fdescfs(5) at /dev/fd.  This is done by adding:
4
4
5
        fdescfs /dev/fd fdescfs rw 0 0
5
        fdescfs /dev/fd fdescfs rw 0 0
6
6
7
to /etc/fstab.  You may need either a customised kernel, or kldload the fdescfs
7
to /etc/fstab.  You may need either a customised kernel, or kldload the fdescfs
8
kernel module.
8
kernel module.
9
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10
To use spamd with ipfw firewall, simply include ipfw rules similar to the 
11
following:
12
13
00400 fwd tcp from table(2) to any dst-port 25
14
00410 allow tcp from table(1) to any dst-port 25
15
00420 fwd 127.0.0.1,8025 tcp from any to any dst-port 25 in
16
17
Other table numbers can be used by using the -t option to spamd and spamd-setup
9
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
18
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Return to bug 94715