git-svn: trunk@1599
Nigel Horne authored on 2005/06/02 01:20:56... | ... |
@@ -22,9 +22,9 @@ |
22 | 22 |
* |
23 | 23 |
* For installation instructions see the file INSTALL that came with this file |
24 | 24 |
*/ |
25 |
-static char const rcsid[] = "$Id: clamav-milter.c,v 1.208 2005/05/28 11:37:27 nigelhorne Exp $"; |
|
25 |
+static char const rcsid[] = "$Id: clamav-milter.c,v 1.209 2005/06/01 16:18:03 nigelhorne Exp $"; |
|
26 | 26 |
|
27 |
-#define CM_VERSION "0.85e" |
|
27 |
+#define CM_VERSION "0.85f" |
|
28 | 28 |
|
29 | 29 |
#if HAVE_CONFIG_H |
30 | 30 |
#include "clamav-config.h" |
... | ... |
@@ -351,7 +351,7 @@ static int cl_error = SMFIS_TEMPFAIL; /* |
351 | 351 |
* an error. Patch from |
352 | 352 |
* Joe Talbott <josepht@cstone.net> |
353 | 353 |
*/ |
354 |
-static int readTimeout = CL_DEFAULT_SCANTIMEOUT; /* |
|
354 |
+static int readTimeout = 0; /* |
|
355 | 355 |
* number of seconds to wait for clamd to |
356 | 356 |
* respond, see ReadTimeout in clamd.conf |
357 | 357 |
*/ |
... | ... |
@@ -510,7 +510,7 @@ main(int argc, char **argv) |
510 | 510 |
{ |
511 | 511 |
extern char *optarg; |
512 | 512 |
int i, Bflag = 0; |
513 |
- const char *cfgfile = CL_DEFAULT_CFG; |
|
513 |
+ char *cfgfile = NULL; |
|
514 | 514 |
const struct cfgstruct *cpt; |
515 | 515 |
char version[VERSION_LENGTH + 1]; |
516 | 516 |
pthread_t tid; |
... | ... |
@@ -853,7 +853,11 @@ main(int argc, char **argv) |
853 | 853 |
/* |
854 | 854 |
* Sanity checks on the clamav configuration file |
855 | 855 |
*/ |
856 |
- if((copt = parsecfg(cfgfile, 1)) == NULL) { |
|
856 |
+ if(cfgfile == NULL) { |
|
857 |
+ cfgfile = cli_malloc(strlen(CONFDIR) + 12); |
|
858 |
+ sprintf(cfgfile, "%s/clamd.conf", CONFDIR); |
|
859 |
+ } |
|
860 |
+ if((copt = getcfg(cfgfile, 1)) == NULL) { |
|
857 | 861 |
fprintf(stderr, _("%s: Can't parse the config file %s\n"), |
858 | 862 |
argv[0], cfgfile); |
859 | 863 |
return EX_CONFIG; |
... | ... |
@@ -918,7 +922,7 @@ main(int argc, char **argv) |
918 | 918 |
#endif |
919 | 919 |
} |
920 | 920 |
|
921 |
- if((cpt = cfgopt(copt, "User")) != NULL) { |
|
921 |
+ if(((cpt = cfgopt(copt, "User")) != NULL) && cpt->enabled) { |
|
922 | 922 |
const struct passwd *user; |
923 | 923 |
|
924 | 924 |
if((user = getpwnam(cpt->strarg)) == NULL) { |
... | ... |
@@ -1022,10 +1026,10 @@ main(int argc, char **argv) |
1022 | 1022 |
* If the --max-children flag isn't set, see if MaxThreads |
1023 | 1023 |
* is set in the config file |
1024 | 1024 |
*/ |
1025 |
- if((max_children == 0) && ((cpt = cfgopt(copt, "MaxThreads")) != NULL)) |
|
1025 |
+ if((max_children == 0) && ((cpt = cfgopt(copt, "MaxThreads")) != NULL) && cpt->enabled) |
|
1026 | 1026 |
max_children = cpt->numarg; |
1027 | 1027 |
|
1028 |
- if((cpt = cfgopt(copt, "ReadTimeout")) != NULL) { |
|
1028 |
+ if(((cpt = cfgopt(copt, "ReadTimeout")) != NULL) && cpt->enabled) { |
|
1029 | 1029 |
readTimeout = cpt->numarg; |
1030 | 1030 |
|
1031 | 1031 |
if(readTimeout < 0) { |
... | ... |
@@ -1033,9 +1037,10 @@ main(int argc, char **argv) |
1033 | 1033 |
argv[0], cfgfile); |
1034 | 1034 |
return EX_CONFIG; |
1035 | 1035 |
} |
1036 |
- } |
|
1036 |
+ } else |
|
1037 |
+ readTimeout = 0; |
|
1037 | 1038 |
|
1038 |
- if((cpt = cfgopt(copt, "StreamMaxLength")) != NULL) { |
|
1039 |
+ if(((cpt = cfgopt(copt, "StreamMaxLength")) != NULL) && cpt->enabled) { |
|
1039 | 1040 |
if(cpt->numarg < 0) { |
1040 | 1041 |
fprintf(stderr, _("%s: StreamMaxLength must not be negative in %s\n"), |
1041 | 1042 |
argv[0], cfgfile); |
... | ... |
@@ -1044,10 +1049,10 @@ main(int argc, char **argv) |
1044 | 1044 |
streamMaxLength = (long)cpt->numarg; |
1045 | 1045 |
} |
1046 | 1046 |
|
1047 |
- if(cfgopt(copt, "LogSyslog")) { |
|
1047 |
+ if(cfgopt(copt, "LogSyslog")->enabled) { |
|
1048 | 1048 |
int fac = LOG_LOCAL6; |
1049 | 1049 |
|
1050 |
- if(cfgopt(copt, "LogVerbose")) { |
|
1050 |
+ if(cfgopt(copt, "LogVerbose")->enabled) { |
|
1051 | 1051 |
logVerbose = 1; |
1052 | 1052 |
#if ((SENDMAIL_VERSION_A > 8) || ((SENDMAIL_VERSION_A == 8) && (SENDMAIL_VERSION_B >= 13))) |
1053 | 1053 |
smfi_setdbg(6); |
... | ... |
@@ -1055,7 +1060,7 @@ main(int argc, char **argv) |
1055 | 1055 |
} |
1056 | 1056 |
use_syslog = 1; |
1057 | 1057 |
|
1058 |
- if((cpt = cfgopt(copt, "LogFacility")) != NULL) |
|
1058 |
+ if(((cpt = cfgopt(copt, "LogFacility")) != NULL) && cpt->enabled) |
|
1059 | 1059 |
if((fac = logg_facility(cpt->strarg)) == -1) { |
1060 | 1060 |
fprintf(stderr, "%s: LogFacility: %s: No such facility\n", |
1061 | 1061 |
argv[0], cpt->strarg); |
... | ... |
@@ -1084,13 +1089,13 @@ main(int argc, char **argv) |
1084 | 1084 |
if(loadDatabase() != 0) |
1085 | 1085 |
return EX_CONFIG; |
1086 | 1086 |
numServers = 1; |
1087 |
- } else if((cpt = cfgopt(copt, "LocalSocket")) != NULL) { |
|
1087 |
+ } else if(((cpt = cfgopt(copt, "LocalSocket")) != NULL) && cpt->enabled) { |
|
1088 | 1088 |
#ifdef SESSION |
1089 | 1089 |
struct sockaddr_un server; |
1090 | 1090 |
#endif |
1091 | 1091 |
char *sockname = NULL; |
1092 | 1092 |
|
1093 |
- if(cfgopt(copt, "TCPSocket") != NULL) { |
|
1093 |
+ if(cfgopt(copt, "TCPSocket")->enabled) { |
|
1094 | 1094 |
fprintf(stderr, _("%s: You can select one server type only (local/TCP) in %s\n"), |
1095 | 1095 |
argv[0], cfgfile); |
1096 | 1096 |
return EX_CONFIG; |
... | ... |
@@ -1159,7 +1164,7 @@ main(int argc, char **argv) |
1159 | 1159 |
* connecting to the localserver via a UNIX domain socket |
1160 | 1160 |
*/ |
1161 | 1161 |
numServers = 1; |
1162 |
- } else if((cpt = cfgopt(copt, "TCPSocket")) != NULL) { |
|
1162 |
+ } else if(((cpt = cfgopt(copt, "TCPSocket")) != NULL) && cpt->enabled) { |
|
1163 | 1163 |
int activeServers; |
1164 | 1164 |
|
1165 | 1165 |
/* |
... | ... |
@@ -1238,7 +1243,7 @@ main(int argc, char **argv) |
1238 | 1238 |
cli_warnmsg(_("Can't talk to clamd server %s on port %d\n"), |
1239 | 1239 |
hostname, tcpSocket); |
1240 | 1240 |
if(serverIPs[i] == (int)inet_addr("127.0.0.1")) { |
1241 |
- if(cfgopt(copt, "TCPAddr") != NULL) |
|
1241 |
+ if(cfgopt(copt, "TCPAddr")->enabled) |
|
1242 | 1242 |
cli_warnmsg(_("Check the value for TCPAddr in %s\n"), cfgfile); |
1243 | 1243 |
} else |
1244 | 1244 |
cli_warnmsg(_("Check the value for TCPAddr in clamd.conf on %s\n"), hostname); |
... | ... |
@@ -1310,9 +1315,9 @@ main(int argc, char **argv) |
1310 | 1310 |
|
1311 | 1311 |
if(((quarantine_dir == NULL) && localSocket) || !external) { |
1312 | 1312 |
/* set the temporary dir */ |
1313 |
- if((cpt = cfgopt(copt, "TemporaryDirectory"))) { |
|
1313 |
+ if((cpt = cfgopt(copt, "TemporaryDirectory")) && cpt->enabled) { |
|
1314 | 1314 |
tmpdir = cpt->strarg; |
1315 |
- cl_settempdir(tmpdir, (short)(cfgopt(copt, "LeaveTemporaryFiles") != NULL)); |
|
1315 |
+ cl_settempdir(tmpdir, (short)(cfgopt(copt, "LeaveTemporaryFiles")->enabled)); |
|
1316 | 1316 |
} else if((tmpdir = getenv("TMPDIR")) == (char *)NULL) |
1317 | 1317 |
if((tmpdir = getenv("TMP")) == (char *)NULL) |
1318 | 1318 |
if((tmpdir = getenv("TEMP")) == (char *)NULL) |
... | ... |
@@ -1336,7 +1341,7 @@ main(int argc, char **argv) |
1336 | 1336 |
} else |
1337 | 1337 |
tmpdir = NULL; |
1338 | 1338 |
|
1339 |
- if(!cfgopt(copt, "Foreground")) { |
|
1339 |
+ if(!cfgopt(copt, "Foreground")->enabled) { |
|
1340 | 1340 |
#ifdef CL_DEBUG |
1341 | 1341 |
printf(_("When debugging it is recommended that you use Foreground mode in %s\n"), cfgfile); |
1342 | 1342 |
puts(_("\tso that you can see all of the messages")); |
... | ... |
@@ -1357,7 +1362,7 @@ main(int argc, char **argv) |
1357 | 1357 |
#ifndef CL_DEBUG |
1358 | 1358 |
close(1); |
1359 | 1359 |
|
1360 |
- if((cpt = cfgopt(copt, "LogFile"))) { |
|
1360 |
+ if((cpt = cfgopt(copt, "LogFile")) && cpt->enabled) { |
|
1361 | 1361 |
logFile = cpt->strarg; |
1362 | 1362 |
|
1363 | 1363 |
#if defined(MSDOS) || defined(C_CYGWIN) || defined(WIN32) |
... | ... |
@@ -1397,17 +1402,14 @@ main(int argc, char **argv) |
1397 | 1397 |
|
1398 | 1398 |
#endif /*!CL_DEBUG*/ |
1399 | 1399 |
|
1400 |
- if(cfgopt(copt, "LogTime")) |
|
1400 |
+ if(cfgopt(copt, "LogTime")->enabled) |
|
1401 | 1401 |
logg_time = 1; |
1402 |
- if(cfgopt(copt, "LogFileUnlock")) |
|
1402 |
+ if(cfgopt(copt, "LogFileUnlock")->enabled) |
|
1403 | 1403 |
logg_lock = 0; |
1404 |
- if(cfgopt(copt, "LogClean")) |
|
1404 |
+ if(cfgopt(copt, "LogClean")->enabled) |
|
1405 | 1405 |
logok = 1; |
1406 |
- if((cpt = cfgopt(copt, "LogFileMaxSize"))) |
|
1406 |
+ if((cpt = cfgopt(copt, "LogFileMaxSize")) != NULL) |
|
1407 | 1407 |
logg_size = cpt->numarg; |
1408 |
- else |
|
1409 |
- logg_size = CL_DEFAULT_LOGSIZE; |
|
1410 |
- |
|
1411 | 1408 |
|
1412 | 1409 |
#ifdef HAVE_SETPGRP |
1413 | 1410 |
#ifdef SETPGRP_VOID |
... | ... |
@@ -1427,55 +1429,53 @@ main(int argc, char **argv) |
1427 | 1427 |
if(!external) { |
1428 | 1428 |
/* TODO: read the limits from clamd.conf */ |
1429 | 1429 |
|
1430 |
- if(cfgopt(copt, "DisableDefaultScanOptions")) { |
|
1431 |
- options &= ~CL_SCAN_STDOPT; |
|
1432 |
- if(!cfgopt(copt, "ScanMail")) |
|
1433 |
- printf(_("%s: ScanMail not defined in %s (needed without --external), enabling\n"), |
|
1434 |
- argv[0], cfgfile); |
|
1435 |
- } |
|
1430 |
+ if(!cfgopt(copt, "ScanMail")->enabled) |
|
1431 |
+ printf(_("%s: ScanMail not defined in %s (needed without --external), enabling\n"), |
|
1432 |
+ argv[0], cfgfile); |
|
1433 |
+ |
|
1436 | 1434 |
options |= CL_SCAN_MAIL; /* no choice */ |
1437 |
- if(!cfgopt(copt, "ScanRAR")) |
|
1438 |
- options |= CL_SCAN_DISABLERAR; |
|
1439 |
- if(cfgopt(copt, "ArchiveBlockEncrypted")) |
|
1435 |
+ /*if(!cfgopt(copt, "ScanRAR")->enabled) |
|
1436 |
+ options |= CL_SCAN_DISABLERAR;*/ |
|
1437 |
+ if(cfgopt(copt, "ArchiveBlockEncrypted")->enabled) |
|
1440 | 1438 |
options |= CL_SCAN_BLOCKENCRYPTED; |
1441 |
- if(cfgopt(copt, "ArchiveBlockMax")) |
|
1439 |
+ if(cfgopt(copt, "ArchiveBlockMax")->enabled) |
|
1442 | 1440 |
options |= CL_SCAN_BLOCKMAX; |
1443 |
- if(cfgopt(copt, "ScanPE")) |
|
1441 |
+ if(cfgopt(copt, "ScanPE")->enabled) |
|
1444 | 1442 |
options |= CL_SCAN_PE; |
1445 |
- if(cfgopt(copt, "DetectBrokenExecutables")) |
|
1443 |
+ if(cfgopt(copt, "DetectBrokenExecutables")->enabled) |
|
1446 | 1444 |
options |= CL_SCAN_BLOCKBROKEN; |
1447 |
- if(cfgopt(copt, "MailFollowURLs")) |
|
1445 |
+ if(cfgopt(copt, "MailFollowURLs")->enabled) |
|
1448 | 1446 |
options |= CL_SCAN_MAILURL; |
1449 |
- if(cfgopt(copt, "ScanOLE2")) |
|
1447 |
+ if(cfgopt(copt, "ScanOLE2")->enabled) |
|
1450 | 1448 |
options |= CL_SCAN_OLE2; |
1451 |
- if(cfgopt(copt, "ScanHTML")) |
|
1449 |
+ if(cfgopt(copt, "ScanHTML")->enabled) |
|
1452 | 1450 |
options |= CL_SCAN_HTML; |
1453 | 1451 |
|
1454 | 1452 |
memset(&limits, '\0', sizeof(struct cl_limits)); |
1455 | 1453 |
|
1456 |
- if(cfgopt(copt, "ScanArchive")) { |
|
1454 |
+ if(cfgopt(copt, "ScanArchive")->enabled) { |
|
1457 | 1455 |
options |= CL_SCAN_ARCHIVE; |
1458 |
- if((cpt = cfgopt(copt, "ArchiveMaxFileSize")) != NULL) |
|
1456 |
+ if(((cpt = cfgopt(copt, "ArchiveMaxFileSize")) != NULL) && cpt->enabled) |
|
1459 | 1457 |
limits.maxfilesize = cpt->numarg; |
1460 | 1458 |
else |
1461 | 1459 |
limits.maxfilesize = 10485760; |
1462 | 1460 |
|
1463 |
- if((cpt = cfgopt(copt, "ArchiveMaxRecursion")) != NULL) |
|
1461 |
+ if(((cpt = cfgopt(copt, "ArchiveMaxRecursion")) != NULL) && cpt->enabled) |
|
1464 | 1462 |
limits.maxreclevel = cpt->numarg; |
1465 | 1463 |
else |
1466 | 1464 |
limits.maxreclevel = 8; |
1467 | 1465 |
|
1468 |
- if((cpt = cfgopt(copt, "ArchiveMaxFiles")) != NULL) |
|
1466 |
+ if(((cpt = cfgopt(copt, "ArchiveMaxFiles")) != NULL) && cpt->enabled) |
|
1469 | 1467 |
limits.maxfiles = cpt->numarg; |
1470 | 1468 |
else |
1471 | 1469 |
limits.maxfiles = 1000; |
1472 | 1470 |
|
1473 |
- if((cpt = cfgopt(copt, "ArchiveMaxCompressionRatio")) != NULL) |
|
1471 |
+ if(((cpt = cfgopt(copt, "ArchiveMaxCompressionRatio")) != NULL) && cpt->enabled) |
|
1474 | 1472 |
limits.maxratio = cpt->numarg; |
1475 | 1473 |
else |
1476 | 1474 |
limits.maxratio = 250; |
1477 | 1475 |
|
1478 |
- if(cfgopt(copt, "ArchiveLimitMemoryUsage") != NULL) |
|
1476 |
+ if(cfgopt(copt, "ArchiveLimitMemoryUsage")->enabled) |
|
1479 | 1477 |
limits.archivememlim = 1; |
1480 | 1478 |
else |
1481 | 1479 |
limits.archivememlim = 0; |
... | ... |
@@ -1488,7 +1488,7 @@ main(int argc, char **argv) |
1488 | 1488 |
#endif |
1489 | 1489 |
pthread_create(&tid, NULL, watchdog, NULL); |
1490 | 1490 |
|
1491 |
- if((cpt = cfgopt(copt, "PidFile")) != NULL) |
|
1491 |
+ if(((cpt = cfgopt(copt, "PidFile")) != NULL) && cpt->enabled) |
|
1492 | 1492 |
pidFile = cpt->strarg; |
1493 | 1493 |
|
1494 | 1494 |
broadcast(_("Starting clamav-milter")); |
... | ... |
@@ -1539,7 +1539,7 @@ main(int argc, char **argv) |
1539 | 1539 |
chdir("/tmp"); |
1540 | 1540 |
#endif |
1541 | 1541 |
|
1542 |
- if(cfgopt(copt, "FixStaleSocket")) { |
|
1542 |
+ if(cfgopt(copt, "FixStaleSocket")->enabled) { |
|
1543 | 1543 |
/* |
1544 | 1544 |
* Get the incoming socket details - the way sendmail talks to |
1545 | 1545 |
* us |
... | ... |
@@ -4778,7 +4778,7 @@ loadDatabase(void) |
4778 | 4778 |
* First time through, find out in which directory the signature |
4779 | 4779 |
* databases are |
4780 | 4780 |
*/ |
4781 |
- if((cpt = cfgopt(copt, "DatabaseDirectory")) || (cpt = cfgopt(copt, "DataDirectory"))) |
|
4781 |
+ if(((cpt = cfgopt(copt, "DatabaseDirectory")) || (cpt = cfgopt(copt, "DataDirectory"))) && cpt->enabled) |
|
4782 | 4782 |
dbdir = cpt->strarg; |
4783 | 4783 |
else |
4784 | 4784 |
dbdir = cl_retdbdir(); |
... | ... |
@@ -5037,7 +5037,7 @@ logger(const char *mess) |
5037 | 5037 |
#else |
5038 | 5038 |
FILE *fout; |
5039 | 5039 |
|
5040 |
- if(cfgopt(copt, "Foreground")) |
|
5040 |
+ if(cfgopt(copt, "Foreground")->enabled) |
|
5041 | 5041 |
fout = stderr; |
5042 | 5042 |
else |
5043 | 5043 |
fout = fopen(logFile, "a"); |