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)
---------------------------------
* 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 */
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;

@ -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;
}

@ -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;

@ -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;
}

@ -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) {

@ -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;
}

@ -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;
}

@ -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);

@ -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);

@ -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);

Loading…
Cancel
Save