annotate src/context.cpp @ 192:8f4a9a37d4d9

delay autowhitelisting to avoid out of office reply bots
author carl
date Sun, 11 Nov 2007 12:49:25 -0800
parents 7a722f482bfb
children 797299e9fffc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1 /*
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
2
152
c7fc218686f5 gpl3, block mail to recipients that cannot reply
carl
parents: 149
diff changeset
3 Copyright (c) 2007 Carl Byington - 510 Software Group, released under
c7fc218686f5 gpl3, block mail to recipients that cannot reply
carl
parents: 149
diff changeset
4 the GPL version 3 or any later version at your choice available at
c7fc218686f5 gpl3, block mail to recipients that cannot reply
carl
parents: 149
diff changeset
5 http://www.gnu.org/licenses/gpl-3.0.txt
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
6
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
7 */
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
8
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
9 #include "includes.h"
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
10
160
b3ed72ee6564 allow manual updates to auto whitelist files
carl
parents: 156
diff changeset
11 #include <arpa/inet.h>
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
12 #include <net/if.h>
160
b3ed72ee6564 allow manual updates to auto whitelist files
carl
parents: 156
diff changeset
13 #include <netdb.h>
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
14 #include <netinet/in.h>
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
15 #include <netinet/tcp.h>
160
b3ed72ee6564 allow manual updates to auto whitelist files
carl
parents: 156
diff changeset
16 #include <sys/ioctl.h>
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
17 #include <sys/socket.h>
160
b3ed72ee6564 allow manual updates to auto whitelist files
carl
parents: 156
diff changeset
18 #include <sys/stat.h>
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
19 #include <sys/un.h>
160
b3ed72ee6564 allow manual updates to auto whitelist files
carl
parents: 156
diff changeset
20 #include <unistd.h>
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
21
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
22 static char* context_version="$Id$";
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
23
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
24 char *token_autowhite;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
25 char *token_black;
178
d6531c702be3 embedded dcc filtering
carl
parents: 175
diff changeset
26 char *token_cctld;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
27 char *token_content;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
28 char *token_context;
178
d6531c702be3 embedded dcc filtering
carl
parents: 175
diff changeset
29 char *token_dccbulk;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
30 char *token_dccfrom;
178
d6531c702be3 embedded dcc filtering
carl
parents: 175
diff changeset
31 char *token_dccgrey;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
32 char *token_dccto;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
33 char *token_default;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
34 char *token_dnsbl;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
35 char *token_dnsbll;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
36 char *token_envfrom;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
37 char *token_envto;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
38 char *token_filter;
168
6bac960af6b4 add generic reverse dns filtering regex
carl
parents: 167
diff changeset
39 char *token_generic;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
40 char *token_host_limit;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
41 char *token_html_limit;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
42 char *token_html_tags;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
43 char *token_ignore;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
44 char *token_include;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
45 char *token_inherit;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
46 char *token_lbrace;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
47 char *token_mailhost;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
48 char *token_many;
178
d6531c702be3 embedded dcc filtering
carl
parents: 175
diff changeset
49 char *token_no;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
50 char *token_off;
178
d6531c702be3 embedded dcc filtering
carl
parents: 175
diff changeset
51 char *token_ok;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
52 char *token_ok2;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
53 char *token_on;
136
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
54 char *token_rate;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
55 char *token_rbrace;
178
d6531c702be3 embedded dcc filtering
carl
parents: 175
diff changeset
56 char *token_require;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
57 char *token_semi;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
58 char *token_soft;
163
97d7da45fe2a spamassassin changes
carl
parents: 162
diff changeset
59 char *token_spamassassin;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
60 char *token_substitute;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
61 char *token_tld;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
62 char *token_unknown;
119
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
63 char *token_uribl;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
64 char *token_verify;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
65 char *token_white;
178
d6531c702be3 embedded dcc filtering
carl
parents: 175
diff changeset
66 char *token_yes;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
67
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
68 char *token_myhostname;
96
1edd4e8d3a60 fix missing include, not all systems define HOST_NAME_MAX
carl
parents: 94
diff changeset
69 #ifndef HOST_NAME_MAX
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
70 #define HOST_NAME_MAX 255
96
1edd4e8d3a60 fix missing include, not all systems define HOST_NAME_MAX
carl
parents: 94
diff changeset
71 #endif
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
72 char myhostname[HOST_NAME_MAX+1];
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
73
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
74 pthread_mutex_t verifier_mutex; // protect the verifier map
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
75 verify_map verifiers;
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
76
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
77 pthread_mutex_t whitelister_mutex; // protect the whitelisters map
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
78 whitelister_map whitelisters;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
79
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
80 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
81 const int maxlen = 1000; // used for snprintf buffers
178
d6531c702be3 embedded dcc filtering
carl
parents: 175
diff changeset
82 const int maxsmtp_age = 60;// smtp verify sockets older than this are ancient
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
83 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
84 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
85 const time_t ERROR_SMTP_SOCKET_TIME = 600; // number of seconds between attempts to open a socket to an smtp server
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
86
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
87
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
88 int SMTP::writer() {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
89 #ifdef VERIFY_DEBUG
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
90 log("writer() sees buffer with %s", buffer);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
91 log("writer() sees error %d", (int)error);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
92 #endif
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
93 int rs = 0;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
94 if (!error) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
95 int len = strlen(buffer);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
96 while (rs < len) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
97 int ws = write(fd, buffer+rs, len-rs);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
98 if (ws > 0) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
99 rs += ws;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
100 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
101 else {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
102 // peer closed the socket!
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
103 rs = 0;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
104 error = true;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
105 break;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
106 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
107 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
108 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
109 return rs;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
110 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
111
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
112
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
113 int SMTP::reader() {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
114 // 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
115 // 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
116 #ifdef VERIFY_DEBUG
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
117 log("reader() sees error %d", (int)error);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
118 #endif
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
119 if (error) return 0;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
120 int len = maxlen-1; // room for null terminator
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
121 while (pending < len) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
122 int ws = read(fd, buffer+pending, len-pending);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
123 if (ws > 0) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
124 pending += ws;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
125 if (buffer[pending-1] == '\n') break;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
126 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
127 else {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
128 // peer closed the socket!
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
129 pending = 0;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
130 error = true;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
131 break;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
132 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
133 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
134 buffer[pending] = '\0';
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
135 #ifdef VERIFY_DEBUG
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
136 log("reader() sees buffer with %s", buffer);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
137 #endif
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
138 return pending;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
139 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
140
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
141
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
142 int SMTP::read_line() {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
143 char *lf = strchr(buffer, '\n');
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
144 if (!lf) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
145 reader(); // get a lf
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
146 lf = strchr(buffer, '\n');
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
147 if (!lf) lf = buffer + pending - 1;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
148 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
149 return (lf-buffer)+1; // number of bytes in this line
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
150 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
151
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
152
97
cc3b79349c9c fix int function not returning value
carl
parents: 96
diff changeset
153 void SMTP::flush_line(int r) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
154 if (pending > r) memmove(buffer, buffer+r, pending-r);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
155 pending -= r;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
156 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
157
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
158
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
159 int SMTP::read_response() {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
160 pending = 0;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
161 buffer[pending] = '\0';
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
162 while (true) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
163 int r = read_line();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
164 #ifdef VERIFY_DEBUG
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
165 log("read_response() sees line with %s", buffer);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
166 log("read_response() sees line length %d", r);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
167 #endif
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
168 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
169 if ((r > 4) && (buffer[3] == '-')) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
170 flush_line(r);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
171 continue;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
172 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
173 return atoi(buffer);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
174 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
175 return 0;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
176 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
177
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
178
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
179 int SMTP::cmd(char *c) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
180 if (c) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
181 init();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
182 append(c);
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 append("\r\n");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
185 writer();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
186 return read_response();
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
187 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
188
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
189
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
190 int SMTP::helo() {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
191 if (read_response() != 220) return 0;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
192 init();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
193 append("HELO ");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
194 append(token_myhostname);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
195 return cmd(NULL);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
196 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
197
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
198
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
199 int SMTP::rset() {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
200 int rc = cmd("RSET");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
201 efrom[0] = '\0';
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
202 return rc;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
203 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
204
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
205
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
206 int SMTP::from(char *f) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
207 // 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
208 // <>. 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
209 // 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
210 // character string <>.
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
211 if (strncmp(efrom, f, maxlen)) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
212 rset();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
213 strncpy(efrom, f, maxlen);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
214 init();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
215 append("MAIL FROM:<");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
216 if (*f != '<') append(f);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
217 append(">");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
218 return cmd(NULL);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
219 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
220 return 250; // pretend it worked
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
221 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
222
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
223
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
224 int SMTP::rcpt(char *t) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
225 init();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
226 append("RCPT TO:<");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
227 append(t);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
228 append(">");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
229 return cmd(NULL);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
230 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
231
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
232
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
233 int SMTP::quit() {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
234 return cmd("QUIT");
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
235 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
236
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
237
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
238 void SMTP::closefd() {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
239 shutdown(fd, SHUT_RDWR);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
240 close(fd);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
241 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
242
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
243
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
244 #ifdef VERIFY_DEBUG
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
245 void SMTP::log(char *m, int v) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
246 char buf[maxlen];
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
247 snprintf(buf, maxlen, m, v);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
248 my_syslog(buf);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
249 }
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
250
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
251
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
252 void SMTP::log(char *m, char *v) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
253 char buf[maxlen];
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
254 snprintf(buf, maxlen, m, v);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
255 my_syslog(buf);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
256 }
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
257 #endif
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
258
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
259
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
260 ////////////////////////////////////////////////
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
261 // smtp verifier so backup mx machines can see the valid users
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
262 //
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
263 VERIFY::VERIFY(char *h) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
264 host = h;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
265 last_err = 0;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
266 pthread_mutex_init(&mutex, 0);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
267 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
268
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
269
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
270 void VERIFY::closer() {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
271 bool ok = true;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
272 while (ok) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
273 SMTP *conn = NULL;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
274 pthread_mutex_lock(&mutex);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
275 if (connections.empty()) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
276 ok = false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
277 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
278 else {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
279 conn = connections.front();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
280 time_t now = time(NULL);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
281 if ((now - conn->get_stamp()) > maxsmtp_age) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
282 // this connection is ancient, remove it
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
283 connections.pop_front();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
284 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
285 else {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
286 ok = false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
287 conn = NULL;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
288 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
289 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
290 pthread_mutex_unlock(&mutex);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
291 // avoid doing this work inside the mutex lock
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
292 if (conn) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
293 #ifdef VERIFY_DEBUG
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
294 conn->log("closer() closes ancient %d", conn->get_fd());
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
295 #endif
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
296 delete conn;
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 }
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
299 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
300
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
301
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
302 SMTP* VERIFY::get_connection() {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
303 SMTP *conn = NULL;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
304 pthread_mutex_lock(&mutex);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
305 if (!connections.empty()) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
306 conn = connections.front();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
307 connections.pop_front();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
308 #ifdef VERIFY_DEBUG
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
309 conn->log("get_connection() %d from cache", conn->get_fd());
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
310 #endif
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
311 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
312 pthread_mutex_unlock(&mutex);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
313 if (conn) return conn;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
314 int sock = NULL_SOCKET;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
315 if ((time(NULL) - last_err) > ERROR_SMTP_SOCKET_TIME) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
316 // nothing recent, maybe this time it will work
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
317 hostent *h = gethostbyname(host);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
318 if (h) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
319 sockaddr_in server;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
320 server.sin_family = h->h_addrtype;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
321 server.sin_port = htons(25);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
322 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
323 sock = socket(PF_INET, SOCK_STREAM, 0);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
324 if (sock != NULL_SOCKET) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
325 bool rc = (connect(sock, (sockaddr *)&server, sizeof(server)) == 0);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
326 if (!rc) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
327 shutdown(sock, SHUT_RDWR);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
328 close(sock);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
329 sock = NULL_SOCKET;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
330 last_err = time(NULL);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
331 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
332 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
333 else last_err = time(NULL);
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 else last_err = time(NULL);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
336 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
337 if (sock != NULL_SOCKET) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
338 conn = new SMTP(sock);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
339 #ifdef VERIFY_DEBUG
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
340 conn->log("get_connection() %d new socket", conn->get_fd());
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
341 #endif
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
342 if (conn->helo() == 250) return conn;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
343 delete conn;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
344 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
345 return NULL;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
346 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
347
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
348
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
349 void VERIFY::put_connection(SMTP *conn) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
350 if (conn->err()) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
351 #ifdef VERIFY_DEBUG
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
352 conn->log("put_socket() %d with error, close it", conn->get_fd());
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
353 #endif
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
354 delete conn;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
355 last_err = time(NULL);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
356 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
357 else {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
358 #ifdef VERIFY_DEBUG
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
359 conn->log("put_socket() %d", conn->get_fd());
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
360 #endif
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
361 conn->now();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
362 pthread_mutex_lock(&mutex);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
363 connections.push_back(conn);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
364 pthread_mutex_unlock(&mutex);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
365 }
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
366 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
367
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
368
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
369 bool VERIFY::ok(char *from, char *to) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
370 if (host == token_myhostname) return true;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
371 SMTP *conn = get_connection();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
372 if (!conn) return true; // cannot verify right now, we have socket errors
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
373 int rc;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
374 rc = conn->from(from);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
375 #ifdef VERIFY_DEBUG
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
376 conn->log("verify::ok() from sees %d", rc);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
377 #endif
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
378 if (rc != 250) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
379 conn->rset();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
380 put_connection(conn);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
381 return (rc >= 500) ? false : true;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
382 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
383 rc = conn->rcpt(to);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
384 #ifdef VERIFY_DEBUG
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
385 conn->log("verify::ok() rcpt sees %d", rc);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
386 #endif
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
387 put_connection(conn);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
388 return (rc >= 500) ? false : true;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
389 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
390
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
391
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
392 ////////////////////////////////////////////////
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
393 // setup a new smtp verify host
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
394 //
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
395 VERIFYP add_verify_host(char *host);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
396 VERIFYP add_verify_host(char *host) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
397 VERIFYP rc = NULL;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
398 pthread_mutex_lock(&verifier_mutex);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
399 verify_map::iterator i = verifiers.find(host);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
400 if (i == verifiers.end()) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
401 rc = new VERIFY(host);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
402 verifiers[host] = rc;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
403 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
404 else rc = (*i).second;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
405 pthread_mutex_unlock(&verifier_mutex);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
406 return rc;
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
407 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
408
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
409
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
410 ////////////////////////////////////////////////
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
411 // thread to check for verify hosts with old sockets that we can close
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
412 //
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
413 void* verify_closer(void *arg) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
414 while (true) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
415 sleep(maxsmtp_age);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
416 pthread_mutex_lock(&verifier_mutex);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
417 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
418 VERIFYP v = (*i).second;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
419 v->closer();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
420 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
421 pthread_mutex_unlock(&verifier_mutex);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
422 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
423 return NULL;
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
424 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
425
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
426
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
427 ////////////////////////////////////////////////
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
428 // automatic whitelister
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
429 //
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
430 WHITELISTER::WHITELISTER(char *f, int d) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
431 fn = f;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
432 days = d;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
433 pthread_mutex_init(&mutex, 0);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
434 need = false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
435 loaded = time(NULL);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
436 merge();
160
b3ed72ee6564 allow manual updates to auto whitelist files
carl
parents: 156
diff changeset
437 }
b3ed72ee6564 allow manual updates to auto whitelist files
carl
parents: 156
diff changeset
438
b3ed72ee6564 allow manual updates to auto whitelist files
carl
parents: 156
diff changeset
439
b3ed72ee6564 allow manual updates to auto whitelist files
carl
parents: 156
diff changeset
440 void WHITELISTER::merge() {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
441 time_t now = time(NULL);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
442 ifstream ifs;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
443 ifs.open(fn);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
444 if (!ifs.fail()) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
445 const int maxlen = 1000;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
446 char buf[maxlen];
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
447 while (ifs.getline(buf, maxlen)) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
448 char *p = strchr(buf, ' ');
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
449 if (p) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
450 *p = '\0';
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
451 char *who = strdup(buf);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
452 time_t when = atoi(p+1);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
453 if ((when == 0) || (when > now)) when = now;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
454 autowhite_sent::iterator i = rcpts.find(who);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
455 if (i == rcpts.end()) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
456 rcpts[who] = when;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
457 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
458 else {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
459 time_t wh = (*i).second;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
460 if ((when == 1) || (when > wh)) (*i).second = when;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
461 free(who);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
462 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
463 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
464 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
465 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
466 ifs.close();
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
467 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
468
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
469
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
470 void WHITELISTER::writer() {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
471 pthread_mutex_lock(&mutex);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
472 time_t limit = time(NULL) - days*86400;
160
b3ed72ee6564 allow manual updates to auto whitelist files
carl
parents: 156
diff changeset
473
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
474 // check for manually modified autowhitelist file
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
475 struct stat st;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
476 if (stat(fn, &st)) need = true; // file has disappeared
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
477 else if (st.st_mtime > loaded) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
478 // file has been manually updated, merge new entries
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
479 merge();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
480 need = true;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
481 }
160
b3ed72ee6564 allow manual updates to auto whitelist files
carl
parents: 156
diff changeset
482
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
483 // purge old entries
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
484 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
485 time_t when = (*i).second;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
486 if (when < limit) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
487 char *who = (*i).first;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
488 free(who);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
489 autowhite_sent::iterator j = i;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
490 j++;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
491 rcpts.erase(i);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
492 i = j;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
493 need = true;
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 else i++;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
496 }
160
b3ed72ee6564 allow manual updates to auto whitelist files
carl
parents: 156
diff changeset
497
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
498 if (need) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
499 // dump the file
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
500 ofstream ofs;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
501 ofs.open(fn);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
502 if (!ofs.fail()) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
503 for (autowhite_sent::iterator i=rcpts.begin(); i!=rcpts.end(); i++) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
504 char *who = (*i).first;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
505 int when = (*i).second;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
506 if (!strchr(who, ' ')) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
507 ofs << who << " " << when << endl;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
508 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
509 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
510 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
511 ofs.close();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
512 need = false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
513 loaded = time(NULL); // update load time
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
514 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
515 pthread_mutex_unlock(&mutex);
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
516 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
517
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
518
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
519 void WHITELISTER::sent(char *to) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
520 // we take ownership of the string
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
521 pthread_mutex_lock(&mutex);
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 autowhite_sent::iterator i = rcpts.find(to);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
524 if (i == rcpts.end()) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
525 rcpts[to] = time(NULL);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
526 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
527 else {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
528 (*i).second = time(NULL);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
529 free(to);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
530 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
531 pthread_mutex_unlock(&mutex);
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
532 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
533
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
534
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
535 bool WHITELISTER::is_white(char *from) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
536 pthread_mutex_lock(&mutex);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
537 autowhite_sent::iterator i = rcpts.find(from);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
538 bool rc = (i != rcpts.end());
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
539 pthread_mutex_unlock(&mutex);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
540 return rc;
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
541 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
542
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
543
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
544 ////////////////////////////////////////////////
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
545 // setup a new auto whitelister file
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
546 //
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
547 WHITELISTERP add_whitelister_file(char *fn, int days);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
548 WHITELISTERP add_whitelister_file(char *fn, int days) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
549 WHITELISTERP rc = NULL;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
550 pthread_mutex_lock(&whitelister_mutex);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
551 whitelister_map::iterator i = whitelisters.find(fn);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
552 if (i == whitelisters.end()) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
553 rc = new WHITELISTER(fn, days);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
554 whitelisters[fn] = rc;
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 rc = (*i).second;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
558 rc->set_days(days);
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(&whitelister_mutex);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
561 return rc;
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
562 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
563
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
564
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
565 ////////////////////////////////////////////////
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
566 // thread to check for whitelister hosts with old sockets that we can close
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
567 //
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
568 void* whitelister_writer(void *arg) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
569 while (true) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
570 sleep(maxauto_age);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
571 pthread_mutex_lock(&whitelister_mutex);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
572 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
573 WHITELISTERP v = (*i).second;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
574 v->writer();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
575 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
576 pthread_mutex_unlock(&whitelister_mutex);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
577 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
578 return NULL;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
579 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
580
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
581
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
582 DELAYWHITE::DELAYWHITE(char *loto_, WHITELISTERP w_, CONTEXTP con_) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
583 loto = loto_;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
584 w = w_;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
585 con = con_;
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
586 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
587
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
588
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
589 DNSBL::DNSBL(char *n, char *s, char *m) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
590 name = n;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
591 suffix = s;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
592 message = m;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
593 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
594
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
595
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
596 bool DNSBL::operator==(const DNSBL &rhs) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
597 return (strcmp(name, rhs.name) == 0) &&
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
598 (strcmp(suffix, rhs.suffix) == 0) &&
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
599 (strcmp(message, rhs.message) == 0);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
600 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
601
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
602
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
603 CONFIG::CONFIG() {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
604 reference_count = 0;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
605 generation = 0;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
606 load_time = 0;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
607 default_context = NULL;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
608 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
609
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
610
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
611 CONFIG::~CONFIG() {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
612 if (debug_syslog) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
613 char buf[maxlen];
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
614 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
615 my_syslog(buf);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
616 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
617 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
618 CONTEXT *c = *i;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
619 delete c;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
620 }
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
621 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
622
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
623
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
624 void CONFIG::add_context(CONTEXTP con) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
625 contexts.push_back(con);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
626 if (!default_context && !con->get_parent()) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
627 // first global context
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
628 default_context = con;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
629 }
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
630 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
631
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
632
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
633 void CONFIG::add_to(char *to, CONTEXTP con) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
634 context_map::iterator i = env_to.find(to);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
635 if (i != env_to.end()) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
636 CONTEXTP c = (*i).second;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
637 if ((c != con) && (c != con->get_parent())) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
638 if (debug_syslog) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
639 char oldname[maxlen];
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
640 char newname[maxlen];
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
641 char *oldn = c->get_full_name(oldname, maxlen);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
642 char *newn = con->get_full_name(newname, maxlen);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
643 char buf[maxlen*3];
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
644 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
645 my_syslog(buf);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
646 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
647 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
648 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
649 env_to[to] = con;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
650 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
651
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
652
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
653 CONTEXTP CONFIG::find_context(char *to) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
654 context_map::iterator i = env_to.find(to);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
655 if (i != env_to.end()) return (*i).second; // found user@domain key
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
656 char *x = strchr(to, '@');
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
657 if (x) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
658 x++;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
659 i = env_to.find(x);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
660 if (i != env_to.end()) return (*i).second; // found domain key
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
661 char y = *x;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
662 *x = '\0';
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
663 i = env_to.find(to);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
664 *x = y;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
665 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
666 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
667 return default_context;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
668 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
669
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
670
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
671 void CONFIG::dump() {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
672 bool spamass = false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
673 if (default_context) default_context->dump(true, spamass);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
674 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
675 CONTEXTP c = *i;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
676 CONTEXTP p = c->get_parent();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
677 if (!p && (c != default_context)) c->dump(false, spamass);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
678 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
679 char buf[maxlen];
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
680 for (context_map::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
681 char *to = (*i).first;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
682 CONTEXTP con = (*i).second;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
683 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
684 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
685 if (spamass && (spamc == spamc_empty)) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
686 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
687 }
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
688 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
689
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
690
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
691 CONTEXT::CONTEXT(CONTEXTP parent_, char *name_) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
692 parent = parent_;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
693 name = name_;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
694 verify_host = NULL;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
695 verifier = NULL;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
696 generic_regx = NULL;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
697 generic_message = NULL;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
698 autowhite_file = NULL;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
699 whitelister = NULL;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
700 env_from_default = (parent) ? token_inherit : token_unknown;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
701 content_filtering = (parent) ? parent->content_filtering : false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
702 content_suffix = NULL;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
703 content_message = NULL;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
704 uribl_suffix = NULL;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
705 uribl_message = NULL;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
706 host_limit = (parent) ? parent->host_limit : 0;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
707 host_limit_message = NULL;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
708 host_random = (parent) ? parent->host_random : false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
709 tag_limit = (parent) ? parent->tag_limit : 0;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
710 tag_limit_message = NULL;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
711 spamassassin_limit = (parent) ? parent->spamassassin_limit : 0;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
712 require_match = (parent) ? parent->require_match : false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
713 dcc_greylist = (parent) ? parent->dcc_greylist : false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
714 dcc_bulk_threshold = (parent) ? parent->dcc_bulk_threshold : 0;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
715 default_rcpt_rate = INT_MAX;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
716 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
717
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
718
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
719 CONTEXT::~CONTEXT() {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
720 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
721 DNSBLP d = (*i).second;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
722 // delete the underlying DNSBL objects.
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
723 delete d;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
724 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
725 if (generic_regx) regfree(&generic_pattern);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
726 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
727
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
728
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
729 bool CONTEXT::is_parent(CONTEXTP p) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
730 if (p == parent) return true;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
731 if (!parent) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
732 return parent->is_parent(p);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
733 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
734
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
735
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
736 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
737 if (!parent) return name;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
738 char buf[maxlen];
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
739 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
740 return buffer;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
741 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
742
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
743
168
6bac960af6b4 add generic reverse dns filtering regex
carl
parents: 167
diff changeset
744 bool CONTEXT::set_generic(char *regx, char *msg)
6bac960af6b4 add generic reverse dns filtering regex
carl
parents: 167
diff changeset
745 {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
746 int rc = 0;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
747 if (generic_regx) regfree(&generic_pattern);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
748 generic_regx = regx;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
749 generic_message = msg;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
750 if (generic_regx) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
751 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
752 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
753 return rc; // true iff bad pattern
168
6bac960af6b4 add generic reverse dns filtering regex
carl
parents: 167
diff changeset
754 }
6bac960af6b4 add generic reverse dns filtering regex
carl
parents: 167
diff changeset
755
6bac960af6b4 add generic reverse dns filtering regex
carl
parents: 167
diff changeset
756
6bac960af6b4 add generic reverse dns filtering regex
carl
parents: 167
diff changeset
757 char *CONTEXT::generic_match(char *client)
6bac960af6b4 add generic reverse dns filtering regex
carl
parents: 167
diff changeset
758 {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
759 if (parent && !generic_regx) return parent->generic_match(client);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
760 if (!generic_regx) return NULL;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
761 if (0 == regexec(&generic_pattern, client, 0, NULL, 0)) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
762 return generic_message;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
763 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
764 return NULL;
168
6bac960af6b4 add generic reverse dns filtering regex
carl
parents: 167
diff changeset
765 }
6bac960af6b4 add generic reverse dns filtering regex
carl
parents: 167
diff changeset
766
6bac960af6b4 add generic reverse dns filtering regex
carl
parents: 167
diff changeset
767
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
768 bool CONTEXT::cover_env_to(char *to) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
769 char buffer[maxlen];
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
770 char *x = strchr(to, '@');
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
771 if (x) x++;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
772 else x = to;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
773 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
774 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
775 string_set::iterator i = env_to.find(x);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
776 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
777 if (x != to) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
778 i = env_to.find(to);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
779 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
780 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
781 return false;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
782 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
783
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
784
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
785 VERIFYP CONTEXT::find_verify(char *to) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
786 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
787 return verifier;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
788 else if (parent)
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
789 return parent->find_verify(to);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
790 else
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
791 return NULL;
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
792 }
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
793
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
794
162
c4bce911c276 don't add auto whitelist for A to A
carl
parents: 160
diff changeset
795 WHITELISTERP CONTEXT::find_autowhite(char *from, char *to) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
796 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
797 return whitelister;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
798 else if (parent)
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
799 return parent->find_autowhite(from, to);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
800 else
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
801 return NULL;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
802 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
803
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
804
136
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
805 int CONTEXT::find_rate(char *user) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
806 if (rcpt_per_hour.empty()) return default_rcpt_rate;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
807 rcpt_rates::iterator i = rcpt_per_hour.find(user);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
808 return (i == rcpt_per_hour.end()) ? default_rcpt_rate : (*i).second;
136
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
809 }
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
810
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
811
173
83fe0be032c1 fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents: 170
diff changeset
812 char *CONTEXT::find_from(char *from, bool update_white) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
813 if (whitelister && whitelister->is_white(from)) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
814 if (update_white) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
815 // update senders timestamp to extend the whitelisting period
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
816 if (debug_syslog > 1) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
817 char buf[maxlen];
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
818 char msg[maxlen];
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
819 snprintf(msg, sizeof(msg), "extend whitelist reply from <%s> in context %s", from, get_full_name(buf,maxlen));
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
820 my_syslog(msg);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
821 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
822 whitelister->sent(strdup(from));
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
823 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
824 return token_white;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
825 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
826 char *rc = env_from_default;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
827 string_map::iterator i = env_from.find(from);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
828 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
829 else {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
830 char *x = strchr(from, '@');
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
831 if (x) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
832 x++;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
833 i = env_from.find(x);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
834 if (i != env_from.end()) rc = (*i).second; // found domain key
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
835 else {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
836 char y = *x;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
837 *x = '\0';
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
838 i = env_from.find(from);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
839 *x = y;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
840 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
841 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
842 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
843 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
844 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
845 return (rc == token_inherit) ? token_unknown : rc;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
846 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
847
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
848
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
849 CONTEXTP CONTEXT::find_context(char *from) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
850 context_map::iterator i = env_from_context.find(from);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
851 if (i != env_from_context.end()) return (*i).second; // found user@domain key
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
852 char *x = strchr(from, '@');
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
853 if (x) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
854 x++;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
855 i = env_from_context.find(x);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
856 if (i != env_from_context.end()) return (*i).second; // found domain key
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
857 char y = *x;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
858 *x = '\0';
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
859 i = env_from_context.find(from);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
860 *x = y;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
861 if (i != env_from_context.end()) return (*i).second; // found user@ key
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
862 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
863 return this;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
864 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
865
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
866
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
867 CONTEXTP CONTEXT::find_from_context_name(char *name) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
868 context_map::iterator i = children.find(name);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
869 if (i != children.end()) return (*i).second;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
870 return NULL;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
871 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
872
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
873
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
874 DNSBLP CONTEXT::find_dnsbl(char *name) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
875 dnsblp_map::iterator i = dnsbl_names.find(name);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
876 if (i != dnsbl_names.end()) return (*i).second;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
877 if (parent) return parent->find_dnsbl(name);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
878 return NULL;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
879 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
880
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
881
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
882 char* CONTEXT::get_content_suffix() {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
883 if (!content_suffix && parent) return parent->get_content_suffix();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
884 return content_suffix;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
885 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
886
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
887
119
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
888 char* CONTEXT::get_uribl_suffix() {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
889 if (!uribl_suffix && parent) return parent->get_uribl_suffix();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
890 return uribl_suffix;
119
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
891 }
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
892
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
893
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
894 char* CONTEXT::get_content_message() {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
895 if (!content_message && parent) return parent->get_content_message();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
896 return content_message;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
897 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
898
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
899
119
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
900 char* CONTEXT::get_uribl_message() {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
901 if (!uribl_message && parent) return parent->get_uribl_message();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
902 return uribl_message;
119
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
903 }
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
904
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
905
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
906 string_set& CONTEXT::get_content_host_ignore() {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
907 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
908 return content_host_ignore;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
909 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
910
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
911
117
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
912 string_set& CONTEXT::get_content_cctlds() {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
913 if (content_cctlds.empty() && parent) return parent->get_content_cctlds();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
914 return content_cctlds;
117
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
915 }
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
916
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
917 string_set& CONTEXT::get_content_tlds() {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
918 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
919 return content_tlds;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
920 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
921
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
922
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
923 string_set& CONTEXT::get_html_tags() {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
924 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
925 return html_tags;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
926 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
927
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
928
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
929 dnsblp_list& CONTEXT::get_dnsbl_list() {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
930 if (dnsbl_list.empty() && parent) return parent->get_dnsbl_list();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
931 return dnsbl_list;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
932 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
933
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
934
178
d6531c702be3 embedded dcc filtering
carl
parents: 175
diff changeset
935 bool CONTEXT::acceptable_content(recorder &memory, int score, int bulk, string& msg) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
936 if (spamassassin_limit && (score > spamassassin_limit)) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
937 char buf[maxlen];
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
938 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
939 msg = string(buf);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
940 return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
941 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
942 if (dcc_bulk_threshold && (bulk > dcc_bulk_threshold)) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
943 char buf[maxlen];
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
944 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
945 msg = string(buf);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
946 return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
947 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
948 if (memory.excessive_bad_tags(tag_limit)) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
949 msg = string(tag_limit_message);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
950 return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
951 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
952 if (!host_random && memory.excessive_hosts(host_limit)) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
953 msg = string(host_limit_message);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
954 return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
955 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
956 return true;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
957 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
958
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
959
167
9b129ed78d7d actually use spamassassin result, allow build without spam assassin, only call it if some recipient needs it.
carl
parents: 164
diff changeset
960 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
961 char indent[maxlen];
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
962 int i = min(maxlen-1, level*4);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
963 memset(indent, ' ', i);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
964 indent[i] = '\0';
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
965 char buf[maxlen];
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
966 char *fullname = get_full_name(buf,maxlen);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
967 printf("%s context %s { \t// %s\n", indent, name, fullname);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
968
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
969 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
970 char *n = (*i).first;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
971 DNSBL &d = *(*i).second;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
972 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
973 }
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
974
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
975 dnsblp_list dl = get_dnsbl_list();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
976 if (!dl.empty()) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
977 printf("%s dnsbl_list", indent);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
978 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
979 DNSBL &d = *(*i);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
980 printf(" %s", d.name);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
981 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
982 printf("; \n");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
983 }
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
984
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
985 if (content_filtering) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
986 printf("%s content on { \n", indent, env_from_default);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
987 if (content_suffix) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
988 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
989 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
990 if (uribl_suffix) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
991 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
992 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
993 if (!content_host_ignore.empty()) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
994 printf("%s ignore { \n", indent);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
995 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
996 printf("%s %s; \n", indent, *i);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
997 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
998 printf("%s }; \n", indent);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
999 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1000 if (!content_cctlds.empty()) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1001 printf("%s cctld { \n", indent);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1002 printf("%s ", indent);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1003 for (string_set::iterator i=content_cctlds.begin(); i!=content_cctlds.end(); i++) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1004 printf("%s; ", *i);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1005 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1006 printf("\n%s }; \n", indent);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1007 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1008 if (!content_tlds.empty()) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1009 printf("%s tld { \n", indent);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1010 printf("%s ", indent);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1011 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
1012 printf("%s; ", *i);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1013 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1014 printf("\n%s }; \n", indent);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1015 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1016 if (!html_tags.empty()) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1017 printf("%s html_tags { \n", indent);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1018 printf("%s ", indent);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1019 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
1020 printf("%s; ", *i);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1021 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1022 printf("\n%s }; \n", indent);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1023 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1024 if (host_limit_message) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1025 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
1026 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1027 else if (host_random) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1028 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
1029 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1030 else {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1031 printf("%s host_limit off; \n", indent);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1032 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1033 if (tag_limit_message) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1034 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
1035 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1036 else {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1037 printf("%s html_limit off; \n", indent);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1038 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1039 printf("%s spamassassin %d; \n", indent, spamassassin_limit);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1040 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
1041 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
1042 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
1043 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
1044 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
1045 printf("%s }; \n", indent);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1046 spamass |= (spamassassin_limit != 0);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1047 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1048 else {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1049 printf("%s content off {}; \n", indent, env_from_default);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1050 }
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1051
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1052 printf("%s env_to { \t// %s\n", indent, fullname);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1053 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
1054 printf("%s %s; \n", indent, *i);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1055 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1056 printf("%s }; \n", indent);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1057
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1058 if (verify_host) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1059 printf("%s verify %s; \n", indent, verify_host);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1060 }
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1061
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1062 if (generic_regx) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1063 printf("%s generic \"%s\" \n", indent, generic_regx);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1064 printf("%s \"%s\"; \n", indent, generic_message);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1065 }
168
6bac960af6b4 add generic reverse dns filtering regex
carl
parents: 167
diff changeset
1066
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1067 if (autowhite_file && whitelister) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1068 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
1069 }
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
1070
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1071 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
1072 CONTEXTP c = (*i).second;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1073 c->dump(false, spamass, level+1);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1074 }
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1075
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1076 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
1077 if (!env_from.empty()) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1078 printf("%s // white/black/unknown \n", indent);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1079 for (string_map::iterator i=env_from.begin(); i!=env_from.end(); i++) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1080 char *f = (*i).first;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1081 char *t = (*i).second;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1082 printf("%s %s \t%s; \n", indent, f, t);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1083 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1084 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1085 if (!env_from_context.empty()) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1086 printf("%s // child contexts \n", indent);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1087 for (context_map::iterator j=env_from_context.begin(); j!=env_from_context.end(); j++) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1088 char *f = (*j).first;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1089 CONTEXTP t = (*j).second;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1090 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
1091 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1092 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1093 printf("%s }; \n", indent);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1094
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1095 if (isdefault) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1096 printf("%s rate_limit %d { \n", indent, default_rcpt_rate);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1097 for (rcpt_rates::iterator j=rcpt_per_hour.begin(); j!=rcpt_per_hour.end(); j++) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1098 char *u = (*j).first;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1099 int l = (*j).second;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1100 printf("%s \"%s\" \t%d; \n", indent, u, l);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1101 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1102 printf("%s }; \n", indent);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1103 }
136
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1104
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1105 printf("%s }; \n", indent);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1106 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1107
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1108
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1109 ////////////////////////////////////////////////
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1110 // helper to discard the strings held by a string_set
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1111 //
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1112 void discard(string_set &s) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1113 for (string_set::iterator i=s.begin(); i!=s.end(); i++) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1114 free(*i);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1115 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1116 s.clear();
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1117 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1118
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1119
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1120 ////////////////////////////////////////////////
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1121 // helper to register a string in a string set
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1122 //
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1123 char* register_string(string_set &s, char *name) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1124 string_set::iterator i = s.find(name);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1125 if (i != s.end()) return *i;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1126 char *x = strdup(name);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1127 s.insert(x);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1128 return x;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1129 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1130
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1131
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1132 ////////////////////////////////////////////////
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1133 // register a global string
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1134 //
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1135 char* register_string(char *name) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1136 return register_string(all_strings, name);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1137 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1138
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1139
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1140 ////////////////////////////////////////////////
164
5809bcdc325b spamassassin changes
carl
parents: 163
diff changeset
1141 // clear all global strings, helper for valgrind checking
5809bcdc325b spamassassin changes
carl
parents: 163
diff changeset
1142 //
5809bcdc325b spamassassin changes
carl
parents: 163
diff changeset
1143 void clear_strings() {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1144 discard(all_strings);
164
5809bcdc325b spamassassin changes
carl
parents: 163
diff changeset
1145 }
5809bcdc325b spamassassin changes
carl
parents: 163
diff changeset
1146
5809bcdc325b spamassassin changes
carl
parents: 163
diff changeset
1147
5809bcdc325b spamassassin changes
carl
parents: 163
diff changeset
1148 ////////////////////////////////////////////////
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1149 //
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1150 bool tsa(TOKEN &tok, char *token);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1151 bool tsa(TOKEN &tok, char *token) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1152 char *have = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1153 if (have == token) return true;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1154 tok.token_error(token, have);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1155 return false;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1156 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1157
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1158
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1159 ////////////////////////////////////////////////
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1160 //
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1161 bool parse_dnsbl(TOKEN &tok, CONFIG &dc, CONTEXT &me);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1162 bool parse_dnsbl(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1163 char *name = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1164 char *suf = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1165 char *msg = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1166 if (!tsa(tok, token_semi)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1167 DNSBLP dnsnew = new DNSBL(name, suf, msg);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1168 DNSBLP dnsold = me.find_dnsbl(name);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1169 if (dnsold && (*dnsold == *dnsnew)) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1170 // duplicate redefinition, ignore it
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1171 delete dnsnew;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1172 return true;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1173 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1174 me.add_dnsbl(name, dnsnew);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1175 return true;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1176 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1177
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1178
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1179 ////////////////////////////////////////////////
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1180 //
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1181 bool parse_dnsbll(TOKEN &tok, CONFIG &dc, CONTEXT &me);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1182 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
1183 while (true) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1184 char *have = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1185 if (!have) break;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1186 if (have == token_semi) break;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1187 DNSBLP dns = me.find_dnsbl(have);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1188 if (dns) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1189 me.add_dnsbl(dns);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1190 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1191 else {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1192 tok.token_error("dnsbl name", have);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1193 return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1194 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1195 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1196 return true;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1197 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1198
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1199
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1200 ////////////////////////////////////////////////
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1201 //
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1202 bool parse_content(TOKEN &tok, CONFIG &dc, CONTEXT &me);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1203 bool parse_content(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1204 char *setting = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1205 if (setting == token_on) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1206 me.set_content_filtering(true);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1207 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1208 else if (setting == token_off) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1209 me.set_content_filtering(false);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1210 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1211 else {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1212 tok.token_error("on/off", setting);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1213 return false;
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 if (!tsa(tok, token_lbrace)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1216 while (true) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1217 char *have = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1218 if (!have) break;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1219 if (have == token_filter) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1220 char *suffix = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1221 char *messag = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1222 me.set_content_suffix(suffix);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1223 me.set_content_message(messag);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1224 if (!tsa(tok, token_semi)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1225 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1226 else if (have == token_uribl) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1227 char *suffix = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1228 char *messag = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1229 me.set_uribl_suffix(suffix);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1230 me.set_uribl_message(messag);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1231 if (!tsa(tok, token_semi)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1232 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1233 else if (have == token_ignore) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1234 if (!tsa(tok, token_lbrace)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1235 while (true) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1236 if (!have) break;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1237 char *have = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1238 if (have == token_rbrace) break; // done
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1239 me.add_ignore(have);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1240 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1241 if (!tsa(tok, token_semi)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1242 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1243 else if (have == token_tld) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1244 if (!tsa(tok, token_lbrace)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1245 while (true) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1246 char *have = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1247 if (!have) break;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1248 if (have == token_rbrace) break; // done
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1249 me.add_tld(have);
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 (!tsa(tok, token_semi)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1252 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1253 else if (have == token_cctld) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1254 if (!tsa(tok, token_lbrace)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1255 while (true) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1256 char *have = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1257 if (!have) break;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1258 if (have == token_rbrace) break; // done
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1259 me.add_cctld(have);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1260 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1261 if (!tsa(tok, token_semi)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1262 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1263 else if (have == token_html_tags) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1264 if (!tsa(tok, token_lbrace)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1265 while (true) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1266 char *have = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1267 if (!have) break;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1268 if (have == token_rbrace) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1269 break; // done
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1270 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1271 else {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1272 me.add_tag(have); // base version
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1273 char buf[200];
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1274 snprintf(buf, sizeof(buf), "/%s", have);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1275 me.add_tag(register_string(buf)); // leading /
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1276 snprintf(buf, sizeof(buf), "%s/", have);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1277 me.add_tag(register_string(buf)); // trailing /
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1278 }
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 (!tsa(tok, token_semi)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1281 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1282 else if (have == token_html_limit) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1283 have = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1284 if (have == token_on) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1285 me.set_tag_limit(tok.nextint());
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1286 me.set_tag_message(tok.next());
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1287 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1288 else if (have == token_off) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1289 me.set_tag_limit(0);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1290 me.set_tag_message(NULL);
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 tok.token_error("on/off", have);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1294 return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1295 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1296 if (!tsa(tok, token_semi)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1297 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1298 else if (have == token_host_limit) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1299 have = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1300 if (have == token_on) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1301 me.set_host_limit(tok.nextint());
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1302 me.set_host_message(tok.next());
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1303 me.set_host_random(false);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1304 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1305 else if (have == token_off) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1306 me.set_host_limit(0);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1307 me.set_host_message(NULL);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1308 me.set_host_random(false);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1309 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1310 else if (have == token_soft) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1311 me.set_host_limit(tok.nextint());
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1312 me.set_host_message(NULL);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1313 me.set_host_random(true);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1314 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1315 else {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1316 tok.token_error("on/off/soft", have);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1317 return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1318 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1319 if (!tsa(tok, token_semi)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1320 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1321 else if (have == token_spamassassin) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1322 me.set_spamassassin_limit(tok.nextint());
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1323 if (!tsa(tok, token_semi)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1324 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1325 else if (have == token_require) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1326 have = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1327 if (have == token_yes) me.set_require(true);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1328 else if (have == token_no) me.set_require(false);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1329 else {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1330 tok.token_error("yes/no", have);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1331 return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1332 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1333 if (!tsa(tok, token_semi)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1334 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1335 else if (have == token_dccgrey) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1336 have = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1337 if (have == token_yes) me.set_grey(true);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1338 else if (have == token_no) me.set_grey(false);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1339 else {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1340 tok.token_error("yes/no", have);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1341 return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1342 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1343 if (!tsa(tok, token_semi)) return false;
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 else if (have == token_dccbulk) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1346 have = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1347 if (have == token_off) me.set_bulk(0);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1348 else if (have == token_many) me.set_bulk(dccbulk);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1349 else {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1350 char *e;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1351 long i = strtol(have, &e, 10);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1352 if (*e != '\0') {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1353 tok.token_error("integer", have);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1354 return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1355 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1356 me.set_bulk((int)i);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1357 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1358 if (!tsa(tok, token_semi)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1359 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1360 else if (have == token_rbrace) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1361 break; // done
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1362 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1363 else {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1364 tok.token_error("content keyword", have);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1365 return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1366 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1367 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1368 return tsa(tok, token_semi);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1369 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1370
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1371
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1372 ////////////////////////////////////////////////
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1373 //
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1374 bool parse_envto(TOKEN &tok, CONFIG &dc, CONTEXT &me);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1375 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
1376 if (!tsa(tok, token_lbrace)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1377 while (true) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1378 char *have = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1379 if (!have) break;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1380 if (have == token_rbrace) break;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1381 if (have == token_semi) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1382 // optional separators
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1383 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1384 else if (have == token_dccto) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1385 char *flavor = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1386 if (!tsa(tok, token_lbrace)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1387 bool keeping = false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1388 while (true) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1389 char *have = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1390 if (!have) break;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1391 if (have == token_rbrace) break;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1392 if (have == flavor) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1393 keeping = true;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1394 continue;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1395 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1396 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
1397 keeping = false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1398 continue;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1399 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1400 if (have == token_envto) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1401 have = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1402 if (keeping) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1403 if (me.allow_env_to(have)) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1404 me.add_to(have);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1405 dc.add_to(have, &me);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1406 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1407 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1408 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1409 //else if (have == token_substitute) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1410 // if (tok.next() == token_mailhost) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1411 // have = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1412 // if (keeping) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1413 // if (me.allow_env_to(have)) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1414 // me.add_to(have);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1415 // dc.add_to(have, &me);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1416 // }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1417 // }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1418 // }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1419 //}
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1420 tok.skipeol();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1421 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1422 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1423 else if (me.allow_env_to(have)) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1424 me.add_to(have);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1425 dc.add_to(have, &me);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1426 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1427 else {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1428 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
1429 return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1430 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1431 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1432 return tsa(tok, token_semi);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1433 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1434
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1435
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1436 ////////////////////////////////////////////////
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1437 //
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1438 bool parse_verify(TOKEN &tok, CONFIG &dc, CONTEXT &me);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1439 bool parse_verify(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1440 char *host = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1441 if (!tsa(tok, token_semi)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1442 me.set_verify(host);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1443 me.set_verifier(add_verify_host(host));
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1444 return true;
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
1445 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
1446
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
1447
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
1448 ////////////////////////////////////////////////
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
1449 //
168
6bac960af6b4 add generic reverse dns filtering regex
carl
parents: 167
diff changeset
1450 bool parse_generic(TOKEN &tok, CONFIG &dc, CONTEXT &me);
6bac960af6b4 add generic reverse dns filtering regex
carl
parents: 167
diff changeset
1451 bool parse_generic(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1452 char *regx = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1453 char *msg = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1454 if (!tsa(tok, token_semi)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1455 if (me.set_generic(regx, msg)) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1456 tok.token_error("invalid regular expression %s", regx, regx);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1457 return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1458 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1459 return true;
168
6bac960af6b4 add generic reverse dns filtering regex
carl
parents: 167
diff changeset
1460 }
6bac960af6b4 add generic reverse dns filtering regex
carl
parents: 167
diff changeset
1461
6bac960af6b4 add generic reverse dns filtering regex
carl
parents: 167
diff changeset
1462
6bac960af6b4 add generic reverse dns filtering regex
carl
parents: 167
diff changeset
1463 ////////////////////////////////////////////////
6bac960af6b4 add generic reverse dns filtering regex
carl
parents: 167
diff changeset
1464 //
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
1465 bool parse_autowhite(TOKEN &tok, CONFIG &dc, CONTEXT &me);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
1466 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
1467 int days = tok.nextint();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1468 char *fn = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1469 if (!tsa(tok, token_semi)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1470 me.set_autowhite(fn);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1471 me.set_whitelister(add_whitelister_file(fn, days));
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1472 return true;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1473 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1474
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1475
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1476 ////////////////////////////////////////////////
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1477 //
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1478 bool parse_envfrom(TOKEN &tok, CONFIG &dc, CONTEXT &me);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1479 bool parse_envfrom(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1480 char *st = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1481 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
1482 me.set_from_default(st);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1483 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1484 else {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1485 tok.push(st);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1486 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1487 if (!tsa(tok, token_lbrace)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1488 while (true) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1489 char *have = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1490 if (!have) break;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1491 if (have == token_rbrace) break;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1492 if (have == token_semi) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1493 // optional separators
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1494 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1495 else if (have == token_dccfrom) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1496 if (!tsa(tok, token_lbrace)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1497 bool keeping = false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1498 bool many = false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1499 while (true) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1500 char *have = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1501 if (!have) break;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1502 if (have == token_rbrace) break;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1503 if (have == token_ok) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1504 keeping = true;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1505 many = false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1506 continue;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1507 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1508 else if (have == token_many) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1509 keeping = true;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1510 many = true;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1511 continue;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1512 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1513 else if (have == token_ok2) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1514 keeping = false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1515 continue;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1516 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1517 if (have == token_envfrom) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1518 have = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1519 if (keeping) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1520 me.add_from(have, (many) ? token_black : token_white);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1521 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1522 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1523 else if (have == token_substitute) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1524 if (tok.next() == token_mailhost) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1525 have = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1526 me.add_from(have, (many) ? token_black : token_white);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1527 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1528 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1529 tok.skipeol();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1530 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1531 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1532 else {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1533 // may be a valid email address or domain name
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1534 char *st = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1535 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
1536 me.add_from(have, st);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1537 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1538 else {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1539 CONTEXTP con = me.find_from_context_name(st);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1540 if (con) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1541 me.add_from_context(have, con);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1542 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1543 else {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1544 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
1545 return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1546 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1547 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1548 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1549 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1550 return tsa(tok, token_semi);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1551 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1552
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1553
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1554 ////////////////////////////////////////////////
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1555 //
136
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1556 bool parse_rate(TOKEN &tok, CONFIG &dc, CONTEXT &me);
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1557 bool parse_rate(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1558 char *def = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1559 tok.push(def);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1560 if (def != token_lbrace) me.set_default_rate(tok.nextint());
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1561 if (!tsa(tok, token_lbrace)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1562 while (true) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1563 char *have = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1564 if (!have) break;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1565 if (have == token_rbrace) break;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1566 if (have == token_semi) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1567 // optional separators
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1568 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1569 else {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1570 me.add_rate(have, tok.nextint());
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1571 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1572 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1573 return tsa(tok, token_semi);
136
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1574 }
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1575
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1576
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1577 ////////////////////////////////////////////////
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1578 //
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1579 bool parse_context(TOKEN &tok, CONFIG &dc, CONTEXTP parent);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1580 bool parse_context(TOKEN &tok, CONFIG &dc, CONTEXTP parent) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1581 char *name = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1582 if (!tsa(tok, token_lbrace)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1583 CONTEXTP con = new CONTEXT(parent, name);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1584
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1585 while (true) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1586 char *have = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1587 if (!have) break;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1588 if (have == token_rbrace) break; // done
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1589 if (have == token_dnsbl) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1590 if (!parse_dnsbl(tok, dc, *con)) 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 else if (have == token_dnsbll) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1593 if (!parse_dnsbll(tok, dc, *con)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1594 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1595 else if (have == token_content) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1596 if (!parse_content(tok, dc, *con)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1597 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1598 else if (have == token_envto) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1599 if (!parse_envto(tok, dc, *con)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1600 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1601 else if (have == token_verify) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1602 if (!parse_verify(tok, dc, *con)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1603 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1604 else if (have == token_generic) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1605 if (!parse_generic(tok, dc, *con)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1606 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1607 else if (have == token_autowhite) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1608 if (!parse_autowhite(tok, dc, *con)) 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_envfrom) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1611 if (!parse_envfrom(tok, dc, *con)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1612 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1613 else if (have == token_rate) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1614 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
1615 if (!parse_rate(tok, dc, *con)) return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1616 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1617 else if (have == token_context) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1618 if (!parse_context(tok, dc, con)) 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 {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1621 tok.token_error("context keyword", have);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1622 return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1623 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1624 }
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1625
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1626 if (!tsa(tok, token_semi)) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1627 delete con;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1628 return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1629 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1630 dc.add_context(con);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1631 if (parent) parent->add_context(con);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1632 return true;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1633 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1634
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1635
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1636 ////////////////////////////////////////////////
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1637 // parse a config file
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1638 //
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1639 bool load_conf(CONFIG &dc, char *fn) {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1640 int count = 0;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1641 TOKEN tok(fn, &dc.config_files);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1642 while (true) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1643 char *have = tok.next();
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1644 if (!have) break;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1645 if (have == token_context) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1646 if (!parse_context(tok, dc, NULL)) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1647 tok.token_error("load_conf() failed to parse context");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1648 return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1649 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1650 else count++;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1651 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1652 else {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1653 tok.token_error(token_context, have);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1654 return false;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1655 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1656 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1657 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
1658 return (dc.default_context) ? true : false;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1659 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1660
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1661
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1662 ////////////////////////////////////////////////
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1663 // init the tokens
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1664 //
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1665 void token_init() {
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1666 token_autowhite = register_string("autowhite");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1667 token_black = register_string("black");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1668 token_cctld = register_string("cctld");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1669 token_content = register_string("content");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1670 token_context = register_string("context");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1671 token_dccbulk = register_string("dcc_bulk_threshold");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1672 token_dccfrom = register_string("dcc_from");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1673 token_dccgrey = register_string("dcc_greylist");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1674 token_dccto = register_string("dcc_to");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1675 token_default = register_string("default");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1676 token_dnsbl = register_string("dnsbl");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1677 token_dnsbll = register_string("dnsbl_list");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1678 token_envfrom = register_string("env_from");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1679 token_envto = register_string("env_to");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1680 token_filter = register_string("filter");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1681 token_generic = register_string("generic");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1682 token_host_limit = register_string("host_limit");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1683 token_html_limit = register_string("html_limit");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1684 token_html_tags = register_string("html_tags");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1685 token_ignore = register_string("ignore");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1686 token_include = register_string("include");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1687 token_inherit = register_string("inherit");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1688 token_lbrace = register_string("{");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1689 token_mailhost = register_string("mail_host");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1690 token_many = register_string("many");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1691 token_no = register_string("no");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1692 token_off = register_string("off");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1693 token_ok = register_string("ok");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1694 token_ok2 = register_string("ok2");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1695 token_on = register_string("on");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1696 token_rate = register_string("rate_limit");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1697 token_rbrace = register_string("}");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1698 token_require = register_string("require_match");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1699 token_semi = register_string(";");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1700 token_soft = register_string("soft");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1701 token_spamassassin = register_string("spamassassin");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1702 token_substitute = register_string("substitute");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1703 token_tld = register_string("tld");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1704 token_unknown = register_string("unknown");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1705 token_uribl = register_string("uribl");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1706 token_verify = register_string("verify");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1707 token_white = register_string("white");
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1708 token_yes = register_string("yes");
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1709
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1710 if (gethostname(myhostname, HOST_NAME_MAX+1) != 0) {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1711 strncpy(myhostname, "localhost", HOST_NAME_MAX+1);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1712 }
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1713 myhostname[HOST_NAME_MAX] = '\0'; // ensure null termination
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 180
diff changeset
1714 token_myhostname = register_string(myhostname);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1715 }