41 #define _FFR_CTX_CONNECT TRUE 42 #ifndef _FFR_CTX_CONNECT 43 #define _FFR_CTX_CONNECT FALSE 47 #if _FFR_PREPEND_HEADERS 48 #if HAVE_SMFI_INSHEADER 49 #define smfi_addheader(a,b,c) smfi_insheader(a,0,b,c) 53 static sfsistat
mlfi_connect(SMFICTX *,
char *, _SOCK_ADDR *);
54 static sfsistat
mlfi_helo(SMFICTX *,
char *);
56 static sfsistat
mlfi_envto(SMFICTX *,
char **);
57 static sfsistat mlfi_data(SMFICTX *);
58 static sfsistat
mlfi_header(SMFICTX *,
char *,
char *);
60 static sfsistat
mlfi_body(SMFICTX *,
unsigned char *,
size_t);
64 static sfsistat mlfi_unknown(SMFICTX *,
const char *);
65 static sfsistat mlfi_negotiate(SMFICTX * ctx,
72 unsigned long *pf2,
unsigned long *pf3);
79 static int mime_encode2val(
char *);
85 static sfsistat check_filter_open_connections(SMFICTX *,
char *,
char *,
87 static sfsistat check_cpu_load(SMFICTX *,
char *,
char *,
int);
95 static char *SYMPA_CMDS[] = {
125 #define INIT_CALLBACK(p, which) \ 128 p->callback_id = which; \ 129 FREE(p->reply_code); \ 133 #define JSM_TO ((time_t ) 10) 135 #define INIT_CALLBACK_DELAY() \ 136 time_t ti = time(NULL), tf = time(NULL); \ 137 uint64_t tims = zeTime_ms(), tfms = zeTime_ms() 139 #define UPDATE_SVCTIME() \ 140 (void) smtprate_add_entry(RATE_SVCTIME, priv->peer_addr, \ 141 priv->peer_name, (tfms - tims), time(NULL)); 143 #define CHECK_CALLBACK_NOW() (zeTime_ms() - tims) 146 #define CHECK_CALLBACK_DELAY() \ 149 if ((priv != NULL) && ((tf - ti) > JSM_TO)) { \ 150 ZE_LogMsgNotice(0, "%s %s : callback handling time too long : " \ 151 " %ld (threshold = %ld)", \ 152 CONNID_STR (priv->id), priv->peer_addr, \ 153 (long ) (tf - ti), (long ) JSM_TO); \ 156 tfms = zeTime_ms(); \ 157 if ((tfms - tims) > 1000 * JSM_TO) { \ 159 if (priv != NULL) { \ 160 priv->t_callback += (tfms - tims); \ 161 if (priv->peer_addr != NULL) \ 162 (void) smtprate_add_entry(RATE_SVCTIME, priv->peer_addr, \ 163 STRNULL(priv->peer_name, "UNKNOWN"), \ 164 (tfms - tims), time(NULL)); \ 166 (void) callback_stats_update(priv->callback_id, (tfms - tims)); \ 171 #define FREE_DELAYED_RESULT(dres) \ 173 dres.result = SMFIS_CONTINUE; \ 174 dres.callback = CALLBACK_CONNECT; \ 202 return "UNKNOWN ???";
242 mime_encode2val(code)
248 if (strcasecmp(code,
"7bit") == 0)
250 if (strcasecmp(code,
"8bit") == 0)
252 if (strcasecmp(code,
"binary") == 0)
254 if (strcasecmp(code,
"base64") == 0)
256 if (strcasecmp(code,
"quoted-printable") == 0)
276 static pthread_mutex_t id_mutex = PTHREAD_MUTEX_INITIALIZER;
282 if (now != sid.
t[0]) {
287 snprintf(sid.
id, sizeof (sid.
id),
"%08lX.%03lX", (
long) sid.
t[0],
304 static pthread_mutex_t cnt_mutex = PTHREAD_MUTEX_INITIALIZER;
305 static int cnt_conn = 0;
306 static time_t old = 0;
317 if ((
new - old) > 60) {
332 check_filter_open_connections(ctx,
id,
ip, ip_class)
345 if ((nbcmax > 0) && (nb_open > nbcmax)) {
348 "I'm too busy. Try again later !");
360 check_cpu_load(ctx,
id,
ip, ip_class)
374 if ((hard > 0) && (load < (
double) hard))
376 if (
IS_UNKNOWN(ip_class) && (soft > 0) && (load < (
double) soft))
381 "I'm too busy. Try again later !");
394 #define MAXINT 1 << 30 398 get_recipient_quarantine_threshold(rcpt)
415 for (rcpt = head; rcpt != NULL; rcpt = rcpt->
next) {
417 get_recipient_quarantine_threshold(rcpt->
user);
418 if (score > threshold) {
460 SMFIF_ADDHDRS | SMFIF_CHGHDRS | SMFIF_CHGBODY | SMFIF_ADDRCPT | SMFIF_DELRCPT
461 #if HAVE_SMFI_CHGFROM 464 #if HAVE_SMFI_CHGFROM 480 #if HAVE_XXFI_UNKNOWN 483 #if HAVE_XXFI_DATA && HAVE_XXFI_UNKNOWN 489 #if HAVE_XXFI_NEGOTIATE && HAVE_XXFI_DATA && HAVE_XXFI_UNKNOWN 507 char *work_dir, *wdb_dir, *cf_dir, *cdb_dir, *root_dir;
509 root_dir = work_dir = wdb_dir = cf_dir = cdb_dir = NULL;
524 if (work_dir == NULL || strlen(work_dir) == 0)
527 if (wdb_dir == NULL || strlen(wdb_dir) == 0)
530 if (cf_dir == NULL || strlen(cf_dir) == 0)
532 if (strlen(root_dir) > 0) {
533 if (*work_dir !=
'/')
535 if (chdir(work_dir) != 0)
543 memset(dbdir, 0,
sizeof (dbdir));
544 if (wdb_dir != NULL && strlen(wdb_dir) > 0)
545 snprintf(dbdir,
sizeof (dbdir),
"%s", wdb_dir);
578 time_t dt_expire, dt_check, dt_sync;
608 size_t msgSize, partSize;
611 memset(path, 0,
sizeof (path));
628 if (partSize < 10000)
632 if (rhs < 0.1 || rhs > 10.)
641 if ((env = getenv(
"LR_FILTER_ENABLE")) != NULL)
660 char *milter_debug = getenv(
"MILTER_DEBUG_LEVEL");
663 if (milter_debug != NULL) {
664 int level = atoi(milter_debug);
668 (void) smfi_setdbg(level);
679 "FATAL ERROR Don't know how to communicate with sendmail");
683 if (smfi_register(
smfilter) == MI_FAILURE) {
685 exit(EX_UNAVAILABLE);
687 #if HAVE_SMFI_SETBACKLOG 688 smfi_setbacklog(256);
690 #if HAVE_SMFI_SETMINWORKERS 694 ZE_MessageInfo(9,
"Setting the minimum number of workers in the pool to %d",
696 smfi_setminworkers(nw);
703 ZE_MessageInfo(9,
"Setting MTA communication timeout to %d s", smto);
704 (void) smfi_settimeout(smto);
#define CF_RESOLVE_CACHE_ENABLE
#define CF_CPU_IDLE_HARD_LIMIT
void launch_periodic_tasks_thread(void)
bool check_recipient_quarantine(rcpt_addr_T *head, int score)
int smtprate_update_table(time_t)
void stats_inc(int, long)
bool set_bfilter_max_sizes(size_t msg, size_t mime)
#define CF_RESOLVE_CACHE_CHECK
#define CF_BAYES_MAX_PART_SIZE
sfsistat mlfi_envfrom(SMFICTX *ctx, char **envfrom)
bool resolve_cache_times(time_t dt_sync, time_t dt_check, time_t dt_expire)
int jsmfi_setreply(SMFICTX *, char *, char *, char *)
sfsistat mlfi_cleanup(SMFICTX *ctx, bool ok)
void print_filter_stats_summary(void)
#define MUTEX_UNLOCK(mutex)
unsigned int smtprate_window
bool resolve_cache_init(char *dbdir, int rwmode)
bool configure_msg_eval_function(char *val)
sfsistat mlfi_close(SMFICTX *ctx)
#define MUTEX_LOCK(mutex)
#define ZE_LogMsgInfo(level,...)
void zeLog_SetOutput(bool, bool)
#define ZE_LogMsgError(level,...)
#define ADJUST_FILENAME(path, fname, cfdir, defval)
void log_counters(int, bool)
bool load_live_history(History_T *, time_t, time_t)
bool open_work_db_env(char *defdir, char *cfdir, bool rdonly)
sfsistat mlfi_body(SMFICTX *ctx, unsigned char *bodyp, size_t bodylen)
#define CF_CPU_IDLE_SOFT_LIMIT
#define CF_BAYES_MAX_MESSAGE_SIZE
bool raw_history_open(bool)
sfsistat mlfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr)
#define CF_RESOLVE_CACHE_SYNC
bool bfilter_init(char *dbname)
sfsistat mlfi_abort(SMFICTX *ctx)
int smtprate_read_table(char *)
bool db_map_open(char *bl)
#define IS_UNKNOWN(class)
bool CycTasks_Init(time_t interval)
#define ZE_MessageInfo(level,...)
bool grey_init(char *, bool, int)
sfsistat mlfi_eom(SMFICTX *ctx)
bool set_bfilter_ham_spam_ratio(double ratio)
#define ZE_MessageWarning(level,...)
sfsistat mlfi_helo(SMFICTX *ctx, char *helohost)
bool get_hostname(char *, size_t)
bool lr_data_load(bool background)
int count_rcpt(rcpt_addr_T *rcpt)
#define ZE_LogSysError(...)
void remove_milter_sock()
char * cf_get_str(int id)
bool free_private_data(CTXPRIV_T *, bool)
int count_connections(int)
#define ZE_LogMsgWarning(level,...)
char * mlfi_result_string(sfsistat)
#define CF_MAX_OPEN_CONNECTIONS
void smtprate_save_table(char *)
bool load_all_modules(char *cfdir, char *modcf, char *moddir)
#define STRCASEEQUAL(a, b)
bool set_bfilter_db_crypt(int crypt)
bool smtprate_init(size_t, size_t)
sfsistat mlfi_eoh(SMFICTX *ctx)
bool db_close_blacklist()
sfsistat mlfi_envto(SMFICTX *ctx, char **envto)
bool setup_filter_signal_handler(void)
#define CF_RESOLVE_CACHE_EXPIRE
#define CF_BAYES_HAM_SPAM_RATIO
bool setup_control_handler()