diff --git a/ChangeLog b/ChangeLog index 492a7d77e..e70696acd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Fri Nov 28 17:42:20 CET 2008 (acab) +----------------------------------- + * cfgparser: backport modifications from branches/milter-v2.0 + Wed Nov 26 14:04:33 CET 2008 (tk) --------------------------------- * libclamav/special.c: respect recursion limits in cli_check_jpeg_exploit() diff --git a/clamav-milter/clamav-milter.c b/clamav-milter/clamav-milter.c index 9319ca851..dc699955e 100644 --- a/clamav-milter/clamav-milter.c +++ b/clamav-milter/clamav-milter.c @@ -1170,7 +1170,7 @@ main(int argc, char **argv) cfgfile = cli_malloc(strlen(CONFDIR) + 12); /* leak */ sprintf(cfgfile, "%s/clamd.conf", CONFDIR); } - if((copt = getcfg(cfgfile, 1)) == NULL) { + if((copt = getcfg(cfgfile, 1, OPT_CLAMD)) == NULL) { fprintf(stderr, _("%s: Can't parse the config file %s\n"), argv[0], cfgfile); return EX_CONFIG; diff --git a/clamconf/clamconf.c b/clamconf/clamconf.c index b4f9a0cab..b9814b1c0 100644 --- a/clamconf/clamconf.c +++ b/clamconf/clamconf.c @@ -84,7 +84,7 @@ static void printcfg(const char *cfgfile, int nondef) unsigned short cfgowner = 0; - if(!(cfg = getcfg(cfgfile, 1))) { + if(!(cfg = getcfg(cfgfile, 1, OPT_FRESHCLAM|OPT_CLAMD))) { printf("Can't parse %s\n", cfgfile); return; } diff --git a/clamd/clamd.c b/clamd/clamd.c index f7c53495d..6b1f6d9f5 100644 --- a/clamd/clamd.c +++ b/clamd/clamd.c @@ -157,7 +157,7 @@ int main(int argc, char **argv) else cfgfile = CONFDIR"/clamd.conf"; - if((copt = getcfg(cfgfile, 1)) == NULL) { + if((copt = getcfg(cfgfile, 1, OPT_CLAMD)) == NULL) { fprintf(stderr, "ERROR: Can't open/parse the config file %s\n", cfgfile); opt_free(opt); return 1; diff --git a/clamdscan/client.c b/clamdscan/client.c index 5c3d44dba..d201d2fb7 100644 --- a/clamdscan/client.c +++ b/clamdscan/client.c @@ -271,7 +271,7 @@ static int dconnect(const struct optstruct *opt, int *is_unix) if(!clamav_conf) clamav_conf = DEFAULT_CFG; - if((copt = getcfg(clamav_conf, 1)) == NULL) { + if((copt = getcfg(clamav_conf, 1, OPT_CLAMD)) == NULL) { logg("^Can't parse the configuration file.\n"); return -1; } diff --git a/freshclam/freshclam.c b/freshclam/freshclam.c index 092c1caf6..e5067b168 100644 --- a/freshclam/freshclam.c +++ b/freshclam/freshclam.c @@ -253,11 +253,11 @@ int main(int argc, char **argv) /* parse the config file */ if((cfgfile = opt_arg(opt, "config-file"))) { - copt = getcfg(cfgfile, 1); + copt = getcfg(cfgfile, 1, OPT_FRESHCLAM); } else { /* TODO: force strict permissions on freshclam.conf */ - if((copt = getcfg((cfgfile = CONFDIR"/freshclam.conf"), 1)) == NULL) - copt = getcfg((cfgfile = CONFDIR"/clamd.conf"), 1); + if((copt = getcfg((cfgfile = CONFDIR"/freshclam.conf"), 1, OPT_FRESHCLAM)) == NULL) + copt = getcfg((cfgfile = CONFDIR"/clamd.conf"), 1, OPT_FRESHCLAM); } if(!copt) { diff --git a/freshclam/manager.c b/freshclam/manager.c index 629ebcf4d..ea54f4758 100644 --- a/freshclam/manager.c +++ b/freshclam/manager.c @@ -560,7 +560,7 @@ int submitstats(const char *clamdcfg, const struct cfgstruct *copt) country = cpt->strarg; } - if(!(clamdopt = getcfg(clamdcfg, 1))) { + if(!(clamdopt = getcfg(clamdcfg, 1, OPT_CLAMD))) { logg("!SubmitDetectionStats: Can't open or parse configuration file %s\n", clamdcfg); return 56; } diff --git a/freshclam/notify.c b/freshclam/notify.c index 068431669..f0b1a1532 100644 --- a/freshclam/notify.c +++ b/freshclam/notify.c @@ -70,7 +70,7 @@ int notify(const char *cfgfile) const char *socktype; - if((copt = getcfg(cfgfile, 1)) == NULL) { + if((copt = getcfg(cfgfile, 1, OPT_CLAMD)) == NULL) { logg("^Clamd was NOT notified: Can't find or parse configuration file %s\n", cfgfile); return 1; } diff --git a/shared/cfgparser.c b/shared/cfgparser.c index 9d2b79517..989f38467 100644 --- a/shared/cfgparser.c +++ b/shared/cfgparser.c @@ -35,14 +35,14 @@ #include "libclamav/str.h" struct cfgoption cfg_options[] = { - {"LogFile", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD}, - {"LogFileUnlock", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, - {"LogFileMaxSize", OPT_COMPSIZE, 1048576, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM}, - {"LogTime", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM}, - {"LogClean", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, - {"LogVerbose", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM}, - {"LogSyslog", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM}, - {"LogFacility", OPT_QUOTESTR, -1, "LOG_LOCAL6", 0, OPT_CLAMD | OPT_FRESHCLAM}, + {"LogFile", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD | OPT_MILTER}, + {"LogFileUnlock", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_MILTER}, + {"LogFileMaxSize", OPT_COMPSIZE, 1048576, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER}, + {"LogTime", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER}, + {"LogClean", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_MILTER}, + {"LogVerbose", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER}, + {"LogSyslog", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER}, + {"LogFacility", OPT_QUOTESTR, -1, "LOG_LOCAL6", 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER}, {"PidFile", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM}, {"TemporaryDirectory", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD}, {"ScanPE", OPT_BOOL, 1, NULL, 0, OPT_CLAMD}, @@ -72,7 +72,7 @@ struct cfgoption cfg_options[] = { {"ScanPDF", OPT_BOOL, 1, NULL, 0, OPT_CLAMD}, {"ScanArchive", OPT_BOOL, 1, NULL, 0, OPT_CLAMD}, {"MaxScanSize", OPT_COMPSIZE, -1, NULL, 0, OPT_CLAMD}, - {"MaxFileSize", OPT_COMPSIZE, -1, NULL, 0, OPT_CLAMD}, + {"MaxFileSize", OPT_COMPSIZE, -1, NULL, 0, OPT_CLAMD | OPT_MILTER}, {"MaxRecursion", OPT_NUM, -1, NULL, 0, OPT_CLAMD}, {"MaxFiles", OPT_NUM, -1, NULL, 0, OPT_CLAMD}, {"ArchiveBlockEncrypted", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, @@ -84,20 +84,20 @@ struct cfgoption cfg_options[] = { {"StreamMaxLength", OPT_COMPSIZE, 10485760, NULL, 0, OPT_CLAMD}, {"StreamMinPort", OPT_NUM, 1024, NULL, 0, OPT_CLAMD}, {"StreamMaxPort", OPT_NUM, 2048, NULL, 0, OPT_CLAMD}, - {"MaxThreads", OPT_NUM, 10, NULL, 0, OPT_CLAMD}, - {"ReadTimeout", OPT_NUM, 120, NULL, 0, OPT_CLAMD}, + {"MaxThreads", OPT_NUM, 10, NULL, 0, OPT_CLAMD | OPT_MILTER}, + {"ReadTimeout", OPT_NUM, 120, NULL, 0, OPT_CLAMD | OPT_MILTER}, {"IdleTimeout", OPT_NUM, 30, NULL, 0, OPT_CLAMD}, {"MaxDirectoryRecursion", OPT_NUM, 15, NULL, 0, OPT_CLAMD}, {"ExcludePath", OPT_QUOTESTR, -1, NULL, 1, OPT_CLAMD}, {"FollowDirectorySymlinks", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, {"FollowFileSymlinks", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, {"ExitOnOOM", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, - {"Foreground", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM}, + {"Foreground", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER}, {"Debug", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM}, {"LeaveTemporaryFiles", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, - {"FixStaleSocket", OPT_BOOL, 1, NULL, 0, OPT_CLAMD}, - {"User", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD}, - {"AllowSupplementaryGroups", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM}, + {"FixStaleSocket", OPT_BOOL, 1, NULL, 0, OPT_CLAMD | OPT_MILTER}, + {"User", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD | OPT_MILTER}, + {"AllowSupplementaryGroups", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER}, {"SelfCheck", OPT_NUM, 1800, NULL, 0, OPT_CLAMD}, {"VirusEvent", OPT_FULLSTR, -1, NULL, 0, OPT_CLAMD}, {"ClamukoScanOnAccess", OPT_BOOL, -1, NULL, 0, OPT_CLAMD}, @@ -135,19 +135,46 @@ struct cfgoption cfg_options[] = { /* Deprecated options */ {"MailMaxRecursion", OPT_NUM, 64, NULL, 0, OPT_CLAMD | OPT_DEPRECATED}, - {"ArchiveMaxFileSize", OPT_COMPSIZE, 10485760, NULL, 0, OPT_CLAMD | OPT_DEPRECATED}, + {"ArchiveMaxScanSize", OPT_COMPSIZE, 10485760, NULL, 0, OPT_CLAMD | OPT_DEPRECATED}, {"ArchiveMaxRecursion", OPT_NUM, 8, NULL, 0, OPT_CLAMD | OPT_DEPRECATED}, {"ArchiveMaxFiles", OPT_NUM, 1000, NULL, 0, OPT_CLAMD | OPT_DEPRECATED}, {"ArchiveMaxCompressionRatio", OPT_NUM, 250, NULL, 0, OPT_CLAMD | OPT_DEPRECATED}, {"ArchiveBlockMax", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_DEPRECATED}, {"ArchiveLimitMemoryUsage", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_DEPRECATED }, + + /* Milter specific options */ + {"ClamdSocket", OPT_QUOTESTR, -1, NULL, 1, OPT_MILTER}, + {"MilterSocket", OPT_QUOTESTR, -1, NULL, 1, OPT_MILTER}, + + /* Deprecated milter options */ + {"ArchiveBlockEncrypted", OPT_BOOL, 0, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, + {"DatabaseDirectory", OPT_QUOTESTR, -1, DATADIR, 0, OPT_MILTER | OPT_DEPRECATED}, + {"Debug", OPT_BOOL, 0, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, + {"DetectBrokenExecutables", OPT_BOOL, 0, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, + {"LeaveTemporaryFiles", OPT_BOOL, 0, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, + {"LocalSocket", OPT_QUOTESTR, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, + {"MailFollowURLs", OPT_BOOL, 0, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, + {"MaxScanSize", OPT_COMPSIZE, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, + {"MaxFiles", OPT_NUM, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, + {"MaxRecursion", OPT_NUM, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, + {"PhishingSignatures", OPT_BOOL, 1, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, + {"PidFile", OPT_QUOTESTR, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, + {"ScanArchive", OPT_BOOL, 1, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, + {"ScanHTML", OPT_BOOL, 1, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, + {"ScanMail", OPT_BOOL, 1, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, + {"ScanOLE2", OPT_BOOL, 1, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, + {"ScanPE", OPT_BOOL, 1, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, + {"StreamMaxLength", OPT_COMPSIZE, 10485760, NULL, OPT_MILTER | OPT_DEPRECATED}, + {"TCPAddr", OPT_QUOTESTR, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, + {"TCPSocket", OPT_NUM, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, + {"TemporaryDirectory", OPT_QUOTESTR, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, {NULL, 0, 0, NULL, 0, 0} }; static int regcfg(struct cfgstruct **copt, const char *optname, char *strarg, int numarg, short multiple); -struct cfgstruct *getcfg(const char *cfgfile, int verbose) +struct cfgstruct *getcfg(const char *cfgfile, int verbose, int toolmask) { char buff[LINE_LENGTH], *name, *arg, *c; FILE *fs; @@ -161,7 +188,7 @@ struct cfgstruct *getcfg(const char *cfgfile, int verbose) if(!pt->name) break; - if(regcfg(&copt, pt->name, pt->strarg ? strdup(pt->strarg) : NULL, pt->numarg, pt->multiple) < 0) { + if((pt->owner & toolmask) && regcfg(&copt, pt->name, pt->strarg ? strdup(pt->strarg) : NULL, pt->numarg, pt->multiple) < 0) { fprintf(stderr, "ERROR: Can't register new options (not enough memory)\n"); freecfg(copt); return NULL; @@ -194,7 +221,7 @@ struct cfgstruct *getcfg(const char *cfgfile, int verbose) for(i = 0; ; i++) { pt = &cfg_options[i]; if(pt->name) { - if(!strcmp(name, pt->name)) { + if((pt->owner & toolmask) && !strcmp(name, pt->name)) { found = 1; if(pt->owner & OPT_DEPRECATED) { fprintf(stderr, "WARNING: Ignoring deprecated option %s at line %u\n", pt->name, line); diff --git a/shared/cfgparser.h b/shared/cfgparser.h index c5baa2e4f..6fe18ebb8 100644 --- a/shared/cfgparser.h +++ b/shared/cfgparser.h @@ -29,9 +29,11 @@ #define OPT_FULLSTR 5 /* string argument, but get a full line */ #define OPT_QUOTESTR 6 /* string argument, (space delimited unless the argument starts with ' or ". If the argument starts with a quote character, then the argument data is what appears between the starting quote character and the matching ending quote character.) */ +/* don't share bits! */ #define OPT_CLAMD 1 #define OPT_FRESHCLAM 2 -#define OPT_DEPRECATED 4 +#define OPT_MILTER 4 +#define OPT_DEPRECATED 16 struct cfgoption { const char *name; @@ -54,7 +56,7 @@ struct cfgstruct { extern struct cfgoption cfg_options[]; -struct cfgstruct *getcfg(const char *cfgfile, int verbose); +struct cfgstruct *getcfg(const char *cfgfile, int verbose, int toolmask); const struct cfgstruct *cfgopt(const struct cfgstruct *copt, const char *optname); void freecfg(struct cfgstruct *copt); diff --git a/shared/misc.c b/shared/misc.c index 419d278ac..f720c652f 100644 --- a/shared/misc.c +++ b/shared/misc.c @@ -75,7 +75,7 @@ char *freshdbdir(void) /* try to find fresh directory */ dbdir = cl_retdbdir(); - if((copt = getcfg(CONFDIR"/freshclam.conf", 0))) { + if((copt = getcfg(CONFDIR"/freshclam.conf", 0, OPT_FRESHCLAM))) { if((cpt = cfgopt(copt, "DatabaseDirectory"))->enabled || (cpt = cfgopt(copt, "DataDirectory"))->enabled) { if(strcmp(dbdir, cpt->strarg)) { char *daily = (char *) malloc(strlen(cpt->strarg) + strlen(dbdir) + 30);