31 static bool check_condition(
char *cond,
47 static bool macro_error_logged =
FALSE;
74 char *s, *ptr, *x = NULL;
77 if ((x = strdup(myself)) != NULL) {
78 for (s = strtok_r(x,
" ", &ptr); s != NULL; s = strtok_r(NULL,
" ", &ptr)) {
112 memset(tstr, 0,
sizeof (tstr));
117 if (gmtime_r(&now, &tm) == NULL)
119 (void) strftime(tstr,
sizeof (tstr),
"+%d%m%y-", &tm);
120 if (strncasecmp(ri, tstr, strlen(tstr)) == 0)
125 if (gmtime_r(&now, &tm) == NULL)
127 (void) strftime(tstr,
sizeof (tstr),
"+%d%m%y-", &tm);
128 if (strncasecmp(ri, tstr, strlen(tstr)) == 0)
134 ri += strlen(
"+DDMMYY-");
137 ok = (strcasecmp(buf,
"OK") == 0);
259 if ((da == NULL) || (db == NULL))
262 if (strcasecmp(da, db) == 0)
269 n = strcspn(da,
".");
305 if ((env_from == NULL) || (from == NULL))
346 memset(&flags, 0,
sizeof (flags));
366 checks->
id = priv->
id;
385 ZE_MessageInfo(10,
"%s SPAM CHECK - C%02d SMTP client resolve failed",
391 ZE_MessageInfo(10,
"%s SPAM CHECK - C%02d SMTP client resolve forged",
398 "%s SPAM CHECK - C%02d SMTP client resolve tempfail",
408 ZE_MessageInfo(10,
"%s SPAM CHECK - C%02d SMTP client blacklisted %s %s",
413 if ((strcasecmp(priv->
peer_name,
"localhost") == 0) &&
414 (strcasecmp(priv->
peer_addr,
"127.0.0.1") != 0)) {
418 "%s SPAM CHECK - C%02d false DNS declared localhost %s/%s ",
423 switch (postmaster) {
442 "%s SPAM CHECK - M%02d message with bad recipients (%d)",
451 "%s SPAM CHECK - M%02d message with spamtrap rcpt (%d)",
461 "%s SPAM CHECK - M%02d too short message - length = %d",
474 "%s SPAM CHECK - M%02d client sending to spamtrap (%d)",
483 ZE_MessageInfo(10,
"%s SPAM CHECK - M%02d NULL sender with %d RCPTS",
509 check_condition(cond, header, rScore)
521 if (cond == NULL || strlen(cond) == 0)
528 for (p = cond, i = 0; *p !=
'\0' && i <
BCONDSZ - 1; p++) {
535 for (i = 0; i < argc && !result; i++) {
542 if (rScore != NULL) {
552 value = strtod(pcond + 1, NULL);
557 if ((
double) rScore->
combined > value)
561 if ((
double) rScore->
combined < value)
580 value = strtod(pcond + 1, NULL);
585 if ((
double) rScore->
bayes > value)
589 if ((
double) rScore->
bayes < value)
608 value = strtod(pcond + 1, NULL);
639 value = strtod(pcond + 1, NULL);
670 value = strtod(pcond + 1, NULL);
676 if ((
double) rScore->
urlbl > value)
680 if ((
double) rScore->
urlbl < value)
699 value = strtod(pcond + 1, NULL);
705 if ((
double) (rScore->
body + rScore->
headers) > value)
709 if ((
double) (rScore->
body + rScore->
headers) < value)
734 if (header != NULL || strlen(header) > 0) {
760 char sbufold[256], sbufnew[256];
765 memset(sbufold, 0,
sizeof (sbufold));
766 memset(sbufnew, 0,
sizeof (sbufnew));
767 memset(sScoreStr, 0,
sizeof (sScoreStr));
769 memset(&rScores, 0,
sizeof (rScores));
799 #if 0 && _FFR_MODULES 834 smfi_addheader(ctx,
"X-ze-filter-Score", sbufnew);
837 if ((priv->
score_str = strdup(sbufnew)) == NULL)
844 char *xstatus = NULL;
847 doit = check_condition(xspam, sbufold, &priv->
rawScores);
850 if ((priv->
score_str = strdup(sbufnew)) == NULL)
865 doit = check_condition(xspam, sbufold, &priv->
rawScores);
879 if (xstatus == NULL || strlen(xstatus) == 0)
880 xstatus =
"X-ze-filter-Status";
883 doit = check_condition(xspam, sbufold, &priv->
rawScores);
885 smfi_addheader(ctx, xstatus,
"Spam HI");
887 if ((priv->
status_str = strdup(
"Spam HI")) == NULL)
898 if (tag == NULL || strlen(tag) == 0) {
899 snprintf(buf,
sizeof (buf),
"[J-%s]", sScoreStr);
916 doit = check_condition(xspam, sbufold, &priv->
rawScores);
918 smfi_addheader(ctx, xstatus,
"Spam LO");
920 if ((priv->
status_str = strdup(
"Spam LO")) == NULL)
929 doit = check_condition(xspam, sbufold, &priv->
rawScores);
931 smfi_addheader(ctx, xstatus,
"Unsure");
933 if ((priv->
status_str = strdup(
"Unsure")) == NULL)
942 doit = check_condition(xspam, sbufold, &priv->
rawScores);
944 smfi_addheader(ctx, xstatus,
"Ham");
946 if ((priv->
status_str = strdup(
"Ham")) == NULL)
991 snprintf(logbuf,
sizeof (logbuf),
"%s : B=%.3f U=%d R=%d O=%d -> G=%.3f",
1001 gScore, time(NULL));
1027 bool result =
FALSE;
1029 if (rcpt == NULL || strlen(rcpt) == 0)
1042 result = (strcasecmp(buf,
"NO") != 0);
1043 ZE_MessageInfo(10,
"SPAMTRAP - %s found at policy database", rcpt);
1067 #define EHLO_OK 0x0000 1068 #define EHLO_NONE 0x0000 1069 #define EHLO_INVALID_CHAR 0x0001 1070 #define EHLO_FORGED_IP 0x0002 1071 #define EHLO_IP_NO_BRACKET 0x0004 1072 #define EHLO_NOT_FQDN 0x0008 1073 #define EHLO_IDENTITY_THEFT 0x0010 1074 #define EHLO_FAKE_LOCALHOST 0x0020 1075 #define EHLO_REGEX 0x0040 1076 #define EHLO_ALL 0x0FFF 1101 uint32_t ehlo_flags = 0, ehlo_res = 0;
1102 char *helohost = NULL;
1104 bool is_bracketed =
FALSE;
1105 bool is_ipv4 =
FALSE;
1106 bool is_ipv6 =
FALSE;
1108 static time_t last_update = (time_t) 0;
1115 char *checks = NULL;
1119 if (checks != NULL && strlen(checks) > 0) {
1125 memset(argv, 0,
sizeof (argv));
1128 for (i = 0; i < argc; i++) {
1153 last_update = time(NULL);
1156 ehlo_flags = ehlo_res = 0;
1161 if ((helohost = strdup(priv->
helohost)) == NULL) {
1172 len = strlen(helohost);
1173 if (helohost[0] ==
'[' && helohost[len - 1] ==
']') {
1176 for (i = 0; i < len - 2; i++)
1177 helohost[i] = helohost[i + 1];
1178 helohost[len - 2] =
'\0';
1179 is_bracketed =
TRUE;
1192 ZE_MessageInfo(10,
"%s SPAM CHECK - C%02d EHLO : Invalid character %s",
1203 "%s SPAM CHECK - C%02d EHLO : doesn't match peer addr %s/%s",
1208 if ((is_ipv4 || is_ipv6) && !is_bracketed) {
1211 ZE_MessageInfo(10,
"%s SPAM CHECK - C%02d EHLO : IP without brackets %s",
1215 if (!is_ipv4 && !is_ipv6 &&
strchr(helohost,
'.') == NULL) {
1221 ZE_MessageInfo(10,
"%s SPAM CHECK - C%02d EHLO : non FQDN parameter %s",
1228 if (is_ipv6 &&
zeStrRegex(helohost,
"(::1)", NULL, NULL,
TRUE)) {
1232 "%s SPAM CHECK - C%02d EHLO : presents as being localhost %s/%s",
1237 if (is_ipv4 &&
STRNCASEEQUAL(helohost,
"127.", strlen(
"127."))) {
1241 "%s SPAM CHECK - C%02d EHLO : presents as being localhost %s/%s",
1246 if (!is_ipv4 && !is_ipv6
1251 "%s SPAM CHECK - C%02d EHLO : presents as being localhost %s/%s",
1260 char *myself = NULL;
1269 strlcpy(tme, myself,
sizeof (tme));
1272 for (i = 0; i < argc; i++) {
1273 char *expr = argv[i];
1282 ZE_MessageInfo(19,
"Checking helo %s against %s", helohost, expr);
1292 "%s SPAM CHECK - C%02d EHLO : presents as being myself %s/%s",
1313 "%s SPAM CHECK - C%02d EHLO (%s) matches regular expression",
1319 ZE_MessageInfo(9,
"%s EHLO CHECK - Bad value ip/value = %s/%s (%08X)",
1328 ehlo_flags &= ehlo_check_rules;
1342 #define DKF_STATUS_GOOD 0 1343 #define DKF_STATUS_BAD 1 1344 #define DKF_STATUS_NOKEY 2 1345 #define DKF_STATUS_REVOKED 3 1346 #define DKF_STATUS_NOSIGNATURE 4 1347 #define DKF_STATUS_BADFORMAT 6 1348 #define DKF_STATUS_NONPART 7 1349 #define DKF_STATUS_UNKNOWN 8 1378 for (p = dkf_status; p->
str != NULL; p++)
1379 if (strcasecmp(p->
str, s) == 0)
1400 int iStatus, iSignature;
1407 if (iStatus >= 0 && iSignature < 0) {
1411 if ((iStatus >= 0) && (iSignature >= 0)) {
1412 if (iStatus > iSignature) {
1443 bool result =
FALSE;
1447 memset(buf, 0,
sizeof (buf));
1449 if (strcasecmp(buf,
"NO") == 0)
1451 if (strcasecmp(buf,
"YES") == 0)
1453 if (strcasecmp(buf,
"RECIPIENT") == 0)
1455 if (strcasecmp(buf,
"SENDER") == 0)
1457 if (strcasecmp(buf,
"DAILY") == 0)
int check_regex(char *, char *, char *, int)
int smtprate_add_entry(int, char *, char *, int, time_t)
#define EHLO_FAKE_LOCALHOST
bool check_helo_myself(char *ip, char *hostname, char *helo)
bool check_policy_all_rcpts(char *prefix, char *ip, char *name, char *netclass, char *from, rcpt_addr_T *rcpt, bool result, int conflict)
#define CF_XSTATUS_HEADER_UNSURE_CONDITION
void stats_inc(int, long)
bool check_policy(char *prefix, char *key, char *buf, size_t size, bool cdef)
#define DKF_STATUS_UNKNOWN
int decode_dk_result(char *s)
#define CF_XSTATUS_HEADER_LO_CONDITION
int jsmfi_setreply(SMFICTX *, char *, char *, char *)
#define DKF_STATUS_NOSIGNATURE
#define SPAM_CONN_RESOLVE_FAIL
bool add_tag2subject(SMFICTX *, char *)
#define SPAM_CONN_FALSE_LOCALHOST
#define SPAM_MSG_HAS_SPAMTRAP
int check_domainkeys(SMFICTX *ctx)
#define STRNCASEEQUAL(a, b, n)
#define SPAM_MSG_TOO_SHORT
bool check_spamtrap_rcpt(char *id, char *ip, char *from, char *rcpt, int ip_class)
bool zeStrRegex(char *, char *, long *, long *, bool)
#define SPAM_MSG_HAS_BADRCPT
bool compatible_domains(char *da, char *db)
#define CF_LOG_LEVEL_ORACLE
int zeStrlEqual(char *, char *)
#define CF_XSTATUS_HEADER
#define EHLO_IDENTITY_THEFT
int zeStr2Tokens(char *, int, char **, char *)
#define CF_BAYESIAN_FILTER
#define STAT_PATTERN_MATCHING
#define DO_QUARANTINE_MESSAGE(priv, why, suffix)
#define CF_SCORE_ON_SUBJECT_TAG
#define CF_SCANNER_ACTION
bool fill_msg_scale(scores_scale_T *scale)
#define CF_XSTATUS_HEADER_HI_CONDITION
sfsistat check_msg_contents(SMFICTX *ctx)
#define ZE_MessageNotice(level,...)
bool create_msg_score_header(char *buf, size_t size, char *id, char *hostname, msg_scores_T *scores)
#define SPAM_CONN_RESOLVE_TEMPFAIL
uint32_t check_ehlo_value(SMFICTX *ctx)
#define IS_UNKNOWN(class)
#define CF_SCORE_ON_SUBJECT
void msg_score_stats_update(msg_scores_T *scores)
#define ZE_MessageInfo(level,...)
#define SPAM_MSG_BAD_NULL_SENDER
#define SPAM_CONN_BL_SPAMTRAP
#define SPAM_CONN_FORGED_EHLO
#define SPAM_CONN_BAD_EHLO
void oracle_stats_update(int)
#define ZE_LogSysError(...)
#define MSG_BODY_CONTENTS
char * cf_get_str(int id)
#define SPAM_MSG_FORGED_POSTMASTER
#define CTX_NETCLASS_LABEL(priv)
#define SPAM_CONN_RESOLVE_FORGED
#define EHLO_IP_NO_BRACKET
bool passport_ok(char *to, char *key)
bool shall_check_virus(SMFICTX *ctx)
#define DKF_STATUS_REVOKED
#define CF_BADEHLO_CHECKS
#define CONNID_STR(connid)
sfsistat evaluate_message_score(SMFICTX *ctx, bool *do_log)
int update_nb_badrcpts(SMFICTX *ctx)
#define CF_XSTATUS_REJECT_CONDITION
#define DKF_STATUS_BADFORMAT
#define STRCASEEQUAL(a, b)
struct lookup dkf_status[]
int get_id_by_name(name2id_T *, char *)
bool shall_check_content(SMFICTX *ctx)
bool shall_check_xfiles(SMFICTX *ctx)
int livehistory_check_host(char *, time_t, int)
int livehistory_add_entry(char *, time_t, int, int)
#define EHLO_INVALID_CHAR
bool enveloppe_postmaster(char *from)
#define DKF_STATUS_NONPART
double compute_msg_score(msg_scores_T *scores)
char * sm_macro_get_str(sm_mac_T *, char *)
void log_msg_context(SMFICTX *ctx, char *why)
#define CF_XSTATUS_HEADER_HAM_CONDITION
bool shall_notify_user(char *user_addr, bool to)
#define POSTMASTER_FORGED
#define CF_SPAM_REGEX_MAX_MSG_SIZE
#define CF_XSTATUS_QUARANTINE_CONDITION
int check_valid_postmaster(char *env_from, char *from, int nbrcpt)
bool shall_designated_quarantine(SMFICTX *ctx, char *rcpt)
int scan_body_contents(char *, char *, char *, size_t, spamchk_T *, msg_flags_T *, msg_scores_T *)