On Wed, Apr 08, 2015 at 04:10:22PM +0200, Joerg Jung wrote: > The longer I think about it (while looking at the existing filter code), the > more I > come to the conclusion that I just should sit down tonight and write this > missing > SA filter. Based on the existing filters in -extras and the code from > http://www.benzedrine.ch/milter-spamd.html a SA filter should be > straightforward to implement.
So, unfortunately I had not much time tonight, hence I started with a rather simple filter as finger exercise: a pause on connect, wait some seconds before the initial 220. Idea borrowed from Sendmails greet_pause feature [1] which I think is worthwhile to keep (some) spammers away. Diff below attached, slightly tested in a local filter chain setup. I do not have a github account on purpose, so no pull request from me. Feel free to commit the patch. I will see if I find some time by the end of the week to write the missing SpamAssassin and ClamAV filter. Thanks, Regards, Joerg [1] http://www.deer-run.com/~hal/sysadmin/greet_pause.html diff --git a/extras/filters/Makefile b/extras/filters/Makefile index c62a112..2b7698b 100644 --- a/extras/filters/Makefile +++ b/extras/filters/Makefile @@ -4,6 +4,7 @@ SUBDIR += filter-dkim-signer SUBDIR += filter-dnsbl #SUBDIR += filter-lua SUBDIR += filter-monkey +SUBDIR += filter-pause SUBDIR += filter-perl SUBDIR += filter-python SUBDIR += filter-stub diff --git a/extras/filters/filter-pause/Makefile b/extras/filters/filter-pause/Makefile new file mode 100644 index 0000000..658cdb2 --- /dev/null +++ b/extras/filters/filter-pause/Makefile @@ -0,0 +1,4 @@ +PROG= filter-pause +SRCS= filter_pause.c + +.include <bsd.prog.mk> diff --git a/extras/filters/filter-pause/filter_pause.c b/extras/filters/filter-pause/filter_pause.c new file mode 100644 index 0000000..7f8a3f0 --- /dev/null +++ b/extras/filters/filter-pause/filter_pause.c @@ -0,0 +1,78 @@ +/* $OpenBSD$ */ + +/* + * Copyright (c) 2015 Joerg Jung <j...@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/types.h> + +#include <inttypes.h> +#include <stdio.h> +#include <unistd.h> + +#include "smtpd-defines.h" +#include "smtpd-api.h" +#include "log.h" + +static unsigned int pause_seconds = 5; + +static int +pause_on_connect(uint64_t id, struct filter_connect *conn) +{ + unsigned int r; + + log_debug("debug: filter-pause: sleeping %u", pause_seconds); + + if ((r = sleep(pause_seconds)) != 0) + log_warnx("filter-pause: wakeup %u seconds too early", r); + + return filter_api_accept(id); +} + +int +main(int argc, char **argv) +{ + int ch; + const char *errstr, *s = NULL; + log_init(-1); + + while ((ch = getopt(argc, argv, "s:")) != -1) { + switch (ch) { + case 's': + s = optarg; + break; + default: + log_warnx("warn: filter-pause: bad option"); + return (1); + /* NOTREACHED */ + } + } + argc -= optind; + argv += optind; + + if (s) { /* RFC 5321 4.5.3.2 Initial 220 Message: 5 Minutes */ + pause_seconds = strtonum(s, 1, 300, &errstr); + if (errstr) + fatalx("filter-pause: seconds option is %s: %s", errstr, s); + } + + log_debug("debug: filter-pause: starting..."); + + filter_api_on_connect(pause_on_connect); + filter_api_loop(); + log_debug("debug: filter-pause: exiting"); + + return (1); +} -- You received this mail because you are subscribed to misc@opensmtpd.org To unsubscribe, send a mail to: misc+unsubscr...@opensmtpd.org