On Monday, September 04, 2006 at 3:57 PM, Tomasz Kojm wrote: > On Thu, 17 Aug 2006 12:19:16 -0700 > Mark Pizzolato wrote: > > > The attached patch will allow clamd and freshclam configuration file > > entries which specify file names and/or directories to contain spaces. > > Hi Mark, > > we already used this approach in 0.88.1 and because it turned out to be > quite problematic it was removed in 0.88.2: > > Sat Apr 29 21:30:47 CEST 2006 > ----------------------------- > V 0.88.2 > * Bugfixes: > [...] > - shared/cfgparser.c: don't use CL_FULLSTR for file directives > Requested by Tomasz Papszun and others
OK, I was not aware of this. > What we really need in this case is support for quoted strings (it's in my > TODO). Good idea. Attached is a patch which implements OPT_QUOTESTR. OPT_QUOTESTR includes everything between quotes (if present), or for backward compatibility, acts as OPT_STR if the next token doesn't start with a quote character (' or "). OPT_QUOTESTR is then used for file and directory paths as in the prior patch. - Mark Pizzolato
diff -r -c -X excluding.txt clamav-devel-20060901/shared/cfgparser.c clamav-devel-20060901.quote-cfgparser/shared/cfgparser.c *** clamav-devel-20060901/shared/cfgparser.c Wed Aug 30 18:30:04 2006 --- clamav-devel-20060901.quote-cfgparser/shared/cfgparser.c Mon Sep 4 18:47:32 2006 *************** *** 33,39 **** #include "libclamav/str.h" struct cfgoption cfg_options[] = { ! {"LogFile", OPT_STR, -1, NULL, 0, OPT_CLAMD}, {"LogFileUnlock", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, {"LogFileMaxSize", OPT_COMPSIZE, 1048576, NULL, 0, OPT_CLAMD}, {"LogTime", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, --- 33,39 ---- #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}, {"LogTime", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, *************** *** 41,48 **** {"LogVerbose", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM}, {"LogSyslog", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM}, {"LogFacility", OPT_STR, -1, "LOG_LOCAL6", 0, OPT_CLAMD | OPT_FRESHCLAM}, ! {"PidFile", OPT_STR, -1, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM}, ! {"TemporaryDirectory", OPT_STR, -1, NULL, 0, OPT_CLAMD}, {"ScanPE", OPT_BOOL, 1, NULL, 0, OPT_CLAMD}, {"DetectBrokenExecutables", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, {"ScanMail", OPT_BOOL, 1, NULL, 0, OPT_CLAMD}, --- 41,48 ---- {"LogVerbose", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM}, {"LogSyslog", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM}, {"LogFacility", OPT_STR, -1, "LOG_LOCAL6", 0, OPT_CLAMD | OPT_FRESHCLAM}, ! {"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}, {"DetectBrokenExecutables", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, {"ScanMail", OPT_BOOL, 1, NULL, 0, OPT_CLAMD}, *************** *** 59,65 **** {"ArchiveLimitMemoryUsage", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, {"ArchiveBlockEncrypted", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, {"ArchiveBlockMax", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, ! {"DatabaseDirectory", OPT_STR, -1, DATADIR, 0, OPT_CLAMD | OPT_FRESHCLAM}, {"TCPAddr", OPT_STR, -1, NULL, 0, OPT_CLAMD}, {"TCPSocket", OPT_NUM, -1, NULL, 0, OPT_CLAMD}, {"LocalSocket", OPT_STR, -1, NULL, 0, OPT_CLAMD}, --- 59,65 ---- {"ArchiveLimitMemoryUsage", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, {"ArchiveBlockEncrypted", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, {"ArchiveBlockMax", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, ! {"DatabaseDirectory", OPT_QUOTESTR, -1, DATADIR, 0, OPT_CLAMD | OPT_FRESHCLAM}, {"TCPAddr", OPT_STR, -1, NULL, 0, OPT_CLAMD}, {"TCPSocket", OPT_NUM, -1, NULL, 0, OPT_CLAMD}, {"LocalSocket", OPT_STR, -1, NULL, 0, OPT_CLAMD}, *************** *** 86,98 **** {"ClamukoScanOnOpen", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, {"ClamukoScanOnClose", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, {"ClamukoScanOnExec", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, ! {"ClamukoIncludePath", OPT_STR, 0, NULL, 0, OPT_CLAMD}, ! {"ClamukoExcludePath", OPT_STR, 0, NULL, 0, OPT_CLAMD}, {"ClamukoMaxFileSize", OPT_COMPSIZE, 5242880, NULL, 0, OPT_CLAMD}, {"ClamukoScanArchive", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, {"DatabaseOwner", OPT_STR, -1, CLAMAVUSER, 0, OPT_FRESHCLAM}, {"Checks", OPT_NUM, 12, NULL, 0, OPT_FRESHCLAM}, ! {"UpdateLogFile", OPT_STR, -1, NULL, 0, OPT_FRESHCLAM}, {"DNSDatabaseInfo", OPT_STR, -1, "current.cvd.clamav.net", 0, OPT_FRESHCLAM}, {"DatabaseMirror", OPT_STR, -1, NULL, 1, OPT_FRESHCLAM}, {"MaxAttempts", OPT_NUM, 3, NULL, 0, OPT_FRESHCLAM}, --- 86,98 ---- {"ClamukoScanOnOpen", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, {"ClamukoScanOnClose", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, {"ClamukoScanOnExec", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, ! {"ClamukoIncludePath", OPT_QUOTESTR, 0, NULL, 0, OPT_CLAMD}, ! {"ClamukoExcludePath", OPT_QUOTESTR, 0, NULL, 0, OPT_CLAMD}, {"ClamukoMaxFileSize", OPT_COMPSIZE, 5242880, NULL, 0, OPT_CLAMD}, {"ClamukoScanArchive", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, {"DatabaseOwner", OPT_STR, -1, CLAMAVUSER, 0, OPT_FRESHCLAM}, {"Checks", OPT_NUM, 12, NULL, 0, OPT_FRESHCLAM}, ! {"UpdateLogFile", OPT_QUOTESTR, -1, NULL, 0, OPT_FRESHCLAM}, {"DNSDatabaseInfo", OPT_STR, -1, "current.cvd.clamav.net", 0, OPT_FRESHCLAM}, {"DatabaseMirror", OPT_STR, -1, NULL, 1, OPT_FRESHCLAM}, {"MaxAttempts", OPT_NUM, 3, NULL, 0, OPT_FRESHCLAM}, *************** *** 199,204 **** --- 199,234 ---- return NULL; } break; + case OPT_QUOTESTR: + /* an ugly hack of the above case */ + if(!arg) { + if(verbose) + fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires string argument.\n", line, name); + fclose(fs); + free(name); + freecfg(copt); + return NULL; + } + if((*arg == '\'') || (*arg == '"')) { + free(arg); + c = strstr(buff, " "); + arg = strdup(c+2); + if(arg) { + if((c = strchr(arg, c[1]))) + *c = '\0'; + else if((c = strpbrk(arg, "\n\r"))) + *c = '\0'; + } + } + if((!arg) || (regcfg(&copt, name, arg, -1, pt->multiple) < 0)) { + fprintf(stderr, "ERROR: Can't register new options (not enough memory)\n"); + fclose(fs); + free(name); + free(arg); + freecfg(copt); + return NULL; + } + break; case OPT_NUM: if(!arg || !isnumb(arg)) { if(verbose) diff -r -c -X excluding.txt clamav-devel-20060901/shared/cfgparser.h clamav-devel-20060901.quote-cfgparser/shared/cfgparser.h *** clamav-devel-20060901/shared/cfgparser.h Sat Apr 15 10:47:41 2006 --- clamav-devel-20060901.quote-cfgparser/shared/cfgparser.h Mon Sep 4 18:47:36 2006 *************** *** 22,32 **** #define LINE_LENGTH 1024 ! #define OPT_STR 1 /* string argument */ #define OPT_NUM 2 /* numerical argument */ #define OPT_COMPSIZE 3 /* convert kilobytes (k) and megabytes (m) to bytes */ #define OPT_BOOL 4 /* boolean value */ #define OPT_FULLSTR 5 /* string argument, but get a full line */ #define OPT_CLAMD 1 #define OPT_FRESHCLAM 2 --- 22,33 ---- #define LINE_LENGTH 1024 ! #define OPT_STR 1 /* string argument (space delimited) */ #define OPT_NUM 2 /* numerical argument */ #define OPT_COMPSIZE 3 /* convert kilobytes (k) and megabytes (m) to bytes */ #define OPT_BOOL 4 /* boolean value */ #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 start with a quote character, then the argument data is what appears between the starting quote character and the matching ending quote character.) */ #define OPT_CLAMD 1 #define OPT_FRESHCLAM 2
_______________________________________________ http://lurker.clamav.net/list/clamav-devel.html