comparison src/context.h @ 153:8d7c439bb6fa

add auto whitelisting
author carl
date Sat, 07 Jul 2007 16:10:39 -0700
parents c7fc218686f5
children a220bfb9211f
comparison
equal deleted inserted replaced
152:c7fc218686f5 153:8d7c439bb6fa
20 20
21 class DNSBL; 21 class DNSBL;
22 class CONTEXT; 22 class CONTEXT;
23 class VERIFY; 23 class VERIFY;
24 class SMTP; 24 class SMTP;
25 class WHITELISTER;
25 class recorder; 26 class recorder;
26 27
27 typedef map<char *, char *, ltstr> string_map; 28 typedef map<char *, char *, ltstr> string_map;
28 typedef set<int> int_set; 29 typedef set<int> int_set;
29 typedef list<SMTP *> smtp_list; 30 typedef list<SMTP *> smtp_list;
30 typedef list<char *> string_list; 31 typedef list<char *> string_list;
31 typedef DNSBL * DNSBLP; 32 typedef DNSBL * DNSBLP;
32 typedef VERIFY * VERIFYP; 33 typedef VERIFY * VERIFYP;
34 typedef WHITELISTER * WHITELISTERP;
33 typedef list<DNSBLP> dnsblp_list; 35 typedef list<DNSBLP> dnsblp_list;
34 typedef map<char *, DNSBLP, ltstr> dnsblp_map; 36 typedef map<char *, DNSBLP, ltstr> dnsblp_map;
35 typedef CONTEXT * CONTEXTP; 37 typedef CONTEXT * CONTEXTP;
36 typedef list<CONTEXTP> context_list; 38 typedef list<CONTEXTP> context_list;
37 typedef map<char *, CONTEXTP, ltstr> context_map; 39 typedef map<char *, CONTEXTP, ltstr> context_map;
38 typedef map<char *, int, ltstr> ns_mapper; 40 typedef map<char *, int, ltstr> ns_mapper;
39 typedef map<char *, int, ltstr> rcpt_rates; 41 typedef map<char *, int, ltstr> rcpt_rates;
42 typedef map<char *, int, ltstr> autowhite_sent;
40 typedef map<char *, VERIFYP, ltstr> verify_map; 43 typedef map<char *, VERIFYP, ltstr> verify_map;
44 typedef map<char *, WHITELISTERP, ltstr> whitelister_map;
41 45
42 class SMTP { 46 class SMTP {
43 static const int maxlen = 1000; 47 static const int maxlen = 1000;
44 int fd; 48 int fd;
45 bool error; 49 bool error;
79 time_t last_err; // time of last socket error 83 time_t last_err; // time of last socket error
80 pthread_mutex_t mutex; // protect the lists of sockets and timestamps 84 pthread_mutex_t mutex; // protect the lists of sockets and timestamps
81 smtp_list connections;// open sockets, ready to be used 85 smtp_list connections;// open sockets, ready to be used
82 public: 86 public:
83 VERIFY(char *h); 87 VERIFY(char *h);
84 void closer(); // if the oldest socket is ancient, close it 88 void closer(); // if the oldest socket is ancient, close it
85 SMTP *get_connection(); 89 SMTP *get_connection();
86 void put_connection(SMTP *conn); 90 void put_connection(SMTP *conn);
87 bool ok(char *from, char *to); 91 bool ok(char *from, char *to);
92 };
93
94 class WHITELISTER {
95 char *fn; // file to use
96 int days; // how long do we keep entries
97 pthread_mutex_t mutex; // protect the flag and map
98 bool need; // force writing on new entries
99 autowhite_sent rcpts; // recipient map to remember when we sent them mail
100 public:
101 WHITELISTER(char *f, int d);
102 void writer(); // dump any changes back to the file
103 void sent(char *to);
104 bool is_white(char *from); // should we white list this sender (did we send them anything recently)
105 int get_days() {return days;};
88 }; 106 };
89 107
90 struct DNSBL { 108 struct DNSBL {
91 char *name; // nickname for this dns based list 109 char *name; // nickname for this dns based list
92 char *suffix; // blacklist suffix like blackholes.five-ten-sg.com 110 char *suffix; // blacklist suffix like blackholes.five-ten-sg.com
99 CONTEXTP parent; 117 CONTEXTP parent;
100 char * name; 118 char * name;
101 context_map children; // map child context names to their contexts 119 context_map children; // map child context names to their contexts
102 string_set env_to; // this context applies to these envelope recipients 120 string_set env_to; // this context applies to these envelope recipients
103 char * verify_host; // use this smtp host to verify email addresses 121 char * verify_host; // use this smtp host to verify email addresses
122 VERIFYP verifier; // pointer to the verifier structure
123 char * autowhite_file; // file to use for automatic whitelisting
124 WHITELISTERP whitelister; // pointer to the auto whitelister structure
104 string_map env_from; // map senders to white/black/unknown 125 string_map env_from; // map senders to white/black/unknown
105 context_map env_from_context; // map senders to a child context 126 context_map env_from_context; // map senders to a child context
106 char * env_from_default; // default value for senders that are not found in the map white/black/unknown/inherit 127 char * env_from_default; // default value for senders that are not found in the map white/black/unknown/inherit
107 bool content_filtering; // 128 bool content_filtering; //
108 char * content_suffix; // for url body filtering based on ip addresses of hostnames in the body 129 char * content_suffix; // for url body filtering based on ip addresses of hostnames in the body
132 char* get_full_name(char *buf, int size); 153 char* get_full_name(char *buf, int size);
133 void add_context(CONTEXTP child) {children[child->name] = child;}; 154 void add_context(CONTEXTP child) {children[child->name] = child;};
134 bool allow_env_to(char *to) {return (parent) ? parent->cover_env_to(to) : true;}; 155 bool allow_env_to(char *to) {return (parent) ? parent->cover_env_to(to) : true;};
135 bool cover_env_to(char *to); 156 bool cover_env_to(char *to);
136 157
158 void set_verifier(VERIFYP v) {verifier = v;};
137 void set_verify(char *host) {verify_host = host;}; 159 void set_verify(char *host) {verify_host = host;};
138 char* get_verify() {return verify_host;}; 160 char* get_verify() {return verify_host;};
139 VERIFYP find_verify(char *to); 161 VERIFYP find_verify(char *to);
162
163 void set_whitelister(WHITELISTERP v) {whitelister = v;};
164 void set_autowhite(char *fn) {autowhite_file = fn;};
165 char* get_autowhite() {return autowhite_file;};
166 WHITELISTERP find_autowhite(char *to);
140 167
141 void set_default_rate(int limit) {default_rcpt_rate = limit;}; 168 void set_default_rate(int limit) {default_rcpt_rate = limit;};
142 void add_rate(char *user, int limit) {rcpt_per_hour[user] = limit;}; 169 void add_rate(char *user, int limit) {rcpt_per_hour[user] = limit;};
143 int find_rate(char *user); 170 int find_rate(char *user);
144 171
212 239
213 struct RATELIMIT { 240 struct RATELIMIT {
214 241
215 }; 242 };
216 243
244 extern char *token_autowhite;
217 extern char *token_black; 245 extern char *token_black;
218 extern char *token_cctld; 246 extern char *token_cctld;
219 extern char *token_content; 247 extern char *token_content;
220 extern char *token_context; 248 extern char *token_context;
221 extern char *token_dccfrom; 249 extern char *token_dccfrom;
247 extern char *token_tld; 275 extern char *token_tld;
248 extern char *token_unknown; 276 extern char *token_unknown;
249 extern char *token_uribl; 277 extern char *token_uribl;
250 extern char *token_white; 278 extern char *token_white;
251 279
252 extern char *token_myhostname; 280 extern pthread_mutex_t verifier_mutex; // protect the verifier map
253 281 extern pthread_mutex_t whitelister_mutex; // protect the
254 extern verify_map verifiers; // map of smtp hosts to verify structures, owns all the verify structures
255 extern string_set all_strings; // owns all the strings, only modified by the config loader thread
256 282
257 void discard(string_set &s); 283 void discard(string_set &s);
258 char* register_string(string_set &s, char *name); 284 char* register_string(string_set &s, char *name);
259 char* register_string(char *name); 285 char* register_string(char *name);
260 CONFIG *parse_config(char *fn); 286 CONFIG *parse_config(char *fn);
261 bool load_conf(CONFIG &dc, char *fn); 287 bool load_conf(CONFIG &dc, char *fn);
262 void add_verify_host(char *host);
263 void* verify_closer(void *arg); 288 void* verify_closer(void *arg);
289 void* whitelister_writer(void *arg);
264 void token_init(); 290 void token_init();
265 291
266 #endif 292 #endif