From c01f0afc18c9f02366a5112ed8e062b9e5682afe Mon Sep 17 00:00:00 2001 From: SJ Date: Sat, 14 Feb 2015 19:47:40 +0100 Subject: [PATCH] add a global extractor enable/disable option to piler.conf --- configure | 5 ++- configure.in | 4 +-- contrib/reload/Makefile.in | 38 ----------------------- contrib/reload/pilerreload.c | 59 ------------------------------------ etc/Makefile.in | 1 + etc/example.conf | 4 ++- src/archive.c | 3 +- src/cfg.c | 2 +- src/cfg.h | 2 +- src/config.h | 2 +- src/parser.c | 2 +- src/pileraget.c | 2 ++ src/pilerpurge.c | 5 ++- 13 files changed, 20 insertions(+), 109 deletions(-) delete mode 100644 contrib/reload/Makefile.in delete mode 100644 contrib/reload/pilerreload.c diff --git a/configure b/configure index 9491bfea..53651794 100755 --- a/configure +++ b/configure @@ -3489,7 +3489,7 @@ fi echo "\"Configure command: ./configure $PARAMS\"" >> $CONFIGURE_PARAMS_FILE -SUBDIRS="src etc util init.d test contrib/reload" +SUBDIRS="src etc util init.d test" @@ -4866,7 +4866,7 @@ CFLAGS="$static -O2 -Wall -g" LIBS="$antispam_libs $sunos_libs " OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o hash.o parser.o parser_utils.o rules.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o imap.o pop3.o extract.o mydomains.o retr.o $objs" -ac_config_files="$ac_config_files Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile test/Makefile contrib/imap/Makefile contrib/reload/Makefile" +ac_config_files="$ac_config_files Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile test/Makefile contrib/imap/Makefile" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -5566,7 +5566,6 @@ do "init.d/Makefile") CONFIG_FILES="$CONFIG_FILES init.d/Makefile" ;; "test/Makefile") CONFIG_FILES="$CONFIG_FILES test/Makefile" ;; "contrib/imap/Makefile") CONFIG_FILES="$CONFIG_FILES contrib/imap/Makefile" ;; - "contrib/reload/Makefile") CONFIG_FILES="$CONFIG_FILES contrib/reload/Makefile" ;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; esac diff --git a/configure.in b/configure.in index f4f04e44..2f0f1956 100644 --- a/configure.in +++ b/configure.in @@ -86,7 +86,7 @@ fi echo "\"Configure command: ./configure $PARAMS\"" >> $CONFIGURE_PARAMS_FILE -SUBDIRS="src etc util init.d test contrib/reload" +SUBDIRS="src etc util init.d test" dnl static build @@ -537,7 +537,7 @@ CFLAGS="$static -O2 -Wall -g" LIBS="$antispam_libs $sunos_libs " OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o hash.o parser.o parser_utils.o rules.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o imap.o pop3.o extract.o mydomains.o retr.o $objs" -AC_CONFIG_FILES([Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile test/Makefile contrib/imap/Makefile contrib/reload/Makefile]) +AC_CONFIG_FILES([Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile test/Makefile contrib/imap/Makefile]) AC_OUTPUT diff --git a/contrib/reload/Makefile.in b/contrib/reload/Makefile.in deleted file mode 100644 index 261f632f..00000000 --- a/contrib/reload/Makefile.in +++ /dev/null @@ -1,38 +0,0 @@ -SHELL = @SHELL@ - -prefix = @prefix@ -exec_prefix = @exec_prefix@ -bindir = @bindir@ -sbindir = @sbindir@ -includedir = @includedir@ -libdir = @libdir@ -libexecdir = @libexecdir@ -srcdir = @srcdir@ -sysconfdir = @sysconfdir@ -mandir = @mandir@ -datarootdir = @datarootdir@ -localstatedir = @localstatedir@ - -CC = @CC@ -CFLAGS = @CFLAGS@ @CPPFLAGS@ -DEFS = @defs@ -INCDIR = -I. -I.. -I../.. -I../../src -I../src @INCDIR@ @sql_includes@ -LIBDIR = -L. @LIBDIR@ @LDFLAGS@ -L../../src -LIBS = @LIBS@ @sql_libs@ -RUNNING_USER = @RUNNING_USER@ -RUNNING_GROUP = `@id_bin@ -gn $(RUNNING_USER)` - -INSTALL = @INSTALL@ - -all: pilerreload - -pilerreload: pilerreload.c ../../src/libpiler.a - $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR) - -install: - -clean: - rm -f pilerreload - -distclean: clean - rm -f Makefile diff --git a/contrib/reload/pilerreload.c b/contrib/reload/pilerreload.c deleted file mode 100644 index c3cbc29d..00000000 --- a/contrib/reload/pilerreload.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * pilerreload.c, SJ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -extern char *optarg; -extern int optind; - -char *configfile = CONFIG_FILE; -struct __config cfg; - - -void fatal(char *s){ - syslog(LOG_PRIORITY, "fatal: %s", s); - exit(1); -} - - -int main(int argc, char **argv){ - char buf[SMALLBUFSIZE]; - int pid; - FILE *f; - - (void) openlog("pilerreload", LOG_PID, LOG_MAIL); - - cfg = read_config(CONFIG_FILE); - - f = fopen(cfg.pidfile, "r"); - if(!f) fatal("cannot open pidfile"); - - if(fgets(buf, sizeof(buf)-2, f) == NULL) fatal("cannot read pidfile"); - - fclose(f); - - pid = atoi(buf); - - if(pid > 1){ - if(kill(pid, SIGHUP) == 0) syslog(LOG_PRIORITY, "reloaded"); - else syslog(LOG_PRIORITY, "failed to reload"); - } - else fatal("invalid pid"); - - return 0; -} - diff --git a/etc/Makefile.in b/etc/Makefile.in index 356e968a..360405e2 100644 --- a/etc/Makefile.in +++ b/etc/Makefile.in @@ -31,6 +31,7 @@ all: -e 's%workdir=.*%workdir=$(localstatedir)/piler/tmp%g' < $(srcdir)/example.conf | grep -v ^\; | grep '=' | sort > $(srcdir)/piler.conf install: + $(INSTALL) -m 0640 -g $(RUNNING_GROUP) $(srcdir)/piler.conf $(DESTDIR)$(sysconfdir)/piler.conf.dist if [ ! -f "$(DESTDIR)$(sysconfdir)/piler.conf" ]; then $(INSTALL) -m 0640 -g $(RUNNING_GROUP) $(srcdir)/piler.conf $(DESTDIR)$(sysconfdir)/piler.conf; fi sed -e 's%LOCALSTATEDIR%$(localstatedir)%g' $(srcdir)/sphinx.conf.in > sphinx.conf.dist $(INSTALL) -m 0644 -g $(RUNNING_GROUP) $(srcdir)/sphinx.conf.dist $(DESTDIR)$(sysconfdir)/sphinx.conf.dist diff --git a/etc/example.conf b/etc/example.conf index 5a72f436..412b3b4f 100644 --- a/etc/example.conf +++ b/etc/example.conf @@ -52,9 +52,11 @@ listen_port=25 clamd_socket=/tmp/clamd -session_timeout=420 helper_timeout=20 +; whether to run external attachment extractors (1) or not (0) +extract_attachments=1 + ; the 2nd parameter of the listen() system call. Please note that this is set ; when piler starts up and you should restart piler if you change this variable. ; Please also note that the meaning of this variable depends on your Unix implementation diff --git a/src/archive.c b/src/archive.c index 66d7173e..d638cb31 100644 --- a/src/archive.c +++ b/src/archive.c @@ -289,8 +289,9 @@ int retrieve_email_from_archive(struct session_data *sdata, struct __data *data, int i, attachments; char *buffer=NULL, *saved_buffer, *p, filename[SMALLBUFSIZE], pointer[SMALLBUFSIZE]; struct ptr_array ptr_arr[MAX_ATTACHMENTS]; +#ifdef HAVE_SUPPORT_FOR_COMPAT_STORAGE_LAYOUT struct stat st; - +#endif if(strlen(sdata->ttmpfile) != RND_STR_LEN){ printf("invalid piler-id: %s\n", sdata->ttmpfile); diff --git a/src/cfg.c b/src/cfg.c index c43b8781..f69191b4 100644 --- a/src/cfg.c +++ b/src/cfg.c @@ -71,6 +71,7 @@ struct _parse_rule config_parse_rules[] = { "enable_cjk", "integer", (void*) int_parser, offsetof(struct __config, enable_cjk), "0", sizeof(int)}, { "encrypt_messages", "integer", (void*) int_parser, offsetof(struct __config, encrypt_messages), "1", sizeof(int)}, { "extra_to_field", "string", (void*) string_parser, offsetof(struct __config, extra_to_field), "", MAXVAL-1}, + { "extract_attachments", "integer", (void*) int_parser, offsetof(struct __config, extract_attachments), "1", sizeof(int)}, { "helper_timeout", "integer", (void*) int_parser, offsetof(struct __config, helper_timeout), "20", sizeof(int)}, { "hostid", "string", (void*) string_parser, offsetof(struct __config, hostid), HOSTID, MAXVAL-1}, { "iv", "string", (void*) string_parser, offsetof(struct __config, iv), "", MAXVAL-1}, @@ -99,7 +100,6 @@ struct _parse_rule config_parse_rules[] = { "pilergetd_pidfile", "string", (void*) string_parser, offsetof(struct __config, pilergetd_pidfile), PILERGETD_PIDFILE, MAXVAL-1}, { "queuedir", "string", (void*) string_parser, offsetof(struct __config, queuedir), QUEUE_DIR, MAXVAL-1}, { "server_id", "integer", (void*) int_parser, offsetof(struct __config, server_id), "0", sizeof(int)}, - { "session_timeout", "integer", (void*) int_parser, offsetof(struct __config, session_timeout), "420", sizeof(int)}, { "spam_header_line", "string", (void*) string_parser, offsetof(struct __config, spam_header_line), "", MAXVAL-1}, { "syslog_recipients", "integer", (void*) int_parser, offsetof(struct __config, syslog_recipients), "0", sizeof(int)}, { "tls_enable", "integer", (void*) int_parser, offsetof(struct __config, tls_enable), "0", sizeof(int)}, diff --git a/src/cfg.h b/src/cfg.h index a1296a4e..21fb63d1 100644 --- a/src/cfg.h +++ b/src/cfg.h @@ -51,8 +51,8 @@ struct __config { int verbosity; char locale[MAXVAL]; - int session_timeout; int helper_timeout; + int extract_attachments; char piler_header_field[MAXVAL]; char extra_to_field[MAXVAL]; diff --git a/src/config.h b/src/config.h index acd34e2f..552b86f2 100644 --- a/src/config.h +++ b/src/config.h @@ -14,7 +14,7 @@ #define VERSION "1.1.1" -#define BUILD 902 +#define BUILD 903 #define HOSTID "mailarchiver" diff --git a/src/parser.c b/src/parser.c index a0991a13..149ac010 100644 --- a/src/parser.c +++ b/src/parser.c @@ -130,7 +130,7 @@ void post_parse(struct session_data *sdata, struct _state *state, struct __confi if(state->attachments[i].dumped == 1){ rec = 0; - if(state->bodylen < BIGBUFSIZE-1024) extract_attachment_content(sdata, state, state->attachments[i].aname, get_attachment_extractor_by_filename(state->attachments[i].filename), &rec, cfg); + if(cfg->extract_attachments == 1 && state->bodylen < BIGBUFSIZE-1024) extract_attachment_content(sdata, state, state->attachments[i].aname, get_attachment_extractor_by_filename(state->attachments[i].filename), &rec, cfg); unlink(state->attachments[i].aname); } diff --git a/src/pileraget.c b/src/pileraget.c index be2bee19..b576f2cb 100644 --- a/src/pileraget.c +++ b/src/pileraget.c @@ -19,7 +19,9 @@ int main(int argc, char **argv){ int readkey=1; char filename[SMALLBUFSIZE]; +#ifdef HAVE_SUPPORT_FOR_COMPAT_STORAGE_LAYOUT struct stat st; +#endif struct __config cfg; diff --git a/src/pilerpurge.c b/src/pilerpurge.c index ce9de883..64951729 100644 --- a/src/pilerpurge.c +++ b/src/pilerpurge.c @@ -60,7 +60,9 @@ ENDE: int remove_message_frame_files(char *s, char *update_meta_sql, struct session_data *sdata, struct __config *cfg){ char *p, puf[SMALLBUFSIZE], filename[SMALLBUFSIZE]; int n=0, result; +#ifdef HAVE_SUPPORT_FOR_COMPAT_STORAGE_LAYOUT struct stat st; +#endif p = s; do { @@ -105,8 +107,9 @@ int remove_attachments(char *in, struct session_data *sdata, struct __data *data char *a, buf[BIGBUFSIZE-300], update_meta_sql[BIGBUFSIZE], delete_attachment_stmt[BIGBUFSIZE]; char piler_id[SMALLBUFSIZE], i[BUFLEN]; int n=0, len, attachment_id; +#ifdef HAVE_SUPPORT_FOR_COMPAT_STORAGE_LAYOUT struct stat st; - +#endif if(strlen(in) < 10) return 0;