aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernard Spil <spil.oss@gmail.com>2016-05-01 11:58:47 +0200
committerBernard Spil <spil.oss@gmail.com>2016-05-01 11:58:47 +0200
commit2e70253bac4dcc7235a2d6ec3ebf3cee88c82ad2 (patch)
treeb6170424df988d73af240832453d7dbd24e83724
parentfilter-spamassassin: Declare h and p options as char (diff)
downloadOpenSMTPD-extras-2e70253bac4dcc7235a2d6ec3ebf3cee88c82ad2.tar.xz
OpenSMTPD-extras-2e70253bac4dcc7235a2d6ec3ebf3cee88c82ad2.zip
filter-clamav: Allow user to set ClamAV host and port
- Add h (host) and p (port) parameters to options - Fix minor typo "Antivirus's"
-rw-r--r--extras/wip/filters/filter-clamav/filter-clamav.821
-rw-r--r--extras/wip/filters/filter-clamav/filter_clamav.c19
2 files changed, 35 insertions, 5 deletions
diff --git a/extras/wip/filters/filter-clamav/filter-clamav.8 b/extras/wip/filters/filter-clamav/filter-clamav.8
index 3a79e23..dbb04e5 100644
--- a/extras/wip/filters/filter-clamav/filter-clamav.8
+++ b/extras/wip/filters/filter-clamav/filter-clamav.8
@@ -22,6 +22,8 @@
.Sh SYNOPSIS
.Nm
.Op Fl dv
+.Op Fl h Ar host
+.Op Fl p Ar port
.Sh DESCRIPTION
.Nm
is a filter for
@@ -38,6 +40,22 @@ Debug mode, if this option is specified,
.Nm
will run in the foreground and log to
.Em stderr .
+.It Fl h
+Set the ClamAV
+.Ar host
+to be used.
+.Pp
+The default
+.Ar host
+is 127.0.0.1.
+.It Fl p Ar port
+Set the
+.Ar port
+ClamAV is listening on.
+.Pp
+The default
+.Ar port
+is 3310.
.It Fl v
Produce more verbose output.
.El
@@ -53,8 +71,9 @@ Non-virus mails are accepted.
.\".Dq X-Filter-ClamAV
.\"header.
.Sh CLAM ANTIVIRUS CONFIGURATION
+By default
.Nm
-expects that Clam AntiVirus's
+expects Clam AntiVirus'
.Xr clamd 1
to listen on 127.0.0.1 port 3310 for incoming requests.
This requires to uncomment the TCPAddr and TCPSocket option in the default
diff --git a/extras/wip/filters/filter-clamav/filter_clamav.c b/extras/wip/filters/filter-clamav/filter_clamav.c
index 907bd27..fc32ae2 100644
--- a/extras/wip/filters/filter-clamav/filter_clamav.c
+++ b/extras/wip/filters/filter-clamav/filter_clamav.c
@@ -30,8 +30,7 @@
#include "log.h"
#include "iobuf.h"
-#define CLAMAV_HOST "127.0.0.1"
-#define CLAMAV_PORT "3310"
+static const char *clamav_host = "127.0.0.1", *clamav_port = "3310";
struct clamav {
int fd, r;
@@ -56,7 +55,7 @@ clamav_open(struct clamav *cl)
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
hints.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV; /* avoid failing name resolution in chroot() */
- if ((r = getaddrinfo(CLAMAV_HOST, CLAMAV_PORT, &hints, &addresses))) {
+ if ((r = getaddrinfo(clamav_host, clamav_port, &hints, &addresses))) {
log_warnx("warn: open: getaddrinfo %s", gai_strerror(r));
return -1;
}
@@ -262,14 +261,21 @@ int
main(int argc, char **argv)
{
int ch, d = 0, v = 0;
+ char *h = NULL, *p = NULL;
log_init(1);
- while ((ch = getopt(argc, argv, "dv")) != -1) {
+ while ((ch = getopt(argc, argv, "dh:p:v")) != -1) {
switch (ch) {
case 'd':
d = 1;
break;
+ case 'h':
+ h = optarg;
+ break;
+ case 'p':
+ p = optarg;
+ break;
case 'v':
v |= TRACE_DEBUG;
break;
@@ -282,6 +288,11 @@ main(int argc, char **argv)
argc -= optind;
argv += optind;
+ if (h)
+ clamav_host = strip(h);
+ if (p)
+ clamav_port = strip(p);
+
log_init(d);
log_verbose(v);