Browse code

cfgparser hacks backported from branches/milter-v2.0

git-svn: trunk@4489

aCaB authored on 2008/11/29 01:57:15
Showing 11 changed files
... ...
@@ -1,3 +1,7 @@
1
+Fri Nov 28 17:42:20 CET 2008 (acab)
2
+-----------------------------------
3
+ * cfgparser: backport modifications from branches/milter-v2.0
4
+
1 5
 Wed Nov 26 14:04:33 CET 2008 (tk)
2 6
 ---------------------------------
3 7
  * libclamav/special.c: respect recursion limits in cli_check_jpeg_exploit()
... ...
@@ -1170,7 +1170,7 @@ main(int argc, char **argv)
1170 1170
 		cfgfile = cli_malloc(strlen(CONFDIR) + 12);	/* leak */
1171 1171
 		sprintf(cfgfile, "%s/clamd.conf", CONFDIR);
1172 1172
 	}
1173
-	if((copt = getcfg(cfgfile, 1)) == NULL) {
1173
+	if((copt = getcfg(cfgfile, 1, OPT_CLAMD)) == NULL) {
1174 1174
 		fprintf(stderr, _("%s: Can't parse the config file %s\n"),
1175 1175
 			argv[0], cfgfile);
1176 1176
 		return EX_CONFIG;
... ...
@@ -84,7 +84,7 @@ static void printcfg(const char *cfgfile, int nondef)
84 84
 	unsigned short cfgowner = 0;
85 85
 
86 86
 
87
-    if(!(cfg = getcfg(cfgfile, 1))) {
87
+	if(!(cfg = getcfg(cfgfile, 1, OPT_FRESHCLAM|OPT_CLAMD))) {
88 88
 	printf("Can't parse %s\n", cfgfile);
89 89
 	return;
90 90
     }
... ...
@@ -157,7 +157,7 @@ int main(int argc, char **argv)
157 157
     else
158 158
 	cfgfile = CONFDIR"/clamd.conf";
159 159
 
160
-    if((copt = getcfg(cfgfile, 1)) == NULL) {
160
+    if((copt = getcfg(cfgfile, 1, OPT_CLAMD)) == NULL) {
161 161
 	fprintf(stderr, "ERROR: Can't open/parse the config file %s\n", cfgfile);
162 162
 	opt_free(opt);
163 163
 	return 1;
... ...
@@ -271,7 +271,7 @@ static int dconnect(const struct optstruct *opt, int *is_unix)
271 271
     if(!clamav_conf)
272 272
 	clamav_conf = DEFAULT_CFG;
273 273
 
274
-    if((copt = getcfg(clamav_conf, 1)) == NULL) {
274
+    if((copt = getcfg(clamav_conf, 1, OPT_CLAMD)) == NULL) {
275 275
 	logg("^Can't parse the configuration file.\n");
276 276
 	return -1;
277 277
     }
... ...
@@ -253,11 +253,11 @@ int main(int argc, char **argv)
253 253
 
254 254
     /* parse the config file */
255 255
     if((cfgfile = opt_arg(opt, "config-file"))) {
256
-	copt = getcfg(cfgfile, 1);
256
+        copt = getcfg(cfgfile, 1, OPT_FRESHCLAM);
257 257
     } else {
258 258
 	/* TODO: force strict permissions on freshclam.conf */
259
-	if((copt = getcfg((cfgfile = CONFDIR"/freshclam.conf"), 1)) == NULL)
260
-	    copt = getcfg((cfgfile = CONFDIR"/clamd.conf"), 1);
259
+	if((copt = getcfg((cfgfile = CONFDIR"/freshclam.conf"), 1, OPT_FRESHCLAM)) == NULL)
260
+	    copt = getcfg((cfgfile = CONFDIR"/clamd.conf"), 1, OPT_FRESHCLAM);
261 261
     }
262 262
 
263 263
     if(!copt) {
... ...
@@ -560,7 +560,7 @@ int submitstats(const char *clamdcfg, const struct cfgstruct *copt)
560 560
 	country = cpt->strarg;
561 561
     }
562 562
 
563
-    if(!(clamdopt = getcfg(clamdcfg, 1))) {
563
+    if(!(clamdopt = getcfg(clamdcfg, 1, OPT_CLAMD))) {
564 564
 	logg("!SubmitDetectionStats: Can't open or parse configuration file %s\n", clamdcfg);
565 565
 	return 56;
566 566
     }
... ...
@@ -70,7 +70,7 @@ int notify(const char *cfgfile)
70 70
 	const char *socktype;
71 71
 
72 72
 
73
-    if((copt = getcfg(cfgfile, 1)) == NULL) {
73
+    if((copt = getcfg(cfgfile, 1, OPT_CLAMD)) == NULL) {
74 74
 	logg("^Clamd was NOT notified: Can't find or parse configuration file %s\n", cfgfile);
75 75
 	return 1;
76 76
     }
... ...
@@ -35,14 +35,14 @@
35 35
 #include "libclamav/str.h"
36 36
 
37 37
 struct cfgoption cfg_options[] = {
38
-    {"LogFile",	OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD},
39
-    {"LogFileUnlock", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
40
-    {"LogFileMaxSize", OPT_COMPSIZE, 1048576, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM},
41
-    {"LogTime", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM},
42
-    {"LogClean", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
43
-    {"LogVerbose", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM},
44
-    {"LogSyslog", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM},
45
-    {"LogFacility", OPT_QUOTESTR, -1, "LOG_LOCAL6", 0, OPT_CLAMD | OPT_FRESHCLAM},
38
+    {"LogFile",	OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD | OPT_MILTER},
39
+    {"LogFileUnlock", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_MILTER},
40
+    {"LogFileMaxSize", OPT_COMPSIZE, 1048576, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER},
41
+    {"LogTime", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER},
42
+    {"LogClean", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_MILTER},
43
+    {"LogVerbose", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER},
44
+    {"LogSyslog", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER},
45
+    {"LogFacility", OPT_QUOTESTR, -1, "LOG_LOCAL6", 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER},
46 46
     {"PidFile", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM},
47 47
     {"TemporaryDirectory", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD},
48 48
     {"ScanPE", OPT_BOOL, 1, NULL, 0, OPT_CLAMD},
... ...
@@ -72,7 +72,7 @@ struct cfgoption cfg_options[] = {
72 72
     {"ScanPDF", OPT_BOOL, 1, NULL, 0, OPT_CLAMD},
73 73
     {"ScanArchive", OPT_BOOL, 1, NULL, 0, OPT_CLAMD},
74 74
     {"MaxScanSize", OPT_COMPSIZE, -1, NULL, 0, OPT_CLAMD},
75
-    {"MaxFileSize", OPT_COMPSIZE, -1, NULL, 0, OPT_CLAMD},
75
+    {"MaxFileSize", OPT_COMPSIZE, -1, NULL, 0, OPT_CLAMD | OPT_MILTER},
76 76
     {"MaxRecursion", OPT_NUM, -1, NULL, 0, OPT_CLAMD},
77 77
     {"MaxFiles", OPT_NUM, -1, NULL, 0, OPT_CLAMD},
78 78
     {"ArchiveBlockEncrypted", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
... ...
@@ -84,20 +84,20 @@ struct cfgoption cfg_options[] = {
84 84
     {"StreamMaxLength", OPT_COMPSIZE, 10485760, NULL, 0, OPT_CLAMD},
85 85
     {"StreamMinPort", OPT_NUM, 1024, NULL, 0, OPT_CLAMD},
86 86
     {"StreamMaxPort", OPT_NUM, 2048, NULL, 0, OPT_CLAMD},
87
-    {"MaxThreads", OPT_NUM, 10, NULL, 0, OPT_CLAMD},
88
-    {"ReadTimeout", OPT_NUM, 120, NULL, 0, OPT_CLAMD},
87
+    {"MaxThreads", OPT_NUM, 10, NULL, 0, OPT_CLAMD | OPT_MILTER},
88
+    {"ReadTimeout", OPT_NUM, 120, NULL, 0, OPT_CLAMD | OPT_MILTER},
89 89
     {"IdleTimeout", OPT_NUM, 30, NULL, 0, OPT_CLAMD},
90 90
     {"MaxDirectoryRecursion", OPT_NUM, 15, NULL, 0, OPT_CLAMD},
91 91
     {"ExcludePath", OPT_QUOTESTR, -1, NULL, 1, OPT_CLAMD},
92 92
     {"FollowDirectorySymlinks", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
93 93
     {"FollowFileSymlinks", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
94 94
     {"ExitOnOOM", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
95
-    {"Foreground", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM},
95
+    {"Foreground", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER},
96 96
     {"Debug", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM},
97 97
     {"LeaveTemporaryFiles", OPT_BOOL, 0, NULL, 0, OPT_CLAMD},
98
-    {"FixStaleSocket", OPT_BOOL, 1, NULL, 0, OPT_CLAMD},
99
-    {"User", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD},
100
-    {"AllowSupplementaryGroups", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM},
98
+    {"FixStaleSocket", OPT_BOOL, 1, NULL, 0, OPT_CLAMD | OPT_MILTER},
99
+    {"User", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD | OPT_MILTER},
100
+    {"AllowSupplementaryGroups", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER},
101 101
     {"SelfCheck", OPT_NUM, 1800, NULL, 0, OPT_CLAMD},
102 102
     {"VirusEvent", OPT_FULLSTR, -1, NULL, 0, OPT_CLAMD},
103 103
     {"ClamukoScanOnAccess", OPT_BOOL, -1, NULL, 0, OPT_CLAMD},
... ...
@@ -135,19 +135,46 @@ struct cfgoption cfg_options[] = {
135 135
 
136 136
     /* Deprecated options */
137 137
     {"MailMaxRecursion", OPT_NUM, 64, NULL, 0, OPT_CLAMD | OPT_DEPRECATED},
138
-    {"ArchiveMaxFileSize", OPT_COMPSIZE, 10485760, NULL, 0, OPT_CLAMD | OPT_DEPRECATED},
138
+    {"ArchiveMaxScanSize", OPT_COMPSIZE, 10485760, NULL, 0, OPT_CLAMD | OPT_DEPRECATED},
139 139
     {"ArchiveMaxRecursion", OPT_NUM, 8, NULL, 0, OPT_CLAMD | OPT_DEPRECATED},
140 140
     {"ArchiveMaxFiles", OPT_NUM, 1000, NULL, 0, OPT_CLAMD | OPT_DEPRECATED},
141 141
     {"ArchiveMaxCompressionRatio", OPT_NUM, 250, NULL, 0, OPT_CLAMD | OPT_DEPRECATED},
142 142
     {"ArchiveBlockMax", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_DEPRECATED},
143 143
     {"ArchiveLimitMemoryUsage", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_DEPRECATED },
144 144
 
145
+
146
+    /* Milter specific options */
147
+    {"ClamdSocket", OPT_QUOTESTR, -1, NULL, 1, OPT_MILTER},
148
+    {"MilterSocket", OPT_QUOTESTR, -1, NULL, 1, OPT_MILTER},
149
+
150
+    /* Deprecated milter options */
151
+    {"ArchiveBlockEncrypted", OPT_BOOL, 0, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
152
+    {"DatabaseDirectory", OPT_QUOTESTR, -1, DATADIR, 0, OPT_MILTER | OPT_DEPRECATED},
153
+    {"Debug", OPT_BOOL, 0, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
154
+    {"DetectBrokenExecutables", OPT_BOOL, 0, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
155
+    {"LeaveTemporaryFiles", OPT_BOOL, 0, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
156
+    {"LocalSocket", OPT_QUOTESTR, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
157
+    {"MailFollowURLs", OPT_BOOL, 0, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
158
+    {"MaxScanSize", OPT_COMPSIZE, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
159
+    {"MaxFiles", OPT_NUM, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
160
+    {"MaxRecursion", OPT_NUM, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
161
+    {"PhishingSignatures", OPT_BOOL, 1, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
162
+    {"PidFile", OPT_QUOTESTR, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
163
+    {"ScanArchive", OPT_BOOL, 1, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
164
+    {"ScanHTML", OPT_BOOL, 1, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
165
+    {"ScanMail", OPT_BOOL, 1, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
166
+    {"ScanOLE2", OPT_BOOL, 1, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
167
+    {"ScanPE", OPT_BOOL, 1, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
168
+    {"StreamMaxLength", OPT_COMPSIZE, 10485760, NULL, OPT_MILTER | OPT_DEPRECATED},
169
+    {"TCPAddr", OPT_QUOTESTR, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
170
+    {"TCPSocket", OPT_NUM, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
171
+    {"TemporaryDirectory", OPT_QUOTESTR, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED},
145 172
     {NULL, 0, 0, NULL, 0, 0}
146 173
 };
147 174
 
148 175
 static int regcfg(struct cfgstruct **copt, const char *optname, char *strarg, int numarg, short multiple);
149 176
 
150
-struct cfgstruct *getcfg(const char *cfgfile, int verbose)
177
+struct cfgstruct *getcfg(const char *cfgfile, int verbose, int toolmask)
151 178
 {
152 179
 	char buff[LINE_LENGTH], *name, *arg, *c;
153 180
 	FILE *fs;
... ...
@@ -161,7 +188,7 @@ struct cfgstruct *getcfg(const char *cfgfile, int verbose)
161 161
 	if(!pt->name)
162 162
 	    break;
163 163
 
164
-	if(regcfg(&copt, pt->name, pt->strarg ? strdup(pt->strarg) : NULL, pt->numarg, pt->multiple) < 0) {
164
+	if((pt->owner & toolmask) && regcfg(&copt, pt->name, pt->strarg ? strdup(pt->strarg) : NULL, pt->numarg, pt->multiple) < 0) {
165 165
 	    fprintf(stderr, "ERROR: Can't register new options (not enough memory)\n");
166 166
 	    freecfg(copt);
167 167
 	    return NULL;
... ...
@@ -194,7 +221,7 @@ struct cfgstruct *getcfg(const char *cfgfile, int verbose)
194 194
 	    for(i = 0; ; i++) {
195 195
 		pt = &cfg_options[i];
196 196
 		if(pt->name) {
197
-		    if(!strcmp(name, pt->name)) {
197
+		    if((pt->owner & toolmask) && !strcmp(name, pt->name)) {
198 198
 			found = 1;
199 199
 			if(pt->owner & OPT_DEPRECATED) {
200 200
 			    fprintf(stderr, "WARNING: Ignoring deprecated option %s at line %u\n", pt->name, line);
... ...
@@ -29,9 +29,11 @@
29 29
 #define OPT_FULLSTR 5 /* string argument, but get a full line */
30 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.) */
31 31
 
32
+/* don't share bits! */
32 33
 #define OPT_CLAMD 1
33 34
 #define OPT_FRESHCLAM 2
34
-#define OPT_DEPRECATED 4
35
+#define OPT_MILTER 4
36
+#define OPT_DEPRECATED 16
35 37
 
36 38
 struct cfgoption {
37 39
     const char *name;
... ...
@@ -54,7 +56,7 @@ struct cfgstruct {
54 54
 
55 55
 extern struct cfgoption cfg_options[];
56 56
 
57
-struct cfgstruct *getcfg(const char *cfgfile, int verbose);
57
+struct cfgstruct *getcfg(const char *cfgfile, int verbose, int toolmask);
58 58
 const struct cfgstruct *cfgopt(const struct cfgstruct *copt, const char *optname);
59 59
 void freecfg(struct cfgstruct *copt);
60 60
 
... ...
@@ -75,7 +75,7 @@ char *freshdbdir(void)
75 75
 
76 76
     /* try to find fresh directory */
77 77
     dbdir = cl_retdbdir();
78
-    if((copt = getcfg(CONFDIR"/freshclam.conf", 0))) {
78
+    if((copt = getcfg(CONFDIR"/freshclam.conf", 0, OPT_FRESHCLAM))) {
79 79
 	if((cpt = cfgopt(copt, "DatabaseDirectory"))->enabled || (cpt = cfgopt(copt, "DataDirectory"))->enabled) {
80 80
 	    if(strcmp(dbdir, cpt->strarg)) {
81 81
 		    char *daily = (char *) malloc(strlen(cpt->strarg) + strlen(dbdir) + 30);