aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile18
-rw-r--r--antispam-plugin.c25
-rw-r--r--antispam-plugin.h31
-rw-r--r--antispam.79
-rw-r--r--debug.c46
-rw-r--r--defconfig7
-rw-r--r--dspam-exec.c4
7 files changed, 85 insertions, 55 deletions
diff --git a/Makefile b/Makefile
index 9e56245..68c30a3 100644
--- a/Makefile
+++ b/Makefile
@@ -21,23 +21,7 @@ INCS += -I$(DOVECOT)/src/imap/
# output name
LIBRARY_NAME ?= lib90_$(PLUGINNAME)_plugin.so
-objs = antispam-storage.o antispam-plugin.o
-
-# debug rules
-ifeq ("$(DEBUG)", "stderr")
-LOCALCFLAGS += -DCONFIG_DEBUG -DDEBUG_STDERR
-objs += debug.o
-else
-ifeq ("$(DEBUG)", "syslog")
-LOCALCFLAGS += -DCONFIG_DEBUG -DDEBUG_SYSLOG
-objs += debug.o
-endif
-endif
-
-ifeq ("$(DEBUG_VERBOSE)", "1")
-LOCALCFLAGS += -DCONFIG_DEBUG_VERBOSE
-endif
-
+objs = antispam-storage.o antispam-plugin.o debug.o
objs += dspam-exec.o signature-log.o crm114-exec.o pipe.o spool2dir.o signature.o
# main make rules
diff --git a/antispam-plugin.c b/antispam-plugin.c
index 5260948..bbcc0e6 100644
--- a/antispam-plugin.c
+++ b/antispam-plugin.c
@@ -300,8 +300,33 @@ void PLUGIN_FUNCTION(init)(void)
char * const *iter;
int spam_folder_count;
+ debug_target = ADT_NONE;
+ verbose_debug = 0;
+
+ tmp = get_setting("DEBUG_TARGET");
+ if (tmp) {
+ if (strcmp(tmp, "syslog") == 0)
+ debug_target = ADT_SYSLOG;
+ else if (strcmp(tmp, "stderr") == 0)
+ debug_target = ADT_STDERR;
+ else
+ exit(4);
+ }
+
debug("plugin initialising (%s)\n", ANTISPAM_VERSION);
+ tmp = get_setting("VERBOSE_DEBUG");
+ if (tmp) {
+ char *endp;
+ unsigned long val = strtoul(tmp, &endp, 10);
+ if (*endp || val >= 2) {
+ debug("Invalid verbose_debug setting");
+ exit(5);
+ }
+ verbose_debug = val;
+ debug_verbose("verbose debug enabled");
+ }
+
global_pool = pool_alloconly_create("antispam-pool", 1024);
parse_folder_setting("TRASH", trash_folders, "trash");
diff --git a/antispam-plugin.h b/antispam-plugin.h
index 728ec1e..a06a1e9 100644
--- a/antispam-plugin.h
+++ b/antispam-plugin.h
@@ -58,28 +58,19 @@ extern struct backend pipe_backend;
extern struct backend signature_backend;
extern struct backend spool2dir_backend;
-#ifdef CONFIG_DEBUG
+enum antispam_debug_target {
+ ADT_NONE,
+ ADT_STDERR,
+ ADT_SYSLOG,
+};
+
+extern enum antispam_debug_target debug_target;
+extern int verbose_debug;
+
void debug(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
void debugv(char **args);
-#else
-static void debug(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
-static inline void debug(const char *fmt __attribute__((unused)), ...)
-{
-}
-static inline void debugv(char **args __attribute__((unused)))
-{
-}
-#endif
-
-#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_VERBOSE)
-/* bit of an ugly short-cut */
-#define debug_verbose debug
-#else
-static void debug_verbose(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
-static inline void debug_verbose(const char *fmt __attribute__((unused)), ...)
-{
-}
-#endif
+void debugv_not_stderr(char **args);
+void debug_verbose(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
void antispam_mail_storage_created(struct mail_storage *storage);
extern void (*antispam_next_hook_mail_storage_created)(struct mail_storage *storage);
diff --git a/antispam.7 b/antispam.7
index 48f5a01..b506ce9 100644
--- a/antispam.7
+++ b/antispam.7
@@ -112,6 +112,15 @@ plugin {
##################
# GENERIC OPTIONS
+ # Debugging options
+ # Uncomment to get the desired debugging behaviour.
+ # Note that in some cases stderr debugging will not be as
+ # verbose as syslog debugging due to internal limitations.
+ #
+ # antispam_debug_target = syslog
+ # antispam_debug_target = stderr
+ # antispam_verbose_debug = 1
+
# backend selection, MUST be configured first,
# there's no default so you need to set one of
# these options:
diff --git a/debug.c b/debug.c
index 7f3e407..a3e0fc4 100644
--- a/debug.c
+++ b/debug.c
@@ -4,22 +4,32 @@
#include <stdio.h>
#include "antispam-plugin.h"
+enum antispam_debug_target debug_target;
+int verbose_debug;
+
static void _debug(const char *format, va_list ap)
{
const char *fmt;
+ if (debug_target == ADT_NONE)
+ return;
+
t_push();
fmt = t_strconcat(stringify(PLUGINNAME), ": ", format, NULL);
-#if defined(DEBUG_SYSLOG)
- vsyslog(LOG_DEBUG, fmt, ap);
-#elif defined(DEBUG_STDERR)
- vfprintf(stderr, fmt, ap);
- fflush(stderr);
-#else
-#error no logging method
-#endif
+ switch (debug_target) {
+ case ADT_NONE:
+ break;
+ case ADT_SYSLOG:
+ vsyslog(LOG_DEBUG, fmt, ap);
+ break;
+ case ADT_STDERR:
+ vfprintf(stderr, fmt, ap);
+ fflush(stderr);
+ break;
+ }
+
t_pop();
}
@@ -64,3 +74,23 @@ void debugv(char **args)
debug("%s", buf);
t_pop();
}
+
+void debugv_not_stderr(char **args)
+{
+ if (debug_target == ADT_STDERR)
+ return;
+
+ debugv(args);
+}
+
+void debug_verbose(const char *fmt, ...)
+{
+ va_list args;
+
+ if (!verbose_debug)
+ return;
+
+ va_start(args, fmt);
+ _debug(fmt, args);
+ va_end(args);
+}
diff --git a/defconfig b/defconfig
index 361c0c5..0eb1db3 100644
--- a/defconfig
+++ b/defconfig
@@ -21,13 +21,6 @@ DOVECOT=/usr/include/dovecot
# NB no need for a final '/'
INSTALLDIR=/usr/lib/dovecot/modules/imap
-# enable debugging to syslog or stderr
-#DEBUG=stderr
-#DEBUG=syslog
-
-# verbose debugging (lots of output!)
-#DEBUG_VERBOSE=1
-
# plugin name, change only if you need to rename the plugin
# (because, for example, you need two instances for different
# spam filters installed)
diff --git a/dspam-exec.c b/dspam-exec.c
index a9e0c1d..c4a49b4 100644
--- a/dspam-exec.c
+++ b/dspam-exec.c
@@ -141,13 +141,11 @@ static int call_dspam(const char *signature, enum classification wanted)
for (i = 0; i < extra_args_num; i++)
argv[i + 4] = (char *)extra_args[i];
-#ifdef DEBUG_SYSLOG
/*
* not good with stderr debuggin since we then write to
* stderr which our parent takes as a bug
*/
- debugv(argv);
-#endif
+ debugv_not_stderr(argv);
execv(dspam_binary, argv);
debug("executing %s failed: %d (uid=%d, gid=%d)",