introduced helper_timeout parameter

This commit is contained in:
SJ 2014-11-04 12:01:39 +01:00
parent 7d1a8628ea
commit 6fed43bddd
10 changed files with 55 additions and 60 deletions

34
configure vendored
View File

@ -701,7 +701,6 @@ enable_starttls
enable_tcpwrappers enable_tcpwrappers
enable_tweak_sent_time enable_tweak_sent_time
with_database with_database
with_plugin_timeout
with_piler_user with_piler_user
' '
ac_precious_vars='build_alias ac_precious_vars='build_alias
@ -1331,7 +1330,6 @@ Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-database[=mysql] select the used database, currently mysql only (default: none) --with-database[=mysql] select the used database, currently mysql only (default: none)
--with-plugin-timeout=N use the timeout binary to kill a hanging extractor plugin program after N seconds
--with-piler-user=username what user the piler daemon shall be run as --with-piler-user=username what user the piler daemon shall be run as
Some influential environment variables: Some influential environment variables:
@ -4504,26 +4502,18 @@ fi
if test z`which timeout 2>/dev/null` != "z"; then
timeout_binary=`which timeout`
# Check whether --with-plugin-timeout was given. cat >>confdefs.h <<_ACEOF
if test "${with_plugin_timeout+set}" = set; then : #define TIMEOUT_BINARY "$timeout_binary"
withval=$with_plugin_timeout; _ACEOF
if test z`which timeout 2>/dev/null` != "z"; then
timeout_binary=`which timeout`" $withval "
fi
if test "$withval" = "yes" || test "$withval" = ""; then
echo "please specify the value for plugin-timeout, eg. --with-plugin-timeout=15";
exit;
fi
fi fi
# Check whether --with-piler-user was given. # Check whether --with-piler-user was given.
if test "${with_piler_user+set}" = set; then : if test "${with_piler_user+set}" = set; then :
withval=$with_piler_user; RUNNING_USER=$withval withval=$with_piler_user; RUNNING_USER=$withval
@ -4757,7 +4747,7 @@ if test z`which pdftotext 2>/dev/null` != "z"; then
pdftotext=`which pdftotext` pdftotext=`which pdftotext`
cat >>confdefs.h <<_ACEOF cat >>confdefs.h <<_ACEOF
#define HAVE_PDFTOTEXT "$timeout_binary$pdftotext" #define HAVE_PDFTOTEXT "$pdftotext"
_ACEOF _ACEOF
fi fi
@ -4766,7 +4756,7 @@ if test z`which catdoc 2>/dev/null` != "z"; then
catdoc=`which catdoc` catdoc=`which catdoc`
cat >>confdefs.h <<_ACEOF cat >>confdefs.h <<_ACEOF
#define HAVE_CATDOC "$timeout_binary$catdoc" #define HAVE_CATDOC "$catdoc"
_ACEOF _ACEOF
fi fi
@ -4776,7 +4766,7 @@ if test z`which catppt 2>/dev/null` != "z"; then
catppt=`which catppt` catppt=`which catppt`
cat >>confdefs.h <<_ACEOF cat >>confdefs.h <<_ACEOF
#define HAVE_CATPPT "$timeout_binary$catppt" #define HAVE_CATPPT "$catppt"
_ACEOF _ACEOF
fi fi
@ -4786,7 +4776,7 @@ if test z`which ppthtml 2>/dev/null` != "z"; then
ppthtml=`which ppthtml` ppthtml=`which ppthtml`
cat >>confdefs.h <<_ACEOF cat >>confdefs.h <<_ACEOF
#define HAVE_PPTHTML "$timeout_binary$ppthtml" #define HAVE_PPTHTML "$ppthtml"
_ACEOF _ACEOF
fi fi
@ -4796,7 +4786,7 @@ if test z`which xls2csv 2>/dev/null` != "z"; then
xls2csv=`which xls2csv` xls2csv=`which xls2csv`
cat >>confdefs.h <<_ACEOF cat >>confdefs.h <<_ACEOF
#define HAVE_XLS2CSV "$timeout_binary$xls2csv" #define HAVE_XLS2CSV "$xls2csv"
_ACEOF _ACEOF
fi fi
@ -4806,7 +4796,7 @@ if test z`which unrtf 2>/dev/null` != "z"; then
unrtf=`which unrtf` unrtf=`which unrtf`
cat >>confdefs.h <<_ACEOF cat >>confdefs.h <<_ACEOF
#define HAVE_UNRTF "$timeout_binary$unrtf" #define HAVE_UNRTF "$unrtf"
_ACEOF _ACEOF
fi fi
@ -4816,7 +4806,7 @@ if test z`which tnef 2>/dev/null` != "z"; then
tnef=`which tnef` tnef=`which tnef`
cat >>confdefs.h <<_ACEOF cat >>confdefs.h <<_ACEOF
#define HAVE_TNEF "$timeout_binary$tnef" #define HAVE_TNEF "$tnef"
_ACEOF _ACEOF
fi fi

View File

@ -253,19 +253,12 @@ AC_ARG_WITH(database,
]) ])
dnl timeout binary
AC_ARG_WITH(plugin-timeout, if test z`which timeout 2>/dev/null` != "z"; then
[ --with-plugin-timeout=N use the timeout binary to kill a hanging extractor plugin program after N seconds],[ timeout_binary=`which timeout`
AC_DEFINE_UNQUOTED(TIMEOUT_BINARY, "$timeout_binary", [timeout binary])
if test z`which timeout 2>/dev/null` != "z"; then fi
timeout_binary=`which timeout`" $withval "
fi
if test "$withval" = "yes" || test "$withval" = ""; then
echo "please specify the value for plugin-timeout, eg. --with-plugin-timeout=15";
exit;
fi
])
dnl user running piler dnl user running piler
@ -465,42 +458,42 @@ fi
if test z`which pdftotext 2>/dev/null` != "z"; then if test z`which pdftotext 2>/dev/null` != "z"; then
pdftotext=`which pdftotext` pdftotext=`which pdftotext`
AC_DEFINE_UNQUOTED(HAVE_PDFTOTEXT, "$timeout_binary$pdftotext", [path to pdftotext]) AC_DEFINE_UNQUOTED(HAVE_PDFTOTEXT, "$pdftotext", [path to pdftotext])
fi fi
if test z`which catdoc 2>/dev/null` != "z"; then if test z`which catdoc 2>/dev/null` != "z"; then
catdoc=`which catdoc` catdoc=`which catdoc`
AC_DEFINE_UNQUOTED(HAVE_CATDOC, "$timeout_binary$catdoc", [path to catdoc]) AC_DEFINE_UNQUOTED(HAVE_CATDOC, "$catdoc", [path to catdoc])
fi fi
if test z`which catppt 2>/dev/null` != "z"; then if test z`which catppt 2>/dev/null` != "z"; then
catppt=`which catppt` catppt=`which catppt`
AC_DEFINE_UNQUOTED(HAVE_CATPPT, "$timeout_binary$catppt", [path to catppt]) AC_DEFINE_UNQUOTED(HAVE_CATPPT, "$catppt", [path to catppt])
fi fi
if test z`which ppthtml 2>/dev/null` != "z"; then if test z`which ppthtml 2>/dev/null` != "z"; then
ppthtml=`which ppthtml` ppthtml=`which ppthtml`
AC_DEFINE_UNQUOTED(HAVE_PPTHTML, "$timeout_binary$ppthtml", [path to ppthtml]) AC_DEFINE_UNQUOTED(HAVE_PPTHTML, "$ppthtml", [path to ppthtml])
fi fi
if test z`which xls2csv 2>/dev/null` != "z"; then if test z`which xls2csv 2>/dev/null` != "z"; then
xls2csv=`which xls2csv` xls2csv=`which xls2csv`
AC_DEFINE_UNQUOTED(HAVE_XLS2CSV, "$timeout_binary$xls2csv", [path to xls2csv]) AC_DEFINE_UNQUOTED(HAVE_XLS2CSV, "$xls2csv", [path to xls2csv])
fi fi
if test z`which unrtf 2>/dev/null` != "z"; then if test z`which unrtf 2>/dev/null` != "z"; then
unrtf=`which unrtf` unrtf=`which unrtf`
AC_DEFINE_UNQUOTED(HAVE_UNRTF, "$timeout_binary$unrtf", [path to unrtf]) AC_DEFINE_UNQUOTED(HAVE_UNRTF, "$unrtf", [path to unrtf])
fi fi
if test z`which tnef 2>/dev/null` != "z"; then if test z`which tnef 2>/dev/null` != "z"; then
tnef=`which tnef` tnef=`which tnef`
AC_DEFINE_UNQUOTED(HAVE_TNEF, "$timeout_binary$tnef", [path to tnef]) AC_DEFINE_UNQUOTED(HAVE_TNEF, "$tnef", [path to tnef])
fi fi

View File

@ -53,6 +53,7 @@ listen_port=25
clamd_socket=/tmp/clamd clamd_socket=/tmp/clamd
session_timeout=420 session_timeout=420
helper_timeout=20
; the 2nd parameter of the listen() system call. Please note that this is set ; 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. ; when piler starts up and you should restart piler if you change this variable.

View File

@ -9,6 +9,8 @@
#define HAVE_DAEMON 1 #define HAVE_DAEMON 1
#undef TIMEOUT_BINARY
#undef HAVE_PDFTOTEXT #undef HAVE_PDFTOTEXT
#undef HAVE_CATDOC #undef HAVE_CATDOC
#undef HAVE_CATPPT #undef HAVE_CATPPT

View File

@ -71,6 +71,7 @@ struct _parse_rule config_parse_rules[] =
{ "enable_cjk", "integer", (void*) int_parser, offsetof(struct __config, enable_cjk), "0", sizeof(int)}, { "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)}, { "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}, { "extra_to_field", "string", (void*) string_parser, offsetof(struct __config, extra_to_field), "", MAXVAL-1},
{ "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}, { "hostid", "string", (void*) string_parser, offsetof(struct __config, hostid), HOSTID, MAXVAL-1},
{ "iv", "string", (void*) string_parser, offsetof(struct __config, iv), "", MAXVAL-1}, { "iv", "string", (void*) string_parser, offsetof(struct __config, iv), "", MAXVAL-1},
{ "listen_addr", "string", (void*) string_parser, offsetof(struct __config, listen_addr), "0.0.0.0", MAXVAL-1}, { "listen_addr", "string", (void*) string_parser, offsetof(struct __config, listen_addr), "0.0.0.0", MAXVAL-1},

View File

@ -52,6 +52,7 @@ struct __config {
char locale[MAXVAL]; char locale[MAXVAL];
int session_timeout; int session_timeout;
int helper_timeout;
char piler_header_field[MAXVAL]; char piler_header_field[MAXVAL];
char extra_to_field[MAXVAL]; char extra_to_field[MAXVAL];

View File

@ -14,7 +14,7 @@
#define VERSION "1.1.1-pre" #define VERSION "1.1.1-pre"
#define BUILD 895 #define BUILD 896
#define HOSTID "mailarchiver" #define HOSTID "mailarchiver"

View File

@ -91,7 +91,7 @@ int extract_opendocument(struct session_data *sdata, struct _state *state, char
} }
int unzip_file(struct session_data *sdata, struct _state *state, char *filename, int *rec){ int unzip_file(struct session_data *sdata, struct _state *state, char *filename, int *rec, struct __config *cfg){
int errorp, i=0, len=0, fd; int errorp, i=0, len=0, fd;
char *p, extracted_filename[SMALLBUFSIZE], buf[MAXBUFSIZE]; char *p, extracted_filename[SMALLBUFSIZE], buf[MAXBUFSIZE];
struct zip *z; struct zip *z;
@ -127,7 +127,7 @@ int unzip_file(struct session_data *sdata, struct _state *state, char *filename,
close(fd); close(fd);
extract_attachment_content(sdata, state, extracted_filename, get_attachment_extractor_by_filename(extracted_filename), rec); extract_attachment_content(sdata, state, extracted_filename, get_attachment_extractor_by_filename(extracted_filename), rec, cfg);
unlink(extracted_filename); unlink(extracted_filename);
@ -156,7 +156,7 @@ int unzip_file(struct session_data *sdata, struct _state *state, char *filename,
#ifdef HAVE_TNEF #ifdef HAVE_TNEF
int extract_tnef(struct session_data *sdata, struct _state *state, char *filename){ int extract_tnef(struct session_data *sdata, struct _state *state, char *filename, struct __config *cfg){
int rc=0, n, rec=1; int rc=0, n, rec=1;
char tmpdir[BUFLEN], buf[SMALLBUFSIZE]; char tmpdir[BUFLEN], buf[SMALLBUFSIZE];
struct dirent **namelist; struct dirent **namelist;
@ -179,7 +179,7 @@ int extract_tnef(struct session_data *sdata, struct _state *state, char *filenam
if(strcmp(namelist[n]->d_name, ".") && strcmp(namelist[n]->d_name, "..")){ if(strcmp(namelist[n]->d_name, ".") && strcmp(namelist[n]->d_name, "..")){
snprintf(buf, sizeof(buf)-1, "%s/%s", tmpdir, namelist[n]->d_name); snprintf(buf, sizeof(buf)-1, "%s/%s", tmpdir, namelist[n]->d_name);
extract_attachment_content(sdata, state, buf, get_attachment_extractor_by_filename(buf), &rec); extract_attachment_content(sdata, state, buf, get_attachment_extractor_by_filename(buf), &rec, cfg);
unlink(buf); unlink(buf);
} }
@ -196,11 +196,13 @@ int extract_tnef(struct session_data *sdata, struct _state *state, char *filenam
#endif #endif
void read_content_with_popen(struct session_data *sdata, struct _state *state, char *cmd){ void read_content_with_popen(struct session_data *sdata, struct _state *state, char *cmd, struct __config *cfg){
int len; int len;
char buf[MAXBUFSIZE]; char buf[MAXBUFSIZE];
FILE *f; FILE *f;
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_INFO, "running command: '%s'", cmd);
f = popen(cmd, "r"); f = popen(cmd, "r");
if(f){ if(f){
while(fgets(buf, sizeof(buf)-1, f)){ while(fgets(buf, sizeof(buf)-1, f)){
@ -220,46 +222,51 @@ void read_content_with_popen(struct session_data *sdata, struct _state *state, c
} }
void extract_attachment_content(struct session_data *sdata, struct _state *state, char *filename, char *type, int *rec){ void extract_attachment_content(struct session_data *sdata, struct _state *state, char *filename, char *type, int *rec, struct __config *cfg){
char cmd[SMALLBUFSIZE]; char cmd[SMALLBUFSIZE], timeout[SMALLBUFSIZE];
if(strcmp(type, "other") == 0) return; if(strcmp(type, "other") == 0) return;
memset(cmd, 0, sizeof(cmd)); memset(cmd, 0, sizeof(cmd));
memset(timeout, 0, sizeof(timeout));
#ifdef TIMEOUT_BINARY
if(cfg->helper_timeout > 0) snprintf(timeout, sizeof(timeout)-1, "%s %d ", TIMEOUT_BINARY, cfg->helper_timeout);
#endif
#ifdef HAVE_PDFTOTEXT #ifdef HAVE_PDFTOTEXT
if(strcmp(type, "pdf") == 0) snprintf(cmd, sizeof(cmd)-1, "%s -enc UTF-8 %s -", HAVE_PDFTOTEXT, filename); if(strcmp(type, "pdf") == 0) snprintf(cmd, sizeof(cmd)-1, "%s%s -enc UTF-8 %s -", timeout, HAVE_PDFTOTEXT, filename);
#endif #endif
#ifdef HAVE_CATDOC #ifdef HAVE_CATDOC
if(strcmp(type, "doc") == 0) snprintf(cmd, sizeof(cmd)-1, "%s -d utf-8 %s", HAVE_CATDOC, filename); if(strcmp(type, "doc") == 0) snprintf(cmd, sizeof(cmd)-1, "%s%s -d utf-8 %s", timeout, HAVE_CATDOC, filename);
#endif #endif
#ifdef HAVE_CATPPT #ifdef HAVE_CATPPT
if(strcmp(type, "ppt") == 0) snprintf(cmd, sizeof(cmd)-1, "%s -d utf-8 %s", HAVE_CATPPT, filename); if(strcmp(type, "ppt") == 0) snprintf(cmd, sizeof(cmd)-1, "%s%s -d utf-8 %s", timeout, HAVE_CATPPT, filename);
#endif #endif
#ifdef HAVE_XLS2CSV #ifdef HAVE_XLS2CSV
if(strcmp(type, "xls") == 0) snprintf(cmd, sizeof(cmd)-1, "%s -d utf-8 %s", HAVE_XLS2CSV, filename); if(strcmp(type, "xls") == 0) snprintf(cmd, sizeof(cmd)-1, "%s%s -d utf-8 %s", timeout, HAVE_XLS2CSV, filename);
#endif #endif
#ifdef HAVE_PPTHTML #ifdef HAVE_PPTHTML
if(strcmp(type, "ppt") == 0) snprintf(cmd, sizeof(cmd)-1, "%s %s", HAVE_PPTHTML, filename); if(strcmp(type, "ppt") == 0) snprintf(cmd, sizeof(cmd)-1, "%s%s %s", timeout, HAVE_PPTHTML, filename);
#endif #endif
#ifdef HAVE_UNRTF #ifdef HAVE_UNRTF
if(strcmp(type, "rtf") == 0) snprintf(cmd, sizeof(cmd)-1, "%s --text %s", HAVE_UNRTF, filename); if(strcmp(type, "rtf") == 0) snprintf(cmd, sizeof(cmd)-1, "%s%s --text %s", timeout, HAVE_UNRTF, filename);
#endif #endif
#ifdef HAVE_TNEF #ifdef HAVE_TNEF
if(strcmp(type, "tnef") == 0){ if(strcmp(type, "tnef") == 0){
extract_tnef(sdata, state, filename); extract_tnef(sdata, state, filename, cfg);
return; return;
} }
#endif #endif
if(strlen(cmd) > 12){ if(strlen(cmd) > 12){
read_content_with_popen(sdata, state, cmd); read_content_with_popen(sdata, state, cmd, cfg);
return; return;
} }
@ -288,7 +295,7 @@ void extract_attachment_content(struct session_data *sdata, struct _state *state
if(strcmp(type, "zip") == 0){ if(strcmp(type, "zip") == 0){
if(*rec < MAX_ZIP_RECURSION_LEVEL){ if(*rec < MAX_ZIP_RECURSION_LEVEL){
unzip_file(sdata, state, filename, rec); unzip_file(sdata, state, filename, rec, cfg);
} }
else { else {
syslog(LOG_PRIORITY, "%s: multiple recursion level zip attachment, skipping %s", sdata->ttmpfile, filename); syslog(LOG_PRIORITY, "%s: multiple recursion level zip attachment, skipping %s", sdata->ttmpfile, filename);

View File

@ -130,7 +130,7 @@ void post_parse(struct session_data *sdata, struct _state *state, struct __confi
if(state->attachments[i].dumped == 1){ if(state->attachments[i].dumped == 1){
rec = 0; 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); 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);
unlink(state->attachments[i].aname); unlink(state->attachments[i].aname);
} }

View File

@ -59,7 +59,7 @@ int add_new_folder(struct session_data *sdata, struct __data *data, char *folder
int store_index_data(struct session_data *sdata, struct _state *state, struct __data *data, uint64 id, struct __config *cfg); int store_index_data(struct session_data *sdata, struct _state *state, struct __data *data, uint64 id, struct __config *cfg);
void extract_attachment_content(struct session_data *sdata, struct _state *state, char *filename, char *type, int *rec); void extract_attachment_content(struct session_data *sdata, struct _state *state, char *filename, char *type, int *rec, struct __config *cfg);
int retrieve_file_from_archive(char *filename, int mode, char **buffer, FILE *dest, struct __config *cfg); int retrieve_file_from_archive(char *filename, int mode, char **buffer, FILE *dest, struct __config *cfg);