annotate src/context.cpp @ 148:9330b8d6a56b

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