Mercurial > dnsbl
annotate src/context.cpp @ 354:2fd904f2efc2
only do greylisting if we don't have any whitelisted recipients
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Mon, 26 Dec 2016 16:27:22 -0800 |
parents | ed04479a8e12 |
children | 17f21fcd44a8 |
rev | line source |
---|---|
94 | 1 /* |
2 | |
270
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
3 Copyright (c) 2013 Carl Byington - 510 Software Group, released under |
152 | 4 the GPL version 3 or any later version at your choice available at |
5 http://www.gnu.org/licenses/gpl-3.0.txt | |
94 | 6 |
7 */ | |
8 | |
9 #include "includes.h" | |
10 | |
160 | 11 #include <arpa/inet.h> |
94 | 12 #include <net/if.h> |
160 | 13 #include <netdb.h> |
94 | 14 #include <netinet/in.h> |
15 #include <netinet/tcp.h> | |
160 | 16 #include <sys/ioctl.h> |
94 | 17 #include <sys/socket.h> |
160 | 18 #include <sys/stat.h> |
94 | 19 #include <sys/un.h> |
160 | 20 #include <unistd.h> |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
21 #include <climits> |
94 | 22 |
270
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
23 const char *token_asterisk; |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
24 const char *token_autowhite; |
270
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
25 const char *token_bang; |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
26 const char *token_black; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
27 const char *token_content; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
28 const char *token_context; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
29 const char *token_dccbulk; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
30 const char *token_dccfrom; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
31 const char *token_dccgrey; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
32 const char *token_dccto; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
33 const char *token_default; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
34 const char *token_dnsbl; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
35 const char *token_dnsbll; |
249 | 36 const char *token_dnswl; |
37 const char *token_dnswll; | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
38 const char *token_envfrom; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
39 const char *token_envto; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
40 const char *token_filter; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
41 const char *token_generic; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
42 const char *token_host_limit; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
43 const char *token_html_limit; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
44 const char *token_html_tags; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
45 const char *token_ignore; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
46 const char *token_include; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
47 const char *token_inherit; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
48 const char *token_lbrace; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
49 const char *token_mailhost; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
50 const char *token_many; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
51 const char *token_no; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
52 const char *token_off; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
53 const char *token_ok; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
54 const char *token_ok2; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
55 const char *token_on; |
270
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
56 const char *token_period; |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
57 const char *token_rate; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
58 const char *token_rbrace; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
59 const char *token_require; |
268
f941563c2a95
Add require_rdns checking
Carl Byington <carl@five-ten-sg.com>
parents:
266
diff
changeset
|
60 const char *token_requirerdns; |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
61 const char *token_semi; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
62 const char *token_soft; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
63 const char *token_spamassassin; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
64 const char *token_substitute; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
65 const char *token_tld; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
66 const char *token_unknown; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
67 const char *token_uribl; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
68 const char *token_verify; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
69 const char *token_white; |
233
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
70 const char *token_white_regex; |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
71 const char *token_yes; |
321
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
72 const char *token_dkim_signer; |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
73 const char *token_dkim_from; |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
74 const char *token_signed_white; |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
75 const char *token_signed_black; |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
76 const char *token_require_signed; |
322
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
77 const char *token_myhostname; |
94 | 78 |
96
1edd4e8d3a60
fix missing include, not all systems define HOST_NAME_MAX
carl
parents:
94
diff
changeset
|
79 #ifndef HOST_NAME_MAX |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
80 #define HOST_NAME_MAX 255 |
96
1edd4e8d3a60
fix missing include, not all systems define HOST_NAME_MAX
carl
parents:
94
diff
changeset
|
81 #endif |
94 | 82 char myhostname[HOST_NAME_MAX+1]; |
83 | |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
84 pthread_mutex_t verifier_mutex; // protect the verifier map |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
85 verify_map verifiers; |
153 | 86 |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
87 pthread_mutex_t whitelister_mutex; // protect the whitelisters map |
153 | 88 whitelister_map whitelisters; |
89 | |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
90 string_set all_strings; // owns all the strings, only modified by the config loader thread |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
91 const int maxlen = 1000; // used for snprintf buffers |
178 | 92 const int maxsmtp_age = 60;// smtp verify sockets older than this are ancient |
153 | 93 const int maxauto_age = 600;// auto whitelister delay before flushing to file |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
94 extern int NULL_SOCKET; |
129
c5cd1261394d
ignore smtp connection attempts for 10 minutes when getting connection errors on verify hosts
carl
parents:
119
diff
changeset
|
95 const time_t ERROR_SMTP_SOCKET_TIME = 600; // number of seconds between attempts to open a socket to an smtp server |
94 | 96 |
97 | |
98 int SMTP::writer() { | |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
99 #ifdef VERIFY_DEBUG |
316
f7c5cfb76e86
better smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
314
diff
changeset
|
100 log("writer(%d) sees buffer with '%s'", buffer); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
101 #endif |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
102 int rs = 0; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
103 if (!error) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
104 int len = strlen(buffer); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
105 while (rs < len) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
106 int ws = write(fd, buffer+rs, len-rs); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
107 if (ws > 0) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
108 rs += ws; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
109 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
110 else { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
111 // peer closed the socket! |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
112 rs = 0; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
113 error = true; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
114 break; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
115 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
116 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
117 } |
316
f7c5cfb76e86
better smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
314
diff
changeset
|
118 #ifdef VERIFY_DEBUG |
f7c5cfb76e86
better smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
314
diff
changeset
|
119 log("writer(%d) sees error %d", (int)error); |
f7c5cfb76e86
better smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
314
diff
changeset
|
120 #endif |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
121 return rs; |
94 | 122 } |
123 | |
124 | |
125 int SMTP::reader() { | |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
126 // read some bytes terminated by lf or end of buffer. |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
127 // we may have a multi line response or part thereof in the buffer. |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
128 #ifdef VERIFY_DEBUG |
314
ef5a6099cbe7
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
311
diff
changeset
|
129 log("reader(%d) sees error %d", (int)error); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
130 #endif |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
131 if (error) return 0; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
132 int len = maxlen-1; // room for null terminator |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
133 while (pending < len) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
134 int ws = read(fd, buffer+pending, len-pending); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
135 if (ws > 0) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
136 pending += ws; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
137 if (buffer[pending-1] == '\n') break; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
138 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
139 else { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
140 // peer closed the socket! |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
141 pending = 0; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
142 error = true; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
143 break; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
144 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
145 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
146 buffer[pending] = '\0'; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
147 #ifdef VERIFY_DEBUG |
316
f7c5cfb76e86
better smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
314
diff
changeset
|
148 log("reader(%d) sees buffer with '%s'", buffer); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
149 #endif |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
150 return pending; |
94 | 151 } |
152 | |
153 | |
154 int SMTP::read_line() { | |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
155 char *lf = strchr(buffer, '\n'); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
156 if (!lf) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
157 reader(); // get a lf |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
158 lf = strchr(buffer, '\n'); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
159 if (!lf) lf = buffer + pending - 1; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
160 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
161 return (lf-buffer)+1; // number of bytes in this line |
94 | 162 } |
163 | |
164 | |
97 | 165 void SMTP::flush_line(int r) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
166 if (pending > r) memmove(buffer, buffer+r, pending-r); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
167 pending -= r; |
94 | 168 } |
169 | |
170 | |
171 int SMTP::read_response() { | |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
172 pending = 0; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
173 buffer[pending] = '\0'; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
174 while (true) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
175 int r = read_line(); |
316
f7c5cfb76e86
better smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
314
diff
changeset
|
176 log("verify::read_response(%d) sees line with '%s'", buffer); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
177 if (r == 0) return 0; // failed to read any bytes |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
178 if ((r > 4) && (buffer[3] == '-')) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
179 flush_line(r); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
180 continue; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
181 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
182 return atoi(buffer); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
183 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
184 return 0; |
94 | 185 } |
186 | |
187 | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
188 int SMTP::cmd(const char *c) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
189 if (c) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
190 init(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
191 append(c); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
192 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
193 append("\r\n"); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
194 writer(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
195 return read_response(); |
94 | 196 } |
197 | |
198 | |
199 int SMTP::helo() { | |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
200 if (read_response() != 220) return 0; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
201 init(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
202 append("HELO "); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
203 append(token_myhostname); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
204 return cmd(NULL); |
94 | 205 } |
206 | |
207 | |
208 int SMTP::rset() { | |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
209 efrom[0] = '\0'; |
316
f7c5cfb76e86
better smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
314
diff
changeset
|
210 return cmd("RSET"); |
94 | 211 } |
212 | |
213 | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
214 int SMTP::from(const char *f) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
215 // the mail from address was originally passed in from sendmail enclosed in |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
216 // <>. to_lower_string() removed the <> and converted the rest to lowercase, |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
217 // except in the case of an empty return path, which was left as the two |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
218 // character string <>. |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
219 if (strncmp(efrom, f, maxlen)) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
220 strncpy(efrom, f, maxlen); |
311
f5547e7b3a09
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
310
diff
changeset
|
221 efrom[maxlen-1] = '\0'; // ensure null termination |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
222 init(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
223 append("MAIL FROM:<"); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
224 if (*f != '<') append(f); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
225 append(">"); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
226 return cmd(NULL); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
227 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
228 return 250; // pretend it worked |
94 | 229 } |
230 | |
231 | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
232 int SMTP::rcpt(const char *t) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
233 init(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
234 append("RCPT TO:<"); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
235 append(t); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
236 append(">"); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
237 return cmd(NULL); |
94 | 238 } |
239 | |
240 | |
241 int SMTP::quit() { | |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
242 return cmd("QUIT"); |
94 | 243 } |
244 | |
245 | |
246 void SMTP::closefd() { | |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
247 shutdown(fd, SHUT_RDWR); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
248 close(fd); |
94 | 249 } |
250 | |
251 | |
311
f5547e7b3a09
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
310
diff
changeset
|
252 void SMTP::log(const char *m, int v) { |
f5547e7b3a09
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
310
diff
changeset
|
253 char buf[maxlen]; |
314
ef5a6099cbe7
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
311
diff
changeset
|
254 snprintf(buf, maxlen, m, get_fd(), v); |
311
f5547e7b3a09
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
310
diff
changeset
|
255 my_syslog(queueid, buf); |
f5547e7b3a09
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
310
diff
changeset
|
256 } |
94 | 257 |
258 | |
311
f5547e7b3a09
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
310
diff
changeset
|
259 void SMTP::log(const char *m, const char *v) { |
f5547e7b3a09
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
310
diff
changeset
|
260 char buf[maxlen]; |
314
ef5a6099cbe7
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
311
diff
changeset
|
261 snprintf(buf, maxlen, m, get_fd(), v); |
311
f5547e7b3a09
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
310
diff
changeset
|
262 my_syslog(queueid, buf); |
f5547e7b3a09
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
310
diff
changeset
|
263 } |
94 | 264 |
265 | |
153 | 266 //////////////////////////////////////////////// |
267 // smtp verifier so backup mx machines can see the valid users | |
268 // | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
269 VERIFY::VERIFY(const char *h) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
270 host = h; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
271 last_err = 0; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
272 pthread_mutex_init(&mutex, 0); |
94 | 273 } |
274 | |
275 | |
320
e27c24c1974a
more smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
318
diff
changeset
|
276 void VERIFY::log(const char *m, const char *q, const char *v) { |
e27c24c1974a
more smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
318
diff
changeset
|
277 char buf[maxlen]; |
e27c24c1974a
more smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
318
diff
changeset
|
278 snprintf(buf, maxlen, m, v, host); |
e27c24c1974a
more smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
318
diff
changeset
|
279 my_syslog(q, buf); |
e27c24c1974a
more smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
318
diff
changeset
|
280 } |
e27c24c1974a
more smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
318
diff
changeset
|
281 |
e27c24c1974a
more smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
318
diff
changeset
|
282 |
94 | 283 void VERIFY::closer() { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
284 bool ok = true; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
285 while (ok) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
286 SMTP *conn = NULL; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
287 pthread_mutex_lock(&mutex); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
288 if (connections.empty()) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
289 ok = false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
290 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
291 else { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
292 conn = connections.front(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
293 time_t now = time(NULL); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
294 if ((now - conn->get_stamp()) > maxsmtp_age) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
295 // this connection is ancient, remove it |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
296 connections.pop_front(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
297 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
298 else { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
299 ok = false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
300 conn = NULL; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
301 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
302 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
303 pthread_mutex_unlock(&mutex); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
304 // avoid doing this work inside the mutex lock |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
305 if (conn) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
306 #ifdef VERIFY_DEBUG |
314
ef5a6099cbe7
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
311
diff
changeset
|
307 conn->log("closer(%d) closes ancient socket %s", ""); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
308 #endif |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
309 delete conn; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
310 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
311 } |
94 | 312 } |
313 | |
314 | |
311
f5547e7b3a09
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
310
diff
changeset
|
315 SMTP* VERIFY::get_connection(const char *queueid) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
316 SMTP *conn = NULL; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
317 pthread_mutex_lock(&mutex); |
314
ef5a6099cbe7
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
311
diff
changeset
|
318 while (!connections.empty()) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
319 conn = connections.front(); |
314
ef5a6099cbe7
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
311
diff
changeset
|
320 time_t now = time(NULL); |
ef5a6099cbe7
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
311
diff
changeset
|
321 if ((now - conn->get_stamp()) > maxsmtp_age) { |
ef5a6099cbe7
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
311
diff
changeset
|
322 // this connection is ancient, remove it |
ef5a6099cbe7
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
311
diff
changeset
|
323 conn->log("verify::get_connection(%d) closes ancient socket %s", ""); |
ef5a6099cbe7
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
311
diff
changeset
|
324 connections.pop_front(); |
ef5a6099cbe7
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
311
diff
changeset
|
325 delete conn; |
ef5a6099cbe7
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
311
diff
changeset
|
326 conn = NULL; |
ef5a6099cbe7
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
311
diff
changeset
|
327 } |
ef5a6099cbe7
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
311
diff
changeset
|
328 else { |
ef5a6099cbe7
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
311
diff
changeset
|
329 conn->set_id(queueid); |
ef5a6099cbe7
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
311
diff
changeset
|
330 connections.pop_front(); |
318
e2dc882839f6
better smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
316
diff
changeset
|
331 conn->log("verify::get_connection(%d) from cache %s", ""); |
314
ef5a6099cbe7
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
311
diff
changeset
|
332 break; |
ef5a6099cbe7
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
311
diff
changeset
|
333 } |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
334 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
335 pthread_mutex_unlock(&mutex); |
316
f7c5cfb76e86
better smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
314
diff
changeset
|
336 if (conn) { |
f7c5cfb76e86
better smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
314
diff
changeset
|
337 int rc = conn->rset(); |
f7c5cfb76e86
better smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
314
diff
changeset
|
338 conn->log("verify::getconnection(%d) rset sees %d", rc); |
f7c5cfb76e86
better smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
314
diff
changeset
|
339 if (rc == 250) return conn; |
318
e2dc882839f6
better smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
316
diff
changeset
|
340 delete conn; |
e2dc882839f6
better smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
316
diff
changeset
|
341 // old connection from cache was unusable, fall thru and make a new one |
316
f7c5cfb76e86
better smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
314
diff
changeset
|
342 } |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
343 int sock = NULL_SOCKET; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
344 if ((time(NULL) - last_err) > ERROR_SMTP_SOCKET_TIME) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
345 // nothing recent, maybe this time it will work |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
346 hostent *h = gethostbyname(host); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
347 if (h) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
348 sockaddr_in server; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
349 server.sin_family = h->h_addrtype; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
350 server.sin_port = htons(25); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
351 memcpy(&server.sin_addr, h->h_addr_list[0], h->h_length); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
352 sock = socket(PF_INET, SOCK_STREAM, 0); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
353 if (sock != NULL_SOCKET) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
354 bool rc = (connect(sock, (sockaddr *)&server, sizeof(server)) == 0); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
355 if (!rc) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
356 shutdown(sock, SHUT_RDWR); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
357 close(sock); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
358 sock = NULL_SOCKET; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
359 last_err = time(NULL); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
360 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
361 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
362 else last_err = time(NULL); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
363 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
364 else last_err = time(NULL); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
365 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
366 if (sock != NULL_SOCKET) { |
314
ef5a6099cbe7
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
311
diff
changeset
|
367 struct timeval tv; |
ef5a6099cbe7
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
311
diff
changeset
|
368 tv.tv_sec = 15; |
ef5a6099cbe7
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
311
diff
changeset
|
369 tv.tv_usec = 0; |
ef5a6099cbe7
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
311
diff
changeset
|
370 setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)); |
316
f7c5cfb76e86
better smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
314
diff
changeset
|
371 setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv, sizeof(struct timeval)); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
372 conn = new SMTP(sock); |
311
f5547e7b3a09
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
310
diff
changeset
|
373 conn->set_id(queueid); |
318
e2dc882839f6
better smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
316
diff
changeset
|
374 conn->log("get_connection(%d) new socket %s", ""); |
311
f5547e7b3a09
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
310
diff
changeset
|
375 int rc = conn->helo(); |
314
ef5a6099cbe7
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
311
diff
changeset
|
376 conn->log("verify::get_connection(%d) helo sees %d", rc); |
311
f5547e7b3a09
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
310
diff
changeset
|
377 if (rc == 250) return conn; |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
378 delete conn; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
379 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
380 return NULL; |
94 | 381 } |
382 | |
383 | |
384 void VERIFY::put_connection(SMTP *conn) { | |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
385 if (conn->err()) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
386 #ifdef VERIFY_DEBUG |
314
ef5a6099cbe7
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
311
diff
changeset
|
387 conn->log("put_socket(%d) with error %s", ""); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
388 #endif |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
389 delete conn; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
390 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
391 else { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
392 #ifdef VERIFY_DEBUG |
314
ef5a6099cbe7
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
311
diff
changeset
|
393 conn->log("put_socket(%d) no error %s", ""); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
394 #endif |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
395 conn->now(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
396 pthread_mutex_lock(&mutex); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
397 connections.push_back(conn); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
398 pthread_mutex_unlock(&mutex); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
399 } |
94 | 400 } |
401 | |
402 | |
310
802e2b779ed1
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
278
diff
changeset
|
403 bool VERIFY::ok(const char *queueid, const char *from, const char *to) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
404 if (host == token_myhostname) return true; |
311
f5547e7b3a09
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
310
diff
changeset
|
405 SMTP *conn = get_connection(queueid); |
320
e27c24c1974a
more smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
318
diff
changeset
|
406 if (!conn) { |
e27c24c1974a
more smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
318
diff
changeset
|
407 log("unable to verify %s with %s due to socket errors", queueid, to); |
e27c24c1974a
more smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
318
diff
changeset
|
408 return true; // cannot verify right now, we have socket errors |
e27c24c1974a
more smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
318
diff
changeset
|
409 } |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
410 int rc; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
411 rc = conn->from(from); |
314
ef5a6099cbe7
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
311
diff
changeset
|
412 conn->log("verify::ok(%d) from sees %d", rc); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
413 if (rc != 250) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
414 put_connection(conn); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
415 return (rc >= 500) ? false : true; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
416 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
417 rc = conn->rcpt(to); |
314
ef5a6099cbe7
enable smtp verify logging
Carl Byington <carl@five-ten-sg.com>
parents:
311
diff
changeset
|
418 conn->log("verify::ok(%d) rcpt sees %d", rc); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
419 put_connection(conn); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
420 return (rc >= 500) ? false : true; |
94 | 421 } |
422 | |
423 | |
153 | 424 //////////////////////////////////////////////// |
425 // setup a new smtp verify host | |
426 // | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
427 VERIFYP add_verify_host(const char *host); |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
428 VERIFYP add_verify_host(const char *host) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
429 VERIFYP rc = NULL; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
430 pthread_mutex_lock(&verifier_mutex); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
431 verify_map::iterator i = verifiers.find(host); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
432 if (i == verifiers.end()) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
433 rc = new VERIFY(host); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
434 verifiers[host] = rc; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
435 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
436 else rc = (*i).second; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
437 pthread_mutex_unlock(&verifier_mutex); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
438 return rc; |
153 | 439 } |
440 | |
441 | |
442 //////////////////////////////////////////////// | |
443 // thread to check for verify hosts with old sockets that we can close | |
444 // | |
445 void* verify_closer(void *arg) { | |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
446 while (true) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
447 sleep(maxsmtp_age); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
448 pthread_mutex_lock(&verifier_mutex); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
449 for (verify_map::iterator i=verifiers.begin(); i!=verifiers.end(); i++) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
450 VERIFYP v = (*i).second; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
451 v->closer(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
452 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
453 pthread_mutex_unlock(&verifier_mutex); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
454 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
455 return NULL; |
153 | 456 } |
457 | |
458 | |
459 //////////////////////////////////////////////// | |
460 // automatic whitelister | |
461 // | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
462 WHITELISTER::WHITELISTER(const char *f, int d) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
463 fn = f; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
464 days = d; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
465 pthread_mutex_init(&mutex, 0); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
466 need = false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
467 loaded = time(NULL); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
468 merge(); |
160 | 469 } |
470 | |
471 | |
472 void WHITELISTER::merge() { | |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
473 time_t now = time(NULL); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
474 ifstream ifs; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
475 ifs.open(fn); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
476 if (!ifs.fail()) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
477 const int maxlen = 1000; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
478 char buf[maxlen]; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
479 while (ifs.getline(buf, maxlen)) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
480 char *p = strchr(buf, ' '); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
481 if (p) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
482 *p = '\0'; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
483 char *who = strdup(buf); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
484 time_t when = atoi(p+1); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
485 if ((when == 0) || (when > now)) when = now; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
486 autowhite_sent::iterator i = rcpts.find(who); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
487 if (i == rcpts.end()) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
488 rcpts[who] = when; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
489 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
490 else { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
491 time_t wh = (*i).second; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
492 if ((when == 1) || (when > wh)) (*i).second = when; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
493 free(who); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
494 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
495 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
496 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
497 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
498 ifs.close(); |
153 | 499 } |
500 | |
501 | |
502 void WHITELISTER::writer() { | |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
503 pthread_mutex_lock(&mutex); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
504 time_t limit = time(NULL) - days*86400; |
160 | 505 |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
506 // check for manually modified autowhitelist file |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
507 struct stat st; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
508 if (stat(fn, &st)) need = true; // file has disappeared |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
509 else if (st.st_mtime > loaded) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
510 // file has been manually updated, merge new entries |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
511 merge(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
512 need = true; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
513 } |
160 | 514 |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
515 // purge old entries |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
516 for (autowhite_sent::iterator i=rcpts.begin(); i!=rcpts.end();) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
517 time_t when = (*i).second; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
518 if (when < limit) { |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
519 const char *who = (*i).first; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
520 free((void*)who); |
195 | 521 rcpts.erase(i++); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
522 need = true; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
523 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
524 else i++; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
525 } |
160 | 526 |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
527 if (need) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
528 // dump the file |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
529 ofstream ofs; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
530 ofs.open(fn); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
531 if (!ofs.fail()) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
532 for (autowhite_sent::iterator i=rcpts.begin(); i!=rcpts.end(); i++) { |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
533 const char *who = (*i).first; |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
534 int when = (*i).second; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
535 if (!strchr(who, ' ')) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
536 ofs << who << " " << when << endl; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
537 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
538 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
539 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
540 ofs.close(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
541 need = false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
542 loaded = time(NULL); // update load time |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
543 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
544 pthread_mutex_unlock(&mutex); |
153 | 545 } |
546 | |
547 | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
548 void WHITELISTER::sent(const char *to) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
549 // we take ownership of the string |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
550 pthread_mutex_lock(&mutex); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
551 need = true; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
552 autowhite_sent::iterator i = rcpts.find(to); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
553 if (i == rcpts.end()) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
554 rcpts[to] = time(NULL); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
555 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
556 else { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
557 (*i).second = time(NULL); |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
558 free((void*)to); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
559 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
560 pthread_mutex_unlock(&mutex); |
153 | 561 } |
562 | |
563 | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
564 bool WHITELISTER::is_white(const char *from) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
565 pthread_mutex_lock(&mutex); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
566 autowhite_sent::iterator i = rcpts.find(from); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
567 bool rc = (i != rcpts.end()); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
568 pthread_mutex_unlock(&mutex); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
569 return rc; |
153 | 570 } |
571 | |
572 | |
573 //////////////////////////////////////////////// | |
574 // setup a new auto whitelister file | |
575 // | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
576 WHITELISTERP add_whitelister_file(const char *fn, int days); |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
577 WHITELISTERP add_whitelister_file(const char *fn, int days) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
578 WHITELISTERP rc = NULL; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
579 pthread_mutex_lock(&whitelister_mutex); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
580 whitelister_map::iterator i = whitelisters.find(fn); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
581 if (i == whitelisters.end()) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
582 rc = new WHITELISTER(fn, days); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
583 whitelisters[fn] = rc; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
584 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
585 else { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
586 rc = (*i).second; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
587 rc->set_days(days); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
588 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
589 pthread_mutex_unlock(&whitelister_mutex); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
590 return rc; |
153 | 591 } |
592 | |
593 | |
594 //////////////////////////////////////////////// | |
595 // thread to check for whitelister hosts with old sockets that we can close | |
596 // | |
597 void* whitelister_writer(void *arg) { | |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
598 while (true) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
599 sleep(maxauto_age); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
600 pthread_mutex_lock(&whitelister_mutex); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
601 for (whitelister_map::iterator i=whitelisters.begin(); i!=whitelisters.end(); i++) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
602 WHITELISTERP v = (*i).second; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
603 v->writer(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
604 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
605 pthread_mutex_unlock(&whitelister_mutex); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
606 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
607 return NULL; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
608 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
609 |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
610 |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
611 DELAYWHITE::DELAYWHITE(const char *loto_, WHITELISTERP w_, CONTEXTP con_) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
612 loto = loto_; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
613 w = w_; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
614 con = con_; |
153 | 615 } |
616 | |
617 | |
321
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
618 DKIM::DKIM(const char *action_, const char *signer_) { |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
619 action = action_; |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
620 signer = signer_; |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
621 } |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
622 |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
623 |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
624 DNSBL::DNSBL(const char *n, const char *s, const char *m) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
625 name = n; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
626 suffix = s; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
627 message = m; |
94 | 628 } |
629 | |
630 | |
631 bool DNSBL::operator==(const DNSBL &rhs) { | |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
632 return (strcmp(name, rhs.name) == 0) && |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
633 (strcmp(suffix, rhs.suffix) == 0) && |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
634 (strcmp(message, rhs.message) == 0); |
94 | 635 } |
636 | |
637 | |
249 | 638 DNSWL::DNSWL(const char *n, const char *s, const int l) { |
639 name = n; | |
640 suffix = s; | |
641 level = l; | |
642 } | |
643 | |
644 | |
645 bool DNSWL::operator==(const DNSWL &rhs) { | |
646 return (strcmp(name, rhs.name) == 0) && | |
647 (strcmp(suffix, rhs.suffix) == 0) && | |
648 (level == rhs.level); | |
649 } | |
650 | |
651 | |
94 | 652 CONFIG::CONFIG() { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
653 reference_count = 0; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
654 generation = 0; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
655 load_time = 0; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
656 default_context = NULL; |
94 | 657 } |
658 | |
659 | |
660 CONFIG::~CONFIG() { | |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
661 if (debug_syslog) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
662 char buf[maxlen]; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
663 snprintf(buf, sizeof(buf), "freeing memory for old configuration generation %d", generation); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
664 my_syslog(buf); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
665 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
666 for (context_list::iterator i=contexts.begin(); i!=contexts.end(); i++) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
667 CONTEXT *c = *i; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
668 delete c; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
669 } |
94 | 670 } |
671 | |
672 | |
673 void CONFIG::add_context(CONTEXTP con) { | |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
674 contexts.push_back(con); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
675 if (!default_context && !con->get_parent()) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
676 // first global context |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
677 default_context = con; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
678 } |
94 | 679 } |
680 | |
681 | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
682 void CONFIG::add_to(const char *to, CONTEXTP con) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
683 context_map::iterator i = env_to.find(to); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
684 if (i != env_to.end()) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
685 CONTEXTP c = (*i).second; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
686 if ((c != con) && (c != con->get_parent())) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
687 if (debug_syslog) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
688 char oldname[maxlen]; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
689 char newname[maxlen]; |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
690 const char *oldn = c->get_full_name(oldname, maxlen); |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
691 const char *newn = con->get_full_name(newname, maxlen); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
692 char buf[maxlen*3]; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
693 snprintf(buf, maxlen*3, "both %s and %s claim envelope to %s, the second one wins", oldn, newn, to); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
694 my_syslog(buf); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
695 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
696 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
697 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
698 env_to[to] = con; |
94 | 699 } |
700 | |
701 | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
702 CONTEXTP CONFIG::find_context(const char *to) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
703 context_map::iterator i = env_to.find(to); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
704 if (i != env_to.end()) return (*i).second; // found user@domain key |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
705 const char *x = strchr(to, '@'); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
706 if (x) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
707 x++; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
708 i = env_to.find(x); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
709 if (i != env_to.end()) return (*i).second; // found domain key |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
710 size_t len = x - to; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
711 char user[len+1]; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
712 memcpy(user, to, len); |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
713 user[len] = '\0'; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
714 i = env_to.find(user); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
715 if (i != env_to.end()) return (*i).second; // found user@ key |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
716 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
717 return default_context; |
94 | 718 } |
719 | |
720 | |
721 void CONFIG::dump() { | |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
722 bool spamass = false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
723 if (default_context) default_context->dump(true, spamass); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
724 for (context_list::iterator i=contexts.begin(); i!=contexts.end(); i++) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
725 CONTEXTP c = *i; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
726 CONTEXTP p = c->get_parent(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
727 if (!p && (c != default_context)) c->dump(false, spamass); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
728 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
729 char buf[maxlen]; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
730 for (context_map::iterator i=env_to.begin(); i!=env_to.end(); i++) { |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
731 const char *to = (*i).first; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
732 CONTEXTP con = (*i).second; |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
733 printf("// envelope to %s \t-> context %s \n", to, con->get_full_name(buf,maxlen)); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
734 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
735 if (spamass && (spamc == spamc_empty)) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
736 printf("// *** warning - spamassassin filtering requested, but spamc not found by autoconf.\n"); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
737 } |
94 | 738 } |
739 | |
740 | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
741 CONTEXT::CONTEXT(CONTEXTP parent_, const char *name_) { |
278
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
742 parent = parent_; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
743 name = name_; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
744 verify_host = NULL; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
745 verifier = NULL; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
746 generic_regx = NULL; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
747 generic_message = NULL; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
748 white_regx = NULL; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
749 autowhite_file = NULL; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
750 whitelister = NULL; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
751 env_from_default = (parent) ? token_inherit : token_unknown; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
752 content_filtering = (parent) ? parent->content_filtering : false; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
753 content_suffix = NULL; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
754 content_message = NULL; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
755 uribl_suffix = NULL; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
756 uribl_message = NULL; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
757 host_limit = (parent) ? parent->host_limit : 0; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
758 host_limit_message = NULL; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
759 host_random = (parent) ? parent->host_random : false; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
760 tag_limit = (parent) ? parent->tag_limit : 0; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
761 tag_limit_message = NULL; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
762 spamassassin_limit = (parent) ? parent->spamassassin_limit : 0; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
763 require_match = (parent) ? parent->require_match : false; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
764 require_rdns = (parent) ? parent->require_rdns : false; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
765 dcc_greylist = (parent) ? parent->dcc_greylist : false; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
766 dcc_bulk_threshold = (parent) ? parent->dcc_bulk_threshold : 0; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
767 dnsbl_list_parsed = false; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
768 dnswl_list_parsed = false; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
769 default_rate_limit = 36000; // 10 per second |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
770 default_address_limit = 10; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
771 daily_rate_multiple = 3; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
772 daily_address_multiple = 3; |
94 | 773 } |
774 | |
775 | |
776 CONTEXT::~CONTEXT() { | |
321
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
777 for (dkimp_map::iterator i=dkim_from_names.begin(); i!=dkim_from_names.end(); i++) { |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
778 DKIMP d = (*i).second; |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
779 // delete the underlying DKIM objects. |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
780 delete d; |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
781 } |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
782 for (dnsblp_map::iterator i=dnsbl_names.begin(); i!=dnsbl_names.end(); i++) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
783 DNSBLP d = (*i).second; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
784 // delete the underlying DNSBL objects. |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
785 delete d; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
786 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
787 if (generic_regx) regfree(&generic_pattern); |
233
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
788 if (white_regx) regfree(&white_pattern); |
94 | 789 } |
790 | |
791 | |
792 bool CONTEXT::is_parent(CONTEXTP p) { | |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
793 if (p == parent) return true; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
794 if (!parent) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
795 return parent->is_parent(p); |
94 | 796 } |
797 | |
798 | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
799 const char *CONTEXT::get_full_name(char *buffer, int size) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
800 if (!parent) return name; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
801 char buf[maxlen]; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
802 snprintf(buffer, size, "%s.%s", parent->get_full_name(buf, maxlen), name); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
803 return buffer; |
94 | 804 } |
805 | |
806 | |
233
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
807 bool CONTEXT::set_white(const char *regx) |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
808 { |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
809 int rc = 0; |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
810 if (white_regx) regfree(&white_pattern); |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
811 white_regx = regx; |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
812 if (white_regx) { |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
813 rc = regcomp(&white_pattern, regx, REG_NOSUB | REG_ICASE | REG_EXTENDED); |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
814 } |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
815 return rc; // true iff bad pattern |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
816 } |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
817 |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
818 |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
819 bool CONTEXT::white_match(const char *from) |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
820 { |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
821 return (from && |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
822 white_regx && |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
823 (0 == regexec(&white_pattern, from, 0, NULL, 0))); |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
824 } |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
825 |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
826 |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
827 bool CONTEXT::set_generic(const char *regx, const char *msg) |
168 | 828 { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
829 int rc = 0; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
830 if (generic_regx) regfree(&generic_pattern); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
831 generic_regx = regx; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
832 generic_message = msg; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
833 if (generic_regx) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
834 rc = regcomp(&generic_pattern, regx, REG_NOSUB | REG_ICASE | REG_EXTENDED); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
835 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
836 return rc; // true iff bad pattern |
168 | 837 } |
838 | |
839 | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
840 const char *CONTEXT::generic_match(const char *client) |
168 | 841 { |
195 | 842 if (!client) return NULL; // allow missing _ macro, which will disable generic checking |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
843 if (parent && !generic_regx) return parent->generic_match(client); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
844 if (!generic_regx) return NULL; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
845 if (0 == regexec(&generic_pattern, client, 0, NULL, 0)) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
846 return generic_message; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
847 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
848 return NULL; |
168 | 849 } |
850 | |
851 | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
852 bool CONTEXT::cover_env_to(const char *to) { |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
853 const char *x = strchr(to, '@'); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
854 if (x) x++; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
855 else x = to; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
856 if (*x == '\0') return true; // always allow covering addresses with no domain name, eg abuse@ |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
857 if (!parent && env_to.empty()) return true; // empty env_to at global level covers everything |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
858 string_set::iterator i = env_to.find(x); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
859 if (i != env_to.end()) return true; // we cover the entire domain |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
860 if (x != to) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
861 i = env_to.find(to); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
862 if (i != env_to.end()) return true; // we cover the specific email address |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
863 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
864 return false; |
94 | 865 } |
866 | |
867 | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
868 VERIFYP CONTEXT::find_verify(const char *to) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
869 if (verifier && (verify_host != token_myhostname) && cover_env_to(to)) |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
870 return verifier; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
871 else if (parent) |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
872 return parent->find_verify(to); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
873 else |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
874 return NULL; |
153 | 875 } |
94 | 876 |
153 | 877 |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
878 WHITELISTERP CONTEXT::find_autowhite(const char *from, const char *to) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
879 if (whitelister && cover_env_to(to) && !cover_env_to(from)) |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
880 return whitelister; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
881 else if (parent) |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
882 return parent->find_autowhite(from, to); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
883 else |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
884 return NULL; |
94 | 885 } |
886 | |
887 | |
278
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
888 int CONTEXT::find_rate_limit(const char *user) { |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
889 if (rcpt_per_hour.empty()) return default_rate_limit; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
890 rates::iterator i = rcpt_per_hour.find(user); // look for authen id, or sender user@email limiting |
259
be939802c64e
add recipient rate limits by email from address or domain
Carl Byington <carl@five-ten-sg.com>
parents:
255
diff
changeset
|
891 if (i != rcpt_per_hour.end()) return (*i).second; // found authen id, or user@email limiting |
be939802c64e
add recipient rate limits by email from address or domain
Carl Byington <carl@five-ten-sg.com>
parents:
255
diff
changeset
|
892 const char *f = strchr(user, '@'); |
278
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
893 if (!f) return default_rate_limit; |
259
be939802c64e
add recipient rate limits by email from address or domain
Carl Byington <carl@five-ten-sg.com>
parents:
255
diff
changeset
|
894 i = rcpt_per_hour.find(f); // look for @domain limiting |
be939802c64e
add recipient rate limits by email from address or domain
Carl Byington <carl@five-ten-sg.com>
parents:
255
diff
changeset
|
895 if (i != rcpt_per_hour.end()) return (*i).second; // found @domain limiting |
278
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
896 return default_rate_limit; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
897 } |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
898 |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
899 |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
900 int CONTEXT::find_address_limit(const char *user) { |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
901 if (addresses_per_hour.empty()) return default_address_limit; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
902 rates::iterator i = addresses_per_hour.find(user); // look for authen id, or sender user@email limiting |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
903 if (i != addresses_per_hour.end()) return (*i).second; // found authen id, or user@email limiting |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
904 const char *f = strchr(user, '@'); |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
905 if (!f) return default_address_limit; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
906 i = addresses_per_hour.find(f); // look for @domain limiting |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
907 if (i != addresses_per_hour.end()) return (*i).second; // found @domain limiting |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
908 return default_address_limit; |
259
be939802c64e
add recipient rate limits by email from address or domain
Carl Byington <carl@five-ten-sg.com>
parents:
255
diff
changeset
|
909 } |
be939802c64e
add recipient rate limits by email from address or domain
Carl Byington <carl@five-ten-sg.com>
parents:
255
diff
changeset
|
910 |
be939802c64e
add recipient rate limits by email from address or domain
Carl Byington <carl@five-ten-sg.com>
parents:
255
diff
changeset
|
911 |
be939802c64e
add recipient rate limits by email from address or domain
Carl Byington <carl@five-ten-sg.com>
parents:
255
diff
changeset
|
912 bool CONTEXT::is_unauthenticated_limited(const char *user) { |
278
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
913 rates::iterator i = rcpt_per_hour.find(user); // look for sender user@email limiting |
259
be939802c64e
add recipient rate limits by email from address or domain
Carl Byington <carl@five-ten-sg.com>
parents:
255
diff
changeset
|
914 if (i != rcpt_per_hour.end()) return true; // found user@email limiting |
be939802c64e
add recipient rate limits by email from address or domain
Carl Byington <carl@five-ten-sg.com>
parents:
255
diff
changeset
|
915 const char *f = strchr(user, '@'); |
266
582cfb9c4031
fix unauthenticated rate limit bug for empty mail from
Carl Byington <carl@five-ten-sg.com>
parents:
263
diff
changeset
|
916 if (!f) return false; |
259
be939802c64e
add recipient rate limits by email from address or domain
Carl Byington <carl@five-ten-sg.com>
parents:
255
diff
changeset
|
917 i = rcpt_per_hour.find(f); // look for sender @domain limiting |
be939802c64e
add recipient rate limits by email from address or domain
Carl Byington <carl@five-ten-sg.com>
parents:
255
diff
changeset
|
918 return (i != rcpt_per_hour.end()); // found @domain limiting |
136 | 919 } |
920 | |
921 | |
233
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
922 const char *CONTEXT::find_from(const char *from, bool update_white, const char *queueid) { |
211
4db1457cd11a
Extend auto-whitelisting when receiving mail even if the auto whitelist is specified in a parent context.
Carl Byington <carl@five-ten-sg.com>
parents:
203
diff
changeset
|
923 WHITELISTERP w = whitelister; |
4db1457cd11a
Extend auto-whitelisting when receiving mail even if the auto whitelist is specified in a parent context.
Carl Byington <carl@five-ten-sg.com>
parents:
203
diff
changeset
|
924 CONTEXTP p = parent; |
4db1457cd11a
Extend auto-whitelisting when receiving mail even if the auto whitelist is specified in a parent context.
Carl Byington <carl@five-ten-sg.com>
parents:
203
diff
changeset
|
925 while (!w && p) { |
4db1457cd11a
Extend auto-whitelisting when receiving mail even if the auto whitelist is specified in a parent context.
Carl Byington <carl@five-ten-sg.com>
parents:
203
diff
changeset
|
926 w = p->whitelister; |
4db1457cd11a
Extend auto-whitelisting when receiving mail even if the auto whitelist is specified in a parent context.
Carl Byington <carl@five-ten-sg.com>
parents:
203
diff
changeset
|
927 p = p->parent; |
4db1457cd11a
Extend auto-whitelisting when receiving mail even if the auto whitelist is specified in a parent context.
Carl Byington <carl@five-ten-sg.com>
parents:
203
diff
changeset
|
928 } |
4db1457cd11a
Extend auto-whitelisting when receiving mail even if the auto whitelist is specified in a parent context.
Carl Byington <carl@five-ten-sg.com>
parents:
203
diff
changeset
|
929 if (w && w->is_white(from)) { |
233
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
930 if (update_white && queueid) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
931 // update senders timestamp to extend the whitelisting period |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
932 if (debug_syslog > 1) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
933 char buf[maxlen]; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
934 char msg[maxlen]; |
233
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
935 snprintf(msg, sizeof(msg), "%s: extend whitelist reply from <%s> in context %s", queueid, from, get_full_name(buf,maxlen)); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
936 my_syslog(msg); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
937 } |
211
4db1457cd11a
Extend auto-whitelisting when receiving mail even if the auto whitelist is specified in a parent context.
Carl Byington <carl@five-ten-sg.com>
parents:
203
diff
changeset
|
938 w->sent(strdup(from)); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
939 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
940 return token_white; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
941 } |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
942 const char *rc = env_from_default; |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
943 string_map::iterator i = env_from.find(from); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
944 if (i != env_from.end()) rc = (*i).second; // found user@domain key |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
945 else { |
244
ef97c7cd4a6e
const correctness fixes from new gcc, libresolv.a moved to glibc-static on newer distributions
Carl Byington <carl@five-ten-sg.com>
parents:
233
diff
changeset
|
946 const char *x = strchr(from, '@'); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
947 if (x) { |
244
ef97c7cd4a6e
const correctness fixes from new gcc, libresolv.a moved to glibc-static on newer distributions
Carl Byington <carl@five-ten-sg.com>
parents:
233
diff
changeset
|
948 char buf[200]; |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
949 x++; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
950 i = env_from.find(x); |
244
ef97c7cd4a6e
const correctness fixes from new gcc, libresolv.a moved to glibc-static on newer distributions
Carl Byington <carl@five-ten-sg.com>
parents:
233
diff
changeset
|
951 size_t n = x - from; // length of user name plus @ |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
952 if (i != env_from.end()) rc = (*i).second; // found domain key |
244
ef97c7cd4a6e
const correctness fixes from new gcc, libresolv.a moved to glibc-static on newer distributions
Carl Byington <carl@five-ten-sg.com>
parents:
233
diff
changeset
|
953 else if (n < sizeof(buf)) { |
ef97c7cd4a6e
const correctness fixes from new gcc, libresolv.a moved to glibc-static on newer distributions
Carl Byington <carl@five-ten-sg.com>
parents:
233
diff
changeset
|
954 // we only test reasonably short user names, since we need |
ef97c7cd4a6e
const correctness fixes from new gcc, libresolv.a moved to glibc-static on newer distributions
Carl Byington <carl@five-ten-sg.com>
parents:
233
diff
changeset
|
955 // to copy them to a buffer to avoid a dup/free cycle on every |
ef97c7cd4a6e
const correctness fixes from new gcc, libresolv.a moved to glibc-static on newer distributions
Carl Byington <carl@five-ten-sg.com>
parents:
233
diff
changeset
|
956 // test here. |
ef97c7cd4a6e
const correctness fixes from new gcc, libresolv.a moved to glibc-static on newer distributions
Carl Byington <carl@five-ten-sg.com>
parents:
233
diff
changeset
|
957 strncpy(buf, from, n); |
ef97c7cd4a6e
const correctness fixes from new gcc, libresolv.a moved to glibc-static on newer distributions
Carl Byington <carl@five-ten-sg.com>
parents:
233
diff
changeset
|
958 buf[n] = '\0'; |
ef97c7cd4a6e
const correctness fixes from new gcc, libresolv.a moved to glibc-static on newer distributions
Carl Byington <carl@five-ten-sg.com>
parents:
233
diff
changeset
|
959 i = env_from.find(buf); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
960 if (i != env_from.end()) rc = (*i).second; // found user@ key |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
961 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
962 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
963 } |
233
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
964 if ((rc == token_inherit) || (rc == token_unknown)) { |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
965 bool ok = white_match(from); |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
966 if (ok) rc = token_white; |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
967 } |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
968 if ((rc == token_inherit) && parent) return parent->find_from(from); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
969 return (rc == token_inherit) ? token_unknown : rc; |
94 | 970 } |
971 | |
972 | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
973 CONTEXTP CONTEXT::find_context(const char *from) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
974 context_map::iterator i = env_from_context.find(from); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
975 if (i != env_from_context.end()) return (*i).second; // found user@domain key |
244
ef97c7cd4a6e
const correctness fixes from new gcc, libresolv.a moved to glibc-static on newer distributions
Carl Byington <carl@five-ten-sg.com>
parents:
233
diff
changeset
|
976 const char *x = strchr(from, '@'); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
977 if (x) { |
244
ef97c7cd4a6e
const correctness fixes from new gcc, libresolv.a moved to glibc-static on newer distributions
Carl Byington <carl@five-ten-sg.com>
parents:
233
diff
changeset
|
978 char buf[200]; |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
979 x++; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
980 i = env_from_context.find(x); |
244
ef97c7cd4a6e
const correctness fixes from new gcc, libresolv.a moved to glibc-static on newer distributions
Carl Byington <carl@five-ten-sg.com>
parents:
233
diff
changeset
|
981 size_t n = x - from; // length of user name plus @ |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
982 if (i != env_from_context.end()) return (*i).second; // found domain key |
244
ef97c7cd4a6e
const correctness fixes from new gcc, libresolv.a moved to glibc-static on newer distributions
Carl Byington <carl@five-ten-sg.com>
parents:
233
diff
changeset
|
983 else if (n < sizeof(buf)) { |
ef97c7cd4a6e
const correctness fixes from new gcc, libresolv.a moved to glibc-static on newer distributions
Carl Byington <carl@five-ten-sg.com>
parents:
233
diff
changeset
|
984 // we only test reasonably short user names, since we need |
ef97c7cd4a6e
const correctness fixes from new gcc, libresolv.a moved to glibc-static on newer distributions
Carl Byington <carl@five-ten-sg.com>
parents:
233
diff
changeset
|
985 // to copy them to a buffer to avoid a dup/free cycle on every |
ef97c7cd4a6e
const correctness fixes from new gcc, libresolv.a moved to glibc-static on newer distributions
Carl Byington <carl@five-ten-sg.com>
parents:
233
diff
changeset
|
986 // test here. |
ef97c7cd4a6e
const correctness fixes from new gcc, libresolv.a moved to glibc-static on newer distributions
Carl Byington <carl@five-ten-sg.com>
parents:
233
diff
changeset
|
987 strncpy(buf, from, n); |
ef97c7cd4a6e
const correctness fixes from new gcc, libresolv.a moved to glibc-static on newer distributions
Carl Byington <carl@five-ten-sg.com>
parents:
233
diff
changeset
|
988 buf[n] = '\0'; |
ef97c7cd4a6e
const correctness fixes from new gcc, libresolv.a moved to glibc-static on newer distributions
Carl Byington <carl@five-ten-sg.com>
parents:
233
diff
changeset
|
989 i = env_from_context.find(buf); |
ef97c7cd4a6e
const correctness fixes from new gcc, libresolv.a moved to glibc-static on newer distributions
Carl Byington <carl@five-ten-sg.com>
parents:
233
diff
changeset
|
990 if (i != env_from_context.end()) return (*i).second; // found user@ key |
ef97c7cd4a6e
const correctness fixes from new gcc, libresolv.a moved to glibc-static on newer distributions
Carl Byington <carl@five-ten-sg.com>
parents:
233
diff
changeset
|
991 } |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
992 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
993 return this; |
94 | 994 } |
995 | |
996 | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
997 CONTEXTP CONTEXT::find_from_context_name(const char *name) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
998 context_map::iterator i = children.find(name); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
999 if (i != children.end()) return (*i).second; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1000 return NULL; |
94 | 1001 } |
1002 | |
1003 | |
321
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
1004 const char *CONTEXT::find_dkim_signer(const char *name) { |
332
ed04479a8e12
allow missing domain in header from value
Carl Byington <carl@five-ten-sg.com>
parents:
331
diff
changeset
|
1005 if (!name) return NULL; |
321
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
1006 string_map::iterator i = dkim_signer_names.find(name); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
1007 if (i != dkim_signer_names.end()) return (*i).second; |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
1008 if (parent) return parent->find_dkim_signer(name); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
1009 return NULL; |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
1010 } |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
1011 |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
1012 |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
1013 DKIMP CONTEXT::find_dkim_from(const char *name) { |
332
ed04479a8e12
allow missing domain in header from value
Carl Byington <carl@five-ten-sg.com>
parents:
331
diff
changeset
|
1014 if (!name) return NULL; |
321
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
1015 dkimp_map::iterator i = dkim_from_names.find(name); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
1016 if (i != dkim_from_names.end()) return (*i).second; |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
1017 if (parent) return parent->find_dkim_from(name); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
1018 return NULL; |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
1019 } |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
1020 |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
1021 |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1022 DNSBLP CONTEXT::find_dnsbl(const char *name) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1023 dnsblp_map::iterator i = dnsbl_names.find(name); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1024 if (i != dnsbl_names.end()) return (*i).second; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1025 if (parent) return parent->find_dnsbl(name); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1026 return NULL; |
94 | 1027 } |
1028 | |
1029 | |
249 | 1030 DNSWLP CONTEXT::find_dnswl(const char *name) { |
1031 dnswlp_map::iterator i = dnswl_names.find(name); | |
1032 if (i != dnswl_names.end()) return (*i).second; | |
1033 if (parent) return parent->find_dnswl(name); | |
1034 return NULL; | |
1035 } | |
1036 | |
1037 | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1038 const char* CONTEXT::get_content_suffix() { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1039 if (!content_suffix && parent) return parent->get_content_suffix(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1040 return content_suffix; |
94 | 1041 } |
1042 | |
1043 | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1044 const char* CONTEXT::get_uribl_suffix() { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1045 if (!uribl_suffix && parent) return parent->get_uribl_suffix(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1046 return uribl_suffix; |
119 | 1047 } |
1048 | |
1049 | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1050 const char* CONTEXT::get_content_message() { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1051 if (!content_message && parent) return parent->get_content_message(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1052 return content_message; |
94 | 1053 } |
1054 | |
1055 | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1056 const char* CONTEXT::get_uribl_message() { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1057 if (!uribl_message && parent) return parent->get_uribl_message(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1058 return uribl_message; |
119 | 1059 } |
1060 | |
1061 | |
94 | 1062 string_set& CONTEXT::get_content_host_ignore() { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1063 if (content_host_ignore.empty() && parent) return parent->get_content_host_ignore(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1064 return content_host_ignore; |
94 | 1065 } |
1066 | |
1067 | |
1068 string_set& CONTEXT::get_content_tlds() { | |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1069 if (content_tlds.empty() && parent) return parent->get_content_tlds(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1070 return content_tlds; |
94 | 1071 } |
1072 | |
1073 | |
270
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1074 string_set& CONTEXT::get_content_tldwilds() { |
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1075 if (content_tldwilds.empty() && parent) return parent->get_content_tldwilds(); |
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1076 return content_tldwilds; |
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1077 } |
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1078 |
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1079 |
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1080 string_set& CONTEXT::get_content_tldnots() { |
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1081 if (content_tldnots.empty() && parent) return parent->get_content_tldnots(); |
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1082 return content_tldnots; |
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1083 } |
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1084 |
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1085 |
94 | 1086 string_set& CONTEXT::get_html_tags() { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1087 if (html_tags.empty() && parent) return parent->get_html_tags(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1088 return html_tags; |
94 | 1089 } |
1090 | |
1091 | |
1092 dnsblp_list& CONTEXT::get_dnsbl_list() { | |
255
d6d5c50b9278
Allow dnswl_list and dnsbl_list to be empty, to override lists specified in the ancestor contexts. Add daily recipient limits as a multiple of the hourly limits.
Carl Byington <carl@five-ten-sg.com>
parents:
249
diff
changeset
|
1093 if (!dnsbl_list_parsed && parent) return parent->get_dnsbl_list(); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1094 return dnsbl_list; |
94 | 1095 } |
1096 | |
1097 | |
249 | 1098 dnswlp_list& CONTEXT::get_dnswl_list() { |
255
d6d5c50b9278
Allow dnswl_list and dnsbl_list to be empty, to override lists specified in the ancestor contexts. Add daily recipient limits as a multiple of the hourly limits.
Carl Byington <carl@five-ten-sg.com>
parents:
249
diff
changeset
|
1099 if (!dnswl_list_parsed && parent) return parent->get_dnswl_list(); |
249 | 1100 return dnswl_list; |
1101 } | |
1102 | |
1103 | |
329
c9932c4d8053
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
326
diff
changeset
|
1104 void CONTEXT::log(const char *queueid, const char *msg, const char *v) { |
330
b5b93a7e1e6d
ignore envelope-from based whitelisting if we have a dkim requirement for that domain
Carl Byington <carl@five-ten-sg.com>
parents:
329
diff
changeset
|
1105 if (debug_syslog > 1) { |
b5b93a7e1e6d
ignore envelope-from based whitelisting if we have a dkim requirement for that domain
Carl Byington <carl@five-ten-sg.com>
parents:
329
diff
changeset
|
1106 char buf[maxlen]; |
b5b93a7e1e6d
ignore envelope-from based whitelisting if we have a dkim requirement for that domain
Carl Byington <carl@five-ten-sg.com>
parents:
329
diff
changeset
|
1107 snprintf(buf, maxlen, msg, v); |
b5b93a7e1e6d
ignore envelope-from based whitelisting if we have a dkim requirement for that domain
Carl Byington <carl@five-ten-sg.com>
parents:
329
diff
changeset
|
1108 my_syslog(queueid, buf); |
b5b93a7e1e6d
ignore envelope-from based whitelisting if we have a dkim requirement for that domain
Carl Byington <carl@five-ten-sg.com>
parents:
329
diff
changeset
|
1109 } |
329
c9932c4d8053
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
326
diff
changeset
|
1110 } |
c9932c4d8053
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
326
diff
changeset
|
1111 |
c9932c4d8053
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
326
diff
changeset
|
1112 |
331
9800776436b9
allow dkim whitelisting to override uribl hosts in the mail body
Carl Byington <carl@five-ten-sg.com>
parents:
330
diff
changeset
|
1113 const char *CONTEXT::acceptable_content(recorder &memory, int score, int bulk, const char *queueid, string_set &signers, const char *from, string& msg) { |
322
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1114 DKIMP dk = find_dkim_from(from); |
326
5e4b5540c8cc
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
324
diff
changeset
|
1115 bool requirement = false; |
5e4b5540c8cc
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
324
diff
changeset
|
1116 for (string_set::iterator s=signers.begin(); s!=signers.end(); s++) { |
5e4b5540c8cc
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
324
diff
changeset
|
1117 const char *st = find_dkim_signer(*s); |
322
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1118 // signed by a white listed signer |
329
c9932c4d8053
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
326
diff
changeset
|
1119 if (st == token_white) { |
c9932c4d8053
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
326
diff
changeset
|
1120 log(queueid, "whitelisted dkim signer %s", *s); |
331
9800776436b9
allow dkim whitelisting to override uribl hosts in the mail body
Carl Byington <carl@five-ten-sg.com>
parents:
330
diff
changeset
|
1121 return token_white; |
329
c9932c4d8053
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
326
diff
changeset
|
1122 } |
326
5e4b5540c8cc
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
324
diff
changeset
|
1123 // signed by a black listed signer |
5e4b5540c8cc
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
324
diff
changeset
|
1124 if (st == token_black) { |
322
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1125 char buf[maxlen]; |
326
5e4b5540c8cc
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
324
diff
changeset
|
1126 snprintf(buf, sizeof(buf), "Mail rejected - dkim signed by %s", *s); |
322
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1127 msg = string(buf); |
331
9800776436b9
allow dkim whitelisting to override uribl hosts in the mail body
Carl Byington <carl@five-ten-sg.com>
parents:
330
diff
changeset
|
1128 return token_black; |
322
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1129 } |
326
5e4b5540c8cc
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
324
diff
changeset
|
1130 |
5e4b5540c8cc
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
324
diff
changeset
|
1131 if (dk) { |
5e4b5540c8cc
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
324
diff
changeset
|
1132 st = dk->action; |
5e4b5540c8cc
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
324
diff
changeset
|
1133 // signed by a white listed signer |
329
c9932c4d8053
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
326
diff
changeset
|
1134 if ((st == token_signed_white) && (strcasecmp(*s,dk->signer) == 0)) { |
c9932c4d8053
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
326
diff
changeset
|
1135 log(queueid, "whitelisted dkim signer %s", *s); |
331
9800776436b9
allow dkim whitelisting to override uribl hosts in the mail body
Carl Byington <carl@five-ten-sg.com>
parents:
330
diff
changeset
|
1136 return token_white; |
329
c9932c4d8053
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
326
diff
changeset
|
1137 } |
c9932c4d8053
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
326
diff
changeset
|
1138 // signed by the required signer |
c9932c4d8053
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
326
diff
changeset
|
1139 if ((st == token_require_signed) && (strcasecmp(*s,dk->signer) == 0)) { |
c9932c4d8053
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
326
diff
changeset
|
1140 log(queueid, "required dkim signer %s", *s); |
c9932c4d8053
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
326
diff
changeset
|
1141 requirement = true; |
c9932c4d8053
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
326
diff
changeset
|
1142 } |
326
5e4b5540c8cc
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
324
diff
changeset
|
1143 // signed by a black listed signer |
5e4b5540c8cc
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
324
diff
changeset
|
1144 if ((st == token_signed_black) && (strcasecmp(*s,dk->signer) == 0)) { |
5e4b5540c8cc
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
324
diff
changeset
|
1145 char buf[maxlen]; |
5e4b5540c8cc
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
324
diff
changeset
|
1146 snprintf(buf, sizeof(buf), "Mail rejected - dkim signed by %s", dk->signer); |
5e4b5540c8cc
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
324
diff
changeset
|
1147 msg = string(buf); |
331
9800776436b9
allow dkim whitelisting to override uribl hosts in the mail body
Carl Byington <carl@five-ten-sg.com>
parents:
330
diff
changeset
|
1148 return token_black; |
326
5e4b5540c8cc
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
324
diff
changeset
|
1149 } |
322
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1150 } |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1151 } |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1152 |
331
9800776436b9
allow dkim whitelisting to override uribl hosts in the mail body
Carl Byington <carl@five-ten-sg.com>
parents:
330
diff
changeset
|
1153 if (dk && (dk->action == token_require_signed)) { |
9800776436b9
allow dkim whitelisting to override uribl hosts in the mail body
Carl Byington <carl@five-ten-sg.com>
parents:
330
diff
changeset
|
1154 if (requirement) return token_white; |
9800776436b9
allow dkim whitelisting to override uribl hosts in the mail body
Carl Byington <carl@five-ten-sg.com>
parents:
330
diff
changeset
|
1155 else { |
9800776436b9
allow dkim whitelisting to override uribl hosts in the mail body
Carl Byington <carl@five-ten-sg.com>
parents:
330
diff
changeset
|
1156 char buf[maxlen]; |
9800776436b9
allow dkim whitelisting to override uribl hosts in the mail body
Carl Byington <carl@five-ten-sg.com>
parents:
330
diff
changeset
|
1157 snprintf(buf, sizeof(buf), "Mail rejected - not dkim signed by %s", dk->signer); |
9800776436b9
allow dkim whitelisting to override uribl hosts in the mail body
Carl Byington <carl@five-ten-sg.com>
parents:
330
diff
changeset
|
1158 msg = string(buf); |
9800776436b9
allow dkim whitelisting to override uribl hosts in the mail body
Carl Byington <carl@five-ten-sg.com>
parents:
330
diff
changeset
|
1159 return token_black; |
9800776436b9
allow dkim whitelisting to override uribl hosts in the mail body
Carl Byington <carl@five-ten-sg.com>
parents:
330
diff
changeset
|
1160 } |
326
5e4b5540c8cc
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
324
diff
changeset
|
1161 } |
5e4b5540c8cc
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
324
diff
changeset
|
1162 |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1163 if (spamassassin_limit && (score > spamassassin_limit)) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1164 char buf[maxlen]; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1165 snprintf(buf, sizeof(buf), "Mail rejected - spam assassin score %d", score); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1166 msg = string(buf); |
331
9800776436b9
allow dkim whitelisting to override uribl hosts in the mail body
Carl Byington <carl@five-ten-sg.com>
parents:
330
diff
changeset
|
1167 return token_black; |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1168 } |
203
92a5c866bdfa
Verify from/to pairs even if they might be explicitly whitelisted.
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
1169 if (dcc_bulk_threshold && (bulk >= dcc_bulk_threshold)) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1170 char buf[maxlen]; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1171 snprintf(buf, sizeof(buf), "Mail rejected - dcc score %d", bulk); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1172 msg = string(buf); |
331
9800776436b9
allow dkim whitelisting to override uribl hosts in the mail body
Carl Byington <carl@five-ten-sg.com>
parents:
330
diff
changeset
|
1173 return token_black; |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1174 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1175 if (memory.excessive_bad_tags(tag_limit)) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1176 msg = string(tag_limit_message); |
331
9800776436b9
allow dkim whitelisting to override uribl hosts in the mail body
Carl Byington <carl@five-ten-sg.com>
parents:
330
diff
changeset
|
1177 return token_black; |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1178 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1179 if (!host_random && memory.excessive_hosts(host_limit)) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1180 msg = string(host_limit_message); |
331
9800776436b9
allow dkim whitelisting to override uribl hosts in the mail body
Carl Byington <carl@five-ten-sg.com>
parents:
330
diff
changeset
|
1181 return token_black; |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1182 } |
331
9800776436b9
allow dkim whitelisting to override uribl hosts in the mail body
Carl Byington <carl@five-ten-sg.com>
parents:
330
diff
changeset
|
1183 return token_unknown; |
94 | 1184 } |
1185 | |
1186 | |
167
9b129ed78d7d
actually use spamassassin result, allow build without spam assassin, only call it if some recipient needs it.
carl
parents:
164
diff
changeset
|
1187 void CONTEXT::dump(bool isdefault, bool &spamass, int level) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1188 char indent[maxlen]; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1189 int i = min(maxlen-1, level*4); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1190 memset(indent, ' ', i); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1191 indent[i] = '\0'; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1192 char buf[maxlen]; |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1193 const char *fullname = get_full_name(buf,maxlen); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1194 printf("%s context %s { \t// %s\n", indent, name, fullname); |
94 | 1195 |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1196 for (dnsblp_map::iterator i=dnsbl_names.begin(); i!=dnsbl_names.end(); i++) { |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1197 const char *n = (*i).first; |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1198 DNSBL &d = *(*i).second; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1199 printf("%s dnsbl %s %s \"%s\"; \n", indent, n, d.suffix, d.message); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1200 } |
94 | 1201 |
249 | 1202 for (dnswlp_map::iterator i=dnswl_names.begin(); i!=dnswl_names.end(); i++) { |
1203 const char *n = (*i).first; | |
1204 DNSWL &d = *(*i).second; | |
1205 printf("%s dnswl %s %s %d; \n", indent, n, d.suffix, d.level); | |
1206 } | |
1207 | |
1208 { | |
255
d6d5c50b9278
Allow dnswl_list and dnsbl_list to be empty, to override lists specified in the ancestor contexts. Add daily recipient limits as a multiple of the hourly limits.
Carl Byington <carl@five-ten-sg.com>
parents:
249
diff
changeset
|
1209 dnsblp_list dl = get_dnsbl_list(); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1210 printf("%s dnsbl_list", indent); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1211 for (dnsblp_list::iterator i=dl.begin(); i!=dl.end(); i++) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1212 DNSBL &d = *(*i); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1213 printf(" %s", d.name); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1214 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1215 printf("; \n"); |
268
f941563c2a95
Add require_rdns checking
Carl Byington <carl@five-ten-sg.com>
parents:
266
diff
changeset
|
1216 printf("%s require_rdns %s; \n", indent, (require_rdns) ? "yes" : "no"); |
255
d6d5c50b9278
Allow dnswl_list and dnsbl_list to be empty, to override lists specified in the ancestor contexts. Add daily recipient limits as a multiple of the hourly limits.
Carl Byington <carl@five-ten-sg.com>
parents:
249
diff
changeset
|
1217 } |
249 | 1218 |
1219 { | |
255
d6d5c50b9278
Allow dnswl_list and dnsbl_list to be empty, to override lists specified in the ancestor contexts. Add daily recipient limits as a multiple of the hourly limits.
Carl Byington <carl@five-ten-sg.com>
parents:
249
diff
changeset
|
1220 dnswlp_list dl = get_dnswl_list(); |
249 | 1221 printf("%s dnswl_list", indent); |
1222 for (dnswlp_list::iterator i=dl.begin(); i!=dl.end(); i++) { | |
1223 DNSWL &d = *(*i); | |
1224 printf(" %s", d.name); | |
1225 } | |
1226 printf("; \n"); | |
255
d6d5c50b9278
Allow dnswl_list and dnsbl_list to be empty, to override lists specified in the ancestor contexts. Add daily recipient limits as a multiple of the hourly limits.
Carl Byington <carl@five-ten-sg.com>
parents:
249
diff
changeset
|
1227 } |
94 | 1228 |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1229 if (content_filtering) { |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1230 printf("%s content on { \n", indent); |
322
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1231 printf("%s dkim_signer { \n", indent); |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1232 for (string_map::iterator i=dkim_signer_names.begin(); i!=dkim_signer_names.end(); i++) { |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1233 const char *n = (*i).first; |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1234 const char *a = (*i).second; |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1235 printf("%s %s %s; \n", indent, n, a); |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1236 } |
329
c9932c4d8053
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
326
diff
changeset
|
1237 printf("%s }; \n", indent); |
322
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1238 printf("%s dkim_from { \n", indent); |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1239 for (dkimp_map::iterator i=dkim_from_names.begin(); i!=dkim_from_names.end(); i++) { |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1240 const char *n = (*i).first; |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1241 DKIM &d = *(*i).second; |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1242 printf("%s %s %s %s; \n", indent, n, d.action, d.signer); |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1243 } |
329
c9932c4d8053
allow multiple dkim signers in authentication results
Carl Byington <carl@five-ten-sg.com>
parents:
326
diff
changeset
|
1244 printf("%s }; \n", indent); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1245 if (content_suffix) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1246 printf("%s filter %s \"%s\"; \n", indent, content_suffix, content_message); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1247 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1248 if (uribl_suffix) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1249 printf("%s uribl %s \"%s\"; \n", indent, uribl_suffix, uribl_message); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1250 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1251 if (!content_host_ignore.empty()) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1252 printf("%s ignore { \n", indent); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1253 for (string_set::iterator i=content_host_ignore.begin(); i!=content_host_ignore.end(); i++) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1254 printf("%s %s; \n", indent, *i); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1255 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1256 printf("%s }; \n", indent); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1257 } |
270
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1258 if (!content_tlds.empty() || !content_tldwilds.empty() || !content_tldnots.empty()) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1259 printf("%s tld { \n", indent); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1260 printf("%s ", indent); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1261 for (string_set::iterator i=content_tlds.begin(); i!=content_tlds.end(); i++) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1262 printf("%s; ", *i); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1263 } |
270
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1264 for (string_set::iterator i=content_tldwilds.begin(); i!=content_tldwilds.end(); i++) { |
274
bdcf203e3f7b
fix -c printing config
Carl Byington <carl@five-ten-sg.com>
parents:
272
diff
changeset
|
1265 printf("*.%s; ", *i); |
270
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1266 } |
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1267 for (string_set::iterator i=content_tldnots.begin(); i!=content_tldnots.end(); i++) { |
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1268 printf("!%s; ", *i); |
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1269 } |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1270 printf("\n%s }; \n", indent); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1271 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1272 if (!html_tags.empty()) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1273 printf("%s html_tags { \n", indent); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1274 printf("%s ", indent); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1275 for (string_set::iterator i=html_tags.begin(); i!=html_tags.end(); i++) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1276 printf("%s; ", *i); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1277 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1278 printf("\n%s }; \n", indent); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1279 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1280 if (host_limit_message) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1281 printf("%s host_limit on %d \"%s\"; \n", indent, host_limit, host_limit_message); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1282 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1283 else if (host_random) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1284 printf("%s host_limit soft %d; \n", indent, host_limit); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1285 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1286 else { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1287 printf("%s host_limit off; \n", indent); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1288 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1289 if (tag_limit_message) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1290 printf("%s html_limit on %d \"%s\"; \n", indent, tag_limit, tag_limit_message); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1291 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1292 else { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1293 printf("%s html_limit off; \n", indent); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1294 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1295 printf("%s spamassassin %d; \n", indent, spamassassin_limit); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1296 printf("%s require_match %s; \n", indent, (require_match) ? "yes" : "no"); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1297 printf("%s dcc_greylist %s; \n", indent, (dcc_greylist) ? "yes" : "no"); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1298 if (dcc_bulk_threshold == 0) printf("%s dcc_bulk_threshold off; \n", indent); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1299 else if (dcc_bulk_threshold >= dccbulk) printf("%s dcc_bulk_threshold many; \n", indent); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1300 else printf("%s dcc_bulk_threshold %d; \n", indent, dcc_bulk_threshold); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1301 printf("%s }; \n", indent); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1302 spamass |= (spamassassin_limit != 0); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1303 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1304 else { |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1305 printf("%s content off {}; \n", indent); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1306 } |
94 | 1307 |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1308 printf("%s env_to { \t// %s\n", indent, fullname); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1309 for (string_set::iterator i=env_to.begin(); i!=env_to.end(); i++) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1310 printf("%s %s; \n", indent, *i); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1311 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1312 printf("%s }; \n", indent); |
94 | 1313 |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1314 if (verify_host) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1315 printf("%s verify %s; \n", indent, verify_host); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1316 } |
94 | 1317 |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1318 if (generic_regx) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1319 printf("%s generic \"%s\" \n", indent, generic_regx); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1320 printf("%s \"%s\"; \n", indent, generic_message); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1321 } |
168 | 1322 |
233
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
1323 if (white_regx) { |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
1324 printf("%s white_regex \"%s\"; \n", indent, white_regx); |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
1325 } |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
1326 |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1327 if (autowhite_file && whitelister) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1328 printf("%s autowhite %d %s; \n", indent, whitelister->get_days(), autowhite_file); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1329 } |
153 | 1330 |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1331 for (context_map::iterator i=children.begin(); i!=children.end(); i++) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1332 CONTEXTP c = (*i).second; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1333 c->dump(false, spamass, level+1); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1334 } |
94 | 1335 |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1336 printf("%s env_from %s { \t// %s\n", indent, env_from_default, fullname); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1337 if (!env_from.empty()) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1338 printf("%s // white/black/unknown \n", indent); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1339 for (string_map::iterator i=env_from.begin(); i!=env_from.end(); i++) { |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1340 const char *f = (*i).first; |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1341 const char *t = (*i).second; |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1342 printf("%s %s \t%s; \n", indent, f, t); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1343 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1344 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1345 if (!env_from_context.empty()) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1346 printf("%s // child contexts \n", indent); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1347 for (context_map::iterator j=env_from_context.begin(); j!=env_from_context.end(); j++) { |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1348 const char *f = (*j).first; |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1349 CONTEXTP t = (*j).second; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1350 printf("%s %s \t%s; \n", indent, f, t->name); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1351 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1352 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1353 printf("%s }; \n", indent); |
94 | 1354 |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1355 if (isdefault) { |
278
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
1356 printf("%s rate_limit %d %d %d %d { \n", indent, default_rate_limit, daily_rate_multiple, default_address_limit, daily_address_multiple); |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
1357 for (rates::iterator j=rcpt_per_hour.begin(); j!=rcpt_per_hour.end(); j++) { |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
1358 const char *u = (*j).first; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
1359 int l = (*j).second; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
1360 rates::iterator k = addresses_per_hour.find(u); |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
1361 int a = (k==addresses_per_hour.end()) ? default_address_limit : (*k).second; |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
1362 printf("%s \"%s\" \t%d %d; \n", indent, u, l, a); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1363 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1364 printf("%s }; \n", indent); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1365 } |
136 | 1366 |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1367 printf("%s }; \n", indent); |
94 | 1368 } |
1369 | |
1370 | |
1371 //////////////////////////////////////////////// | |
1372 // helper to discard the strings held by a string_set | |
1373 // | |
1374 void discard(string_set &s) { | |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1375 for (string_set::iterator i=s.begin(); i!=s.end(); i++) { |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1376 free((void*)*i); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1377 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1378 s.clear(); |
94 | 1379 } |
1380 | |
1381 | |
1382 //////////////////////////////////////////////// | |
1383 // helper to register a string in a string set | |
1384 // | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1385 const char* register_string(string_set &s, const char *name) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1386 string_set::iterator i = s.find(name); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1387 if (i != s.end()) return *i; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1388 char *x = strdup(name); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1389 s.insert(x); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1390 return x; |
94 | 1391 } |
1392 | |
1393 | |
1394 //////////////////////////////////////////////// | |
1395 // register a global string | |
1396 // | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1397 const char* register_string(const char *name) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1398 return register_string(all_strings, name); |
94 | 1399 } |
1400 | |
1401 | |
1402 //////////////////////////////////////////////// | |
164 | 1403 // clear all global strings, helper for valgrind checking |
1404 // | |
1405 void clear_strings() { | |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1406 discard(all_strings); |
164 | 1407 } |
1408 | |
1409 | |
1410 //////////////////////////////////////////////// | |
94 | 1411 // |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1412 bool tsa(TOKEN &tok, const char *token); |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1413 bool tsa(TOKEN &tok, const char *token) { |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1414 const char *have = tok.next(); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1415 if (have == token) return true; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1416 tok.token_error(token, have); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1417 return false; |
94 | 1418 } |
1419 | |
1420 | |
1421 //////////////////////////////////////////////// | |
1422 // | |
1423 bool parse_dnsbl(TOKEN &tok, CONFIG &dc, CONTEXT &me); | |
1424 bool parse_dnsbl(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1425 const char *name = tok.next(); |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1426 const char *suf = tok.next(); |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1427 const char *msg = tok.next(); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1428 if (!tsa(tok, token_semi)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1429 DNSBLP dnsnew = new DNSBL(name, suf, msg); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1430 DNSBLP dnsold = me.find_dnsbl(name); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1431 if (dnsold && (*dnsold == *dnsnew)) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1432 // duplicate redefinition, ignore it |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1433 delete dnsnew; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1434 return true; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1435 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1436 me.add_dnsbl(name, dnsnew); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1437 return true; |
94 | 1438 } |
1439 | |
1440 | |
1441 //////////////////////////////////////////////// | |
1442 // | |
249 | 1443 bool parse_dnswl(TOKEN &tok, CONFIG &dc, CONTEXT &me); |
1444 bool parse_dnswl(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
1445 const char *name = tok.next(); | |
1446 const char *suf = tok.next(); | |
1447 const int lev = tok.nextint(); | |
1448 if (!tsa(tok, token_semi)) return false; | |
1449 DNSWLP dnsnew = new DNSWL(name, suf, lev); | |
1450 DNSWLP dnsold = me.find_dnswl(name); | |
1451 if (dnsold && (*dnsold == *dnsnew)) { | |
1452 // duplicate redefinition, ignore it | |
1453 delete dnsnew; | |
1454 return true; | |
1455 } | |
1456 me.add_dnswl(name, dnsnew); | |
1457 return true; | |
1458 } | |
1459 | |
1460 | |
1461 //////////////////////////////////////////////// | |
1462 // | |
94 | 1463 bool parse_dnsbll(TOKEN &tok, CONFIG &dc, CONTEXT &me); |
1464 bool parse_dnsbll(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1465 while (true) { |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1466 const char *have = tok.next(); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1467 if (!have) break; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1468 if (have == token_semi) break; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1469 DNSBLP dns = me.find_dnsbl(have); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1470 if (dns) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1471 me.add_dnsbl(dns); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1472 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1473 else { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1474 tok.token_error("dnsbl name", have); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1475 return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1476 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1477 } |
255
d6d5c50b9278
Allow dnswl_list and dnsbl_list to be empty, to override lists specified in the ancestor contexts. Add daily recipient limits as a multiple of the hourly limits.
Carl Byington <carl@five-ten-sg.com>
parents:
249
diff
changeset
|
1478 me.set_dnsbll_parsed(); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1479 return true; |
94 | 1480 } |
1481 | |
1482 | |
1483 //////////////////////////////////////////////// | |
1484 // | |
249 | 1485 bool parse_dnswll(TOKEN &tok, CONFIG &dc, CONTEXT &me); |
1486 bool parse_dnswll(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
1487 while (true) { | |
1488 const char *have = tok.next(); | |
1489 if (!have) break; | |
1490 if (have == token_semi) break; | |
1491 DNSWLP dns = me.find_dnswl(have); | |
1492 if (dns) { | |
1493 me.add_dnswl(dns); | |
1494 } | |
1495 else { | |
1496 tok.token_error("dnswl name", have); | |
1497 return false; | |
1498 } | |
1499 } | |
255
d6d5c50b9278
Allow dnswl_list and dnsbl_list to be empty, to override lists specified in the ancestor contexts. Add daily recipient limits as a multiple of the hourly limits.
Carl Byington <carl@five-ten-sg.com>
parents:
249
diff
changeset
|
1500 me.set_dnswll_parsed(); |
249 | 1501 return true; |
1502 } | |
1503 | |
1504 | |
1505 //////////////////////////////////////////////// | |
1506 // | |
268
f941563c2a95
Add require_rdns checking
Carl Byington <carl@five-ten-sg.com>
parents:
266
diff
changeset
|
1507 bool parse_requirerdns(TOKEN &tok, CONFIG &dc, CONTEXT &me); |
f941563c2a95
Add require_rdns checking
Carl Byington <carl@five-ten-sg.com>
parents:
266
diff
changeset
|
1508 bool parse_requirerdns(TOKEN &tok, CONFIG &dc, CONTEXT &me) { |
f941563c2a95
Add require_rdns checking
Carl Byington <carl@five-ten-sg.com>
parents:
266
diff
changeset
|
1509 const char *have = tok.next(); |
f941563c2a95
Add require_rdns checking
Carl Byington <carl@five-ten-sg.com>
parents:
266
diff
changeset
|
1510 if (have == token_yes) me.set_requirerdns(true); |
f941563c2a95
Add require_rdns checking
Carl Byington <carl@five-ten-sg.com>
parents:
266
diff
changeset
|
1511 else if (have == token_no) me.set_requirerdns(false); |
f941563c2a95
Add require_rdns checking
Carl Byington <carl@five-ten-sg.com>
parents:
266
diff
changeset
|
1512 else { |
f941563c2a95
Add require_rdns checking
Carl Byington <carl@five-ten-sg.com>
parents:
266
diff
changeset
|
1513 tok.token_error("yes/no", have); |
f941563c2a95
Add require_rdns checking
Carl Byington <carl@five-ten-sg.com>
parents:
266
diff
changeset
|
1514 return false; |
f941563c2a95
Add require_rdns checking
Carl Byington <carl@five-ten-sg.com>
parents:
266
diff
changeset
|
1515 } |
f941563c2a95
Add require_rdns checking
Carl Byington <carl@five-ten-sg.com>
parents:
266
diff
changeset
|
1516 if (!tsa(tok, token_semi)) return false; |
f941563c2a95
Add require_rdns checking
Carl Byington <carl@five-ten-sg.com>
parents:
266
diff
changeset
|
1517 return true; |
f941563c2a95
Add require_rdns checking
Carl Byington <carl@five-ten-sg.com>
parents:
266
diff
changeset
|
1518 } |
f941563c2a95
Add require_rdns checking
Carl Byington <carl@five-ten-sg.com>
parents:
266
diff
changeset
|
1519 |
f941563c2a95
Add require_rdns checking
Carl Byington <carl@five-ten-sg.com>
parents:
266
diff
changeset
|
1520 |
f941563c2a95
Add require_rdns checking
Carl Byington <carl@five-ten-sg.com>
parents:
266
diff
changeset
|
1521 //////////////////////////////////////////////// |
f941563c2a95
Add require_rdns checking
Carl Byington <carl@five-ten-sg.com>
parents:
266
diff
changeset
|
1522 // |
322
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1523 bool parse_dkim_signer(TOKEN &tok, CONFIG &dc, CONTEXT &me); |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1524 bool parse_dkim_signer(TOKEN &tok, CONFIG &dc, CONTEXT &me) { |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1525 if (!tsa(tok, token_lbrace)) return false; |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1526 while (true) { |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1527 const char *have = tok.next(); |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1528 if (!have) break; |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1529 if (have == token_rbrace) break; |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1530 if (have == token_semi) { |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1531 // optional separators |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1532 } |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1533 else { |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1534 const char *signer = have; |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1535 const char *action = tok.next(); |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1536 if ((action == token_white) || (action == token_black)) { |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1537 me.add_dkim_signer(signer, action); |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1538 } |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1539 else { |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1540 tok.token_error("white/black", action); |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1541 } |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1542 } |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1543 } |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1544 return tsa(tok, token_semi); |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1545 } |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1546 |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1547 |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1548 //////////////////////////////////////////////// |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1549 // |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1550 bool parse_dkim_from(TOKEN &tok, CONFIG &dc, CONTEXT &me); |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1551 bool parse_dkim_from(TOKEN &tok, CONFIG &dc, CONTEXT &me) { |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1552 if (!tsa(tok, token_lbrace)) return false; |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1553 while (true) { |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1554 const char *have = tok.next(); |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1555 if (!have) break; |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1556 if (have == token_rbrace) break; |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1557 if (have == token_semi) { |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1558 // optional separators |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1559 } |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1560 else { |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1561 const char *from = have; |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1562 const char *action = tok.next(); |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1563 if ((action == token_signed_white) || (action == token_signed_black) || (action == token_require_signed)) { |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1564 const char *signer = tok.next(); |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1565 if (!signer) break; |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1566 else me.add_dkim_from(from, action, signer); |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1567 } |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1568 else { |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1569 tok.token_error("signed_white/signed_black/require_signed", action); |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1570 } |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1571 } |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1572 } |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1573 return tsa(tok, token_semi); |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1574 } |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1575 |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1576 |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1577 //////////////////////////////////////////////// |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1578 // |
94 | 1579 bool parse_content(TOKEN &tok, CONFIG &dc, CONTEXT &me); |
1580 bool parse_content(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1581 const char *setting = tok.next(); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1582 if (setting == token_on) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1583 me.set_content_filtering(true); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1584 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1585 else if (setting == token_off) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1586 me.set_content_filtering(false); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1587 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1588 else { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1589 tok.token_error("on/off", setting); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1590 return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1591 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1592 if (!tsa(tok, token_lbrace)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1593 while (true) { |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1594 const char *have = tok.next(); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1595 if (!have) break; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1596 if (have == token_filter) { |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1597 const char *suffix = tok.next(); |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1598 const char *messag = tok.next(); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1599 me.set_content_suffix(suffix); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1600 me.set_content_message(messag); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1601 if (!tsa(tok, token_semi)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1602 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1603 else if (have == token_uribl) { |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1604 const char *suffix = tok.next(); |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1605 const char *messag = tok.next(); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1606 me.set_uribl_suffix(suffix); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1607 me.set_uribl_message(messag); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1608 if (!tsa(tok, token_semi)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1609 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1610 else if (have == token_ignore) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1611 if (!tsa(tok, token_lbrace)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1612 while (true) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1613 if (!have) break; |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1614 const char *have = tok.next(); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1615 if (have == token_rbrace) break; // done |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1616 me.add_ignore(have); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1617 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1618 if (!tsa(tok, token_semi)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1619 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1620 else if (have == token_tld) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1621 if (!tsa(tok, token_lbrace)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1622 while (true) { |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1623 const char *have = tok.next(); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1624 if (!have) break; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1625 if (have == token_rbrace) break; // done |
270
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1626 if (have == token_bang) { |
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1627 have = tok.next(); |
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1628 if (!have) break; |
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1629 if (have == token_rbrace) break; // done |
272
a99b6c1f5f67
Code cleanup, increase minimum hostname length for uribl checking
Carl Byington <carl@five-ten-sg.com>
parents:
270
diff
changeset
|
1630 me.add_tldnot(have); |
270
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1631 } |
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1632 else if (have == token_asterisk) { |
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1633 have = tok.next(); |
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1634 if (!have) break; |
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1635 if (have == token_rbrace) break; // done |
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1636 if (have == token_period) { |
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1637 have = tok.next(); |
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1638 if (!have) break; |
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1639 if (have == token_rbrace) break; // done |
272
a99b6c1f5f67
Code cleanup, increase minimum hostname length for uribl checking
Carl Byington <carl@five-ten-sg.com>
parents:
270
diff
changeset
|
1640 me.add_tldwild(have); |
270
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1641 } |
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1642 } |
f92f24950bd3
Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
Carl Byington <carl@five-ten-sg.com>
parents:
268
diff
changeset
|
1643 else me.add_tld(have); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1644 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1645 if (!tsa(tok, token_semi)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1646 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1647 else if (have == token_html_tags) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1648 if (!tsa(tok, token_lbrace)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1649 while (true) { |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1650 const char *have = tok.next(); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1651 if (!have) break; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1652 if (have == token_rbrace) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1653 break; // done |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1654 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1655 else { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1656 me.add_tag(have); // base version |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1657 char buf[200]; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1658 snprintf(buf, sizeof(buf), "/%s", have); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1659 me.add_tag(register_string(buf)); // leading / |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1660 snprintf(buf, sizeof(buf), "%s/", have); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1661 me.add_tag(register_string(buf)); // trailing / |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1662 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1663 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1664 if (!tsa(tok, token_semi)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1665 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1666 else if (have == token_html_limit) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1667 have = tok.next(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1668 if (have == token_on) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1669 me.set_tag_limit(tok.nextint()); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1670 me.set_tag_message(tok.next()); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1671 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1672 else if (have == token_off) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1673 me.set_tag_limit(0); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1674 me.set_tag_message(NULL); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1675 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1676 else { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1677 tok.token_error("on/off", have); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1678 return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1679 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1680 if (!tsa(tok, token_semi)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1681 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1682 else if (have == token_host_limit) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1683 have = tok.next(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1684 if (have == token_on) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1685 me.set_host_limit(tok.nextint()); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1686 me.set_host_message(tok.next()); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1687 me.set_host_random(false); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1688 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1689 else if (have == token_off) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1690 me.set_host_limit(0); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1691 me.set_host_message(NULL); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1692 me.set_host_random(false); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1693 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1694 else if (have == token_soft) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1695 me.set_host_limit(tok.nextint()); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1696 me.set_host_message(NULL); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1697 me.set_host_random(true); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1698 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1699 else { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1700 tok.token_error("on/off/soft", have); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1701 return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1702 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1703 if (!tsa(tok, token_semi)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1704 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1705 else if (have == token_spamassassin) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1706 me.set_spamassassin_limit(tok.nextint()); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1707 if (!tsa(tok, token_semi)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1708 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1709 else if (have == token_require) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1710 have = tok.next(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1711 if (have == token_yes) me.set_require(true); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1712 else if (have == token_no) me.set_require(false); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1713 else { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1714 tok.token_error("yes/no", have); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1715 return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1716 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1717 if (!tsa(tok, token_semi)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1718 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1719 else if (have == token_dccgrey) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1720 have = tok.next(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1721 if (have == token_yes) me.set_grey(true); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1722 else if (have == token_no) me.set_grey(false); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1723 else { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1724 tok.token_error("yes/no", have); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1725 return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1726 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1727 if (!tsa(tok, token_semi)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1728 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1729 else if (have == token_dccbulk) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1730 have = tok.next(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1731 if (have == token_off) me.set_bulk(0); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1732 else if (have == token_many) me.set_bulk(dccbulk); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1733 else { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1734 char *e; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1735 long i = strtol(have, &e, 10); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1736 if (*e != '\0') { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1737 tok.token_error("integer", have); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1738 return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1739 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1740 me.set_bulk((int)i); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1741 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1742 if (!tsa(tok, token_semi)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1743 } |
322
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1744 else if (have == token_dkim_signer) { |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1745 if (!parse_dkim_signer(tok, dc, me)) return false; |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1746 } |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1747 else if (have == token_dkim_from) { |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1748 if (!parse_dkim_from(tok, dc, me)) return false; |
9f8411f3919c
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
321
diff
changeset
|
1749 } |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1750 else if (have == token_rbrace) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1751 break; // done |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1752 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1753 else { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1754 tok.token_error("content keyword", have); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1755 return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1756 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1757 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1758 return tsa(tok, token_semi); |
94 | 1759 } |
1760 | |
1761 | |
1762 //////////////////////////////////////////////// | |
1763 // | |
1764 bool parse_envto(TOKEN &tok, CONFIG &dc, CONTEXT &me); | |
1765 bool parse_envto(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1766 if (!tsa(tok, token_lbrace)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1767 while (true) { |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1768 const char *have = tok.next(); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1769 if (!have) break; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1770 if (have == token_rbrace) break; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1771 if (have == token_semi) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1772 // optional separators |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1773 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1774 else if (have == token_dccto) { |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1775 const char *flavor = tok.next(); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1776 if (!tsa(tok, token_lbrace)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1777 bool keeping = false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1778 while (true) { |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1779 const char *have = tok.next(); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1780 if (!have) break; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1781 if (have == token_rbrace) break; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1782 if (have == flavor) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1783 keeping = true; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1784 continue; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1785 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1786 else if ((have == token_ok) || (have == token_ok2) || (have == token_many)) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1787 keeping = false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1788 continue; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1789 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1790 if (have == token_envto) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1791 have = tok.next(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1792 if (keeping) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1793 if (me.allow_env_to(have)) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1794 me.add_to(have); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1795 dc.add_to(have, &me); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1796 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1797 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1798 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1799 //else if (have == token_substitute) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1800 // if (tok.next() == token_mailhost) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1801 // have = tok.next(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1802 // if (keeping) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1803 // if (me.allow_env_to(have)) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1804 // me.add_to(have); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1805 // dc.add_to(have, &me); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1806 // } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1807 // } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1808 // } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1809 //} |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1810 tok.skipeol(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1811 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1812 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1813 else if (me.allow_env_to(have)) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1814 me.add_to(have); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1815 dc.add_to(have, &me); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1816 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1817 else { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1818 tok.token_error("user@ or user@domain.tld or domain.tld where domain.tld allowed by parent context", have); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1819 return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1820 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1821 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1822 return tsa(tok, token_semi); |
94 | 1823 } |
1824 | |
1825 | |
1826 //////////////////////////////////////////////// | |
1827 // | |
1828 bool parse_verify(TOKEN &tok, CONFIG &dc, CONTEXT &me); | |
1829 bool parse_verify(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1830 const char *host = tok.next(); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1831 if (!tsa(tok, token_semi)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1832 me.set_verify(host); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1833 me.set_verifier(add_verify_host(host)); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1834 return true; |
153 | 1835 } |
1836 | |
1837 | |
1838 //////////////////////////////////////////////// | |
1839 // | |
168 | 1840 bool parse_generic(TOKEN &tok, CONFIG &dc, CONTEXT &me); |
1841 bool parse_generic(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1842 const char *regx = tok.next(); |
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1843 const char *msg = tok.next(); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1844 if (!tsa(tok, token_semi)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1845 if (me.set_generic(regx, msg)) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1846 tok.token_error("invalid regular expression %s", regx, regx); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1847 return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1848 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1849 return true; |
168 | 1850 } |
1851 | |
1852 | |
1853 //////////////////////////////////////////////// | |
1854 // | |
233
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
1855 bool parse_white(TOKEN &tok, CONFIG &dc, CONTEXT &me); |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
1856 bool parse_white(TOKEN &tok, CONFIG &dc, CONTEXT &me) { |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
1857 const char *regx = tok.next(); |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
1858 if (!tsa(tok, token_semi)) return false; |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
1859 if (me.set_white(regx)) { |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
1860 tok.token_error("invalid regular expression %s", regx, regx); |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
1861 return false; |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
1862 } |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
1863 return true; |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
1864 } |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
1865 |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
1866 |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
1867 //////////////////////////////////////////////// |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
1868 // |
153 | 1869 bool parse_autowhite(TOKEN &tok, CONFIG &dc, CONTEXT &me); |
1870 bool parse_autowhite(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1871 int days = tok.nextint(); |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1872 const char *fn = tok.next(); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1873 if (!tsa(tok, token_semi)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1874 me.set_autowhite(fn); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1875 me.set_whitelister(add_whitelister_file(fn, days)); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1876 return true; |
94 | 1877 } |
1878 | |
1879 | |
1880 //////////////////////////////////////////////// | |
1881 // | |
1882 bool parse_envfrom(TOKEN &tok, CONFIG &dc, CONTEXT &me); | |
1883 bool parse_envfrom(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1884 const char *st = tok.next(); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1885 if ((st == token_black) || (st == token_white) || (st == token_unknown) || (st == token_inherit)) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1886 me.set_from_default(st); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1887 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1888 else { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1889 tok.push(st); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1890 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1891 if (!tsa(tok, token_lbrace)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1892 while (true) { |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1893 const char *have = tok.next(); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1894 if (!have) break; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1895 if (have == token_rbrace) break; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1896 if (have == token_semi) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1897 // optional separators |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1898 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1899 else if (have == token_dccfrom) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1900 if (!tsa(tok, token_lbrace)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1901 bool keeping = false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1902 bool many = false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1903 while (true) { |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1904 const char *have = tok.next(); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1905 if (!have) break; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1906 if (have == token_rbrace) break; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1907 if (have == token_ok) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1908 keeping = true; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1909 many = false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1910 continue; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1911 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1912 else if (have == token_many) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1913 keeping = true; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1914 many = true; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1915 continue; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1916 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1917 else if (have == token_ok2) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1918 keeping = false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1919 continue; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1920 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1921 if (have == token_envfrom) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1922 have = tok.next(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1923 if (keeping) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1924 me.add_from(have, (many) ? token_black : token_white); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1925 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1926 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1927 else if (have == token_substitute) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1928 if (tok.next() == token_mailhost) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1929 have = tok.next(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1930 me.add_from(have, (many) ? token_black : token_white); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1931 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1932 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1933 tok.skipeol(); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1934 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1935 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1936 else { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1937 // may be a valid email address or domain name |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1938 const char *st = tok.next(); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1939 if ((st == token_white) || (st == token_black) || (st == token_unknown) || (st == token_inherit)) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1940 me.add_from(have, st); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1941 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1942 else { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1943 CONTEXTP con = me.find_from_context_name(st); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1944 if (con) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1945 me.add_from_context(have, con); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1946 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1947 else { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1948 tok.token_error("white/black/unknown/inherit or child context name", st); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1949 return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1950 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1951 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1952 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1953 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1954 return tsa(tok, token_semi); |
94 | 1955 } |
1956 | |
1957 | |
1958 //////////////////////////////////////////////// | |
1959 // | |
136 | 1960 bool parse_rate(TOKEN &tok, CONFIG &dc, CONTEXT &me); |
1961 bool parse_rate(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
278
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
1962 me.set_default_rate_limit(tok.nextint()); |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
1963 me.set_daily_rate_multiple(tok.nextint()); |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
1964 me.set_default_address_limit(tok.nextint()); |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
1965 me.set_daily_address_multiple(tok.nextint()); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1966 if (!tsa(tok, token_lbrace)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1967 while (true) { |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1968 const char *have = tok.next(); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1969 if (!have) break; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1970 if (have == token_rbrace) break; |
278
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
1971 me.add_rate_limit(have, tok.nextint()); |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
1972 me.add_address_limit(have, tok.nextint()); |
368572c57013
add limits on unique ip addresses per hour per authenticated user
Carl Byington <carl@five-ten-sg.com>
parents:
274
diff
changeset
|
1973 if (!tsa(tok, token_semi)) return false; |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1974 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1975 return tsa(tok, token_semi); |
136 | 1976 } |
1977 | |
1978 | |
1979 //////////////////////////////////////////////// | |
1980 // | |
94 | 1981 bool parse_context(TOKEN &tok, CONFIG &dc, CONTEXTP parent); |
1982 bool parse_context(TOKEN &tok, CONFIG &dc, CONTEXTP parent) { | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1983 const char *name = tok.next(); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1984 if (!tsa(tok, token_lbrace)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1985 CONTEXTP con = new CONTEXT(parent, name); |
94 | 1986 |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1987 while (true) { |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
1988 const char *have = tok.next(); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1989 if (!have) break; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1990 if (have == token_rbrace) break; // done |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1991 if (have == token_dnsbl) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1992 if (!parse_dnsbl(tok, dc, *con)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1993 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1994 else if (have == token_dnsbll) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1995 if (!parse_dnsbll(tok, dc, *con)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
1996 } |
249 | 1997 else if (have == token_dnswl) { |
1998 if (!parse_dnswl(tok, dc, *con)) return false; | |
1999 } | |
2000 else if (have == token_dnswll) { | |
2001 if (!parse_dnswll(tok, dc, *con)) return false; | |
2002 } | |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2003 else if (have == token_content) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2004 if (!parse_content(tok, dc, *con)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2005 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2006 else if (have == token_envto) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2007 if (!parse_envto(tok, dc, *con)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2008 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2009 else if (have == token_verify) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2010 if (!parse_verify(tok, dc, *con)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2011 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2012 else if (have == token_generic) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2013 if (!parse_generic(tok, dc, *con)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2014 } |
233
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
2015 else if (have == token_white_regex) { |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
2016 if (!parse_white(tok, dc, *con)) return false; |
5c3e9bf45bb5
Add whitelisting by regex expression filtering.
Carl Byington <carl@five-ten-sg.com>
parents:
214
diff
changeset
|
2017 } |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2018 else if (have == token_autowhite) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2019 if (!parse_autowhite(tok, dc, *con)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2020 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2021 else if (have == token_envfrom) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2022 if (!parse_envfrom(tok, dc, *con)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2023 } |
321
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2024 else if (have == token_dkim_signer) { |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2025 if (!parse_dkim_signer(tok, dc, *con)) return false; |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2026 } |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2027 else if (have == token_dkim_from) { |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2028 if (!parse_dkim_from(tok, dc, *con)) return false; |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2029 } |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2030 else if (have == token_rate) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2031 if (parent || dc.default_context) tok.token_error("rate limit ignored in non default context"); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2032 if (!parse_rate(tok, dc, *con)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2033 } |
321
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2034 else if (have == token_requirerdns) { |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2035 if (!parse_requirerdns(tok, dc, *con)) return false; |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2036 } |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2037 else if (have == token_context) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2038 if (!parse_context(tok, dc, con)) return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2039 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2040 else { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2041 tok.token_error("context keyword", have); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2042 return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2043 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2044 } |
94 | 2045 |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2046 if (!tsa(tok, token_semi)) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2047 delete con; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2048 return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2049 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2050 dc.add_context(con); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2051 if (parent) parent->add_context(con); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2052 return true; |
94 | 2053 } |
2054 | |
2055 | |
2056 //////////////////////////////////////////////// | |
2057 // parse a config file | |
2058 // | |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
2059 bool load_conf(CONFIG &dc, const char *fn) { |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2060 int count = 0; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2061 TOKEN tok(fn, &dc.config_files); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2062 while (true) { |
214
82886d4dd71f
Fixes to compile on Fedora 9 and for const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
211
diff
changeset
|
2063 const char *have = tok.next(); |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2064 if (!have) break; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2065 if (have == token_context) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2066 if (!parse_context(tok, dc, NULL)) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2067 tok.token_error("load_conf() failed to parse context"); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2068 return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2069 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2070 else count++; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2071 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2072 else { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2073 tok.token_error(token_context, have); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2074 return false; |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2075 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2076 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2077 tok.token_error("load_conf() found %d contexts in %s", count, fn); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2078 return (dc.default_context) ? true : false; |
94 | 2079 } |
2080 | |
2081 | |
2082 //////////////////////////////////////////////// | |
2083 // init the tokens | |
2084 // | |
2085 void token_init() { | |
321
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2086 token_asterisk = register_string("*"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2087 token_autowhite = register_string("autowhite"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2088 token_bang = register_string("!"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2089 token_black = register_string("black"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2090 token_content = register_string("content"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2091 token_context = register_string("context"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2092 token_dccbulk = register_string("dcc_bulk_threshold"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2093 token_dccfrom = register_string("dcc_from"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2094 token_dccgrey = register_string("dcc_greylist"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2095 token_dccto = register_string("dcc_to"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2096 token_default = register_string("default"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2097 token_dnsbl = register_string("dnsbl"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2098 token_dnsbll = register_string("dnsbl_list"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2099 token_dnswl = register_string("dnswl"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2100 token_dnswll = register_string("dnswl_list"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2101 token_envfrom = register_string("env_from"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2102 token_envto = register_string("env_to"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2103 token_filter = register_string("filter"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2104 token_generic = register_string("generic"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2105 token_host_limit = register_string("host_limit"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2106 token_html_limit = register_string("html_limit"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2107 token_html_tags = register_string("html_tags"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2108 token_ignore = register_string("ignore"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2109 token_include = register_string("include"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2110 token_inherit = register_string("inherit"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2111 token_lbrace = register_string("{"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2112 token_mailhost = register_string("mail_host"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2113 token_many = register_string("many"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2114 token_no = register_string("no"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2115 token_off = register_string("off"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2116 token_ok = register_string("ok"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2117 token_ok2 = register_string("ok2"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2118 token_on = register_string("on"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2119 token_period = register_string("."); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2120 token_rate = register_string("rate_limit"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2121 token_rbrace = register_string("}"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2122 token_require = register_string("require_match"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2123 token_requirerdns = register_string("require_rdns"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2124 token_semi = register_string(";"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2125 token_soft = register_string("soft"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2126 token_spamassassin = register_string("spamassassin"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2127 token_substitute = register_string("substitute"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2128 token_tld = register_string("tld"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2129 token_unknown = register_string("unknown"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2130 token_uribl = register_string("uribl"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2131 token_verify = register_string("verify"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2132 token_white = register_string("white"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2133 token_white_regex = register_string("white_regex"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2134 token_yes = register_string("yes"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2135 token_dkim_signer = register_string("dkim_signer"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2136 token_dkim_from = register_string("dkim_from"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2137 token_signed_white = register_string("signed_white"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2138 token_signed_black = register_string("signed_black"); |
e172dc10fe24
add dkim white/black listing
Carl Byington <carl@five-ten-sg.com>
parents:
320
diff
changeset
|
2139 token_require_signed = register_string("require_signed"); |
94 | 2140 |
192
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2141 if (gethostname(myhostname, HOST_NAME_MAX+1) != 0) { |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2142 strncpy(myhostname, "localhost", HOST_NAME_MAX+1); |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2143 } |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2144 myhostname[HOST_NAME_MAX] = '\0'; // ensure null termination |
8f4a9a37d4d9
delay autowhitelisting to avoid out of office reply bots
carl
parents:
180
diff
changeset
|
2145 token_myhostname = register_string(myhostname); |
94 | 2146 } |