annotate src/context.cpp @ 153:8d7c439bb6fa

add auto whitelisting
author carl
date Sat, 07 Jul 2007 16:10:39 -0700
parents c7fc218686f5
children 89ce226e5383
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
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
11 // needed for socket io
96
1edd4e8d3a60 fix missing include, not all systems define HOST_NAME_MAX
carl
parents: 94
diff changeset
12 #include <unistd.h>
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
13 #include <sys/ioctl.h>
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
14 #include <net/if.h>
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
15 #include <arpa/inet.h>
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
16 #include <netinet/in.h>
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
17 #include <netinet/tcp.h>
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
18 #include <netdb.h>
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
19 #include <sys/socket.h>
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
20 #include <sys/un.h>
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;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
26 char *token_content;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
27 char *token_context;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
28 char *token_dccfrom;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
29 char *token_dccto;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
30 char *token_default;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
31 char *token_dnsbl;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
32 char *token_dnsbll;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
33 char *token_envfrom;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
34 char *token_envto;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
35 char *token_filter;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
36 char *token_host_limit;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
37 char *token_html_limit;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
38 char *token_html_tags;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
39 char *token_ignore;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
40 char *token_include;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
41 char *token_inherit;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
42 char *token_lbrace;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
43 char *token_mailhost;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
44 char *token_many;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
45 char *token_off;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
46 char *token_ok2;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
47 char *token_ok;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
48 char *token_on;
136
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
49 char *token_rate;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
50 char *token_rbrace;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
51 char *token_semi;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
52 char *token_soft;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
53 char *token_substitute;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
54 char *token_tld;
117
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
55 char *token_cctld;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
56 char *token_unknown;
119
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
57 char *token_uribl;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
58 char *token_verify;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
59 char *token_white;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
60
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
61 char *token_myhostname;
96
1edd4e8d3a60 fix missing include, not all systems define HOST_NAME_MAX
carl
parents: 94
diff changeset
62 #ifndef HOST_NAME_MAX
1edd4e8d3a60 fix missing include, not all systems define HOST_NAME_MAX
carl
parents: 94
diff changeset
63 #define HOST_NAME_MAX 255
1edd4e8d3a60 fix missing include, not all systems define HOST_NAME_MAX
carl
parents: 94
diff changeset
64 #endif
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
65 char myhostname[HOST_NAME_MAX+1];
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
66
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
67 pthread_mutex_t verifier_mutex; // protect the verifier map
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
68 verify_map verifiers;
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
69
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
70 pthread_mutex_t whitelister_mutex; // protect the
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
71 whitelister_map whitelisters;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
72
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
73 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
74 const int maxlen = 1000; // used for snprintf buffers
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
75 const int maxsmtp_age = 120;// smtp verify sockets older than this are ancient
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
76 const int maxauto_age = 600;// auto whitelister delay before flushing to file
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
77 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
78 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
79
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
80
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
81 int SMTP::writer() {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
82 #ifdef VERIFY_DEBUG
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
83 log("writer() sees buffer with %s", buffer);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
84 log("writer() sees error %d", (int)error);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
85 #endif
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
86 int rs = 0;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
87 if (!error) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
88 int len = strlen(buffer);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
89 while (rs < len) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
90 int ws = write(fd, buffer+rs, len-rs);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
91 if (ws > 0) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
92 rs += ws;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
93 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
94 else {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
95 // peer closed the socket!
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
96 rs = 0;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
97 error = true;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
98 break;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
99 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
100 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
101 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
102 return rs;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
103 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
104
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
105
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
106 int SMTP::reader() {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
107 // read some bytes terminated by lf or end of buffer.
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
108 // we may have a multi line response or part thereof in the buffer.
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
109 #ifdef VERIFY_DEBUG
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
110 log("reader() sees error %d", (int)error);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
111 #endif
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
112 if (error) return 0;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
113 int len = maxlen-1; // room for null terminator
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
114 while (pending < len) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
115 int ws = read(fd, buffer+pending, len-pending);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
116 if (ws > 0) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
117 pending += ws;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
118 if (buffer[pending-1] == '\n') break;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
119 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
120 else {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
121 // peer closed the socket!
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
122 pending = 0;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
123 error = true;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
124 break;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
125 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
126 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
127 buffer[pending] = '\0';
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
128 #ifdef VERIFY_DEBUG
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
129 log("reader() sees buffer with %s", buffer);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
130 #endif
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
131 return pending;
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
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
135 int SMTP::read_line() {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
136 char *lf = strchr(buffer, '\n');
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
137 if (!lf) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
138 reader(); // get a lf
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
139 lf = strchr(buffer, '\n');
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
140 if (!lf) lf = buffer + pending - 1;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
141 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
142 return (lf-buffer)+1; // number of bytes in this line
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
143 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
144
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
145
97
cc3b79349c9c fix int function not returning value
carl
parents: 96
diff changeset
146 void SMTP::flush_line(int r) {
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
147 if (pending > r) memmove(buffer, buffer+r, pending-r);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
148 pending -= r;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
149 }
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 int SMTP::read_response() {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
153 pending = 0;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
154 buffer[pending] = '\0';
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
155 while (true) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
156 int r = read_line();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
157 #ifdef VERIFY_DEBUG
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
158 log("read_response() sees line with %s", buffer);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
159 log("read_response() sees line length %d", r);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
160 #endif
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
161 if (r == 0) return 0; // failed to read any bytes
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
162 if ((r > 4) && (buffer[3] == '-')) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
163 flush_line(r);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
164 continue;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
165 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
166 return atoi(buffer);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
167 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
168 return 0;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
169 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
170
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
171
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
172 int SMTP::cmd(char *c) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
173 if (c) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
174 init();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
175 append(c);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
176 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
177 append("\r\n");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
178 writer();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
179 return read_response();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
180 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
181
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
182
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
183 int SMTP::helo() {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
184 if (read_response() != 220) return 0;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
185 init();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
186 append("HELO ");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
187 append(token_myhostname);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
188 return cmd(NULL);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
189 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
190
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
191
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
192 int SMTP::rset() {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
193 int rc = cmd("RSET");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
194 efrom[0] = '\0';
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
195 return rc;
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::from(char *f) {
101
6ac7ba4a8312 fix <> passed as <<>> to verification hosts
carl
parents: 100
diff changeset
200 // the mail from address was originally passed in from sendmail enclosed in
6ac7ba4a8312 fix <> passed as <<>> to verification hosts
carl
parents: 100
diff changeset
201 // <>. to_lower_string() removed the <> and converted the rest to lowercase,
6ac7ba4a8312 fix <> passed as <<>> to verification hosts
carl
parents: 100
diff changeset
202 // 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
203 // character string <>.
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
204 if (strncmp(efrom, f, maxlen)) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
205 rset();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
206 strncpy(efrom, f, maxlen);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
207 init();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
208 append("MAIL FROM:<");
101
6ac7ba4a8312 fix <> passed as <<>> to verification hosts
carl
parents: 100
diff changeset
209 if (*f != '<') append(f);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
210 append(">");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
211 return cmd(NULL);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
212 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
213 return 250; // pretend it worked
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
214 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
215
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
216
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
217 int SMTP::rcpt(char *t) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
218 init();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
219 append("RCPT TO:<");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
220 append(t);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
221 append(">");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
222 return cmd(NULL);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
223 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
224
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
225
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
226 int SMTP::quit() {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
227 return cmd("QUIT");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
228 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
229
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
230
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
231 void SMTP::closefd() {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
232 shutdown(fd, SHUT_RDWR);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
233 close(fd);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
234 }
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 #ifdef VERIFY_DEBUG
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
238 void SMTP::log(char *m, int v) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
239 char buf[maxlen];
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
240 snprintf(buf, maxlen, m, v);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
241 my_syslog(buf);
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
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
245 void SMTP::log(char *m, char *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 #endif
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
251
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
252
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
253 ////////////////////////////////////////////////
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
254 // smtp verifier so backup mx machines can see the valid users
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
255 //
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
256 VERIFY::VERIFY(char *h) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
257 host = h;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
258 last_err = 0;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
259 pthread_mutex_init(&mutex, 0);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
260 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
261
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
262
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
263 void VERIFY::closer() {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
264 bool ok = true;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
265 while (ok) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
266 SMTP *conn = NULL;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
267 pthread_mutex_lock(&mutex);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
268 if (connections.empty()) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
269 ok = false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
270 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
271 else {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
272 conn = connections.front();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
273 time_t now = time(NULL);
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
274 if ((now - conn->get_stamp()) > maxsmtp_age) {
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
275 // this connection is ancient, remove it
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
276 connections.pop_front();
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 ok = false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
280 conn = NULL;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
281 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
282 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
283 pthread_mutex_unlock(&mutex);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
284 // avoid doing this work inside the mutex lock
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
285 if (conn) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
286 #ifdef VERIFY_DEBUG
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
287 conn->log("closer() closes ancient %d", conn->get_fd());
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
288 #endif
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
289 delete conn;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
290 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
291 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
292 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
293
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
294
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
295 SMTP* VERIFY::get_connection() {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
296 SMTP *conn = NULL;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
297 pthread_mutex_lock(&mutex);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
298 if (!connections.empty()) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
299 conn = connections.front();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
300 connections.pop_front();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
301 #ifdef VERIFY_DEBUG
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
302 conn->log("get_connection() %d from cache", conn->get_fd());
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
303 #endif
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
304 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
305 pthread_mutex_unlock(&mutex);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
306 if (conn) return conn;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
307 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
308 if ((time(NULL) - last_err) > ERROR_SMTP_SOCKET_TIME) {
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
309 // nothing recent, maybe this time it will work
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
310 hostent *h = gethostbyname(host);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
311 if (h) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
312 sockaddr_in server;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
313 server.sin_family = h->h_addrtype;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
314 server.sin_port = htons(25);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
315 memcpy(&server.sin_addr, h->h_addr_list[0], h->h_length);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
316 sock = socket(PF_INET, SOCK_STREAM, 0);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
317 if (sock != NULL_SOCKET) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
318 bool rc = (connect(sock, (sockaddr *)&server, sizeof(server)) == 0);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
319 if (!rc) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
320 shutdown(sock, SHUT_RDWR);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
321 close(sock);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
322 sock = NULL_SOCKET;
129
c5cd1261394d ignore smtp connection attempts for 10 minutes when getting connection errors on verify hosts
carl
parents: 119
diff changeset
323 last_err = time(NULL);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
324 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
325 }
129
c5cd1261394d ignore smtp connection attempts for 10 minutes when getting connection errors on verify hosts
carl
parents: 119
diff changeset
326 else last_err = time(NULL);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
327 }
129
c5cd1261394d ignore smtp connection attempts for 10 minutes when getting connection errors on verify hosts
carl
parents: 119
diff changeset
328 else last_err = time(NULL);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
329 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
330 if (sock != NULL_SOCKET) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
331 conn = new SMTP(sock);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
332 #ifdef VERIFY_DEBUG
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
333 conn->log("get_connection() %d new socket", conn->get_fd());
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
334 #endif
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
335 if (conn->helo() == 250) return conn;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
336 delete conn;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
337 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
338 return NULL;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
339 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
340
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
341
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
342 void VERIFY::put_connection(SMTP *conn) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
343 if (conn->err()) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
344 #ifdef VERIFY_DEBUG
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
345 conn->log("put_socket() %d with error, close it", conn->get_fd());
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
346 #endif
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
347 delete conn;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
348 last_err = time(NULL);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
349 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
350 else {
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", 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 conn->now();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
355 pthread_mutex_lock(&mutex);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
356 connections.push_back(conn);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
357 pthread_mutex_unlock(&mutex);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
358 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
359 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
360
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
361
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
362 bool VERIFY::ok(char *from, char *to) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
363 if (host == token_myhostname) return true;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
364 SMTP *conn = get_connection();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
365 if (!conn) return true; // cannot verify right now, we have socket errors
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
366 int rc;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
367 rc = conn->from(from);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
368 #ifdef VERIFY_DEBUG
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
369 conn->log("verify::ok() from sees %d", rc);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
370 #endif
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
371 if (rc != 250) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
372 conn->rset();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
373 put_connection(conn);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
374 return (rc >= 500) ? false : true;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
375 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
376 rc = conn->rcpt(to);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
377 #ifdef VERIFY_DEBUG
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
378 conn->log("verify::ok() rcpt sees %d", rc);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
379 #endif
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
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
384
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
385 ////////////////////////////////////////////////
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
386 // setup a new smtp verify host
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
387 //
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
388 VERIFYP add_verify_host(char *host);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
389 VERIFYP add_verify_host(char *host) {
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
390 VERIFYP rc = NULL;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
391 pthread_mutex_lock(&verifier_mutex);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
392 verify_map::iterator i = verifiers.find(host);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
393 if (i == verifiers.end()) {
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
394 rc = new VERIFY(host);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
395 verifiers[host] = rc;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
396 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
397 else rc = (*i).second;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
398 pthread_mutex_unlock(&verifier_mutex);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
399 return rc;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
400 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
401
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
402
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
403 ////////////////////////////////////////////////
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
404 // thread to check for verify hosts with old sockets that we can close
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
405 //
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
406 void* verify_closer(void *arg) {
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
407 while (true) {
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
408 sleep(maxsmtp_age);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
409 pthread_mutex_lock(&verifier_mutex);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
410 for (verify_map::iterator i=verifiers.begin(); i!=verifiers.end(); i++) {
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
411 VERIFYP v = (*i).second;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
412 v->closer();
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
413 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
414 pthread_mutex_unlock(&verifier_mutex);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
415 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
416 return NULL;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
417 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
418
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
419
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
420 ////////////////////////////////////////////////
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
421 // automatic whitelister
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
422 //
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
423 WHITELISTER::WHITELISTER(char *f, int d) {
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
424 fn = f;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
425 days = d;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
426 pthread_mutex_init(&mutex, 0);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
427 need = false;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
428 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
429
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
430
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
431 void WHITELISTER::writer() {
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
432 pthread_mutex_lock(&mutex);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
433 time_t limit = time(NULL) - days*86400;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
434 for (autowhite_sent::iterator i=rcpts.begin(); i!=rcpts.end();) {
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
435 time_t when = (*i).second;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
436 if (when < limit) {
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
437 autowhite_sent::iterator j = i;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
438 j++;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
439 rcpts.erase(i);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
440 i = j;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
441 need = true;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
442 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
443 else i++;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
444 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
445 if (need) {
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
446 // dump the file
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
447 ofstream os;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
448 os.open(fn);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
449 if (!os.fail()) {
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
450 for (autowhite_sent::iterator i=rcpts.begin(); i!=rcpts.end(); i++) {
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
451 char *who = (*i).first;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
452 int when = (*i).second;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
453 os << who << " " << when << endl;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
454 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
455 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
456 os.close();
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
457 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
458 pthread_mutex_unlock(&mutex);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
459 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
460
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
461
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
462 void WHITELISTER::sent(char *to) {
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
463 pthread_mutex_lock(&mutex);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
464 need = true;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
465 rcpts[to] = time(NULL);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
466 pthread_mutex_unlock(&mutex);
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 bool WHITELISTER::is_white(char *from) {
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
471 bool rc = false;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
472 pthread_mutex_lock(&mutex);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
473 autowhite_sent::iterator i = rcpts.find(from);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
474 if (i != rcpts.end()) {
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
475 time_t when = (*i).second;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
476 time_t now = time(NULL);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
477 rc = (when+(days*8640) > now);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
478 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
479 pthread_mutex_unlock(&mutex);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
480 return rc;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
481 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
482
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
483
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
484 ////////////////////////////////////////////////
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
485 // setup a new auto whitelister file
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
486 //
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
487 WHITELISTERP add_whitelister_file(char *fn, int days);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
488 WHITELISTERP add_whitelister_file(char *fn, int days) {
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
489 WHITELISTERP rc = NULL;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
490 pthread_mutex_lock(&whitelister_mutex);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
491 whitelister_map::iterator i = whitelisters.find(fn);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
492 if (i == whitelisters.end()) {
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
493 rc = new WHITELISTER(fn, days);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
494 whitelisters[fn] = rc;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
495 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
496 else rc = (*i).second;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
497 pthread_mutex_unlock(&whitelister_mutex);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
498 return rc;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
499 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
500
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
501
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
502 ////////////////////////////////////////////////
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
503 // thread to check for whitelister hosts with old sockets that we can close
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
504 //
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
505 void* whitelister_writer(void *arg) {
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
506 while (true) {
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
507 sleep(maxauto_age);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
508 pthread_mutex_lock(&whitelister_mutex);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
509 for (whitelister_map::iterator i=whitelisters.begin(); i!=whitelisters.end(); i++) {
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
510 WHITELISTERP v = (*i).second;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
511 v->writer();
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
512 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
513 pthread_mutex_unlock(&whitelister_mutex);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
514 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
515 return NULL;
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
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
519 DNSBL::DNSBL(char *n, char *s, char *m) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
520 name = n;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
521 suffix = s;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
522 message = m;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
523 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
524
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
525
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
526 bool DNSBL::operator==(const DNSBL &rhs) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
527 return (strcmp(name, rhs.name) == 0) &&
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
528 (strcmp(suffix, rhs.suffix) == 0) &&
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
529 (strcmp(message, rhs.message) == 0);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
530 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
531
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
532
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
533 CONFIG::CONFIG() {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
534 reference_count = 0;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
535 generation = 0;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
536 load_time = 0;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
537 default_context = NULL;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
538 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
539
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
540
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
541 CONFIG::~CONFIG() {
146
7278c9766e26 free old configs when last reference goes away
carl
parents: 145
diff changeset
542 if (debug_syslog) {
7278c9766e26 free old configs when last reference goes away
carl
parents: 145
diff changeset
543 char buf[maxlen];
7278c9766e26 free old configs when last reference goes away
carl
parents: 145
diff changeset
544 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
545 my_syslog(buf);
7278c9766e26 free old configs when last reference goes away
carl
parents: 145
diff changeset
546 }
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
547 for (context_list::iterator i=contexts.begin(); i!=contexts.end(); i++) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
548 CONTEXT *c = *i;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
549 delete c;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
550 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
551 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
552
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
553
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
554 void CONFIG::add_context(CONTEXTP con) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
555 contexts.push_back(con);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
556 if (!default_context && !con->get_parent()) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
557 // first global context
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
558 default_context = con;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
559 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
560 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
561
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
562
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
563 void CONFIG::add_to(char *to, CONTEXTP con) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
564 context_map::iterator i = env_to.find(to);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
565 if (i != env_to.end()) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
566 CONTEXTP c = (*i).second;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
567 if ((c != con) && (c != con->get_parent())) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
568 if (debug_syslog) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
569 char oldname[maxlen];
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
570 char newname[maxlen];
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
571 char *oldn = c->get_full_name(oldname, maxlen);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
572 char *newn = con->get_full_name(newname, maxlen);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
573 char buf[maxlen*3];
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
574 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
575 my_syslog(buf);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
576 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
577 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
578 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
579 env_to[to] = con;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
580 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
581
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
582
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
583 CONTEXTP CONFIG::find_context(char *to) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
584 context_map::iterator i = env_to.find(to);
117
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
585 if (i != env_to.end()) return (*i).second; // found user@domain key
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
586 char *x = strchr(to, '@');
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
587 if (x) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
588 x++;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
589 i = env_to.find(x);
117
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
590 if (i != env_to.end()) return (*i).second; // found domain key
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
591 char y = *x;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
592 *x = '\0';
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
593 i = env_to.find(to);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
594 *x = y;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
595 if (i != env_to.end()) return (*i).second; // found user@ key
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
596 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
597 return default_context;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
598 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
599
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
600
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
601 void CONFIG::dump() {
144
31ff00ea6bfb allow parent/child to share a fully qualified env_to address
carl
parents: 143
diff changeset
602 if (default_context) default_context->dump(true);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
603 for (context_list::iterator i=contexts.begin(); i!=contexts.end(); i++) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
604 CONTEXTP c = *i;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
605 CONTEXTP p = c->get_parent();
144
31ff00ea6bfb allow parent/child to share a fully qualified env_to address
carl
parents: 143
diff changeset
606 if (!p && (c != default_context)) c->dump(false);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
607 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
608 char buf[maxlen];
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
609 for (context_map::iterator i=env_to.begin(); i!=env_to.end(); i++) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
610 char *to = (*i).first;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
611 CONTEXTP con = (*i).second;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
612 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
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 CONTEXT::CONTEXT(CONTEXTP parent_, char *name_) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
618 parent = parent_;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
619 name = name_;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
620 verify_host = NULL;
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
621 verifier = NULL;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
622 autowhite_file = NULL;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
623 whitelister = NULL;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
624 env_from_default = (parent) ? token_inherit : token_unknown;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
625 content_filtering = (parent) ? parent->content_filtering : false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
626 content_suffix = NULL;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
627 content_message = NULL;
119
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
628 uribl_suffix = NULL;
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
629 uribl_message = NULL;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
630 host_limit = (parent) ? parent->host_limit : 0;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
631 host_limit_message = NULL;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
632 host_random = (parent) ? parent->host_random : false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
633 tag_limit = (parent) ? parent->tag_limit : 0;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
634 tag_limit_message = NULL;
140
4028de9b46dd cleanup smtp rate limit code
carl
parents: 136
diff changeset
635 default_rcpt_rate = INT_MAX;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
636 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
637
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
638
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
639 CONTEXT::~CONTEXT() {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
640 for (dnsblp_map::iterator i=dnsbl_names.begin(); i!=dnsbl_names.end(); i++) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
641 DNSBLP d = (*i).second;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
642 // delete the underlying DNSBL objects.
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
643 delete d;
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
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
647
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
648 bool CONTEXT::is_parent(CONTEXTP p) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
649 if (p == parent) return true;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
650 if (!parent) return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
651 return parent->is_parent(p);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
652 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
653
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
654
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
655 char *CONTEXT::get_full_name(char *buffer, int size) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
656 if (!parent) return name;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
657 char buf[maxlen];
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
658 snprintf(buffer, size, "%s.%s", parent->get_full_name(buf, maxlen), name);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
659 return buffer;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
660 }
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 bool CONTEXT::cover_env_to(char *to) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
664 char buffer[maxlen];
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
665 char *x = strchr(to, '@');
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
666 if (x) x++;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
667 else x = to;
144
31ff00ea6bfb allow parent/child to share a fully qualified env_to address
carl
parents: 143
diff changeset
668 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
669 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
670 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
671 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
672 if (x != to) {
31ff00ea6bfb allow parent/child to share a fully qualified env_to address
carl
parents: 143
diff changeset
673 i = env_to.find(to);
31ff00ea6bfb allow parent/child to share a fully qualified env_to address
carl
parents: 143
diff changeset
674 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
675 }
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
676 return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
677 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
678
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
679
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
680 VERIFYP CONTEXT::find_verify(char *to) {
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
681 if (verifier && (verify_host != token_myhostname) && cover_env_to(to))
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
682 return verifier;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
683 else if (parent)
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
684 return parent->find_verify(to);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
685 else
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
686 return NULL;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
687 }
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
688
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
689
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
690 WHITELISTERP CONTEXT::find_autowhite(char *to) {
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
691 if (whitelister && cover_env_to(to))
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
692 return whitelister;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
693 else if (parent)
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
694 return parent->find_autowhite(to);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
695 else
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
696 return NULL;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
697 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
698
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
699
136
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
700 int CONTEXT::find_rate(char *user) {
140
4028de9b46dd cleanup smtp rate limit code
carl
parents: 136
diff changeset
701 if (rcpt_per_hour.empty()) return default_rcpt_rate;
136
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
702 rcpt_rates::iterator i = rcpt_per_hour.find(user);
140
4028de9b46dd cleanup smtp rate limit code
carl
parents: 136
diff changeset
703 return (i == rcpt_per_hour.end()) ? default_rcpt_rate : (*i).second;
136
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
704 }
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
705
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
706
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
707 char *CONTEXT::find_from(char *from) {
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
708 if (whitelister && whitelister->is_white(from)) return token_white;
148
9330b8d6a56b add documentation fixes, allow env_from target of inherit
carl
parents: 146
diff changeset
709 char *rc = env_from_default;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
710 string_map::iterator i = env_from.find(from);
117
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
711 if (i != env_from.end()) rc = (*i).second; // found user@domain key
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
712 else {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
713 char *x = strchr(from, '@');
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
714 if (x) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
715 x++;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
716 i = env_from.find(x);
117
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
717 if (i != env_from.end()) rc = (*i).second; // found domain key
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
718 else {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
719 char y = *x;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
720 *x = '\0';
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
721 i = env_from.find(from);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
722 *x = y;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
723 if (i != env_from.end()) rc = (*i).second; // found user@ key
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
724 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
725 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
726 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
727 if ((rc == token_inherit) && parent) return parent->find_from(from);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
728 return (rc == token_inherit) ? token_unknown : rc;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
729 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
730
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
731
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
732 CONTEXTP CONTEXT::find_context(char *from) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
733 context_map::iterator i = env_from_context.find(from);
117
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
734 if (i != env_from_context.end()) return (*i).second; // found user@domain key
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
735 char *x = strchr(from, '@');
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
736 if (x) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
737 x++;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
738 i = env_from_context.find(x);
117
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
739 if (i != env_from_context.end()) return (*i).second; // found domain key
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
740 char y = *x;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
741 *x = '\0';
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
742 i = env_from_context.find(from);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
743 *x = y;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
744 if (i != env_from_context.end()) return (*i).second; // found user@ key
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
745 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
746 return this;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
747 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
748
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
749
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
750 CONTEXTP CONTEXT::find_from_context_name(char *name) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
751 context_map::iterator i = children.find(name);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
752 if (i != children.end()) return (*i).second;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
753 return NULL;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
754 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
755
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
756
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
757 DNSBLP CONTEXT::find_dnsbl(char *name) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
758 dnsblp_map::iterator i = dnsbl_names.find(name);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
759 if (i != dnsbl_names.end()) return (*i).second;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
760 if (parent) return parent->find_dnsbl(name);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
761 return NULL;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
762 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
763
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
764
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
765 char* CONTEXT::get_content_suffix() {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
766 if (!content_suffix && parent) return parent->get_content_suffix();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
767 return content_suffix;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
768 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
769
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
770
119
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
771 char* CONTEXT::get_uribl_suffix() {
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
772 if (!uribl_suffix && parent) return parent->get_uribl_suffix();
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
773 return uribl_suffix;
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
774 }
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
775
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
776
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
777 char* CONTEXT::get_content_message() {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
778 if (!content_message && parent) return parent->get_content_message();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
779 return content_message;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
780 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
781
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
782
119
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
783 char* CONTEXT::get_uribl_message() {
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
784 if (!uribl_message && parent) return parent->get_uribl_message();
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
785 return uribl_message;
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
786 }
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
787
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
788
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
789 string_set& CONTEXT::get_content_host_ignore() {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
790 if (content_host_ignore.empty() && parent) return parent->get_content_host_ignore();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
791 return content_host_ignore;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
792 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
793
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
794
117
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
795 string_set& CONTEXT::get_content_cctlds() {
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
796 if (content_cctlds.empty() && parent) return parent->get_content_cctlds();
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
797 return content_cctlds;
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
798 }
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
799
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
800 string_set& CONTEXT::get_content_tlds() {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
801 if (content_tlds.empty() && parent) return parent->get_content_tlds();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
802 return content_tlds;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
803 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
804
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
805
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
806 string_set& CONTEXT::get_html_tags() {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
807 if (html_tags.empty() && parent) return parent->get_html_tags();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
808 return html_tags;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
809 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
810
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
811
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
812 dnsblp_list& CONTEXT::get_dnsbl_list() {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
813 if (dnsbl_list.empty() && parent) return parent->get_dnsbl_list();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
814 return dnsbl_list;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
815 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
816
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
817
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
818 bool CONTEXT::acceptable_content(recorder &memory, char *&msg) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
819 if (memory.excessive_bad_tags(tag_limit)) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
820 msg = tag_limit_message;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
821 return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
822 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
823 if (!host_random && memory.excessive_hosts(host_limit)) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
824 msg = host_limit_message;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
825 return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
826 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
827 return true;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
828 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
829
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
830
144
31ff00ea6bfb allow parent/child to share a fully qualified env_to address
carl
parents: 143
diff changeset
831 void CONTEXT::dump(bool isdefault, int level) {
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
832 char indent[maxlen];
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
833 int i = min(maxlen-1, level*4);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
834 memset(indent, ' ', i);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
835 indent[i] = '\0';
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
836 char buf[maxlen];
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
837 char *fullname = get_full_name(buf,maxlen);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
838 printf("%s context %s { \t// %s\n", indent, name, fullname);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
839
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
840 for (dnsblp_map::iterator i=dnsbl_names.begin(); i!=dnsbl_names.end(); i++) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
841 char *n = (*i).first;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
842 DNSBL &d = *(*i).second;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
843 printf("%s dnsbl %s %s \"%s\"; \n", indent, n, d.suffix, d.message);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
844 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
845
145
9b9bab1d3c21 dump effective dnsbl_list with -c switch
carl
parents: 144
diff changeset
846 dnsblp_list dl = get_dnsbl_list();
9b9bab1d3c21 dump effective dnsbl_list with -c switch
carl
parents: 144
diff changeset
847 if (!dl.empty()) {
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
848 printf("%s dnsbl_list", indent);
145
9b9bab1d3c21 dump effective dnsbl_list with -c switch
carl
parents: 144
diff changeset
849 for (dnsblp_list::iterator i=dl.begin(); i!=dl.end(); i++) {
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
850 DNSBL &d = *(*i);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
851 printf(" %s", d.name);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
852 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
853 printf("; \n");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
854 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
855
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
856 if (content_filtering) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
857 printf("%s content on { \n", indent, env_from_default);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
858 if (content_suffix) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
859 printf("%s filter %s \"%s\"; \n", indent, content_suffix, content_message);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
860 }
119
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
861 if (uribl_suffix) {
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
862 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
863 }
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
864 if (!content_host_ignore.empty()) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
865 printf("%s ignore { \n", indent);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
866 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
867 printf("%s %s; \n", indent, *i);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
868 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
869 printf("%s }; \n", indent);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
870 }
117
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
871 if (!content_cctlds.empty()) {
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
872 printf("%s cctld { \n", indent);
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
873 printf("%s ", indent);
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
874 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
875 printf("%s; ", *i);
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
876 }
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
877 printf("\n%s }; \n", indent);
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
878 }
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
879 if (!content_tlds.empty()) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
880 printf("%s tld { \n", indent);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
881 printf("%s ", indent);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
882 for (string_set::iterator i=content_tlds.begin(); i!=content_tlds.end(); i++) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
883 printf("%s; ", *i);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
884 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
885 printf("\n%s }; \n", indent);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
886 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
887 if (!html_tags.empty()) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
888 printf("%s html_tags { \n", indent);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
889 printf("%s ", indent);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
890 for (string_set::iterator i=html_tags.begin(); i!=html_tags.end(); i++) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
891 printf("%s; ", *i);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
892 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
893 printf("\n%s }; \n", indent);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
894 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
895 if (host_limit_message) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
896 printf("%s host_limit on %d \"%s\"; \n", indent, host_limit, host_limit_message);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
897 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
898 else if (host_random) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
899 printf("%s host_limit soft %d; \n", indent, host_limit);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
900 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
901 else {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
902 printf("%s host_limit off; \n", indent);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
903 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
904 if (tag_limit_message) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
905 printf("%s html_limit on %d \"%s\"; \n", indent, tag_limit, tag_limit_message);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
906 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
907 else {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
908 printf("%s html_limit off; \n", indent);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
909 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
910 printf("%s }; \n", indent);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
911 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
912 else {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
913 printf("%s content off {}; \n", indent, env_from_default);
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 printf("%s env_to { \t// %s\n", indent, fullname);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
917 for (string_set::iterator i=env_to.begin(); i!=env_to.end(); i++) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
918 printf("%s %s; \n", indent, *i);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
919 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
920 printf("%s }; \n", indent);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
921
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
922 if (verify_host) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
923 printf("%s verify %s; \n", indent, verify_host);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
924 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
925
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
926 if (autowhite_file && whitelister) {
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
927 printf("%s autowhite %d %s; \n", indent, whitelister->get_days(), autowhite_file);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
928 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
929
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
930 for (context_map::iterator i=children.begin(); i!=children.end(); i++) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
931 CONTEXTP c = (*i).second;
144
31ff00ea6bfb allow parent/child to share a fully qualified env_to address
carl
parents: 143
diff changeset
932 c->dump(false, level+1);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
933 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
934
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
935 printf("%s env_from %s { \t// %s\n", indent, env_from_default, fullname);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
936 if (!env_from.empty()) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
937 printf("%s // white/black/unknown \n", indent);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
938 for (string_map::iterator i=env_from.begin(); i!=env_from.end(); i++) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
939 char *f = (*i).first;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
940 char *t = (*i).second;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
941 printf("%s %s \t%s; \n", indent, f, t);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
942 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
943 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
944 if (!env_from_context.empty()) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
945 printf("%s // child contexts \n", indent);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
946 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
947 char *f = (*j).first;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
948 CONTEXTP t = (*j).second;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
949 printf("%s %s \t%s; \n", indent, f, t->name);
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 printf("%s }; \n", indent);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
953
144
31ff00ea6bfb allow parent/child to share a fully qualified env_to address
carl
parents: 143
diff changeset
954 if (isdefault) {
31ff00ea6bfb allow parent/child to share a fully qualified env_to address
carl
parents: 143
diff changeset
955 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
956 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
957 char *u = (*j).first;
31ff00ea6bfb allow parent/child to share a fully qualified env_to address
carl
parents: 143
diff changeset
958 int l = (*j).second;
31ff00ea6bfb allow parent/child to share a fully qualified env_to address
carl
parents: 143
diff changeset
959 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
960 }
31ff00ea6bfb allow parent/child to share a fully qualified env_to address
carl
parents: 143
diff changeset
961 printf("%s }; \n", indent);
136
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
962 }
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
963
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
964 printf("%s }; \n", indent);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
965 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
966
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
967
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
968 ////////////////////////////////////////////////
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
969 // helper to discard the strings held by a string_set
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
970 //
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
971 void discard(string_set &s) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
972 for (string_set::iterator i=s.begin(); i!=s.end(); i++) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
973 free(*i);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
974 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
975 s.clear();
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
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
979 ////////////////////////////////////////////////
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
980 // helper to register a string in a string set
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
981 //
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
982 char* register_string(string_set &s, char *name) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
983 string_set::iterator i = s.find(name);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
984 if (i != s.end()) return *i;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
985 char *x = strdup(name);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
986 s.insert(x);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
987 return x;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
988 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
989
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
990
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
991 ////////////////////////////////////////////////
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
992 // register a global string
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
993 //
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
994 char* register_string(char *name) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
995 return register_string(all_strings, name);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
996 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
997
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
998
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
999 ////////////////////////////////////////////////
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1000 //
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1001 bool tsa(TOKEN &tok, char *token);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1002 bool tsa(TOKEN &tok, char *token) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1003 char *have = tok.next();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1004 if (have == token) return true;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1005 tok.token_error(token, have);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1006 return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1007 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1008
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1009
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1010 ////////////////////////////////////////////////
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1011 //
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1012 bool parse_dnsbl(TOKEN &tok, CONFIG &dc, CONTEXT &me);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1013 bool parse_dnsbl(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1014 char *name = tok.next();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1015 char *suf = tok.next();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1016 char *msg = tok.next();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1017 if (!tsa(tok, token_semi)) return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1018 DNSBLP dnsnew = new DNSBL(name, suf, msg);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1019 DNSBLP dnsold = me.find_dnsbl(name);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1020 if (dnsold && (*dnsold == *dnsnew)) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1021 // duplicate redefinition, ignore it
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1022 delete dnsnew;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1023 return true;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1024 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1025 me.add_dnsbl(name, dnsnew);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1026 return true;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1027 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1028
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1029
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1030 ////////////////////////////////////////////////
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1031 //
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1032 bool parse_dnsbll(TOKEN &tok, CONFIG &dc, CONTEXT &me);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1033 bool parse_dnsbll(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1034 while (true) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1035 char *have = tok.next();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1036 if (!have) break;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1037 if (have == token_semi) break;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1038 DNSBLP dns = me.find_dnsbl(have);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1039 if (dns) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1040 me.add_dnsbl(dns);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1041 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1042 else {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1043 tok.token_error("dnsbl name", have);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1044 return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1045 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1046 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1047 return true;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1048 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1049
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1050
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1051 ////////////////////////////////////////////////
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1052 //
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1053 bool parse_content(TOKEN &tok, CONFIG &dc, CONTEXT &me);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1054 bool parse_content(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1055 char *setting = tok.next();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1056 if (setting == token_on) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1057 me.set_content_filtering(true);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1058 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1059 else if (setting == token_off) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1060 me.set_content_filtering(false);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1061 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1062 else {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1063 tok.token_error("on/off", setting);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1064 return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1065 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1066 if (!tsa(tok, token_lbrace)) return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1067 while (true) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1068 char *have = tok.next();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1069 if (!have) break;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1070 if (have == token_filter) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1071 char *suffix = tok.next();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1072 char *messag = tok.next();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1073 me.set_content_suffix(suffix);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1074 me.set_content_message(messag);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1075 if (!tsa(tok, token_semi)) return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1076 }
119
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
1077 else if (have == token_uribl) {
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
1078 char *suffix = tok.next();
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
1079 char *messag = tok.next();
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
1080 me.set_uribl_suffix(suffix);
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
1081 me.set_uribl_message(messag);
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
1082 if (!tsa(tok, token_semi)) return false;
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
1083 }
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1084 else if (have == token_ignore) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1085 if (!tsa(tok, token_lbrace)) return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1086 while (true) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1087 if (!have) break;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1088 char *have = tok.next();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1089 if (have == token_rbrace) break; // done
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1090 me.add_ignore(have);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1091 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1092 if (!tsa(tok, token_semi)) return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1093 }
117
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
1094 else if (have == token_cctld) {
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
1095 if (!tsa(tok, token_lbrace)) return false;
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
1096 while (true) {
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
1097 char *have = tok.next();
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
1098 if (!have) break;
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
1099 if (have == token_rbrace) break; // done
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
1100 me.add_cctld(have);
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
1101 }
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
1102 if (!tsa(tok, token_semi)) return false;
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
1103 }
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1104 else if (have == token_tld) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1105 if (!tsa(tok, token_lbrace)) return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1106 while (true) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1107 char *have = tok.next();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1108 if (!have) break;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1109 if (have == token_rbrace) break; // done
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1110 me.add_tld(have);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1111 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1112 if (!tsa(tok, token_semi)) return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1113 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1114 else if (have == token_html_limit) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1115 have = tok.next();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1116 if (have == token_on) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1117 me.set_tag_limit(tok.nextint());
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1118 me.set_tag_message(tok.next());
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1119 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1120 else if (have == token_off) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1121 me.set_tag_limit(0);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1122 me.set_tag_message(NULL);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1123 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1124 else {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1125 tok.token_error("on/off", have);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1126 return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1127 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1128 if (!tsa(tok, token_semi)) return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1129 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1130 else if (have == token_html_tags) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1131 if (!tsa(tok, token_lbrace)) return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1132 while (true) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1133 char *have = tok.next();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1134 if (!have) break;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1135 if (have == token_rbrace) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1136 break; // done
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1137 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1138 else {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1139 me.add_tag(have); // base version
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1140 char buf[200];
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1141 snprintf(buf, sizeof(buf), "/%s", have);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1142 me.add_tag(register_string(buf)); // leading /
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1143 snprintf(buf, sizeof(buf), "%s/", have);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1144 me.add_tag(register_string(buf)); // trailing /
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1145 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1146 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1147 if (!tsa(tok, token_semi)) return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1148 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1149 else if (have == token_host_limit) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1150 have = tok.next();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1151 if (have == token_on) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1152 me.set_host_limit(tok.nextint());
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1153 me.set_host_message(tok.next());
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1154 me.set_host_random(false);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1155 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1156 else if (have == token_off) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1157 me.set_host_limit(0);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1158 me.set_host_message(NULL);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1159 me.set_host_random(false);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1160 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1161 else if (have == token_soft) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1162 me.set_host_limit(tok.nextint());
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1163 me.set_host_message(NULL);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1164 me.set_host_random(true);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1165 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1166 else {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1167 tok.token_error("on/off/soft", have);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1168 return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1169 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1170 if (!tsa(tok, token_semi)) return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1171 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1172 else if (have == token_rbrace) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1173 break; // done
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1174 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1175 else {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1176 tok.token_error("content keyword", have);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1177 return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1178 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1179 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1180 return tsa(tok, token_semi);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1181 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1182
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1183
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1184 ////////////////////////////////////////////////
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1185 //
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1186 bool parse_envto(TOKEN &tok, CONFIG &dc, CONTEXT &me);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1187 bool parse_envto(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1188 if (!tsa(tok, token_lbrace)) return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1189 while (true) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1190 char *have = tok.next();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1191 if (!have) break;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1192 if (have == token_rbrace) break;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1193 if (have == token_semi) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1194 // optional separators
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1195 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1196 else if (have == token_dccto) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1197 char *flavor = tok.next();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1198 if (!tsa(tok, token_lbrace)) return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1199 bool keeping = false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1200 while (true) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1201 char *have = tok.next();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1202 if (!have) break;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1203 if (have == token_rbrace) break;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1204 if (have == flavor) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1205 keeping = true;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1206 continue;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1207 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1208 else if ((have == token_ok) || (have == token_ok2) || (have == token_many)) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1209 keeping = false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1210 continue;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1211 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1212 if (have == token_envto) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1213 have = tok.next();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1214 if (keeping) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1215 if (me.allow_env_to(have)) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1216 me.add_to(have);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1217 dc.add_to(have, &me);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1218 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1219 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1220 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1221 //else if (have == token_substitute) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1222 // if (tok.next() == token_mailhost) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1223 // have = tok.next();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1224 // if (keeping) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1225 // if (me.allow_env_to(have)) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1226 // me.add_to(have);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1227 // dc.add_to(have, &me);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1228 // }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1229 // }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1230 // }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1231 //}
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1232 tok.skipeol();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1233 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1234 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1235 else if (me.allow_env_to(have)) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1236 me.add_to(have);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1237 dc.add_to(have, &me);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1238 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1239 else {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1240 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
1241 return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1242 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1243 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1244 return tsa(tok, token_semi);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1245 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1246
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1247
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1248 ////////////////////////////////////////////////
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1249 //
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1250 bool parse_verify(TOKEN &tok, CONFIG &dc, CONTEXT &me);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1251 bool parse_verify(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1252 char *host = tok.next();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1253 if (!tsa(tok, token_semi)) return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1254 me.set_verify(host);
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
1255 me.set_verifier(add_verify_host(host));
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
1256 return true;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
1257 }
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
1258
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
1259
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
1260 ////////////////////////////////////////////////
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
1261 //
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
1262 bool parse_autowhite(TOKEN &tok, CONFIG &dc, CONTEXT &me);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
1263 bool parse_autowhite(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
1264 int days = tok.nextint();
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
1265 char *fn = tok.next();
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
1266 if (!tsa(tok, token_semi)) return false;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
1267 me.set_autowhite(fn);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
1268 me.set_whitelister(add_whitelister_file(fn, days));
99
f8963ddf7143 failed to return a value from parse_verify()
carl
parents: 97
diff changeset
1269 return true;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1270 }
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 ////////////////////////////////////////////////
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1274 //
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1275 bool parse_envfrom(TOKEN &tok, CONFIG &dc, CONTEXT &me);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1276 bool parse_envfrom(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1277 char *st = tok.next();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1278 if ((st == token_black) || (st == token_white) || (st == token_unknown) || (st == token_inherit)) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1279 me.set_from_default(st);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1280 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1281 else {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1282 tok.push(st);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1283 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1284 if (!tsa(tok, token_lbrace)) return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1285 while (true) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1286 char *have = tok.next();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1287 if (!have) break;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1288 if (have == token_rbrace) break;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1289 if (have == token_semi) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1290 // optional separators
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1291 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1292 else if (have == token_dccfrom) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1293 if (!tsa(tok, token_lbrace)) return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1294 bool keeping = false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1295 bool many = false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1296 while (true) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1297 char *have = tok.next();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1298 if (!have) break;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1299 if (have == token_rbrace) break;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1300 if (have == token_ok) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1301 keeping = true;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1302 many = false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1303 continue;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1304 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1305 else if (have == token_many) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1306 keeping = true;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1307 many = true;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1308 continue;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1309 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1310 else if (have == token_ok2) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1311 keeping = false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1312 continue;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1313 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1314 if (have == token_envfrom) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1315 have = tok.next();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1316 if (keeping) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1317 me.add_from(have, (many) ? token_black : token_white);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1318 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1319 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1320 else if (have == token_substitute) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1321 if (tok.next() == token_mailhost) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1322 have = tok.next();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1323 me.add_from(have, (many) ? token_black : token_white);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1324 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1325 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1326 tok.skipeol();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1327 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1328 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1329 else {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1330 // may be a valid email address or domain name
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1331 char *st = tok.next();
148
9330b8d6a56b add documentation fixes, allow env_from target of inherit
carl
parents: 146
diff changeset
1332 if ((st == token_white) || (st == token_black) || (st == token_unknown) || (st == token_inherit)) {
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1333 me.add_from(have, st);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1334 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1335 else {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1336 CONTEXTP con = me.find_from_context_name(st);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1337 if (con) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1338 me.add_from_context(have, con);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1339 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1340 else {
148
9330b8d6a56b add documentation fixes, allow env_from target of inherit
carl
parents: 146
diff changeset
1341 tok.token_error("white/black/unknown/inherit or child context name", st);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1342 return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1343 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1344 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1345 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1346 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1347 return tsa(tok, token_semi);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1348 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1349
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1350
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1351 ////////////////////////////////////////////////
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1352 //
136
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1353 bool parse_rate(TOKEN &tok, CONFIG &dc, CONTEXT &me);
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1354 bool parse_rate(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
140
4028de9b46dd cleanup smtp rate limit code
carl
parents: 136
diff changeset
1355 char *def = tok.next();
141
6256cab02248 cleanup smtp rate limit code
carl
parents: 140
diff changeset
1356 tok.push(def);
6256cab02248 cleanup smtp rate limit code
carl
parents: 140
diff changeset
1357 if (def != token_lbrace) me.set_default_rate(tok.nextint());
136
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1358 if (!tsa(tok, token_lbrace)) return false;
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1359 while (true) {
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1360 char *have = tok.next();
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1361 if (!have) break;
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1362 if (have == token_rbrace) break;
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1363 if (have == token_semi) {
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1364 // optional separators
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1365 }
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1366 else {
140
4028de9b46dd cleanup smtp rate limit code
carl
parents: 136
diff changeset
1367 me.add_rate(have, tok.nextint());
136
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1368 }
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1369 }
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1370 return tsa(tok, token_semi);
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1371 }
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1372
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1373
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1374 ////////////////////////////////////////////////
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1375 //
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1376 bool parse_context(TOKEN &tok, CONFIG &dc, CONTEXTP parent);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1377 bool parse_context(TOKEN &tok, CONFIG &dc, CONTEXTP parent) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1378 char *name = 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 CONTEXTP con = new CONTEXT(parent, name);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1381
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1382 while (true) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1383 char *have = tok.next();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1384 if (!have) break;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1385 if (have == token_rbrace) break; // done
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1386 if (have == token_dnsbl) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1387 if (!parse_dnsbl(tok, dc, *con)) return false;
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_dnsbll) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1390 if (!parse_dnsbll(tok, dc, *con)) return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1391 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1392 else if (have == token_content) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1393 if (!parse_content(tok, dc, *con)) return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1394 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1395 else if (have == token_envto) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1396 if (!parse_envto(tok, dc, *con)) return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1397 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1398 else if (have == token_verify) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1399 if (!parse_verify(tok, dc, *con)) return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1400 }
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
1401 else if (have == token_autowhite) {
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
1402 if (!parse_autowhite(tok, dc, *con)) return false;
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
1403 }
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1404 else if (have == token_envfrom) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1405 if (!parse_envfrom(tok, dc, *con)) return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1406 }
140
4028de9b46dd cleanup smtp rate limit code
carl
parents: 136
diff changeset
1407 else if (have == token_rate) {
4028de9b46dd cleanup smtp rate limit code
carl
parents: 136
diff changeset
1408 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
1409 if (!parse_rate(tok, dc, *con)) return false;
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1410 }
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1411 else if (have == token_context) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1412 if (!parse_context(tok, dc, con)) return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1413 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1414 else {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1415 tok.token_error("context keyword", have);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1416 return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1417 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1418 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1419
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1420 if (!tsa(tok, token_semi)) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1421 delete con;
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 dc.add_context(con);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1425 if (parent) parent->add_context(con);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1426 return true;
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 // parse a config file
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1432 //
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1433 bool load_conf(CONFIG &dc, char *fn) {
99
f8963ddf7143 failed to return a value from parse_verify()
carl
parents: 97
diff changeset
1434 int count = 0;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1435 TOKEN tok(fn, &dc.config_files);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1436 while (true) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1437 char *have = tok.next();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1438 if (!have) break;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1439 if (have == token_context) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1440 if (!parse_context(tok, dc, NULL)) {
99
f8963ddf7143 failed to return a value from parse_verify()
carl
parents: 97
diff changeset
1441 tok.token_error("load_conf() failed to parse context");
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1442 return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1443 }
99
f8963ddf7143 failed to return a value from parse_verify()
carl
parents: 97
diff changeset
1444 else count++;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1445 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1446 else {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1447 tok.token_error(token_context, have);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1448 return false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1449 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1450 }
99
f8963ddf7143 failed to return a value from parse_verify()
carl
parents: 97
diff changeset
1451 tok.token_error("load_conf() found %d contexts in %s", count, fn);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1452 return (dc.default_context) ? true : false;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1453 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1454
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1455
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1456 ////////////////////////////////////////////////
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1457 // init the tokens
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1458 //
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1459 void token_init() {
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
1460 token_autowhite = register_string("autowhite");
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1461 token_black = register_string("black");
117
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 101
diff changeset
1462 token_cctld = register_string("cctld");
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1463 token_content = register_string("content");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1464 token_context = register_string("context");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1465 token_dccfrom = register_string("dcc_from");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1466 token_dccto = register_string("dcc_to");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1467 token_default = register_string("default");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1468 token_dnsbl = register_string("dnsbl");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1469 token_dnsbll = register_string("dnsbl_list");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1470 token_envfrom = register_string("env_from");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1471 token_envto = register_string("env_to");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1472 token_filter = register_string("filter");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1473 token_host_limit = register_string("host_limit");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1474 token_html_limit = register_string("html_limit");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1475 token_html_tags = register_string("html_tags");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1476 token_ignore = register_string("ignore");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1477 token_include = register_string("include");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1478 token_inherit = register_string("inherit");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1479 token_lbrace = register_string("{");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1480 token_mailhost = register_string("mail_host");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1481 token_many = register_string("many");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1482 token_off = register_string("off");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1483 token_ok = register_string("ok");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1484 token_ok2 = register_string("ok2");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1485 token_on = register_string("on");
136
f4746d8a12a3 add smtp auth rate limits
carl
parents: 129
diff changeset
1486 token_rate = register_string("rate_limit");
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1487 token_rbrace = register_string("}");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1488 token_semi = register_string(";");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1489 token_soft = register_string("soft");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1490 token_substitute = register_string("substitute");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1491 token_tld = register_string("tld");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1492 token_unknown = register_string("unknown");
119
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
1493 token_uribl = register_string("uribl");
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1494 token_verify = register_string("verify");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1495 token_white = register_string("white");
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1496
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1497 if (gethostname(myhostname, HOST_NAME_MAX+1) != 0) {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1498 strncpy(myhostname, "localhost", HOST_NAME_MAX+1);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1499 }
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1500 myhostname[HOST_NAME_MAX] = '\0'; // ensure null termination
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1501 token_myhostname = register_string(myhostname);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
1502 }