ze-filter  (ze-filter-0.8.0-develop-180218)
ze-filter-data.h
Go to the documentation of this file.
1 /*
2  *
3  * ze-filter - Mail Server Filter for sendmail
4  *
5  * Copyright (c) 2001-2018 - Jose-Marcio Martins da Cruz
6  *
7  * Auteur : Jose Marcio Martins da Cruz
8  * jose.marcio.mc@gmail.org
9  *
10  * Historique :
11  * Creation : janvier 2002
12  *
13  * This program is free software, but with restricted license :
14  *
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19  *
20  * More details about ze-filter license can be found at ze-filter
21  * web site : http://foss.jose-marcio.org
22  */
23 
24 #ifndef __ZE_FILTER_DATA_H
25 
26 #include "libmilter/mfapi.h"
27 
28 #ifndef SM_LM_VRS_MAJOR
29 # define SM_LM_VRS_MAJOR(v) (((v) & 0x7f000000) >> 24)
30 #endif
31 #ifndef SM_LM_VRS_MINOR
32 # define SM_LM_VRS_MINOR(v) (((v) & 0x007fff00) >> 8)
33 #endif
34 #ifndef SM_LM_VRS_PLVL
35 # define SM_LM_VRS_PLVL(v) ((v) & 0x0000007f)
36 #endif
37 
38 #define SMFI_VERSION_MAJOR SM_LM_VRS_MAJOR(SMFI_VERSION)
39 #define SMFI_VERSION_MINOR SM_LM_VRS_MINOR(SMFI_VERSION)
40 #define SMFI_VERSION_PLVL SM_LM_VRS_PLVL(SMFI_VERSION)
41 
42 #include "ze-smmacros.h"
43 #include "ze-reply.h"
44 
45 #if 0
46 #ifndef LIBMILTER_VERSION_MAJOR
47 # define LIBMILTER_VERSION_MAJOR 8
48 # define LIBMILTER_VERSION_MINOR 12
49 # define LIBMILTER_VERSION_PATCH 10
50 #endif
51 #endif
52 
53 #include "ze-history.h"
54 
55 typedef struct
56 {
57  char *virus;
58 } MSG_T;
59 
60 typedef struct
61 {
62  unsigned long f0;
63  unsigned long f1;
64  unsigned long f2;
65  unsigned long f3;
66 } MTA_caps_T;
67 
68 typedef struct
69 {
70  sfsistat result;
71  int callback;
72  char *reply;
73  char *why;
74 } dresult_T;
75 
76 typedef struct
77 {
78  time_t conn_id; /* connection ID - obsolete */
79  CONNID_T id; /* connection ID */
80 #if 1
81  char *mailserver; /* server name (Macro $j) */
82 #endif
84 
86 
87  char *reply_code;
88 
90 
91  /*
92  ** Connection data
93  */
94 #if HAVE_HRTIME_T
95  hrtime_t t_open; /* connection open date */
96  hrtime_t t_close; /* connection close date */
97  hrtime_t t_callback; /* time spent by the callback */
98  hrtime_t t_xmsg; /* time spent processing message body */
99 #else
100  time_t t_open;
101  time_t t_close;
102  time_t t_callback;
103  time_t t_xmsg;
104 #endif
105 
107 
108  /*
109  ** Client and server state
110  */
111  int serv_rate; /* server connection rate */
112  int conn_rate; /* client connection rate */
113  int nb_open; /* # of open connections */
114  int msg_rate; /* client message rate */
115 
118 
120 
121  uint32_t ehlo_flags; /* result of helo parameter check */
122 
124 
125  /*
126  ** Spool file
127  */
128  char *fname; /* spool file name */
129  char *fsuffix; /* quarantined file name suffix */
130  int fd;
131  bool fp_open; /* True if spool open */
132  bool save_msg; /* shall message be quarantined */
133  int save_why; /* quarantine reason */
134 
135 #if 0
136  MSG_SPOOL_T spoolfile;
137 #endif
139 
140  /*
141  ** Input data
142  */
143  char *daemon;
144  sa_family_t addr_family;
145  char *peer_addr;
146  char *peer_name;
147  char *ident;
148 
149  char *helohost;
150 
151  /* message flags */
153 
154  /*
155  ** Message
156  */
158  char *sm_msgid;
159 
160  char *env_from;
161  char *env_to;
164 
165  bool pass_ok; /* access granted */
166 
167  char *hdr_mailer;
168  char *hdr_from;
169  char *hdr_to;
170  char *hdr_subject;
172 
174 
175  /* Anti-spam */
179 
181 
182  char *score_str;
183  char *status_str;
184 
185  /* bayes filter result */
186  int nb_bspam;
187  int nb_bham;
188 
189  /* Contents */
190  char body_chunk[SZ_CHUNK];
193  int body_nb;
194 
197 
198  bool msg_short;
199  unsigned long msg_size;
200  unsigned long nb_bytes;
201 
202  int nb_from;
203  int nb_rcpt; /* nb of recipients */
204 
205  int nb_files; /* nb of attached files */
206  int nb_xfiles; /* nb of X-Files */
207  int nb_virus; /* nb of virus */
208  int nb_policy; /* nb of policy violations */
209  int nb_msgs; /* nb of messagess */
210  int nb_abort; /* nb of aborted messages */
211 
212  int nb_spams; /* nb spams */
213 
214  /* RCPT database check results */
222 
223  int nb_mbadrcpt; /* nb of bad recipients - message */
224  int nb_cbadrcpt; /* nb of bad recipients - connection */
225 
226  /*
227  ** Results
228  */
231 
232  int rej_rcpt;
238 
241  bool rej_open;
242  bool rej_empty;
244  bool rej_msgs;
246 
250 
252 
253  int result;
254 } CTXPRIV_T;
255 
256 #define MLFIPRIV(ctx) \
257  ((ctx) != NULL ? (CTXPRIV_T *) smfi_getpriv(ctx) : NULL)
258 
259 #define CTX_NETCLASS_LABEL(priv) \
260  ((priv) != NULL ? \
261  STREMPTY(priv->netclass.label, NET_CLASS_LABEL(priv->netclass.class)) : \
262  "UNKNOWN")
263 
264 #include <ze-check-connection.h>
265 
266 #include <ze-callback.h>
267 #include <ze-callbackchecks.h>
268 #include <ze-callbacklogs.h>
269 
270 #include <ze-log-files.h>
271 #include <ze-log-virus.h>
272 #include <ze-log-quarantine.h>
273 #include <ze-log-grey.h>
274 #include <ze-log-regex.h>
275 
276 #include <ze-libmilter.h>
277 #include <ze-mod-tools.h>
278 
279 extern char my_hostname[];
280 
281 extern int mx_check_level;
282 
283 #define LOG_CONNECTION_HEADER(s,msg,n,ip,class) \
284  do \
285  { \
286  snprintf(s, sizeof (s), "%s : %s : %d [%02X - %s]", \
287  msg, ip, n, class, NET_CLASS(class)); \
288  } \
289  while (0)
290 
291 #define DO_QUARANTINE_MESSAGE(priv,why,suffix) \
292  do { \
293  ASSERT(priv != NULL); \
294  priv->save_msg = TRUE; \
295  priv->save_why = why; \
296  if (suffix == NULL) { \
297  switch (why) { \
298  case WHY_XFILE: \
299  priv->fsuffix = SUFFIX_XFILE; \
300  break; \
301  case WHY_VIRUS: \
302  priv->fsuffix = SUFFIX_VIRUS; \
303  break; \
304  case WHY_POLICY: \
305  priv->fsuffix = SUFFIX_POLICY; \
306  break; \
307  case WHY_SPAM: \
308  priv->fsuffix = SUFFIX_SPAM; \
309  break; \
310  case WHY_QUARANTINE: \
311  priv->fsuffix = SUFFIX_QUARANTINE; \
312  break; \
313  case WHY_ARCHIVE: \
314  priv->fsuffix = SUFFIX_ARCHIVE; \
315  break; \
316  default: \
317  priv->fsuffix = NULL; \
318  break; \
319  } \
320  } \
321  else \
322  priv->fsuffix = suffix; \
323  } while (0)
324 
325 #define __ZE_FILTER_DATA_H
326 #endif
#define SZ_CHUNK
Definition: ze-filter.h:98
rcpt_addr_T * env_rcpt
char * virus
bool rej_conn_rate
msg_scores_T rawScores
char * fname
int dbrcpt_conn_unknown
time_t t_xmsg
uint32_t flag_rej_connection
MTA_caps_T mta_caps
unsigned long f0
char * peer_addr
char * reply_code
unsigned long f1
time_t conn_id
unsigned long f2
int hdr_content_encoding
char * hdr_mailer
bool rej_msg_rate
int dbrcpt_bad_network
time_t t_callback
bool reject_connect
char * env_to
int dbrcpt_msg_spamtrap
sa_family_t addr_family
bool rej_resolve
struct mlfiPfiv CTXPRIV_T
char my_hostname[]
Definition: ze-filter.c:89
CONNID_T id
unsigned long msg_size
content_field_T tcontent
char * mailserver
char * why
char * hdr_to
iprbwl_T rbwl
char * fsuffix
time_t t_open
char * daemon
int dbrcpt_conn_spamtrap
unsigned long nb_bytes
int dbrcpt_msg_unknown
dresult_T delayed_result
content_field_T * lcontent
header_T * headers
uint32_t flag_rej_contents
char * peer_name
char * reply
msg_scores_T netScores
char * env_from
char * helohost
char * score_str
uint32_t ehlo_flags
char * ident
sm_mac_T * sm
int body_scan_state
int mx_check_level
Definition: ze-mxcheck.c:69
char * status_str
char * hdr_subject
bool rej_badrcpt
char * hdr_from
netclass_T netclass
int nb_unknown_cmd
msg_scores_T dspScores
unsigned long f3
long uint32_t
Definition: ze-sys.h:489
msg_flags_T flags
char * sm_msgid
spamchk_T spamchk
sfsistat result
time_t t_close