cfgparser hacks backported from branches/milter-v2.0

git-svn: trunk@4489
0.95
aCaB 17 years ago
parent 695e6fd402
commit cd04ff0694
  1. 4
      ChangeLog
  2. 2
      clamav-milter/clamav-milter.c
  3. 2
      clamconf/clamconf.c
  4. 2
      clamd/clamd.c
  5. 2
      clamdscan/client.c
  6. 6
      freshclam/freshclam.c
  7. 2
      freshclam/manager.c
  8. 2
      freshclam/notify.c
  9. 65
      shared/cfgparser.c
  10. 6
      shared/cfgparser.h
  11. 2
      shared/misc.c

@ -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) Wed Nov 26 14:04:33 CET 2008 (tk)
--------------------------------- ---------------------------------
* libclamav/special.c: respect recursion limits in cli_check_jpeg_exploit() * libclamav/special.c: respect recursion limits in cli_check_jpeg_exploit()

@ -1170,7 +1170,7 @@ main(int argc, char **argv)
cfgfile = cli_malloc(strlen(CONFDIR) + 12); /* leak */ cfgfile = cli_malloc(strlen(CONFDIR) + 12); /* leak */
sprintf(cfgfile, "%s/clamd.conf", CONFDIR); 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"), fprintf(stderr, _("%s: Can't parse the config file %s\n"),
argv[0], cfgfile); argv[0], cfgfile);
return EX_CONFIG; return EX_CONFIG;

@ -84,7 +84,7 @@ static void printcfg(const char *cfgfile, int nondef)
unsigned short cfgowner = 0; 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); printf("Can't parse %s\n", cfgfile);
return; return;
} }

@ -157,7 +157,7 @@ int main(int argc, char **argv)
else else
cfgfile = CONFDIR"/clamd.conf"; 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); fprintf(stderr, "ERROR: Can't open/parse the config file %s\n", cfgfile);
opt_free(opt); opt_free(opt);
return 1; return 1;

@ -271,7 +271,7 @@ static int dconnect(const struct optstruct *opt, int *is_unix)
if(!clamav_conf) if(!clamav_conf)
clamav_conf = DEFAULT_CFG; 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"); logg("^Can't parse the configuration file.\n");
return -1; return -1;
} }

@ -253,11 +253,11 @@ int main(int argc, char **argv)
/* parse the config file */ /* parse the config file */
if((cfgfile = opt_arg(opt, "config-file"))) { if((cfgfile = opt_arg(opt, "config-file"))) {
copt = getcfg(cfgfile, 1); copt = getcfg(cfgfile, 1, OPT_FRESHCLAM);
} else { } else {
/* TODO: force strict permissions on freshclam.conf */ /* TODO: force strict permissions on freshclam.conf */
if((copt = getcfg((cfgfile = CONFDIR"/freshclam.conf"), 1)) == NULL) if((copt = getcfg((cfgfile = CONFDIR"/freshclam.conf"), 1, OPT_FRESHCLAM)) == NULL)
copt = getcfg((cfgfile = CONFDIR"/clamd.conf"), 1); copt = getcfg((cfgfile = CONFDIR"/clamd.conf"), 1, OPT_FRESHCLAM);
} }
if(!copt) { if(!copt) {

@ -560,7 +560,7 @@ int submitstats(const char *clamdcfg, const struct cfgstruct *copt)
country = cpt->strarg; 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); logg("!SubmitDetectionStats: Can't open or parse configuration file %s\n", clamdcfg);
return 56; return 56;
} }

@ -70,7 +70,7 @@ int notify(const char *cfgfile)
const char *socktype; 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); logg("^Clamd was NOT notified: Can't find or parse configuration file %s\n", cfgfile);
return 1; return 1;
} }

@ -35,14 +35,14 @@
#include "libclamav/str.h" #include "libclamav/str.h"
struct cfgoption cfg_options[] = { struct cfgoption cfg_options[] = {
{"LogFile", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD}, {"LogFile", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD | OPT_MILTER},
{"LogFileUnlock", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, {"LogFileUnlock", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_MILTER},
{"LogFileMaxSize", OPT_COMPSIZE, 1048576, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM}, {"LogFileMaxSize", OPT_COMPSIZE, 1048576, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER},
{"LogTime", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM}, {"LogTime", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER},
{"LogClean", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, {"LogClean", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_MILTER},
{"LogVerbose", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM}, {"LogVerbose", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER},
{"LogSyslog", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM}, {"LogSyslog", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER},
{"LogFacility", OPT_QUOTESTR, -1, "LOG_LOCAL6", 0, OPT_CLAMD | OPT_FRESHCLAM}, {"LogFacility", OPT_QUOTESTR, -1, "LOG_LOCAL6", 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER},
{"PidFile", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM}, {"PidFile", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM},
{"TemporaryDirectory", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD}, {"TemporaryDirectory", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD},
{"ScanPE", OPT_BOOL, 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}, {"ScanPDF", OPT_BOOL, 1, NULL, 0, OPT_CLAMD},
{"ScanArchive", OPT_BOOL, 1, NULL, 0, OPT_CLAMD}, {"ScanArchive", OPT_BOOL, 1, NULL, 0, OPT_CLAMD},
{"MaxScanSize", OPT_COMPSIZE, -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}, {"MaxRecursion", OPT_NUM, -1, NULL, 0, OPT_CLAMD},
{"MaxFiles", OPT_NUM, -1, NULL, 0, OPT_CLAMD}, {"MaxFiles", OPT_NUM, -1, NULL, 0, OPT_CLAMD},
{"ArchiveBlockEncrypted", OPT_BOOL, 0, 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}, {"StreamMaxLength", OPT_COMPSIZE, 10485760, NULL, 0, OPT_CLAMD},
{"StreamMinPort", OPT_NUM, 1024, NULL, 0, OPT_CLAMD}, {"StreamMinPort", OPT_NUM, 1024, NULL, 0, OPT_CLAMD},
{"StreamMaxPort", OPT_NUM, 2048, NULL, 0, OPT_CLAMD}, {"StreamMaxPort", OPT_NUM, 2048, NULL, 0, OPT_CLAMD},
{"MaxThreads", OPT_NUM, 10, NULL, 0, OPT_CLAMD}, {"MaxThreads", OPT_NUM, 10, NULL, 0, OPT_CLAMD | OPT_MILTER},
{"ReadTimeout", OPT_NUM, 120, NULL, 0, OPT_CLAMD}, {"ReadTimeout", OPT_NUM, 120, NULL, 0, OPT_CLAMD | OPT_MILTER},
{"IdleTimeout", OPT_NUM, 30, NULL, 0, OPT_CLAMD}, {"IdleTimeout", OPT_NUM, 30, NULL, 0, OPT_CLAMD},
{"MaxDirectoryRecursion", OPT_NUM, 15, NULL, 0, OPT_CLAMD}, {"MaxDirectoryRecursion", OPT_NUM, 15, NULL, 0, OPT_CLAMD},
{"ExcludePath", OPT_QUOTESTR, -1, NULL, 1, OPT_CLAMD}, {"ExcludePath", OPT_QUOTESTR, -1, NULL, 1, OPT_CLAMD},
{"FollowDirectorySymlinks", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, {"FollowDirectorySymlinks", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
{"FollowFileSymlinks", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, {"FollowFileSymlinks", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
{"ExitOnOOM", 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}, {"Debug", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM},
{"LeaveTemporaryFiles", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, {"LeaveTemporaryFiles", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
{"FixStaleSocket", OPT_BOOL, 1, NULL, 0, OPT_CLAMD}, {"FixStaleSocket", OPT_BOOL, 1, NULL, 0, OPT_CLAMD | OPT_MILTER},
{"User", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD}, {"User", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD | OPT_MILTER},
{"AllowSupplementaryGroups", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM}, {"AllowSupplementaryGroups", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER},
{"SelfCheck", OPT_NUM, 1800, NULL, 0, OPT_CLAMD}, {"SelfCheck", OPT_NUM, 1800, NULL, 0, OPT_CLAMD},
{"VirusEvent", OPT_FULLSTR, -1, NULL, 0, OPT_CLAMD}, {"VirusEvent", OPT_FULLSTR, -1, NULL, 0, OPT_CLAMD},
{"ClamukoScanOnAccess", OPT_BOOL, -1, NULL, 0, OPT_CLAMD}, {"ClamukoScanOnAccess", OPT_BOOL, -1, NULL, 0, OPT_CLAMD},
@ -135,19 +135,46 @@ struct cfgoption cfg_options[] = {
/* Deprecated options */ /* Deprecated options */
{"MailMaxRecursion", OPT_NUM, 64, NULL, 0, OPT_CLAMD | OPT_DEPRECATED}, {"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}, {"ArchiveMaxRecursion", OPT_NUM, 8, NULL, 0, OPT_CLAMD | OPT_DEPRECATED},
{"ArchiveMaxFiles", OPT_NUM, 1000, 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}, {"ArchiveMaxCompressionRatio", OPT_NUM, 250, NULL, 0, OPT_CLAMD | OPT_DEPRECATED},
{"ArchiveBlockMax", OPT_BOOL, 0, 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 }, {"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} {NULL, 0, 0, NULL, 0, 0}
}; };
static int regcfg(struct cfgstruct **copt, const char *optname, char *strarg, int numarg, short multiple); 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; char buff[LINE_LENGTH], *name, *arg, *c;
FILE *fs; FILE *fs;
@ -161,7 +188,7 @@ struct cfgstruct *getcfg(const char *cfgfile, int verbose)
if(!pt->name) if(!pt->name)
break; 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"); fprintf(stderr, "ERROR: Can't register new options (not enough memory)\n");
freecfg(copt); freecfg(copt);
return NULL; return NULL;
@ -194,7 +221,7 @@ struct cfgstruct *getcfg(const char *cfgfile, int verbose)
for(i = 0; ; i++) { for(i = 0; ; i++) {
pt = &cfg_options[i]; pt = &cfg_options[i];
if(pt->name) { if(pt->name) {
if(!strcmp(name, pt->name)) { if((pt->owner & toolmask) && !strcmp(name, pt->name)) {
found = 1; found = 1;
if(pt->owner & OPT_DEPRECATED) { if(pt->owner & OPT_DEPRECATED) {
fprintf(stderr, "WARNING: Ignoring deprecated option %s at line %u\n", pt->name, line); fprintf(stderr, "WARNING: Ignoring deprecated option %s at line %u\n", pt->name, line);

@ -29,9 +29,11 @@
#define OPT_FULLSTR 5 /* string argument, but get a full line */ #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.) */ #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_CLAMD 1
#define OPT_FRESHCLAM 2 #define OPT_FRESHCLAM 2
#define OPT_DEPRECATED 4 #define OPT_MILTER 4
#define OPT_DEPRECATED 16
struct cfgoption { struct cfgoption {
const char *name; const char *name;
@ -54,7 +56,7 @@ struct cfgstruct {
extern struct cfgoption cfg_options[]; 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); const struct cfgstruct *cfgopt(const struct cfgstruct *copt, const char *optname);
void freecfg(struct cfgstruct *copt); void freecfg(struct cfgstruct *copt);

@ -75,7 +75,7 @@ char *freshdbdir(void)
/* try to find fresh directory */ /* try to find fresh directory */
dbdir = cl_retdbdir(); 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((cpt = cfgopt(copt, "DatabaseDirectory"))->enabled || (cpt = cfgopt(copt, "DataDirectory"))->enabled) {
if(strcmp(dbdir, cpt->strarg)) { if(strcmp(dbdir, cpt->strarg)) {
char *daily = (char *) malloc(strlen(cpt->strarg) + strlen(dbdir) + 30); char *daily = (char *) malloc(strlen(cpt->strarg) + strlen(dbdir) + 30);

Loading…
Cancel
Save