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); |