ze-filter
(ze-filter-0.8.0-develop-180218)
ze-grey-cleanup.c
Go to the documentation of this file.
1
2
/*
3
*
4
* ze-filter - Mail Server Filter for sendmail
5
*
6
* Copyright (c) 2001-2018 - Jose-Marcio Martins da Cruz
7
*
8
* Auteur : Jose Marcio Martins da Cruz
9
* jose.marcio.mc@gmail.org
10
*
11
* Historique :
12
* Creation : Tue Apr 12 14:14:49 CEST 2005
13
*
14
* This program is free software, but with restricted license :
15
*
16
*
17
* This program is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20
*
21
* More details about ze-filter license can be found at ze-filter
22
* web site : http://foss.jose-marcio.org
23
*/
24
25
26
#include <ze-sys.h>
27
#include <
libze.h
>
28
#include <
ze-filter.h
>
29
#include <
ze-grey-cleanup.h
>
30
31
static
double
threshold = -1;
32
static
bool
threshok =
FALSE
;
33
34
/* ****************************************************************************
35
* *
36
* *
37
**************************************************************************** */
38
void
39
set_grey_dewhitelist_threshold
(val)
40
double
val;
41
{
42
threshold = val;
43
threshok =
TRUE
;
44
}
45
46
/* ****************************************************************************
47
* *
48
* *
49
**************************************************************************** */
50
static
void
51
set_threshold_from_env()
52
{
53
char
*env = NULL;
54
55
if
(threshok)
56
return
;
57
58
env = getenv(
"GREY_DEWHITELIST_THRESHOLD"
);
59
if
(env != NULL) {
60
double
t =
zeStr2double
(env, NULL, 0);
61
62
if
(errno != EINVAL && errno != ERANGE)
63
threshold = t;
64
}
65
threshok =
TRUE
;
66
}
67
68
/* ****************************************************************************
69
* *
70
* *
71
**************************************************************************** */
72
bool
73
grey_check_bad_smtp_client
(ip, flags)
74
char
*ip;
75
uint32_t
flags;
76
{
77
int
conn, msgs, score;
78
int
spamtraps, badrcpt, badmx;
79
80
double
res = 0;
81
82
if
(!threshok)
83
set_threshold_from_env();
84
85
if
(flags ==
GREY_DW_NONE
)
86
return
FALSE
;
87
88
if
(threshold <= 0)
89
return
FALSE
;
90
91
conn =
smtprate_check
(
RATE_CONN
, ip, 10
MINUTES
);
92
93
#if 0
94
{
95
int
xfiles;
96
97
xfiles =
smtprate_check
(
RATE_XFILES
, ip, 10
MINUTES
);
98
res += xfiles / 3.;
99
}
100
#endif
101
102
if
((flags &
GREY_DW_SPAMTRAP
) !=
GREY_DW_NONE
) {
103
spamtraps =
livehistory_check_host
(ip, 4
HOURS
,
LH_SPAMTRAP
);
104
res += spamtraps / 5.;
105
}
106
107
if
((flags &
GREY_DW_BAD_RCPT
) !=
GREY_DW_NONE
) {
108
badrcpt =
livehistory_check_host
(ip, 4
HOURS
,
LH_BADRCPT
);
109
res += badrcpt / 3.;
110
}
111
112
if
((flags &
GREY_DW_BAD_MX
) !=
GREY_DW_NONE
) {
113
badmx =
livehistory_check_host
(ip, 4
HOURS
,
LH_BADMX
);
114
res += badmx / 3.;
115
}
116
117
if
((flags &
GREY_DW_BAD_CLIENT
) !=
GREY_DW_NONE
) {
118
msgs =
smtprate_check
(
RATE_MSGS
, ip, 10
MINUTES
);
119
score =
smtprate_check
(
RATE_SCORE
, ip, 10
MINUTES
);
120
if
(msgs > 1)
121
res += (1. * score) / msgs;
122
}
123
124
if
(threshold > 0.)
125
return
res > threshold;
126
127
return
FALSE
;
128
}
ze-grey-cleanup.h
GREY_DW_NONE
#define GREY_DW_NONE
Definition:
ze-grey.h:54
GREY_DW_SPAMTRAP
#define GREY_DW_SPAMTRAP
Definition:
ze-grey.h:59
LH_BADMX
#define LH_BADMX
Definition:
ze-livehistory.h:31
RATE_XFILES
#define RATE_XFILES
Definition:
ze-smtprate.h:58
FALSE
#define FALSE
Definition:
macros.h:160
LH_SPAMTRAP
#define LH_SPAMTRAP
Definition:
ze-livehistory.h:28
ze-filter.h
libze.h
GREY_DW_BAD_RCPT
#define GREY_DW_BAD_RCPT
Definition:
ze-grey.h:60
LH_BADRCPT
#define LH_BADRCPT
Definition:
ze-livehistory.h:27
set_grey_dewhitelist_threshold
void set_grey_dewhitelist_threshold(double val)
Definition:
ze-grey-cleanup.c:39
GREY_DW_BAD_MX
#define GREY_DW_BAD_MX
Definition:
ze-grey.h:61
zeStr2double
double zeStr2double(char *s, int *error, double dval)
Definition:
zeStrConvert.c:202
RATE_MSGS
#define RATE_MSGS
Definition:
ze-smtprate.h:54
TRUE
#define TRUE
Definition:
macros.h:157
grey_check_bad_smtp_client
bool grey_check_bad_smtp_client(char *ip, uint32_t flags)
Definition:
ze-grey-cleanup.c:73
smtprate_check
int smtprate_check(int, char *, time_t)
Definition:
ze-smtprate.c:479
RATE_SCORE
#define RATE_SCORE
Definition:
ze-smtprate.h:57
GREY_DW_BAD_CLIENT
#define GREY_DW_BAD_CLIENT
Definition:
ze-grey.h:58
MINUTES
#define MINUTES
Definition:
macros.h:143
HOURS
#define HOURS
Definition:
macros.h:144
livehistory_check_host
int livehistory_check_host(char *, time_t, int)
Definition:
ze-livehistory.c:338
uint32_t
long uint32_t
Definition:
ze-sys.h:489
RATE_CONN
#define RATE_CONN
Definition:
ze-smtprate.h:51
libjoe
ze-grey-cleanup.c
Generated by
1.8.13