From: Tom Kistner Date: Tue, 30 Nov 2004 15:18:58 +0000 (+0000) Subject: WITH_CONTENT_SCAN checkin - compiles OK now X-Git-Url: https://git.exim.org/users/jgh/exim.git/commitdiff_plain/ef4454d691573b79884f6c1da6bc1c5c9a62d959 WITH_CONTENT_SCAN checkin - compiles OK now --- diff --git a/src/OS/Makefile-Base b/src/OS/Makefile-Base index e5eebc9e2..af4472443 100644 --- a/src/OS/Makefile-Base +++ b/src/OS/Makefile-Base @@ -1,4 +1,4 @@ -# $Cambridge: exim/src/OS/Makefile-Base,v 1.1.2.1 2004/11/26 14:17:33 tom Exp $ +# $Cambridge: exim/src/OS/Makefile-Base,v 1.1.2.2 2004/11/30 15:18:58 tom Exp $ # This file is the basis of the main makefile for Exim and friends. The # makefile at the top level arranges to build the main makefile by calling @@ -287,7 +287,7 @@ convert4r4: Makefile ../src/convert4r4.src # Targets for final binaries; the main one has a build number which is # updated each time. We don't bother with that for the auxiliaries. -OBJ_WITH_CONTENT_SCAN = malware.o mime.o regex.o spam.o spool-mbox.o +OBJ_WITH_CONTENT_SCAN = malware.o mime.o regex.o spam.o spool_mbox.o OBJ_EXIM = acl.o child.o crypt16.o daemon.o dbfn.o debug.o deliver.o \ directory.o dns.o drtables.o enq.o exim.o expand.o filter.o \ @@ -555,7 +555,7 @@ malware.o: $(HDRS) malware.c mime.o: $(HDRS) mime.c regex.o: $(HDRS) regex.c spam.o: $(HDRS) spam.c -spool-mbox.o: $(HDRS) spool_mbox.c +spool_mbox.o: $(HDRS) spool_mbox.c # The module containing tables of available lookups, routers, auths, and diff --git a/src/src/acl.c b/src/src/acl.c index ffd7e9451..80ac7f036 100644 --- a/src/src/acl.c +++ b/src/src/acl.c @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/src/acl.c,v 1.5.2.1 2004/11/25 15:33:55 tom Exp $ */ +/* $Cambridge: exim/src/src/acl.c,v 1.5.2.2 2004/11/30 15:18:58 tom Exp $ */ /************************************************* * Exim - an Internet mail transport agent * @@ -49,7 +49,7 @@ enum { ACLC_ACL, ACLC_AUTHENTICATED, ACLC_CONDITION, ACLC_CONTROL, #endif ACLC_RECIPIENTS, #ifdef WITH_CONTENT_SCAN - ACLC_REGEX + ACLC_REGEX, #endif ACLC_SENDER_DOMAINS, ACLC_SENDERS, ACLC_SET, #ifdef WITH_CONTENT_SCAN @@ -1384,6 +1384,9 @@ uschar *user_message = NULL; uschar *log_message = NULL; uschar *p; int rc = OK; +#ifdef WITH_CONTENT_SCAN +int sep = '/'; +#endif for (; cb != NULL; cb = cb->next) { diff --git a/src/src/config.h.defaults b/src/src/config.h.defaults index e31cffb10..9e098b760 100644 --- a/src/src/config.h.defaults +++ b/src/src/config.h.defaults @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/src/config.h.defaults,v 1.2 2004/10/18 09:16:57 ph10 Exp $ */ +/* $Cambridge: exim/src/src/config.h.defaults,v 1.2.2.1 2004/11/30 15:18:58 tom Exp $ */ /************************************************* * Exim - an Internet mail transport agent * @@ -138,6 +138,8 @@ in config.h unless some value is defined in Local/Makefile. */ #define USE_TCP_WRAPPERS #define USE_TDB +#define WITH_CONTENT_SCAN + /* Things that are not routinely changed but are nevertheless configurable just in case. */ diff --git a/src/src/exim.h b/src/src/exim.h index 397a13687..c46af2c58 100644 --- a/src/src/exim.h +++ b/src/src/exim.h @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/src/exim.h,v 1.3 2004/11/24 15:43:36 ph10 Exp $ */ +/* $Cambridge: exim/src/src/exim.h,v 1.2.2.1 2004/11/30 15:18:58 tom Exp $ */ /************************************************* * Exim - an Internet mail transport agent * @@ -279,11 +279,9 @@ header files. I don't suppose they have T_SRV either. */ #endif /* We use the private type T_ZNS for retrieving the nameservers for the -enclosing zone of a domain, and the private type T_MXH for retrieving -the MX hostnames only (without their priorities). */ +enclosing zone of a domain. */ #define T_ZNS (-1) -#define T_MXH (-2) /* The resolv.h header defines __P(x) on some Solaris 2.5.1 systems (without checking that it is already defined, in fact). This conflicts with other @@ -383,8 +381,8 @@ extern int ferror(FILE *); mytypes.h and store.h, so we don't need to mention them explicitly. */ #include "local_scan.h" -#include "macros.h" #include "config.h" +#include "macros.h" #include "dbstuff.h" #include "structs.h" #include "globals.h" diff --git a/src/src/functions.h b/src/src/functions.h index 32a3c288a..f1180b81f 100644 --- a/src/src/functions.h +++ b/src/src/functions.h @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/src/functions.h,v 1.6 2004/11/25 13:54:31 ph10 Exp $ */ +/* $Cambridge: exim/src/src/functions.h,v 1.5.2.1 2004/11/30 15:18:58 tom Exp $ */ /************************************************* * Exim - an Internet mail transport agent * @@ -92,7 +92,7 @@ extern int expand_string_integer(uschar *); extern int filter_interpret(uschar *, int, address_item **, uschar **); extern BOOL filter_personal(string_item *, BOOL); -extern BOOL filter_runtest(int, uschar *, BOOL, BOOL); +extern BOOL filter_runtest(int, BOOL, BOOL); extern BOOL filter_system_interpret(address_item **, uschar **); extern void header_add(int, char *, ...); @@ -126,6 +126,9 @@ extern int ip_socket(int, int); extern uschar *local_part_quote(uschar *lpart); extern void log_close_all(void); +#ifdef WITH_CONTENT_SCAN +extern int malware(uschar **); +#endif extern int match_address_list(uschar *, BOOL, BOOL, uschar **, unsigned int *, int, int, uschar **); extern int match_check_list(uschar **, int, tree_node **, unsigned int **, @@ -139,6 +142,13 @@ extern void md5_end(md5 *, const uschar *, int, uschar *); extern void md5_mid(md5 *, const uschar *); extern void md5_start(md5 *); extern void millisleep(int); +#ifdef WITH_CONTENT_SCAN +struct mime_boundary_context; +extern int mime_acl_check(FILE *f, struct mime_boundary_context *, + uschar **, uschar **); +extern int mime_decode(uschar **); +extern int mime_regex(uschar **); +#endif extern uschar *moan_check_errorcopy(uschar *); extern BOOL moan_skipped_syntax_errors(uschar *, error_block *, uschar *, BOOL, uschar *); @@ -183,6 +193,9 @@ extern BOOL receive_check_set_sender(uschar *); extern BOOL receive_msg(BOOL); extern int receive_statvfs(BOOL, int *); extern void receive_swallow_smtp(void); +#ifdef WITH_CONTENT_SCAN +extern int regex(uschar **); +#endif extern BOOL regex_match_and_setup(const pcre *, uschar *, int, int); extern const pcre *regex_must_compile(uschar *, BOOL, BOOL); extern void retry_add_item(address_item *, uschar *, int); @@ -243,6 +256,10 @@ extern int smtp_setup_msg(void); extern BOOL smtp_start_session(void); extern int smtp_ungetc(int); extern int smtp_write_command(smtp_outblock *, BOOL, char *, ...); +#ifdef WITH_CONTENT_SCAN +extern int spam(uschar **); +extern FILE *spool_mbox(unsigned long long *); +#endif extern BOOL spool_move_message(uschar *, uschar *, uschar *, uschar *); extern BOOL spool_open_datafile(uschar *); extern int spool_open_temp(uschar *); @@ -294,6 +311,10 @@ extern int tree_insertnode(tree_node **, tree_node *); extern tree_node *tree_search(tree_node *, uschar *); extern void tree_write(tree_node *, FILE *); +#ifdef WITH_CONTENT_SCAN +extern void unspool_mbox(void); +#endif + extern int verify_address(address_item *, FILE *, int, int, int, int, uschar *, uschar *, BOOL *); extern int verify_check_dnsbl(uschar **); diff --git a/src/src/macros.h b/src/src/macros.h index 94431fc93..d4e7b8a65 100644 --- a/src/src/macros.h +++ b/src/src/macros.h @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/src/macros.h,v 1.2.2.1 2004/11/25 15:33:55 tom Exp $ */ +/* $Cambridge: exim/src/src/macros.h,v 1.2.2.2 2004/11/30 15:18:58 tom Exp $ */ /************************************************* * Exim - an Internet mail transport agent * @@ -734,6 +734,8 @@ ordered to make it easy to implement tests for certain ACLs when processing order without checking carefully! Furthermore, remember to keep these in step with the tables of names and response codes in globals.c. */ +/* FIXME: the #ifdef below does not work here. Why? */ + enum { ACL_WHERE_RCPT, /* Some controls are for RCPT only */ ACL_WHERE_MAIL, /* ) */ ACL_WHERE_PREDATA, /* ) There are several tests for "in message", */ diff --git a/src/src/malware.c b/src/src/malware.c index a24d0de87..972bad37f 100644 --- a/src/src/malware.c +++ b/src/src/malware.c @@ -1,21 +1,19 @@ -/* $Cambridge: exim/src/src/malware.c,v 1.1.2.2 2004/11/26 16:04:26 tom Exp $ */ +/* $Cambridge: exim/src/src/malware.c,v 1.1.2.3 2004/11/30 15:18:58 tom Exp $ */ /************************************************* * Exim - an Internet mail transport agent * *************************************************/ -#ifdef WITH_CONTENT_SCAN - /* Copyright (c) Tom Kistner 2003-???? */ /* License: GPL */ /* Code for calling virus (malware) scanners. Called from acl.c. */ #include "exim.h" +#ifdef WITH_CONTENT_SCAN /* declaration of private routines */ int mksd_scan_packed(int sock); -int mksd_scan_unpacked(int sock, int maxproc); /* SHUT_WR seems to be undefined on Unixware? */ #ifndef SHUT_WR @@ -1150,10 +1148,7 @@ int malware(uschar **listptr) { malware_name = NULL; - /* choose the appropriate scan routine */ - retval = demime_ok ? - mksd_scan_unpacked(sock, mksd_maxproc) : - mksd_scan_packed(sock); + retval = mksd_scan_packed(sock); if (retval != OK) return retval; @@ -1324,94 +1319,4 @@ int mksd_scan_packed (int sock) return mksd_parse_line (CS av_buffer); } -int mksd_scan_unpacked (int sock, int maxproc) -{ - struct iovec iov[5]; - char *cmd = "\nSQ/"; - DIR *unpdir; - struct dirent *entry; - int pending = 0; - uschar *line; - int i, offset; - uschar mbox_name[1024]; - uschar unpackdir[1024]; - uschar av_buffer[16384]; - - snprintf (CS mbox_name, sizeof (mbox_name), "%s.eml", CS message_id); - snprintf (CS unpackdir, sizeof (unpackdir), "%s/scan/%s", CS spool_directory, CS message_id); - - if ((unpdir = opendir (CS unpackdir)) == NULL) { - close (sock); - log_write(0, LOG_MAIN|LOG_PANIC, - "malware acl condition: unable to scan spool directory"); - return DEFER; - } - - iov[0].iov_base = cmd; - iov[0].iov_len = 3; - iov[1].iov_base = CS unpackdir; - iov[1].iov_len = Ustrlen (unpackdir); - iov[2].iov_base = cmd + 3; - iov[2].iov_len = 1; - iov[4].iov_base = cmd; - iov[4].iov_len = 1; - - /* main loop */ - while ((unpdir != NULL) || (pending > 0)) { - - /* write loop */ - while ((pending < maxproc) && (unpdir != NULL)) { - if ((entry = readdir (unpdir)) != NULL) { - if ((Ustrcmp (entry->d_name, ".") != 0) && - (Ustrcmp (entry->d_name, "..") != 0) && - (Ustrcmp (entry->d_name, mbox_name) != 0)) { - iov[3].iov_base = entry->d_name; - iov[3].iov_len = strlen (entry->d_name); - if (mksd_writev (sock, iov, 5) < 0) { - closedir (unpdir); - return DEFER; - } - iov[0].iov_base = cmd + 1; - iov[0].iov_len = 2; - pending++; - } - } else { - closedir (unpdir); - unpdir = NULL; - } - } - - /* read and parse */ - if (pending > 0) { - if ((offset = mksd_read_lines (sock, av_buffer, sizeof (av_buffer))) < 0) { - if (unpdir != NULL) - closedir (unpdir); - return DEFER; - } - line = av_buffer; - do { - if (((i = mksd_parse_line (CS line)) != OK) || (malware_name != NULL)) { - close (sock); - if (unpdir != NULL) - closedir (unpdir); - return i; - } - pending--; - if ((line = Ustrchr (line, '\n')) == NULL) { - close (sock); - if (unpdir != NULL) - closedir (unpdir); - log_write(0, LOG_MAIN|LOG_PANIC, - "malware acl condition: unterminated line received from mksd"); - return DEFER; - } - } while (++line != (av_buffer + offset)); - offset = 0; - } - } - - close (sock); - return OK; -} - #endif diff --git a/src/src/mime.c b/src/src/mime.c index 1203b4833..ac0126d18 100644 --- a/src/src/mime.c +++ b/src/src/mime.c @@ -1,15 +1,14 @@ -/* $Cambridge: exim/src/src/mime.c,v 1.1.2.2 2004/11/26 16:04:26 tom Exp $ */ +/* $Cambridge: exim/src/src/mime.c,v 1.1.2.3 2004/11/30 15:18:58 tom Exp $ */ /************************************************* * Exim - an Internet mail transport agent * *************************************************/ -#ifdef WITH_CONTENT_SCAN - /* Copyright (c) Tom Kistner 2004 */ /* License: GPL */ #include "exim.h" +#ifdef WITH_CONTENT_SCAN #include "mime.h" #include diff --git a/src/src/mime.h b/src/src/mime.h index 29cb37d89..8fb948158 100644 --- a/src/src/mime.h +++ b/src/src/mime.h @@ -1,14 +1,13 @@ -/* $Cambridge: exim/src/src/mime.h,v 1.1.2.2 2004/11/26 16:04:26 tom Exp $ */ +/* $Cambridge: exim/src/src/mime.h,v 1.1.2.3 2004/11/30 15:18:58 tom Exp $ */ /************************************************* * Exim - an Internet mail transport agent * *************************************************/ -#ifdef WITH_CONTENT_SCAN - /* Copyright (c) Tom Kistner 2004 */ /* License: GPL */ +#ifdef WITH_CONTENT_SCAN #define MIME_MAX_HEADER_SIZE 8192 #define MIME_MAX_LINE_LENGTH 32768 diff --git a/src/src/regex.c b/src/src/regex.c index a97ea0592..37178a6dd 100644 --- a/src/src/regex.c +++ b/src/src/regex.c @@ -1,11 +1,9 @@ -/* $Cambridge: exim/src/src/regex.c,v 1.1.2.2 2004/11/26 16:04:26 tom Exp $ */ +/* $Cambridge: exim/src/src/regex.c,v 1.1.2.3 2004/11/30 15:18:58 tom Exp $ */ /************************************************* * Exim - an Internet mail transport agent * *************************************************/ -#ifdef WITH_CONTENT_SCAN - /* Copyright (c) Tom Kistner 2003-???? */ /* License: GPL */ @@ -13,6 +11,7 @@ Called from acl.c. */ #include "exim.h" +#ifdef WITH_CONTENT_SCAN #include #include diff --git a/src/src/spam.c b/src/src/spam.c index 134c3a814..b533d285d 100644 --- a/src/src/spam.c +++ b/src/src/spam.c @@ -1,17 +1,16 @@ -/* $Cambridge: exim/src/src/spam.c,v 1.1.2.2 2004/11/26 16:04:26 tom Exp $ */ +/* $Cambridge: exim/src/src/spam.c,v 1.1.2.3 2004/11/30 15:18:58 tom Exp $ */ /************************************************* * Exim - an Internet mail transport agent * *************************************************/ -#ifdef WITH_CONTENT_SCAN - /* Copyright (c) Tom Kistner 2003-???? */ /* License: GPL */ /* Code for calling spamassassin's spamd. Called from acl.c. */ #include "exim.h" +#ifdef WITH_CONTENT_SCAN #include "spam.h" uschar spam_score_buffer[16]; diff --git a/src/src/spam.h b/src/src/spam.h index ace7bb64c..1a1592b83 100644 --- a/src/src/spam.h +++ b/src/src/spam.h @@ -1,16 +1,16 @@ -/* $Cambridge: exim/src/src/spam.h,v 1.1.2.2 2004/11/26 16:04:26 tom Exp $ */ +/* $Cambridge: exim/src/src/spam.h,v 1.1.2.3 2004/11/30 15:18:58 tom Exp $ */ /************************************************* * Exim - an Internet mail transport agent * *************************************************/ -#ifdef WITH_CONTENT_SCAN - /* Copyright (c) Tom Kistner 2003-???? */ /* License: GPL */ /* spam defines */ +#ifdef WITH_CONTENT_SCAN + /* timeout for reading from spamd */ #define SPAMD_READ_TIMEOUT 3600 diff --git a/src/src/spool_mbox.c b/src/src/spool_mbox.c index 8fa3f6883..f08278bb7 100644 --- a/src/src/spool_mbox.c +++ b/src/src/spool_mbox.c @@ -1,11 +1,9 @@ -/* $Cambridge: exim/src/src/spool_mbox.c,v 1.1.2.2 2004/11/26 16:04:26 tom Exp $ */ +/* $Cambridge: exim/src/src/spool_mbox.c,v 1.1.2.3 2004/11/30 15:18:58 tom Exp $ */ /************************************************* * Exim - an Internet mail transport agent * *************************************************/ -#ifdef WITH_CONTENT_SCAN - /* Copyright (c) Tom Kistner 2003-???? */ /* License: GPL */ @@ -13,10 +11,13 @@ sub directory of exim's spool directory. */ #include "exim.h" +#ifdef WITH_CONTENT_SCAN /* externals, we must reset them on unspooling */ +#ifdef WITH_OLD_DEMIME extern int demime_ok; extern struct file_extension *file_extensions; +#endif extern int malware_ok; extern int spam_ok; @@ -126,10 +127,13 @@ FILE *spool_mbox(unsigned long long *mbox_file_size) { void unspool_mbox(void) { /* reset all exiscan state variables */ + #ifdef WITH_OLD_DEMIME demime_ok = 0; demime_errorlevel = 0; demime_reason = NULL; file_extensions = NULL; + #endif + spam_ok = 0; malware_ok = 0;