-
Notifications
You must be signed in to change notification settings - Fork 0
/
greylist.patch
199 lines (189 loc) · 5.87 KB
/
greylist.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
--- scripts/MakeLinks 2015-07-24 00:20:37.000000000 +0300
+++ scripts/MakeLinks 2015-08-07 13:03:56.046010000 +0300
@@ -123,7 +123,7 @@
# EXPERIMENTAL_*
for f in arc.c bmi_spam.c bmi_spam.h dcc.c dcc.h dane.c dane-openssl.c \
- danessl.h imap_utf7.c spf.c spf.h srs.c srs.h utf8.c
+ danessl.h greylist.c imap_utf7.c spf.c spf.h srs.c srs.h utf8.c
do
ln -s ../src/$f $f
done
--- src/exim_dbutil.c 2015-07-24 00:20:37.000000000 +0300
+++ src/exim_dbutil.c 2015-08-07 13:02:45.868954000 +0300
@@ -35,6 +35,7 @@
#define type_misc 3
#define type_callout 4
#define type_ratelimit 5
+#define type_greylist 6
/* This is used by our cut-down dbfn_open(). */
@@ -91,7 +92,7 @@
usage(uschar *name, uschar *options)
{
printf("Usage: exim_%s%s <spool-directory> <database-name>\n", name, options);
-printf(" <database-name> = retry | misc | wait-<transport-name> | callout | ratelimit\n");
+printf(" <database-name> = retry | misc | wait-<transport-name> | callout | ratelimit | greylist\n");
exit(1);
}
@@ -114,6 +115,7 @@
if (Ustrncmp(argv[2], "wait-", 5) == 0) return type_wait;
if (Ustrcmp(argv[2], "callout") == 0) return type_callout;
if (Ustrcmp(argv[2], "ratelimit") == 0) return type_ratelimit;
+ if (Ustrcmp(argv[2], "greylist") == 0) return type_greylist;
}
usage(name, options);
return -1; /* Never obeyed */
@@ -529,6 +531,7 @@
dbdata_wait *wait;
dbdata_callout_cache *callout;
dbdata_ratelimit *ratelimit;
+ dbdata_serialize *greylist;
dbdata_ratelimit_unique *rate_unique;
int count_bad = 0;
int i, length;
@@ -664,6 +667,13 @@
keybuffer);
}
break;
+
+ case type_greylist:
+ greylist = (dbdata_serialize *)value;
+ printf("%s key: %s count: %d\n",
+ print_time(greylist->time_stamp), keybuffer, greylist->count);
+
+ break;
}
store_reset(value);
}
@@ -736,6 +746,7 @@
dbdata_wait *wait;
dbdata_callout_cache *callout;
dbdata_ratelimit *ratelimit;
+ dbdata_serialize *greylist;
dbdata_ratelimit_unique *rate_unique;
int i, oldlength;
uschar *t;
@@ -947,6 +958,27 @@
break;
}
break;
+
+ case type_greylist:
+ greylist = (dbdata_serialize *)record;
+ //length = sizeof(dbdata_serialize);
+ switch(fieldno)
+ {
+ case 0:
+ if ((tt = read_time(value)) > 0) greylist->time_stamp = tt;
+ else printf("bad time value\n");
+ break;
+
+ case 1:
+ greylist->count = Uatoi(value);
+ break;
+
+ default:
+ printf("unknown field number\n");
+ verify = 0;
+ break;
+ }
+ break;
}
dbfn_write(dbm, name, record, oldlength);
@@ -1060,6 +1092,12 @@
printf("5 add element to filter\n");
}
break;
+
+ case type_greylist:
+ greylist = (dbdata_serialize *)record;
+ printf("0 time stamp: %s\n", print_time(greylist->time_stamp));
+ printf("1 count: %d\n", greylist->count);
+ break;
}
}
--- src/greylist.c 2015-08-07 13:02:45.869136000 +0300
+++ src/greylist.c 2015-08-07 13:05:41.863151000 +0300
@@ -0,0 +1,56 @@
+/*
+ Idea: Lena(at)lena.kiev.ua, http://wiki.exim.org/DbLessGreyListingC
+ Written by: vc(at)vc.org.ua, 2008-06-10
+ License: GNU GENERAL PUBLIC LICENSE Version 2
+ Compile: cc -shared -fPIC -o greylist.so greylist.c
+*/
+#include "local_scan.h"
+#include "dbstuff.h"
+#include "dbfunctions.h"
+#include <stdlib.h>
+#include <fcntl.h>
+#include <time.h>
+
+int greylist(uschar **yield, int argc, uschar *argv[])
+{
+ time_t defer_timeout = 60*10; // 10m
+ time_t allow_timeout = 60*60*8; // 8h
+ time_t t = time(NULL);
+ open_db db;
+ dbdata_serialize *grey_data_p;
+
+ if (argc < 1 || argc > 3) {
+ *yield = US "bad number of arguments";
+ return ERROR;
+ }
+ if (argc > 1) defer_timeout = atol(CS argv[1]);
+ if (argc > 2) allow_timeout = atol(CS argv[2]);
+ if (!(dbfn_open(US "greylist", O_RDWR, &db, TRUE))) {
+ *yield = US "can't open greylist database in spool directory";
+ return ERROR;
+ }
+ if (!(grey_data_p = dbfn_read(&db, argv[0]))) {
+ dbdata_serialize grey_data;
+ *yield = US "1"; // defer
+ grey_data.time_stamp = t;
+ grey_data.count = 0;
+ dbfn_write(&db, argv[0], &grey_data, sizeof(dbdata_serialize));
+ } else {
+ if (t - grey_data_p->time_stamp > allow_timeout) {
+ *yield = US "1"; // defer
+ grey_data_p->time_stamp = t;
+ grey_data_p->count = 0;
+ dbfn_write(&db, argv[0], grey_data_p, sizeof(dbdata_serialize));
+ } else if (grey_data_p->count > 0) {
+ *yield = US "0"; // allow
+ } else if (t - grey_data_p->time_stamp > defer_timeout) {
+ *yield = US "0"; // allow
+ grey_data_p->count = 1;
+ dbfn_write(&db, argv[0], grey_data_p, sizeof(dbdata_serialize));
+ } else {
+ *yield = US "1"; // defer
+ }
+ }
+ dbfn_close(&db);
+ return OK;
+}
--- OS/Makefile-Base 2015-07-24 00:20:37.000000000 +0300
+++ OS/Makefile-Base 2015-08-07 13:11:47.516270000 +0300
@@ -103,7 +103,7 @@
utils: $(EXIM_MONITOR) exicyclog exinext exiwhat \
exigrep eximstats exipick exiqgrep exiqsumm \
transport-filter.pl convert4r3 convert4r4 \
- exim_checkaccess \
+ exim_checkaccess greylist.so \
exim_dbmbuild exim_dumpdb exim_fixdb exim_tidydb exim_lock
@@ -340,6 +340,19 @@
@echo ">>> exim binary built"
@echo " "
+# Compile instructions for greylist.so
+
+greylist.so: greylist.c
+ @echo "$(LNCC) -o greylist.so"
+ $(FE)$(LNCC) $(CFLAGS_DYNAMIC) $(LFLAGS) -o greylist.so greylist.c
+ @if [ x"$(STRIP_COMMAND)" != x"" ]; then \
+ echo $(STRIP_COMMAND) greylist.so; \
+ $(STRIP_COMMAND) greylist.so; \
+ fi
+ @echo ">>> greylist.so utility built"
+ @echo " "
+
+
# The utility for dumping the contents of an exim database
OBJ_DUMPDB = exim_dumpdb.o util-os.o util-store.o