29 static sfsistat eom_check_xfiles(SMFICTX * ctx,
attachment_T * ahead,
31 static sfsistat eom_check_virus(SMFICTX * ctx,
attachment_T * ahead,
33 static sfsistat eom_check_content(SMFICTX * ctx,
bool * done);
39 #define LOG_NOCHECK(priv, reason) \ 41 char bufh[512], buft[512]; \ 45 memset(bufh, 0, sizeof(bufh)); \ 46 memset(st, 0, sizeof(st)); \ 47 if (priv->peer_addr != NULL && strlen(priv->peer_addr) > 0) \ 49 snprintf(st, sizeof (st), ", PeerAddr=(%s)", priv->peer_addr); \ 50 strlcat(bufh, st, sizeof (bufh)); \ 52 if (priv->peer_name != NULL && strlen(priv->peer_name) > 0) \ 54 snprintf(st, sizeof (st), ", PeerName=(%s)", priv->peer_name); \ 55 strlcat(bufh, st, sizeof (bufh)); \ 58 pc = CTX_NETCLASS_LABEL(priv); \ 59 if (pc != NULL && strlen(pc) > 0) \ 61 snprintf(st, sizeof (st), ", NetClass=(%s)", pc); \ 62 strlcat(bufh, st, sizeof (bufh)); \ 64 if (priv->env_from != NULL && strlen(priv->env_from) > 0) \ 66 snprintf(st, sizeof (st), ", MAIL=(%s)", priv->env_from); \ 67 strlcat(bufh, st, sizeof (bufh)); \ 75 for (p = priv->env_rcpt; p != NULL; p = p->next) \ 79 if (p->access != RCPT_OK) \ 83 memset(buft, 0, sizeof(buft)); \ 85 snprintf(st, sizeof (st), ", NbRCPT=(%d/%d)", \ 86 nr, priv->env_nb_rcpt); \ 87 strlcat(buft, st, sizeof (buft)); \ 89 if (p->rcpt != NULL && strlen(p->rcpt) > 0) \ 91 snprintf(st, sizeof (st), ", RCPT=(%s)", p->rcpt); \ 92 strlcat(buft, st, sizeof (buft)); \ 95 ZE_MessageInfo(10, "%s Content Unchecked by policy %s %s", \ 96 CONNID_STR(priv->id), bufh, buft); \ 117 char *log_msg = NULL;
118 char log_msg_buf[1024];
120 time_t now = time(NULL);
141 (priv->
msg_size + 512) / 1024, now);
150 bool addrPlusEmail =
FALSE;
153 if ((s = getenv(
"FROMRATEFULL")) != NULL) {
155 addrPlusEmail =
TRUE;
169 char *auth_authen = NULL;
172 if (auth_authen != NULL && strlen(auth_authen) > 0) {
214 char *unwanted_hdrs[] = {
215 "Disposition-Notification-To",
216 "X-Confirm-Reading-To",
217 "Generate-Delivery-Report",
218 "Disclose-Recipients",
222 for (hdr = unwanted_hdrs; *hdr != NULL; hdr++) {
228 if (h->
value == NULL)
238 smfi_chgheader(ctx, *hdr, nb--, NULL);
248 char *mac_srv_name = NULL;
249 char *mac_cl_addr = NULL;
250 char *mac_cl_ptr = NULL;
251 char *mac_cl_name = NULL;
252 char *mac_qid = NULL;
254 memset(host, 0,
sizeof (host));
256 snprintf(host,
sizeof (host),
"localhost");
264 p = smfi_getsymval(ctx,
"j");
271 if ((p != NULL) && (strlen(p) > 0))
272 strlcpy(host, p,
sizeof (host));
275 if (strcasecmp(url,
"http://foss.jose-marcio.org") == 0)
276 url =
"http : // foss dot jose-marcio dot org";
277 if (strcasecmp(url,
"NO") == 0)
279 if (strlen(url) > 0) {
280 snprintf(hbuf,
sizeof hbuf,
281 "at %s with ID %s by Joe's ze-filter (%s)!",
284 snprintf(hbuf,
sizeof hbuf,
285 "at %s with ID %s by Joe's ze-filter !", host,
288 smfi_addheader(ctx,
"X-Miltered", hbuf);
293 mac_cl_addr =
STREMPTY(mac_cl_addr,
"null");
295 mac_cl_ptr =
STREMPTY(mac_cl_ptr,
"null");
297 mac_cl_name =
STREMPTY(mac_cl_name,
"null");
299 mac_qid =
STREMPTY(mac_qid,
"null");
302 char *mac_auth_type = NULL;
303 char *mac_auth_authen = NULL;
308 if ((mac_auth_type != NULL) && (strlen(mac_auth_type) > 0) ||
309 (mac_auth_authen != NULL) && (strlen(mac_auth_authen) > 0)) {
310 snprintf(hbuf,
sizeof (hbuf),
"USER-ID %s",
312 smfi_addheader(ctx,
"X-ze-filter-Auth", hbuf);
316 snprintf(hbuf,
sizeof (hbuf),
317 "%s from %s/%s/%s/%s/%s",
319 mac_cl_name, mac_cl_ptr, mac_cl_addr,
322 smfi_addheader(ctx,
"X-ze-filter-Envelope", hbuf);
331 char buf[512], *p = NULL;
338 memset(buf, 0,
sizeof (buf));
340 for (i = 0; i < argc; i++) {
341 if (strlen(argv[i]) == 0 ||
STRCASEEQUAL(argv[i],
"none"))
346 (void) smfi_chgheader(ctx, argv[i], n, NULL);
358 char buf[512], *p = NULL;
365 memset(buf, 0,
sizeof (buf));
379 if (h->
value == NULL || strlen(h->
value) == 0)
382 for (i = 0; i < argc; i++) {
384 bool preserve =
FALSE;
387 if (strlen(arg) == 0) {
404 if (strlen(arg) == 0) {
413 snprintf(expr,
sizeof (expr),
"on [^ ]*%s : ze-filter score", arg);
422 (void) smfi_chgheader(ctx,
"X-ze-filter-Score", n, NULL);
495 if (h->
value == NULL)
497 for (cmd = SYMPA_CMDS; (*cmd != NULL); cmd++) {
564 #define DEFAULT_ORDER "XFILES,VIRUS,CONTENT" 572 char *env = getenv(
"ORDER_CHECKS");
574 if (env == NULL || strlen(env) == 0)
576 strlcpy(buf, env,
sizeof (buf));
579 for (i = 0; i < argc; i++) {
583 result = eom_check_xfiles(ctx, ahead, &done);
585 result = eom_check_virus(ctx, ahead, &done);
587 result = eom_check_content(ctx, &done);
621 log_msg =
STRNULL(log_msg,
"*** ATTACHMENTS : ");
660 eom_check_xfiles(ctx, ahead, done)
691 char *log_msg = NULL;
693 memset(str_action, 0,
sizeof (str_action));
696 memset(str_action, 0,
sizeof (str_action));
699 str_action, sizeof (str_action));
701 && (strlen(str_action) == 0 || !
STRCASEEQUAL(str_action,
"ok")))
733 char *xstatus = NULL;
736 if (xstatus == NULL || strlen(xstatus) == 0)
737 xstatus =
"X-ze-filter-Status";
738 smfi_addheader(ctx, xstatus,
"Spam HI");
745 memset(&reply, 0,
sizeof (reply));
747 if (strlen(str_action) > 0) {
773 (
"XfilesAction", str_action, buf,
sizeof (buf),
FALSE)) {
782 switch (res_action) {
821 if (nb_xfiles > 0 || (done != NULL && *done))
834 eom_check_virus(ctx, ahead, done)
841 char log_msg_buf[1024];
852 memset(log_msg_buf, 0,
sizeof (log_msg_buf));
865 memset(why, 0,
sizeof (data));
866 memset(data, 0,
sizeof (why));
868 avres =
av_client(why,
sizeof (why), data,
sizeof (data), question);
882 "Temporary system error. Come back later");
898 snprintf(log_msg_buf,
sizeof (log_msg_buf),
"%s : %s",
MSG_VIRUS, data);
928 result =
do_notify(ctx, ahead, data, msg,
"VIRUS");
962 eom_check_content(ctx, done)
975 LOG_NOCHECK(priv,
"Content check disabled by policy");
983 bool check_it =
TRUE;
994 LOG_NOCHECK(priv,
"Statistical filter disabled by policy");
1001 memset(&bcheck, 0,
sizeof (bcheck));
1003 if (bcheck.
nbt <= 0)
1040 bool check_it =
TRUE;
1042 size_t fsize_max = 300
KBYTES;
1047 if ((env = getenv(
"LR_MAX_FSIZE")) != NULL)
1048 fsize_max =
zeStr2size(env, NULL, fsize_max);
1052 ZE_MessageInfo(10,
"%s LogReg filter sizes : size %7d, size max %7d %s %s",
1054 (fsize >= fsize_max ?
"XXX" :
"---"),
1055 (fsize >= 300000 && fsize < fsize_max ?
"YYY" :
"---"));
1057 if (fsize < fsize_max)
1071 memset(&mscore, 0,
sizeof (mscore));
1072 memset(&cargs, 0,
sizeof (cargs));
1073 memset(&margs, 0,
sizeof (margs));
1093 #define KLOGBAY (2./3.) 1094 #define MLOGBAY (2.) 1099 double Klb = 2. / 3.;
1100 double BLogit, LLogit;
1103 char *s = getenv(
"MLOGBAY");
1113 char *s = getenv(
"KLOGBAY");
1117 if (Klb < 0. || Klb > 1.)
1126 agree = (
SIGN(BLogit) ==
SIGN(LLogit));
1127 win =
SIGN(fabs(BLogit) - fabs(LLogit));
1128 odds = BLogit + LLogit;
1140 nscore.
value = gres;
1148 nscore.
value = gres;
1156 nscore.
value = gres;
1170 snprintf(buf,
sizeof (buf),
"%s B=%.5f L=%.5f G=%.5f %-8s %s%s",
1175 STRBOOL(agree,
"Agree",
"Disagree"),
1181 smfi_addheader(ctx,
"X-Scores-Stats", buf);
1187 smfi_addheader(ctx,
"X-Label-Query",
"YES");
1197 bool do_regex, do_oracle, do_urlbl;
1207 if (do_regex || do_oracle || do_urlbl)
1210 LOG_NOCHECK(priv,
"Content check disabled by policy");
1218 bool do_log =
FALSE;
1224 snprintf(logbuf,
sizeof (logbuf),
"%s : B=%.3f U=%d R=%d O=%d -> G=%.3f",
1235 char *env = getenv(
"DUMP_MESSAGE_SCORE");
#define CF_REMOVE_HEADERS
int smtprate_add_entry(int, char *, char *, int, time_t)
double sfilter_check_message(char *id, char *fname, sfilter_vsm_T *bcheck)
#define CF_XFILE_SUBJECT_TAG
sfsistat check_nb_badrcpts(SMFICTX *)
#define CF_LOG_ATTACHMENTS
bool check_policy_all_rcpts(char *prefix, char *ip, char *name, char *netclass, char *from, rcpt_addr_T *rcpt, bool result, int conflict)
void stats_inc(int, long)
bool shall_check_xfiles(SMFICTX *)
#define CF_REJECT_SHORT_BODIES
int jsmfi_setreply(SMFICTX *, char *, char *, char *)
sfsistat mlfi_cleanup(SMFICTX *ctx, bool ok)
bool add_tag2subject(SMFICTX *, char *)
#define MSG_SIZE_EXCEED_LIMIT
int check_domainkeys(SMFICTX *ctx)
sfsistat do_notify(SMFICTX *, attachment_T *, char *, char *, char *)
bool lr_classify(char *id, char *fname, lr_cargs_T *cargs, lr_margs_T *margs, test_score_T *score)
#define CF_BAYES_NB_TOKENS
bool jc_fill_reply(smtp_reply_T *, char *, char *, char *, int)
bool zeStrRegex(char *, char *, long *, long *, bool)
#define CF_REJECT_BAD_NULL_SENDER
#define CF_SCANNER_REJECT_ON_ERROR
bool dump_msg_scores4stats(SMFICTX *ctx)
bool shall_check_content(SMFICTX *)
bool shall_check_virus(SMFICTX *)
bool spool_file_close(CTXPRIV_T *)
#define CF_XSTATUS_HEADER
char * zeStrChomp(char *)
int zeStr2Tokens(char *, int, char **, char *)
#define CF_BAYESIAN_FILTER
#define INIT_CALLBACK(p, which)
#define DO_QUARANTINE_MESSAGE(priv, why, suffix)
sfsistat check_msg_contents(SMFICTX *)
void sm_macro_update(SMFICTX *, sm_mac_T *)
#define CF_SCANNER_ACTION
int jsmfi_vsetreply(SMFICTX *ctx, char *ca, char *cb, char *format,...)
size_t zeStr2size(char *s, int *error, size_t dval)
#define INIT_CALLBACK_DELAY()
double zeStr2double(char *s, int *error, double dval)
#define LOG_NOCHECK(priv, reason)
long check_limit_all_rcpts(char *prefix, char *ip, char *name, char *netclass, char *from, rcpt_addr_T *rcpt, long defval)
#define IS_UNKNOWN(class)
void log_virus(char *, char *, char *)
#define ZE_MessageInfo(level,...)
sfsistat mlfi_eom(SMFICTX *ctx)
bool get_hostname(char *, size_t)
#define CF_XFILE_SAVE_MSG
#define ZE_MessageError(level,...)
#define CF_DROP_DELIVERY_NOTIFICATION_REQUEST
content_field_T * lcontent
char * cf_get_str(int id)
double logitinv(double x)
#define ZE_LogMsgWarning(level,...)
#define CTX_NETCLASS_LABEL(priv)
bool log_attached_files(char *, char *, attachment_T *)
void log_quarantine(SMFICTX *, attachment_T *)
#define CONNID_STR(connid)
#define CHECK_CALLBACK_DELAY()
int update_nb_badrcpts(SMFICTX *)
#define STRCASEEQUAL(a, b)
bool check_xfiles(char *, char *, size_t, char *, size_t)
sfsistat evaluate_message_score(SMFICTX *ctx, bool *)
int livehistory_add_entry(char *, time_t, int, int)
char * sm_macro_get_str(sm_mac_T *, char *)
void log_msg_context(SMFICTX *ctx, char *why)
struct attachment_T * next
int jc_string2reply(smtp_reply_T *, char *)
int av_client(char *, size_t, char *, size_t, char *)
#define MSG_BAD_NULL_SENDER