bmf-milter

bmf filter milter daemon
git clone git://r-36.net/bmf-milter
Log | Files | Refs | LICENSE

commit d79cf88df178f18663ef6e9102796a18a7a30c69
parent 95f0bdc0f1a4d74ef7fa12c3dc7e768d7cb3b7d0
Author: Christoph Lohmann <20h@r-36.net>
Date:   Sun, 14 Jun 2020 16:21:06 +0200

Add option to set bmf path and database.

Diffstat:
bmf-milter.c | 47+++++++++++++++++++++++++++++++----------------
1 file changed, 31 insertions(+), 16 deletions(-)

diff --git a/bmf-milter.c b/bmf-milter.c @@ -29,6 +29,7 @@ * message would be rejected. */ int donothing = 0, dodebug = 0; +char *bmfdb = NULL, *bmfpath = "/usr/bin/bmf"; struct Priv { /* read from execpipe[0], write to execpipe[1] */ @@ -93,8 +94,8 @@ sfsistat mlfi_helo(SMFICTX *ctx, char *helohost) { struct Priv *priv; - char *ident; - int pid, nullfd; + char *ident, *bmfargs[6]; + int pid, nullfd, argp; if (dodebug) fprintf(stderr, "mlfi_helo(%s)\n", helohost); @@ -122,6 +123,11 @@ mlfi_helo(SMFICTX *ctx, char *helohost) while(dup2(priv->execpipe[0], 0) < 0 && errno == EINTR); close(priv->execpipe[1]); + argp = 0; + bmfargs[argp++] = "bmf"; + /* Test for spam mode. */ + bmfargs[argp++] = "-t"; + if (!dodebug) { nullfd = open("/dev/null", O_WRONLY); if (nullfd < 0) { @@ -133,18 +139,20 @@ mlfi_helo(SMFICTX *ctx, char *helohost) while(dup2(priv->execpipe[0], 2) < 0 && errno == EINTR); - if (execl("/usr/bin/bmf", "bmf", "-t", - (char *)NULL) < 0) { - perror("execl"); - _exit(1); - } - } else { - /* Run with -v(erbose) for debug. */ - if (execl("/usr/bin/bmf", "bmf", "-t", - "-v", (char *)NULL) < 0) { - perror("execl"); - _exit(1); - } + /* Verbose for bmf. */ + bmfargs[argp++] = "-v"; + } + + if (bmfdb != NULL) { + /* Set database directory, if set. */ + bmfargs[argp++] = "-d"; + bmfargs[argp++] = bmfdb; + } + bmfargs[argp++] = NULL; + + if (execv(bmfpath, bmfargs) < 0) { + perror("execv"); + _exit(1); } break; case -1: @@ -373,8 +381,9 @@ void usage(char *argv0) { fprintf(stderr, - "Usage: %s [-hd] [-v dbglvl] [-p listen] [-t timeout] " - "[-u user] [-g group]\n", + "Usage: %s [-hd] [-b bmfdb] [-f bmfpath] [-g group] " + "[-p portdef] [-t timeout] [-u user] " + "[-v loglevel]\n", argv0); } @@ -387,9 +396,15 @@ main(int argc, char *argv[]) struct group *gr = NULL; ARGBEGIN(argv0) { + case 'b': + bmfdb = EARGF(usage(argv0)); + break; case 'd': dofork = 0; break; + case 'f': + bmfpath = EARGF(usage(argv0)); + break; case 'g': group = EARGF(usage(argv0)); break;