aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Berg <johannes@sipsolutions.net>2007-09-30 16:37:19 +0200
committerJohannes Berg <johannes@sipsolutions.net>2007-09-30 16:37:19 +0200
commitb61c062501065d35c95fc6eb538d3468baf6fac3 (patch)
tree6f5c5f5ffc4c44a9343642fecd0da4b9bc637e29
parent962f82ed3028cd8de2c19f4c9baf4299c15ea4e4 (diff)
downloaddovecot-antispam-b61c062501065d35c95fc6eb538d3468baf6fac3.tar.gz
dovecot-antispam-b61c062501065d35c95fc6eb538d3468baf6fac3.tar.xz
dovecot-antispam-b61c062501065d35c95fc6eb538d3468baf6fac3.zip
dspam-exec backend: allow extra arguments
This allows people who need --user given on the command line to add something like this to the configuration: antispam_dspam_args = --user;%u where the semicolon is the separator between arguments to build the dspam command line as indicated by the dspam manual page: dspam [--user user1 user2 ...]
-rw-r--r--dspam-exec.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/dspam-exec.c b/dspam-exec.c
index b3e9ca2..7a58100 100644
--- a/dspam-exec.c
+++ b/dspam-exec.c
@@ -27,6 +27,10 @@
#include "plugin.h"
static const char *dspam_binary = "/usr/bin/dspam";
+static char **extra_args = NULL;
+static int extra_args_num = 0;
+
+#define FIXED_ARGS_NUM 6
static int call_dspam(pool_t pool, const char *signature, bool is_spam)
{
@@ -88,6 +92,12 @@ static int call_dspam(pool_t pool, const char *signature, bool is_spam)
return WEXITSTATUS(status);
} else {
int fd = open("/dev/null", O_RDONLY);
+ char **argv;
+ int sz = sizeof(char *) * (FIXED_ARGS_NUM + extra_args_num);
+ int i;
+
+ argv = p_malloc(pool, sz);
+ memset(argv, 0, sz);
close(0);
close(1);
@@ -105,12 +115,19 @@ static int call_dspam(pool_t pool, const char *signature, bool is_spam)
exit(1);
close(fd);
- debug("antispam: %s --source=error --stdout %s %s",
+ argv[0] = (char *)dspam_binary;
+ argv[1] = "--source=error";
+ argv[2] = "--stdout";
+ argv[3] = (char *)class_arg;
+ argv[4] = (char *)sign_arg;
+
+ debug("antispam: %s --source=error --stdout %s %s ...",
dspam_binary, class_arg, sign_arg);
- execl(dspam_binary, dspam_binary,
- "--source=error", "--stdout", class_arg,
- sign_arg, NULL);
+ for (i = 0; i < extra_args_num; i++)
+ argv[i + 5] = (char *)extra_args[i];
+
+ execv(dspam_binary, argv);
/* fall through if dspam can't be found */
exit(127);
/* not reached */
@@ -136,12 +153,23 @@ bool backend(pool_t pool, bool spam, struct strlist *sigs)
void backend_init(pool_t pool)
{
char *tmp;
+ int i;
tmp = getenv("ANTISPAM_DSPAM_BINARY");
if (tmp) {
dspam_binary = tmp;
debug("dspam binary set to %s\n", tmp);
}
+
+ tmp = getenv("ANTISPAM_DSPAM_ARGS");
+ if (tmp) {
+ extra_args = p_strsplit(pool, tmp, ";");
+ extra_args_num = strarray_length(
+ (const char *const *)extra_args);
+ for (i = 0; i < extra_args_num; i++)
+ debug("antispam: dspam extra arg %s\n",
+ extra_args[i]);
+ }
}
void backend_exit(void)