0
|
1 /* Distributed Checksum Clearinghouse |
|
2 * |
|
3 * common threaded client definitions |
|
4 * |
|
5 * Copyright (c) 2008 by Rhyolite Software, LLC |
|
6 * |
|
7 * This agreement is not applicable to any entity which sells anti-spam |
|
8 * solutions to others or provides an anti-spam solution as part of a |
|
9 * security solution sold to other entities, or to a private network |
|
10 * which employs the DCC or uses data provided by operation of the DCC |
|
11 * but does not provide corresponding data to other users. |
|
12 * |
|
13 * Permission to use, copy, modify, and distribute this software without |
|
14 * changes for any purpose with or without fee is hereby granted, provided |
|
15 * that the above copyright notice and this permission notice appear in all |
|
16 * copies and any distributed versions or copies are either unchanged |
|
17 * or not called anything similar to "DCC" or "Distributed Checksum |
|
18 * Clearinghouse". |
|
19 * |
|
20 * Parties not eligible to receive a license under this agreement can |
|
21 * obtain a commercial license to use DCC by contacting Rhyolite Software |
|
22 * at sales@rhyolite.com. |
|
23 * |
|
24 * A commercial license would be for Distributed Checksum and Reputation |
|
25 * Clearinghouse software. That software includes additional features. This |
|
26 * free license for Distributed ChecksumClearinghouse Software does not in any |
|
27 * way grant permision to use Distributed Checksum and Reputation Clearinghouse |
|
28 * software |
|
29 * |
|
30 * THE SOFTWARE IS PROVIDED "AS IS" AND RHYOLITE SOFTWARE, LLC DISCLAIMS ALL |
|
31 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES |
|
32 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL RHYOLITE SOFTWARE, LLC |
|
33 * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES |
|
34 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, |
|
35 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, |
|
36 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS |
|
37 * SOFTWARE. |
|
38 * |
|
39 * Rhyolite Software DCC 1.3.103-1.88 $Revision$ |
|
40 */ |
|
41 |
|
42 #ifndef CLNT_DEFS_H |
|
43 #define CLNT_DEFS_H |
|
44 |
|
45 #include "dcc_ck.h" |
|
46 #include "dcc_xhdr.h" |
|
47 #include "dcc_heap_debug.h" |
|
48 #ifdef HAVE_PTHREAD_H |
|
49 #include <pthread.h> |
|
50 #else |
|
51 #include <sys/pthread.h> |
|
52 #endif |
|
53 #include <sys/un.h> |
|
54 #include <sys/resource.h> |
|
55 #include <arpa/inet.h> |
|
56 #include <signal.h> |
|
57 |
|
58 |
|
59 /* what to do about checksums whose counts say "spam" */ |
|
60 typedef enum { |
|
61 CMN_REJECT = 0, /* tell sendmail to reject spam */ |
|
62 CMN_DISCARD, /* discard spam */ |
|
63 CMN_IGNORE /* ignore spam reports */ |
|
64 } CMN_ACTION; |
|
65 extern CMN_ACTION action; |
|
66 |
|
67 typedef enum { |
|
68 SETHDR, ADDHDR, NOHDR |
|
69 } CHGHDR; |
|
70 extern CHGHDR chghdr; |
|
71 |
|
72 |
|
73 typedef struct { |
|
74 int msgs; /* total messages */ |
|
75 int tgts; /* total addressees */ |
|
76 int tgts_discarded; /* discarded for this many addressess */ |
|
77 int tgts_rejected; |
|
78 int tgts_ignored; |
|
79 int tgts_embargoed; |
|
80 int msgs_embargoed; |
|
81 int msgs_spam; |
|
82 time_t msg_prev, msg_next; |
|
83 } TOTALS; |
|
84 extern TOTALS totals; |
|
85 |
|
86 |
|
87 /* This is a wild guess of open files hidden in libraries and elsewhere. |
|
88 * Some systems such as Solaris seem to have an amazing number of them |
|
89 * Each whitelist context involves an open hash table file */ |
|
90 #define EXTRA_FILES (32 + NUM_CWFS) |
|
91 |
|
92 #define MAX_SELECT_WORK ((FD_SETSIZE-EXTRA_FILES)/FILES_PER_JOB) |
|
93 /* dccm and dccifd have differing values for FILES_PER_JOB */ |
|
94 #define MIN_MAX_WORK 2 |
|
95 extern int max_max_work; |
|
96 extern const char *max_max_work_src; |
|
97 extern int max_work; |
|
98 extern int init_work; |
|
99 extern int total_work; |
|
100 |
|
101 |
|
102 typedef struct { |
|
103 const char *log_result; /* "reject" etc. for log */ |
|
104 const char *rcode; |
|
105 const char *xcode; |
|
106 const char *str; |
|
107 char str_buf[REPLY_BUF_LEN]; |
|
108 } REPLY_STRS; |
|
109 #define DCC_RCODE "550" |
|
110 #define DCC_XCODE "5.7.1" |
|
111 extern REPLY_TPLT reject_reply; |
|
112 extern REPLY_TPLT grey_reply; |
|
113 extern REPLY_TPLT reputation_reply; |
|
114 extern REPLY_TPLT dcc_fail_reply; |
|
115 extern REPLY_TPLT dnsbl_timeo_reply; |
|
116 |
|
117 |
|
118 /* Some of these flags are computed for all recipients (e.g. white- or |
|
119 * blacklisting from the main whiteclnt file) in the common flags and |
|
120 * then copied to individual recipient flags words. |
|
121 * Others are kept only in the common word. */ |
|
122 typedef u_short RCPT_FGS; |
|
123 # define RCPT_FG_NULL_WHITECLNT 0x0001 /* no entries in it */ |
|
124 # define RCPT_FG_REJ_FILTER 0x0002 /* rejected by dccifd or dccm */ |
|
125 # define RCPT_FG_BAD_USERNAME 0x0004 /* user bad & rejected by MTA */ |
|
126 # define RCPT_FG_WLIST_ISSPAM 0x0008 /* whiteclnt blacklisted */ |
|
127 # define RCPT_FG_WLIST_NOTSPAM 0x0010 /* whiteclnt whitelisted */ |
|
128 # define RCPT_FG_WHITE 0x0020 |
|
129 # define RCPT_FG_BLACK 0x0040 |
|
130 # define RCPT_FG_ISSPAM 0x0080 /* result for this target */ |
|
131 # define RCPT_FG_GREY_END 0x0100 /* end of greylist embargo */ |
|
132 # define RCPT_FG_GREY_WHITE 0x0200 /* whitelisted for greylist */ |
|
133 # define RCPT_FG_INCOMPAT_REJ 0x0400 /* incompatible & so rejected */ |
|
134 |
|
135 /* per-recipient state */ |
|
136 typedef struct rcpt_st { |
|
137 struct rcpt_st *fwd; |
|
138 struct cmn_work *cwp; |
|
139 off_t log_pos_to; /* env_To line in main log file */ |
|
140 off_t log_pos_white; |
|
141 DCC_CKS_WTGTS wtgts; |
|
142 DCC_TGTS env_to_tgts, user_tgts; |
|
143 ASK_GREY_RESULT grey_result; |
|
144 u_int embargo_num; |
|
145 DCC_SUM wf_sum; |
|
146 DCC_CKSUM_THOLDS tholds_rej; |
|
147 FLTR_SWS sws; |
|
148 RCPT_FGS fgs; |
|
149 RCPT_FGS global_env_to_fgs; |
|
150 RCPT_FGS env_to_fgs; |
|
151 # define RCTP_MAXNAME 257 /* sendmail MAXNAME limit */ |
|
152 char env_to[RCTP_MAXNAME]; /* env_to */ |
|
153 char user[RCTP_MAXNAME]; /* mailbox */ |
|
154 char rej_msg[REPLY_BUF_LEN]; |
|
155 const char *rej_result; |
|
156 DCC_SUM env_to_sum; |
|
157 DCC_SUM user_sum; |
|
158 DCC_SUM msg_sum; |
|
159 DCC_SUM triple_sum; |
|
160 DCC_PATH dir; /* recipient's whitelist and logdir */ |
|
161 DCC_PATH user_log_nm; |
|
162 } RCPT_ST; |
|
163 |
|
164 |
|
165 /* per message state common to threaded DCC clients */ |
|
166 typedef struct cmn_work { |
|
167 struct work *wp; |
|
168 DCC_CLNT_CTXT *dcc_ctxt; |
|
169 u_int dcc_ctxt_sn; |
|
170 struct timeval ldate; |
|
171 CMN_ACTION action; |
|
172 u_int xhdr_fname_len; |
|
173 char xhdr_fname[sizeof(DCC_XHDR_START)+sizeof(DCC_BRAND)+1]; |
|
174 char clnt_name[DCC_MAXDOMAINLEN]; /* SMTP client */ |
|
175 char clnt_str[INET6_ADDRSTRLEN+1]; |
|
176 struct in6_addr clnt_addr; |
|
177 char sender_name[DCC_MAXDOMAINLEN]; /* source of mail message */ |
|
178 char sender_str[INET6_ADDRSTRLEN+1]; |
|
179 char helo[DCC_HELO_MAX]; |
|
180 char env_from[DCC_ENV_FROM_MAX+1]; |
|
181 char mail_host[DCC_MAXDOMAINLEN]; /* Mail_From host name */ |
|
182 char id[DCC_MSG_ID_LEN+1]; |
|
183 DCC_EMSG emsg; |
|
184 DCC_PATH tmp_nm; |
|
185 DCC_PATH log_nm; /* log file for this message */ |
|
186 int num_rcpts; |
|
187 # define MAX_RCPTS 1024 |
|
188 RCPT_ST *rcpt_st_first, *rcpt_st_last; |
|
189 int log_fd; /* -1=none */ |
|
190 int tmp_fd; /* copy of entire message */ |
|
191 DCC_HEADER_BUF header; |
|
192 EARLY_LOG early_log; |
|
193 |
|
194 u_short cmn_fgs; |
|
195 # define CMN_FG_ENV_LOGGED 0x0001 /* have logged the envelope */ |
|
196 # define CMN_FG_LOG_EARLY 0x0002 /* too early to write to log file */ |
|
197 # define CMN_FG_CHECK_REP 0x0004 /* check DCC reputations */ |
|
198 # define CMN_FG_FROM_MX 0x0008 /* don't reject MX secondary */ |
|
199 # define CMN_FG_FROM_SUBMIT 0x0010 /* SMTP submission clients */ |
|
200 # define CMN_FG_LOCAL_SPAM 0x0020 |
|
201 # define CMN_FG_LOG_ENV_TO 0x0040 /* env_to checksum to log */ |
|
202 # define CMN_FG_THOLDS_SET 0x0080 |
|
203 |
|
204 DCC_GOT_CKS cks; |
|
205 |
|
206 #define CMN_WORK_ZERO log_ip_pos /* here down cleared for each msg */ |
|
207 |
|
208 off_t log_ip_pos; /* position and length of IP: line */ |
|
209 int log_ip_len; |
|
210 off_t log_pos_to_first; /* first env_To line in log file */ |
|
211 off_t log_pos_to_end; /* end of env_To lines in log file */ |
|
212 off_t log_pos_white_first; /* first whitelist result */ |
|
213 off_t log_pos_white_last; /* last whitelist result */ |
|
214 off_t log_pos_ask_error; /* final DCC errors */ |
|
215 u_int max_embargo_num; |
|
216 REPLY_STRS reply; |
|
217 DCC_TGTS tgts; /* total accepted Mail_From values */ |
|
218 DCC_TGTS white_tgts; /* # of ->tgts whitelisting message */ |
|
219 DCC_TGTS reject_tgts; /* # of ->tgts rejecting message */ |
|
220 DCC_TGTS deliver_tgts; /* # of ->tgts wanting the message */ |
|
221 DCC_TGTS mta_rej_tgts; /* not accepted by order of MTA */ |
|
222 DCC_TGTS early_grey_tgts; /* report to DCC if embargoed */ |
|
223 DCC_TGTS late_grey_tgts; /* don't report to DCC if delivered */ |
|
224 DCC_TGTS local_tgts; /* what we told the DCC server */ |
|
225 size_t log_size; |
|
226 DCC_CKS_WTGTS wtgts; |
|
227 FLTR_SWS init_sws; /* initial value for rcpt_st->sws */ |
|
228 FLTR_SWS rcpts_sws; /* common among recipients */ |
|
229 RCPT_FGS rcpt_fgs; |
|
230 ASK_ST ask_st; /* ASK_ST_* */ |
|
231 } CMN_WORK; |
|
232 |
|
233 |
|
234 extern u_int dcc_ctxt_sn; /* change X-DCC header server name */ |
|
235 |
|
236 extern RCPT_ST *rcpt_st_free; |
|
237 |
|
238 const char *userdirs; |
|
239 |
|
240 extern u_char dcc_query_only; |
|
241 extern u_char cannot_discard; /* cannot trim targets after DATA */ |
|
242 extern u_char cannot_reject; /* cannot reject RCPT_TO targets */ |
|
243 extern u_char try_extra_hard; /* 0 or DCC_CLNT_FG_NO_FAIL */ |
|
244 extern u_char to_white_only; |
|
245 extern const char *mapfile_nm; |
|
246 extern const char *main_white_nm; |
|
247 |
|
248 extern pthread_mutex_t user_log_mutex; |
|
249 extern pthread_t user_log_owner; |
|
250 |
|
251 extern void clnt_sigs_off(sigset_t *); |
|
252 |
|
253 extern void parse_userdirs(const char *); |
|
254 extern u_char get_user_dir(RCPT_ST *, const char *, int, const char *, int); |
|
255 extern void make_tplt(REPLY_TPLT *, u_char, |
|
256 const char *, const char *, const char *, const char *); |
|
257 extern void parse_reply_arg(const char *); |
|
258 extern void make_reply(REPLY_STRS *, const REPLY_TPLT *, |
|
259 const CMN_WORK *, const DNSBL_GROUP *); |
|
260 extern void finish_replies(void); |
|
261 extern void cmn_init(void); |
|
262 extern void cmn_create(CMN_WORK *); |
|
263 extern u_char cmn_open_tmp(CMN_WORK *); |
|
264 extern void cmn_close_tmp(CMN_WORK *); |
|
265 extern u_char cmn_write_tmp(CMN_WORK *cwp, const void *, int); |
|
266 extern u_char check_mx_listing(CMN_WORK *); |
|
267 extern void cmn_clear(CMN_WORK *, struct work *, u_char); |
|
268 extern void free_rcpt_sts(CMN_WORK *, u_char); |
|
269 extern RCPT_ST *alloc_rcpt_st(CMN_WORK *, u_char); |
|
270 extern void log_start(CMN_WORK *); |
|
271 extern void log_stop(CMN_WORK *); |
|
272 extern void log_write(CMN_WORK *, const void *, u_int); |
|
273 extern void log_body_write(CMN_WORK *, const char *, u_int); |
|
274 #define LOG_CMN_CAPTION(cwp, s) log_write(cwp, s, LITZ(s)) |
|
275 #define LOG_CMN_EOL(cwp) LOG_CMN_CAPTION(cwp, "\n") |
|
276 #define LOG_CAPTION(wp, s) LOG_CMN_CAPTION(&(wp)->cw, s) |
|
277 #define LOG_EOL(wp) LOG_CAPTION(wp, "\n") |
|
278 extern off_t log_lseek_get(CMN_WORK *); |
|
279 extern void thr_log_late(CMN_WORK *); |
|
280 extern void thr_log_envelope(CMN_WORK *, u_char); |
|
281 extern u_char ck_dcc_ctxt(CMN_WORK *); |
|
282 extern u_char cmn_compat_whitelist(CMN_WORK *, RCPT_ST *); |
|
283 extern void cmn_ask_white(CMN_WORK *); |
|
284 extern int cmn_ask_dcc(CMN_WORK *); |
|
285 extern void users_process(CMN_WORK *); |
|
286 extern void users_log_result(CMN_WORK *, const char *); |
|
287 |
|
288 extern void user_reject_discard(CMN_WORK *, RCPT_ST *); |
|
289 extern void log_smtp_reply(CMN_WORK *); |
|
290 |
|
291 extern void totals_init(void); |
|
292 extern void totals_stop(void); |
|
293 extern void totals_msg(void); |
|
294 extern void work_clean(void); |
|
295 |
|
296 |
|
297 #endif /* CLNT_DEFS_H */ |