annotate src/context.h @ 193:3ea79ef741a0

delay autowhitelisting to avoid out of office reply bots
author carl
date Sun, 11 Nov 2007 13:05:41 -0800
parents 8f4a9a37d4d9
children 82886d4dd71f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
143
ecb40aa3eaa5 require two periods for ip addresses
carl
parents: 140
diff changeset
1 /*
ecb40aa3eaa5 require two periods for ip addresses
carl
parents: 140
diff changeset
2
152
c7fc218686f5 gpl3, block mail to recipients that cannot reply
carl
parents: 144
diff changeset
3 Copyright (c) 2007 Carl Byington - 510 Software Group, released under
c7fc218686f5 gpl3, block mail to recipients that cannot reply
carl
parents: 144
diff changeset
4 the GPL version 3 or any later version at your choice available at
c7fc218686f5 gpl3, block mail to recipients that cannot reply
carl
parents: 144
diff changeset
5 http://www.gnu.org/licenses/gpl-3.0.txt
143
ecb40aa3eaa5 require two periods for ip addresses
carl
parents: 140
diff changeset
6
ecb40aa3eaa5 require two periods for ip addresses
carl
parents: 140
diff changeset
7 */
ecb40aa3eaa5 require two periods for ip addresses
carl
parents: 140
diff changeset
8
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
9 #ifndef context_include
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
10 #define context_include
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
11
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
12 #include "tokenizer.h"
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
13 #include <map>
168
6bac960af6b4 add generic reverse dns filtering regex
carl
parents: 167
diff changeset
14 #include <regex.h>
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
15
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
16
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
17 enum status {oksofar, // not rejected yet
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
18 white, // whitelisted
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
19 black, // blacklisted
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
20 reject}; // rejected by a dns list
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
21
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
22 class DNSBL;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
23 class CONTEXT;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
24 class VERIFY;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
25 class SMTP;
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
26 class WHITELISTER;
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 179
diff changeset
27 class DELAYWHITE;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
28 class recorder;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
29
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
30 typedef map<char *, char *, ltstr> string_map;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
31 typedef set<int> int_set;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
32 typedef list<SMTP *> smtp_list;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
33 typedef list<char *> string_list;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
34 typedef DNSBL * DNSBLP;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
35 typedef VERIFY * VERIFYP;
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
36 typedef WHITELISTER * WHITELISTERP;
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 179
diff changeset
37 typedef DELAYWHITE * DELAYWHITEP;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
38 typedef list<DNSBLP> dnsblp_list;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
39 typedef map<char *, DNSBLP, ltstr> dnsblp_map;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
40 typedef CONTEXT * CONTEXTP;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
41 typedef list<CONTEXTP> context_list;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
42 typedef map<char *, CONTEXTP, ltstr> context_map;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
43 typedef map<char *, int, ltstr> ns_mapper;
136
f4746d8a12a3 add smtp auth rate limits
carl
parents: 119
diff changeset
44 typedef map<char *, int, ltstr> rcpt_rates;
160
b3ed72ee6564 allow manual updates to auto whitelist files
carl
parents: 156
diff changeset
45 typedef map<char *, time_t, ltstr> autowhite_sent;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
46 typedef map<char *, VERIFYP, ltstr> verify_map;
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
47 typedef map<char *, WHITELISTERP, ltstr> whitelister_map;
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 179
diff changeset
48 typedef list<DELAYWHITEP> delay_whitelist;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
49
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
50 class SMTP {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
51 static const int maxlen = 1000;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
52 int fd;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
53 bool error;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
54 time_t stamp;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
55 char efrom[maxlen]; // last envelope from sent on this socket
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
56 int pending; // unread bytes in buffer, not including the null terminator
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
57 char buffer[maxlen];
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
58 public:
99
f8963ddf7143 failed to return a value from parse_verify()
carl
parents: 97
diff changeset
59 SMTP(int f) {fd = f; error = false; now(); efrom[0] = '\0'; init();};
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
60 ~SMTP() {if (!error) quit(); closefd();};
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
61 void init() {pending = 0; buffer[0] = '\0';};
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
62 void append(char *c) {strncat(buffer, c, max(0, maxlen-1-(int)strlen(c)));};
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
63 bool err() {return error;};
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
64 void now() {stamp = time(NULL);};
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
65 time_t get_stamp() {return stamp;};
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
66 int get_fd() {return fd;};
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
67 int writer();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
68 int reader();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
69 int read_line();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
70 int read_response();
97
cc3b79349c9c fix int function not returning value
carl
parents: 94
diff changeset
71 void flush_line(int r);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
72 int cmd(char *c);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
73 int helo();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
74 int rset();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
75 int from(char *f);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
76 int rcpt(char *t);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
77 int quit();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
78 void closefd();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
79 #ifdef VERIFY_DEBUG
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
80 static void log(char *m, int v);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
81 static void log(char *m, char *v);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
82 #endif
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
83 };
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
84
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
85 class VERIFY {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
86 char *host; // host to be used to verify recipient addresses
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
87 time_t last_err; // time of last socket error
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
88 pthread_mutex_t mutex; // protect the lists of sockets and timestamps
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
89 smtp_list connections;// open sockets, ready to be used
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
90 public:
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
91 VERIFY(char *h);
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
92 void closer(); // if the oldest socket is ancient, close it
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
93 SMTP *get_connection();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
94 void put_connection(SMTP *conn);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
95 bool ok(char *from, char *to);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
96 };
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
97
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
98 class WHITELISTER {
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
99 char *fn; // file to use
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
100 int days; // how long do we keep entries
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
101 pthread_mutex_t mutex; // protect the flag and map
160
b3ed72ee6564 allow manual updates to auto whitelist files
carl
parents: 156
diff changeset
102 time_t loaded; // when we loaded this file
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
103 bool need; // force writing on new entries
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
104 autowhite_sent rcpts; // recipient map to remember when we sent them mail
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
105 public:
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
106 WHITELISTER(char *f, int d);
160
b3ed72ee6564 allow manual updates to auto whitelist files
carl
parents: 156
diff changeset
107 void merge();
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
108 void writer(); // dump any changes back to the file
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
109 void sent(char *to);
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
110 bool is_white(char *from); // should we white list this sender (did we send them anything recently)
156
a220bfb9211f add auto whitelisting
carl
parents: 153
diff changeset
111 int get_days() {return days;};
a220bfb9211f add auto whitelisting
carl
parents: 153
diff changeset
112 void set_days(int d) {days = d;};
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
113 };
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
114
192
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 179
diff changeset
115 class DELAYWHITE {
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 179
diff changeset
116 char* loto;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 179
diff changeset
117 WHITELISTERP w;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 179
diff changeset
118 CONTEXTP con;
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 179
diff changeset
119 public:
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 179
diff changeset
120 DELAYWHITE(char *loto_, WHITELISTERP w_, CONTEXTP con_);
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 179
diff changeset
121 char *get_loto() {return loto;};
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 179
diff changeset
122 WHITELISTERP get_w() {return w;};
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 179
diff changeset
123 CONTEXTP get_con() {return con;};
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 179
diff changeset
124 };
8f4a9a37d4d9 delay autowhitelisting to avoid out of office reply bots
carl
parents: 179
diff changeset
125
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
126 struct DNSBL {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
127 char *name; // nickname for this dns based list
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
128 char *suffix; // blacklist suffix like blackholes.five-ten-sg.com
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
129 char *message; // error message with one or two %s operators for the ip address replacement
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
130 DNSBL(char *n, char *s, char *m);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
131 bool operator==(const DNSBL &rhs);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
132 };
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
133
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
134 class CONTEXT {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
135 CONTEXTP parent;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
136 char * name;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
137 context_map children; // map child context names to their contexts
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
138 string_set env_to; // this context applies to these envelope recipients
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
139 char * verify_host; // use this smtp host to verify email addresses
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
140 VERIFYP verifier; // pointer to the verifier structure
168
6bac960af6b4 add generic reverse dns filtering regex
carl
parents: 167
diff changeset
141 char * generic_regx; // pointer to generic regular expression
6bac960af6b4 add generic reverse dns filtering regex
carl
parents: 167
diff changeset
142 char * generic_message; // pointer to generic message with one %s
170
bd33eaccfed8 fix pre/post scripts in rpm spec file
carl
parents: 168
diff changeset
143 regex_t generic_pattern; // compiled regex pattern
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
144 char * autowhite_file; // file to use for automatic whitelisting
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
145 WHITELISTERP whitelister; // pointer to the auto whitelister structure
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
146 string_map env_from; // map senders to white/black/unknown
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
147 context_map env_from_context; // map senders to a child context
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
148 char * env_from_default; // default value for senders that are not found in the map white/black/unknown/inherit
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
149 bool content_filtering; //
119
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
150 char * content_suffix; // for url body filtering based on ip addresses of hostnames in the body
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
151 char * content_message; // ""
119
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
152 char * uribl_suffix; // for uribl body filtering based on hostnames in the body
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
153 char * uribl_message; // ""
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
154 string_set content_host_ignore;// hosts to ignore for content sbl checking
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
155 string_set content_tlds; //
117
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 99
diff changeset
156 string_set content_cctlds; //
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
157 string_set html_tags; // set of valid html tags
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
158 int host_limit; // limit on host names
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
159 char * host_limit_message; // error message for excessive host names
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
160 bool host_random; // pick a random selection of host names rather than error for excessive hosts
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
161 int tag_limit; // limit on bad html tags
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
162 char * tag_limit_message; // error message for excessive bad html tags
163
97d7da45fe2a spamassassin changes
carl
parents: 162
diff changeset
163 int spamassassin_limit; // max score from spamassassin
178
d6531c702be3 embedded dcc filtering
carl
parents: 173
diff changeset
164 bool require_match; // require matching context filtering context
d6531c702be3 embedded dcc filtering
carl
parents: 173
diff changeset
165 bool dcc_greylist; // should we do dcc greylisting?
d6531c702be3 embedded dcc filtering
carl
parents: 173
diff changeset
166 int dcc_bulk_threshold; // off = 0, many = 1000
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
167 dnsblp_map dnsbl_names; // name to dnsbl mapping for lists that are available in this context and children
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
168 dnsblp_list dnsbl_list; // list of dnsbls to be used in this context
140
4028de9b46dd cleanup smtp rate limit code
carl
parents: 136
diff changeset
169 int default_rcpt_rate; // if not specified per user
136
f4746d8a12a3 add smtp auth rate limits
carl
parents: 119
diff changeset
170 rcpt_rates rcpt_per_hour; // per user limits on number of recipients per hour
f4746d8a12a3 add smtp auth rate limits
carl
parents: 119
diff changeset
171
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
172
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
173 public:
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
174 CONTEXT(CONTEXTP parent_, char *name_);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
175 ~CONTEXT();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
176 CONTEXTP get_parent() {return parent;};
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
177 bool is_parent(CONTEXTP p); // is p a parent of this?
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
178 char* get_full_name(char *buf, int size);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
179 void add_context(CONTEXTP child) {children[child->name] = child;};
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
180 bool allow_env_to(char *to) {return (parent) ? parent->cover_env_to(to) : true;};
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
181 bool cover_env_to(char *to);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
182
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
183 void set_verifier(VERIFYP v) {verifier = v;};
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
184 void set_verify(char *host) {verify_host = host;};
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
185 char* get_verify() {return verify_host;};
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
186 VERIFYP find_verify(char *to);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
187
168
6bac960af6b4 add generic reverse dns filtering regex
carl
parents: 167
diff changeset
188
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
189 void set_whitelister(WHITELISTERP v) {whitelister = v;};
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
190 void set_autowhite(char *fn) {autowhite_file = fn;};
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
191 char* get_autowhite() {return autowhite_file;};
162
c4bce911c276 don't add auto whitelist for A to A
carl
parents: 160
diff changeset
192 WHITELISTERP find_autowhite(char *from, char *to);
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
193
140
4028de9b46dd cleanup smtp rate limit code
carl
parents: 136
diff changeset
194 void set_default_rate(int limit) {default_rcpt_rate = limit;};
136
f4746d8a12a3 add smtp auth rate limits
carl
parents: 119
diff changeset
195 void add_rate(char *user, int limit) {rcpt_per_hour[user] = limit;};
f4746d8a12a3 add smtp auth rate limits
carl
parents: 119
diff changeset
196 int find_rate(char *user);
f4746d8a12a3 add smtp auth rate limits
carl
parents: 119
diff changeset
197
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
198 void add_to(char *to) {env_to.insert(to);};
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
199 void add_from(char *from, char *status) {env_from[from] = status;};
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
200 void add_from_context(char *from, CONTEXTP con) {env_from_context[from] = con;};
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
201 void set_from_default(char *status) {env_from_default = status;};
173
83fe0be032c1 fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents: 170
diff changeset
202 char* find_from(char *from, bool update_white = false);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
203 CONTEXTP find_context(char *from);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
204 CONTEXTP find_from_context_name(char *name);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
205
163
97d7da45fe2a spamassassin changes
carl
parents: 162
diff changeset
206 void set_content_filtering(bool filter) {content_filtering = filter; };
97d7da45fe2a spamassassin changes
carl
parents: 162
diff changeset
207 void set_content_suffix(char *suffix) {content_suffix = suffix; };
97d7da45fe2a spamassassin changes
carl
parents: 162
diff changeset
208 void set_content_message(char *message) {content_message = message; };
97d7da45fe2a spamassassin changes
carl
parents: 162
diff changeset
209 void set_uribl_suffix(char *suffix) {uribl_suffix = suffix; };
97d7da45fe2a spamassassin changes
carl
parents: 162
diff changeset
210 void set_uribl_message(char *message) {uribl_message = message; };
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
211 void add_ignore(char *host) {content_host_ignore.insert(host);};
163
97d7da45fe2a spamassassin changes
carl
parents: 162
diff changeset
212 void add_tld(char *tld) {content_tlds.insert(tld); };
97d7da45fe2a spamassassin changes
carl
parents: 162
diff changeset
213 void add_cctld(char *cctld) {content_cctlds.insert(cctld); };
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
214
163
97d7da45fe2a spamassassin changes
carl
parents: 162
diff changeset
215 void set_host_limit(int limit) {host_limit = limit; };
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
216 void set_host_message(char *message) {host_limit_message = message;};
163
97d7da45fe2a spamassassin changes
carl
parents: 162
diff changeset
217 void set_host_random(bool random) {host_random = random; };
167
9b129ed78d7d actually use spamassassin result, allow build without spam assassin, only call it if some recipient needs it.
carl
parents: 164
diff changeset
218 void set_spamassassin_limit(int limit) {spamassassin_limit = limit; };
163
97d7da45fe2a spamassassin changes
carl
parents: 162
diff changeset
219 void set_tag_limit(int limit) {tag_limit = limit; };
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
220 void set_tag_message(char *message) {tag_limit_message = message;};
163
97d7da45fe2a spamassassin changes
carl
parents: 162
diff changeset
221 void add_tag(char *tag) {html_tags.insert(tag); };
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
222
163
97d7da45fe2a spamassassin changes
carl
parents: 162
diff changeset
223 void add_dnsbl(char *name, DNSBLP dns) {dnsbl_names[name] = dns; };
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
224 void add_dnsbl(DNSBLP dns) {dnsbl_list.push_back(dns);};
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
225 DNSBLP find_dnsbl(char *name);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
226
168
6bac960af6b4 add generic reverse dns filtering regex
carl
parents: 167
diff changeset
227 bool set_generic(char *regx, char *msg);
6bac960af6b4 add generic reverse dns filtering regex
carl
parents: 167
diff changeset
228 char* generic_match(char *client);
6bac960af6b4 add generic reverse dns filtering regex
carl
parents: 167
diff changeset
229
178
d6531c702be3 embedded dcc filtering
carl
parents: 173
diff changeset
230 void set_require(bool r) {require_match = r; };
d6531c702be3 embedded dcc filtering
carl
parents: 173
diff changeset
231 void set_grey(bool g) {dcc_greylist = g; };
d6531c702be3 embedded dcc filtering
carl
parents: 173
diff changeset
232 void set_bulk(int b) {dcc_bulk_threshold = b; };
d6531c702be3 embedded dcc filtering
carl
parents: 173
diff changeset
233
163
97d7da45fe2a spamassassin changes
carl
parents: 162
diff changeset
234 bool get_content_filtering() {return content_filtering; };
179
8b86a894514d embedded dcc filtering
carl
parents: 178
diff changeset
235 bool get_require() {return content_filtering && require_match; };
8b86a894514d embedded dcc filtering
carl
parents: 178
diff changeset
236 bool get_grey() {return content_filtering && dcc_greylist; };
8b86a894514d embedded dcc filtering
carl
parents: 178
diff changeset
237 int get_bulk() {return (content_filtering) ? dcc_bulk_threshold : 0;};
8b86a894514d embedded dcc filtering
carl
parents: 178
diff changeset
238 int get_host_limit() {return (content_filtering) ? host_limit : 0;};
8b86a894514d embedded dcc filtering
carl
parents: 178
diff changeset
239 bool get_host_random() {return (content_filtering) ? host_random : 0;};
167
9b129ed78d7d actually use spamassassin result, allow build without spam assassin, only call it if some recipient needs it.
carl
parents: 164
diff changeset
240 int get_spamassassin_limit() {return (content_filtering) ? spamassassin_limit : 0;};
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
241 char* get_content_suffix();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
242 char* get_content_message();
119
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
243 char* get_uribl_suffix();
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
244 char* get_uribl_message();
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
245 string_set& get_content_host_ignore();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
246 string_set& get_content_tlds();
117
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 99
diff changeset
247 string_set& get_content_cctlds();
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
248 string_set& get_html_tags();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
249 dnsblp_list& get_dnsbl_list();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
250
178
d6531c702be3 embedded dcc filtering
carl
parents: 173
diff changeset
251 bool acceptable_content(recorder &memory, int score, int bulk, string& msg);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
252 bool ignore_host(char *host);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
253
167
9b129ed78d7d actually use spamassassin result, allow build without spam assassin, only call it if some recipient needs it.
carl
parents: 164
diff changeset
254 void dump(bool isdefault, bool &spamass, int level = 0);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
255 };
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
256
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
257
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
258 struct CONFIG {
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
259 // the only mutable stuff once it has been loaded from the config file
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
260 int reference_count; // protected by the global config_mutex
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
261 // all the rest is constant after loading from the config file
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
262 int generation;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
263 time_t load_time;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
264 string_set config_files;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
265 context_list contexts; // owns all the contexts, not just top level contexts
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
266 context_map env_to; // map recipient to a filtering context
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
267 CONTEXTP default_context;// for env_to values that don't have their own specific filtering context
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
268 // the default context is also used for some of the content filtering values
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
269
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
270 CONFIG();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
271 ~CONFIG();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
272 void add_context(CONTEXTP con);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
273 void add_to(char *to, CONTEXTP con);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
274 CONTEXTP find_context(char *to);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
275 void dump();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
276 };
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
277
136
f4746d8a12a3 add smtp auth rate limits
carl
parents: 119
diff changeset
278
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
279 extern char *token_autowhite;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
280 extern char *token_black;
117
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 99
diff changeset
281 extern char *token_cctld;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
282 extern char *token_content;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
283 extern char *token_context;
178
d6531c702be3 embedded dcc filtering
carl
parents: 173
diff changeset
284 extern char *token_dccbulk;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
285 extern char *token_dccfrom;
178
d6531c702be3 embedded dcc filtering
carl
parents: 173
diff changeset
286 extern char *token_dccgrey;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
287 extern char *token_dccto;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
288 extern char *token_default;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
289 extern char *token_dnsbl;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
290 extern char *token_dnsbll;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
291 extern char *token_envfrom;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
292 extern char *token_envto;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
293 extern char *token_filter;
168
6bac960af6b4 add generic reverse dns filtering regex
carl
parents: 167
diff changeset
294 extern char *token_generic;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
295 extern char *token_host_limit;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
296 extern char *token_html_limit;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
297 extern char *token_html_tags;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
298 extern char *token_ignore;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
299 extern char *token_include;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
300 extern char *token_inherit;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
301 extern char *token_lbrace;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
302 extern char *token_mailhost;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
303 extern char *token_many;
178
d6531c702be3 embedded dcc filtering
carl
parents: 173
diff changeset
304 extern char *token_no;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
305 extern char *token_off;
178
d6531c702be3 embedded dcc filtering
carl
parents: 173
diff changeset
306 extern char *token_ok;
117
aa07452e641b uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 99
diff changeset
307 extern char *token_ok2;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
308 extern char *token_on;
136
f4746d8a12a3 add smtp auth rate limits
carl
parents: 119
diff changeset
309 extern char *token_rate;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
310 extern char *token_rbrace;
178
d6531c702be3 embedded dcc filtering
carl
parents: 173
diff changeset
311 extern char *token_require;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
312 extern char *token_semi;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
313 extern char *token_soft;
163
97d7da45fe2a spamassassin changes
carl
parents: 162
diff changeset
314 extern char *token_spamassassin;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
315 extern char *token_substitute;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
316 extern char *token_tld;
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
317 extern char *token_unknown;
119
d9d2f8699621 uribl patch from Jeff Evans <jeffe@tricab.com>
carl
parents: 117
diff changeset
318 extern char *token_uribl;
178
d6531c702be3 embedded dcc filtering
carl
parents: 173
diff changeset
319 extern char *token_verify;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
320 extern char *token_white;
178
d6531c702be3 embedded dcc filtering
carl
parents: 173
diff changeset
321 extern char *token_yes;
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
322
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
323 extern pthread_mutex_t verifier_mutex; // protect the verifier map
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
324 extern pthread_mutex_t whitelister_mutex; // protect the
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
325
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
326 void discard(string_set &s);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
327 char* register_string(string_set &s, char *name);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
328 char* register_string(char *name);
164
5809bcdc325b spamassassin changes
carl
parents: 163
diff changeset
329 void clear_strings();
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
330 CONFIG *parse_config(char *fn);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
331 bool load_conf(CONFIG &dc, char *fn);
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
332 void* verify_closer(void *arg);
153
8d7c439bb6fa add auto whitelisting
carl
parents: 152
diff changeset
333 void* whitelister_writer(void *arg);
94
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
334 void token_init();
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
335
e107ade3b1c0 fix dos line terminators
carl
parents: 92
diff changeset
336 #endif