Browse code

add support for OPT_QUOTESTR

git-svn: trunk@2270

Tomasz Kojm authored on 2006/09/15 07:09:38
Showing 4 changed files
... ...
@@ -1,3 +1,8 @@
1
+Fri Sep 15 00:07:02 CEST 2006 (tk)
2
+----------------------------------
3
+  * shared/cfgparser.c: add support for OPT_QUOTESTR and use it for file
4
+			directives, patch from Mark Pizzolato
5
+
1 6
 Thu Sep 14 22:06:52 CEST 2006 (acab)
2 7
 ------------------------------------
3 8
   * etc/clamd.conf: fix typo
... ...
@@ -47,6 +47,7 @@ void printopt(const struct cfgoption *opt, const struct cfgstruct *cpt)
47 47
     switch(opt->argtype) {
48 48
 	case OPT_STR:
49 49
 	case OPT_FULLSTR:
50
+	case OPT_QUOTESTR:
50 51
 	    printf("%s = \"%s\"\n", opt->name, cpt->strarg);
51 52
 	    break;
52 53
 	case OPT_NUM:
... ...
@@ -33,7 +33,7 @@
33 33
 #include "libclamav/str.h"
34 34
 
35 35
 struct cfgoption cfg_options[] = {
36
-    {"LogFile",	OPT_STR, -1, NULL, 0, OPT_CLAMD},
36
+    {"LogFile",	OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD},
37 37
     {"LogFileUnlock", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
38 38
     {"LogFileMaxSize", OPT_COMPSIZE, 1048576, NULL, 0, OPT_CLAMD},
39 39
     {"LogTime", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
... ...
@@ -41,8 +41,8 @@ struct cfgoption cfg_options[] = {
41 41
     {"LogVerbose", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM},
42 42
     {"LogSyslog", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM},
43 43
     {"LogFacility", OPT_STR, -1, "LOG_LOCAL6", 0, OPT_CLAMD | OPT_FRESHCLAM},
44
-    {"PidFile", OPT_STR, -1, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM},
45
-    {"TemporaryDirectory", OPT_STR, -1, NULL, 0, OPT_CLAMD},
44
+    {"PidFile", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM},
45
+    {"TemporaryDirectory", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD},
46 46
     {"ScanPE", OPT_BOOL, 1, NULL, 0, OPT_CLAMD},
47 47
     {"DetectBrokenExecutables", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
48 48
     {"ScanMail", OPT_BOOL, 1, NULL, 0, OPT_CLAMD},
... ...
@@ -63,7 +63,7 @@ struct cfgoption cfg_options[] = {
63 63
     {"ArchiveLimitMemoryUsage", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
64 64
     {"ArchiveBlockEncrypted", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
65 65
     {"ArchiveBlockMax", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
66
-    {"DatabaseDirectory", OPT_STR, -1, DATADIR, 0, OPT_CLAMD | OPT_FRESHCLAM},
66
+    {"DatabaseDirectory", OPT_QUOTESTR, -1, DATADIR, 0, OPT_CLAMD | OPT_FRESHCLAM},
67 67
     {"TCPAddr", OPT_STR, -1, NULL, 0, OPT_CLAMD},
68 68
     {"TCPSocket", OPT_NUM, -1, NULL, 0, OPT_CLAMD},
69 69
     {"LocalSocket", OPT_STR, -1, NULL, 0, OPT_CLAMD},
... ...
@@ -91,13 +91,13 @@ struct cfgoption cfg_options[] = {
91 91
     {"ClamukoScanOnOpen", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
92 92
     {"ClamukoScanOnClose", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
93 93
     {"ClamukoScanOnExec", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
94
-    {"ClamukoIncludePath", OPT_STR, 0, NULL, 0, OPT_CLAMD},
95
-    {"ClamukoExcludePath", OPT_STR, 0, NULL, 0, OPT_CLAMD},
94
+    {"ClamukoIncludePath", OPT_QUOTESTR, 0, NULL, 0, OPT_CLAMD},
95
+    {"ClamukoExcludePath", OPT_QUOTESTR, 0, NULL, 0, OPT_CLAMD},
96 96
     {"ClamukoMaxFileSize", OPT_COMPSIZE, 5242880, NULL, 0, OPT_CLAMD},
97 97
     {"ClamukoScanArchive", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
98 98
     {"DatabaseOwner", OPT_STR, -1, CLAMAVUSER, 0, OPT_FRESHCLAM},
99 99
     {"Checks", OPT_NUM, 12, NULL, 0, OPT_FRESHCLAM},
100
-    {"UpdateLogFile", OPT_STR, -1, NULL, 0, OPT_FRESHCLAM},
100
+    {"UpdateLogFile", OPT_QUOTESTR, -1, NULL, 0, OPT_FRESHCLAM},
101 101
     {"DNSDatabaseInfo", OPT_STR, -1, "current.cvd.clamav.net", 0, OPT_FRESHCLAM},
102 102
     {"DatabaseMirror", OPT_STR, -1, NULL, 1, OPT_FRESHCLAM},
103 103
     {"MaxAttempts", OPT_NUM, 3, NULL, 0, OPT_FRESHCLAM},
... ...
@@ -210,6 +210,43 @@ struct cfgstruct *getcfg(const char *cfgfile, int verbose)
210 210
 				    return NULL;
211 211
 				}
212 212
 				break;
213
+			    case OPT_QUOTESTR:
214
+				/* an ugly hack of the above case */
215
+				if(!arg) {
216
+				    if(verbose)
217
+					fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires string argument.\n", line, name);
218
+				    fclose(fs);
219
+				    free(name);
220
+				    freecfg(copt);
221
+				    return NULL;
222
+				}
223
+				if((*arg == '\'') || (*arg == '"')) {
224
+				    free(arg);
225
+				    c = strstr(buff, " ");
226
+				    arg = strdup(c+2);
227
+				    if(arg) {
228
+					if((c = strchr(arg, c[1])))
229
+					    *c = '\0';
230
+					else {
231
+					    if(verbose)
232
+						fprintf(stderr, "ERROR: Parse error at line %d: Option %s missing closing quote.\n", line, name);
233
+					    fclose(fs);
234
+					    free(name);
235
+					    free(arg);
236
+					    freecfg(copt);
237
+					    return NULL;
238
+					}
239
+				    }
240
+				}
241
+				if((!arg) || (regcfg(&copt, name, arg, -1, pt->multiple) < 0)) {
242
+				    fprintf(stderr, "ERROR: Can't register new options (not enough memory)\n");
243
+				    fclose(fs);
244
+				    free(name);
245
+				    free(arg);
246
+				    freecfg(copt);
247
+				    return NULL;
248
+				}
249
+				break;
213 250
 			    case OPT_NUM:
214 251
 				if(!arg || !isnumb(arg)) {
215 252
 				    if(verbose)
... ...
@@ -22,11 +22,12 @@
22 22
 
23 23
 #define LINE_LENGTH 1024
24 24
 
25
-#define OPT_STR 1 /* string argument */
25
+#define OPT_STR 1 /* string argument (space delimited) */
26 26
 #define OPT_NUM 2 /* numerical argument */
27 27
 #define OPT_COMPSIZE 3 /* convert kilobytes (k) and megabytes (m) to bytes */
28 28
 #define OPT_BOOL 4 /* boolean value */
29 29
 #define OPT_FULLSTR 5 /* string argument, but get a full line */
30
+#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.) */
30 31
 
31 32
 #define OPT_CLAMD 1
32 33
 #define OPT_FRESHCLAM 2