36 #define ADDROKTOANSWER(x) ((strlen(STRNULL(x)) != 0) && (strcmp(NULLSENDER,x) != 0)) 42 if ((p == NULL) || (strlen(p) == 0))
65 bool warn_send =
FALSE;
66 bool warn_rcpt =
FALSE;
71 if (!warn_send && !warn_rcpt)
79 smfi_delrcpt(ctx, p->
rcpt);
100 if (!warn_send && !warn_rcpt)
109 smfi_chgheader(ctx,
"Content-type", 1, NULL);
110 smfi_chgheader(ctx,
"Content-disposition", 1, NULL);
111 smfi_chgheader(ctx,
"Content-transfer-encoding", 1, NULL);
114 snprintf(buf,
sizeof (buf),
"<%s.%04X.ze-filter@%s>",
CONNID_STR(priv->
id),
116 smfi_chgheader(ctx,
"Message-ID", 1, buf);
124 if ((sender != NULL) && (strlen(sender) > 0))
125 smfi_chgheader(ctx,
"From", 1, sender);
133 if ((subject != NULL) && (strlen(subject) > 0))
134 smfi_chgheader(ctx,
"Subject", 1, subject);
139 if (smfi_replacebody(ctx, (
unsigned char *) msg, strlen(msg)) != 0)
169 static pthread_mutex_t
mutex = PTHREAD_MUTEX_INITIALIZER;
176 if (cfdir == NULL || strlen(cfdir) == 0)
185 if ((fin = fopen(path,
"r")) != NULL) {
194 snprintf(tag_begin,
sizeof (tag_begin),
"<%s>", tag);
195 snprintf(tag_end,
sizeof (tag_end),
"</%s>", tag);
196 compile_ok = !regcomp(&re,
"_+[A-Z]+_+", REG_ICASE | REG_EXTENDED);
198 while (((strlen(buf) +
sizeof (line)) < sz) &&
199 (fgets(line,
sizeof (line), fin) != NULL)) {
201 char *p = line + strlen(line) - 1;
208 p = line + strspn(line,
" \t");
212 if (strstr(line, tag_begin) == NULL)
217 if (strstr(line, tag_end) != NULL)
221 if (compile_ok && !regexec(&re, line, 1, &pm, 0)) {
229 for (j = pm.rm_so; j < pm.rm_eo; j++) {
234 if (strcasecmp(s1,
"MSGID") == 0) {
238 if (priv->
fname == NULL)
245 snprintf(line,
sizeof (line),
" **** MSG ID : %s%s", filename,
248 snprintf(line,
sizeof (line),
" **** MSG ID : %s%s", priv->
fname,
255 if (strcasecmp(s1,
"FROM") == 0) {
258 from =
STRNULL(from,
"Unknown sender");
262 snprintf(line,
sizeof (line),
" **** From : %s", from);
267 if (strcasecmp(s1,
"TO") == 0) {
273 snprintf(line,
sizeof (line),
" **** To : %s", to);
278 if (strcasecmp(s1,
"SUBJECT") == 0) {
282 snprintf(line,
sizeof (line),
" **** Subject : %s", p);
287 if (strcasecmp(s1,
"SMTP-PEER") == 0) {
291 snprintf(line,
sizeof (line),
" **** Peer : %s", p);
296 if (strcasecmp(s1,
"WHY") == 0) {
297 strlcpy(line, why,
sizeof (line));
302 if (strcasecmp(s1,
"VIRUS") == 0) {
303 snprintf(line,
sizeof (line),
" VIRUS FOUND : %s",
304 answer ? answer :
"NONE");
309 if (strcasecmp(s1,
"TO") == 0)
311 if (strcasecmp(s1,
"ATTACHMENT") == 0 && ahead != NULL) {
316 snprintf(line,
sizeof (line),
317 " There isn't attached files !!!");
326 snprintf(line,
sizeof (line),
" **** (%-11s) : %s", serror,
331 sprintf(line,
" TYPE : %s", p->
mimetype);
339 snprintf(line,
sizeof (line),
" **** SUSPECT FILES : %d", nb);
359 " This message was verified by the filtering system of our mail server.\n" 361 "Original message was replaced by this one by the following reason :\n" 363 "*** A suspicious file (executable code) was found in the message !\n" 375 "ze-filter - (c) Ecole des Mines de Paris 2002, ...";
392 strlcpy_replace(out, in, sz, except, replace)
403 if (
strchr(except, replace) != NULL)
405 while ((p = strpbrk(out, except)) != NULL)
427 if (
id == NULL || strlen(
id) == 0)
434 memset(buf, 0,
sizeof (buf));
435 memset(st, 0,
sizeof (st));
437 strlcpy(buf, st,
sizeof (buf));
439 snprintf(buf,
sizeof (buf),
"%12s : SMQID=(%s)",
id, smid);
442 snprintf(st,
sizeof (st),
", Txn#=(%d)", priv->
nb_from);
443 strlcat(buf, st,
sizeof (buf));
447 if (pc != NULL && strlen(pc) > 0) {
448 snprintf(st,
sizeof (st),
", Callback=(%s)", pc);
449 strlcat(buf, st,
sizeof (buf));
453 char *name, *port, *addr;
464 snprintf(st,
sizeof (st),
", Daemon=(%s;%s;%s)", name, addr, port);
465 strlcat(buf, st,
sizeof (buf));
469 snprintf(st,
sizeof (st),
", Why=(%s)", why);
470 strlcat(buf, st,
sizeof (buf));
474 snprintf(st,
sizeof (st),
", PeerAddr=(%s)", priv->
peer_addr);
475 strlcat(buf, st,
sizeof (buf));
479 snprintf(st,
sizeof (st),
", PeerName=(%s)", priv->
peer_name);
480 strlcat(buf, st,
sizeof (buf));
484 if (pc != NULL && strlen(pc) > 0) {
485 snprintf(st,
sizeof (st),
", NetClass=(%s)", pc);
486 strlcat(buf, st,
sizeof (buf));
493 snprintf(st,
sizeof (st),
", Ehlo=(%s)", priv->
helohost);
494 strlcat(buf, st,
sizeof (buf));
499 snprintf(st,
sizeof (st),
", MAIL=(%s)", priv->
env_from);
500 strlcat(buf, st,
sizeof (buf));
504 snprintf(st,
sizeof (st),
", NbRCPT=(%d)", priv->
env_nb_rcpt);
505 strlcat(buf, st,
sizeof (buf));
507 snprintf(st,
sizeof (st),
", RCPT=(%s)",
STRNULL(priv->
env_to,
"NULL"));
508 strlcat(buf, st,
sizeof (buf));
530 snprintf(st,
sizeof (st),
", Reply=(%s)", priv->
reply_code);
531 strlcat(buf, st,
sizeof (buf));
549 strlcpy(sbuf, buf,
sizeof (sbuf));
551 snprintf(st,
sizeof (st),
", NbRCPT=(%d/%d)", nr, priv->
env_nb_rcpt);
552 strlcat(sbuf, st,
sizeof (sbuf));
554 if (p->
rcpt != NULL && strlen(p->
rcpt) > 0) {
555 snprintf(st,
sizeof (st),
", RCPT=(%s)", p->
rcpt);
556 strlcat(sbuf, st,
sizeof (sbuf));
560 unsigned char *p = (
unsigned char *) priv->
hdr_from;
564 if (*p > 0x7F || *p < 0x20)
574 snprintf(st,
sizeof (st),
", HeaderFrom=(%s)", priv->
hdr_from);
575 strlcat(sbuf, st,
sizeof (sbuf));
579 unsigned char *p = (
unsigned char *) priv->
hdr_mailer;
583 if (*p > 0x7F || *p < 0x20)
594 snprintf(st,
sizeof (st),
", Mailer=(%s)", priv->
hdr_mailer);
597 strlcpy_replace(stc, stc,
sizeof (stc),
"[]",
'\'');
598 strlcpy_replace(stc, stc,
sizeof (stc),
"()",
'.');
599 snprintf(st,
sizeof (st),
", Mailer=(%s)", stc);
602 strlcat(sbuf, st,
sizeof (sbuf));
613 gScore = combine_scores(&priv->
netScores);
623 snprintf(st,
sizeof (st),
624 ", Scores=(R=%d U=%d O=%d B=%5.3f -> %6.3f)",
628 strlcat(sbuf, st,
sizeof (sbuf));
633 snprintf(st,
sizeof (st),
", Size=(%ld)", priv->
msg_size);
634 strlcat(sbuf, st,
sizeof (sbuf));
638 snprintf(st,
sizeof (st),
", Reply=(%s)", priv->
reply_code);
639 strlcat(sbuf, st,
sizeof (sbuf));
643 snprintf(st,
sizeof (st),
", QuarantineFile=(%s)",
645 strlcat(sbuf, st,
sizeof (sbuf));
660 #define UNDEF_TAG "[SUSPECT]" 668 char *osubject = NULL;
672 if (tag != NULL && strlen(tag) > 0)
679 if (strstr(osubject, ntag) == NULL)
682 char *nsubject = NULL;
685 sz = strlen(osubject) + strlen(ntag) + 8;
686 if ((nsubject = (
char *) malloc(sz)) != NULL) {
687 snprintf(nsubject, sz,
"%s %s", ntag, osubject);
688 result = (smfi_chgheader(ctx,
"Subject", 1, nsubject) == MI_SUCCESS);
703 static pthread_mutex_t scf_mutex = PTHREAD_MUTEX_INITIALIZER;
704 static int scf_fd = -1;
705 static int scf_nerr = 0;
707 #define ZE_SERIES_FNAME ZE_WORKDIR "/ze-series.txt" 716 scf_fd = open(fname, O_WRONLY | O_CREAT | O_APPEND, 0644);
739 scf_fd = open(fname, O_WRONLY | O_CREAT | O_APPEND, 0644);
757 #define GLOBAL_CLASS(s) ((s) >= 4 ? "FORT": ((s) > 1 ? "FAIBLE" : "HAM")) 759 #define BAYES_CLASS(s) ((s) >= BSCORE_HI ? "SPAM": ((s) > BSCORE_LO ? "UNSURE" : "HAM")) 761 #define SPAM_CLASS(s) ((s) >= BSCORE_HI ? "SPAM" : (((s) >= BSCORE_MI ? "LO" : ((s) > 0.25 ? "UNSURE" : "HAM")))) 775 static pthread_mutex_t
mutex = PTHREAD_MUTEX_INITIALIZER;
776 static int scf_fd = -1;
777 static int scf_nerr = 0;
784 scf_fd = open(fname, O_WRONLY | O_CREAT | O_APPEND, 0644);
797 gScore = combine_scores(&priv->
netScores);
799 memset(from, 0,
sizeof (from));
806 snprintf(buf,
sizeof (buf),
807 "%10ld SCORE=%.3f GSCORE=%d CLASS=%s B=%.3f R=%d O=%d U=%d IP=%s FROM=%s\n",
815 snprintf(buf,
sizeof (buf),
816 "%10ld SCORE=%5d %-6s %6.3f %-6s %5d %5d %5d %-16s %s\n",
824 snprintf(buf,
sizeof (buf),
825 "%10ld %5d %-6s %6.3f %-6s %5d %5d %5d %-16s %s\n", time(NULL),
833 if (write(scf_fd, buf, strlen(buf)) < strlen(buf)) {
int Smfi_ChgFrom(SMFICTX *ctx, char *mail, char *args)
bool add_tag2subject(SMFICTX *ctx, char *tag)
#define MUTEX_UNLOCK(mutex)
bool reopen_scores4stats_file()
void zeStrCenter(char *, char *, int)
sfsistat do_notify(SMFICTX *ctx, attachment_T *ahead, char *answer, char *why, char *tag)
#define MUTEX_LOCK(mutex)
#define ZE_LogMsgError(level,...)
#define ADJUST_FILENAME(path, fname, cfdir, defval)
bool zeStrRegex(char *, char *, long *, long *, bool)
char * extract_email_address(char *, char *, size_t)
bool dump_msg_scores4stats(SMFICTX *ctx)
char * callback_name(int id)
#define ZE_MessageNotice(level,...)
char * zeStrSet(char *, int, int)
#define ZE_MessageInfo(level,...)
#define ZE_LogSysError(...)
char * cf_get_str(int id)
#define CTX_NETCLASS_LABEL(priv)
#define CONNID_STR(connid)
bool check_address_ok2warn(char *p)
char * sm_macro_get_str(sm_mac_T *, char *)
#define ZE_ERROR_MSG_FILE
void log_msg_context(SMFICTX *ctx, char *why)
#define CF_ERROR_MSG_FILE
struct attachment_T * next
void read_error_msg(char *buf, int sz, attachment_T *ahead, char *answer, char *from, char *why, char *tag, CTXPRIV_T *priv)
bool open_scores4stats_file()