annotate src/context.cpp @ 188:edcefdb7ccc1

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