git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@741 77e5149b-7576-45b1-b177-96237e5ba77b
Nigel Horne authored on 2004/08/11 19:36:25... | ... |
@@ -1,3 +1,8 @@ |
1 |
+Wed Aug 11 11:34:57 BST 2004 (njh) |
|
2 |
+---------------------------------- |
|
3 |
+ * clamav-milter: Installed a new isLocalAddr checker written by |
|
4 |
+ David Champion <dgc@uchicago.edu> |
|
5 |
+ |
|
1 | 6 |
Tue Aug 10 15:53:25 CEST 2004 (tk) |
2 | 7 |
---------------------------------- |
3 | 8 |
* clamdscan: support --disable-summary for backward compatibility (problem |
... | ... |
@@ -19,7 +24,7 @@ Mon Aug 9 02:32:49 CEST 2004 (tk) |
19 | 19 |
Sun Aug 8 22:31:12 BST 2004 (njh) |
20 | 20 |
---------------------------------- |
21 | 21 |
* libclamav/mbox.c: Started code (not yet enabled by default) to scan URLs |
22 |
- embedded in emails for viruses. |
|
22 |
+ embedded in emails for viruses. |
|
23 | 23 |
|
24 | 24 |
Sun Aug 8 20:14:04 BST 2004 (njh) |
25 | 25 |
---------------------------------- |
... | ... |
@@ -465,6 +465,7 @@ Changes |
465 | 465 |
"Denis Ustimenko" <den@uzsci.net> |
466 | 466 |
Quarantined file's names now contain the name of the virus |
467 | 467 |
0.75h 07/8/04 Some tweaking of the load balancing code |
468 |
+0.75i 11/8/04 Added David Champion <dgc@uchicago.edu> isLocalAddr routine |
|
468 | 469 |
|
469 | 470 |
BUG REPORTS |
470 | 471 |
|
... | ... |
@@ -26,6 +26,9 @@ |
26 | 26 |
* |
27 | 27 |
* Change History: |
28 | 28 |
* $Log: clamav-milter.c,v $ |
29 |
+ * Revision 1.117 2004/08/11 10:34:07 nigelhorne |
|
30 |
+ * Better isLocal handler |
|
31 |
+ * |
|
29 | 32 |
* Revision 1.116 2004/08/07 13:10:33 nigelhorne |
30 | 33 |
* Better load balancing |
31 | 34 |
* |
... | ... |
@@ -359,9 +362,9 @@ |
359 | 359 |
* Revision 1.6 2003/09/28 16:37:23 nigelhorne |
360 | 360 |
* Added -f flag use MaxThreads if --max-children not set |
361 | 361 |
*/ |
362 |
-static char const rcsid[] = "$Id: clamav-milter.c,v 1.116 2004/08/07 13:10:33 nigelhorne Exp $"; |
|
362 |
+static char const rcsid[] = "$Id: clamav-milter.c,v 1.117 2004/08/11 10:34:07 nigelhorne Exp $"; |
|
363 | 363 |
|
364 |
-#define CM_VERSION "0.75h" |
|
364 |
+#define CM_VERSION "0.75i" |
|
365 | 365 |
|
366 | 366 |
/*#define CONFDIR "/usr/local/etc"*/ |
367 | 367 |
|
... | ... |
@@ -459,6 +462,29 @@ struct header_list_struct { |
459 | 459 |
typedef struct header_list_struct *header_list_t; |
460 | 460 |
|
461 | 461 |
/* |
462 |
+ * Local addresses are those not scanned if --local is not set |
|
463 |
+ * 127.0.0.0 is not in this table since that's goverend by --outgoing |
|
464 |
+ * Andy Fiddaman <clam@fiddaman.net> added 69.254.0.0/16 |
|
465 |
+ * (Microsoft default DHCP) |
|
466 |
+ * |
|
467 |
+ * TODO: read this table in from a file (clamav.conf?) |
|
468 |
+ */ |
|
469 |
+#define PACKADDR(a, b, c, d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d)) |
|
470 |
+#define MAKEMASK(bits) (0xffffffff << (bits)) |
|
471 |
+ |
|
472 |
+static const struct cidr_net { |
|
473 |
+ uint32_t base; |
|
474 |
+ uint32_t mask; |
|
475 |
+} localNets[] = { |
|
476 |
+ /*{ PACKADDR(127, 0, 0, 0), MAKEMASK(24) }, /* 127.0.0.0/24 */ |
|
477 |
+ { PACKADDR(192, 168, 0, 0), MAKEMASK(16) }, /* 192.168.0.0/16 */ |
|
478 |
+ { PACKADDR( 10, 0, 0, 0), MAKEMASK(24) }, /* 10.0.0.0/24 */ |
|
479 |
+ { PACKADDR(172, 16, 0, 0), MAKEMASK(20) }, /* 172.16.0.0/20 */ |
|
480 |
+ { PACKADDR(169, 254, 0, 0), MAKEMASK(16) }, /* 169.254.0.0/16 */ |
|
481 |
+ { 0, 0 } |
|
482 |
+}; |
|
483 |
+ |
|
484 |
+/* |
|
462 | 485 |
* Each thread has one of these |
463 | 486 |
*/ |
464 | 487 |
struct privdata { |
... | ... |
@@ -511,6 +537,7 @@ static int sendtemplate(SMFICTX *ctx, const char *filename, FILE *sendmail, cons |
511 | 511 |
static int qfile(struct privdata *privdata, const char *virusname); |
512 | 512 |
static void setsubject(SMFICTX *ctx, const char *virusname); |
513 | 513 |
static int clamfi_gethostbyname(const char *hostname, struct hostent *hp, char *buf, size_t len); |
514 |
+static int isLocalAddr(in_addr_t addr); |
|
514 | 515 |
|
515 | 516 |
static char clamav_version[128]; |
516 | 517 |
static int fflag = 0; /* force a scan, whatever */ |
... | ... |
@@ -1609,53 +1636,14 @@ clamfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr) |
1609 | 1609 |
#endif |
1610 | 1610 |
return SMFIS_ACCEPT; |
1611 | 1611 |
} |
1612 |
- if(!lflag) { |
|
1613 |
- /* |
|
1614 |
- * Decide what constitutes a local IP address. Emails from |
|
1615 |
- * local machines are not scanned. |
|
1616 |
- * |
|
1617 |
- * TODO: read these from clamav.conf |
|
1618 |
- * |
|
1619 |
- * Better table by Damian Menscher <menscher@uiuc.edu> |
|
1620 |
- * |
|
1621 |
- * Andy Fiddaman <clam@fiddaman.net> added |
|
1622 |
- * 169.254.0.0/16 (Microsoft default DHCP) |
|
1623 |
- */ |
|
1624 |
- static const char *localAddresses[] = { |
|
1625 |
- "^127\\.0\\.0\\.1$", |
|
1626 |
- "^192\\.168\\.[0-9]+\\.[0-9]+$", |
|
1627 |
- "^10\\.[0-9]+\\.[0-9]+\\.[0-9]+$", |
|
1628 |
- "^172\\.1[6-9]\\.[0-9]+\\.[0-9]+$", |
|
1629 |
- "^172\\.2[0-9]\\.[0-9]+\\.[0-9]+$", |
|
1630 |
- "^172\\.3[0-1]\\.[0-9]+\\.[0-9]+$", |
|
1631 |
- "^169\\.254\\.[0-9]+\\.[0-9]+$", |
|
1632 |
- NULL |
|
1633 |
- }; |
|
1634 |
- const char **possible; |
|
1635 |
- |
|
1636 |
- for(possible = localAddresses; *possible; possible++) { |
|
1637 |
- int rc; |
|
1638 |
- regex_t reg; |
|
1639 |
- |
|
1640 |
- if(regcomp(®, *possible, REG_EXTENDED) != 0) { |
|
1641 |
- if(use_syslog) |
|
1642 |
- syslog(LOG_ERR, "Couldn't parse local regexp"); |
|
1643 |
- return cl_error; |
|
1644 |
- } |
|
1645 |
- |
|
1646 |
- rc = (regexec(®, remoteIP, 0, NULL, 0) == REG_NOMATCH) ? 0 : 1; |
|
1647 | 1612 |
|
1648 |
- regfree(®); |
|
1649 |
- |
|
1650 |
- if(rc) { |
|
1613 |
+ if((!lflag) && isLocalAddr(inet_addr(remoteIP))) { |
|
1651 | 1614 |
#ifdef CL_DEBUG |
1652 |
- if(use_syslog) |
|
1653 |
- syslog(LOG_DEBUG, "clamfi_connect: not scanning local messages"); |
|
1654 |
- cli_dbgmsg("clamfi_connect: not scanning outgoing messages\n"); |
|
1615 |
+ if(use_syslog) |
|
1616 |
+ syslog(LOG_DEBUG, "clamfi_connect: not scanning local messages"); |
|
1617 |
+ cli_dbgmsg("clamfi_connect: not scanning outgoing messages\n"); |
|
1655 | 1618 |
#endif |
1656 |
- return SMFIS_ACCEPT; |
|
1657 |
- } |
|
1658 |
- } |
|
1619 |
+ return SMFIS_ACCEPT; |
|
1659 | 1620 |
} |
1660 | 1621 |
|
1661 | 1622 |
return SMFIS_CONTINUE; |
... | ... |
@@ -2218,7 +2206,7 @@ clamfi_eom(SMFICTX *ctx) |
2218 | 2218 |
(void)strcpy(ptr, "\n"); |
2219 | 2219 |
|
2220 | 2220 |
/* Include the sendmail queue ID in the log */ |
2221 |
- syslog(LOG_NOTICE, "%s: %s%s", sendmailId, mess, err); |
|
2221 |
+ syslog(LOG_NOTICE, "%s: %s %s", sendmailId, mess, err); |
|
2222 | 2222 |
#ifdef CL_DEBUG |
2223 | 2223 |
cli_dbgmsg("%s\n", err); |
2224 | 2224 |
#endif |
... | ... |
@@ -3258,3 +3246,24 @@ clamfi_gethostbyname(const char *hostname, struct hostent *hp, char *buf, size_t |
3258 | 3258 |
|
3259 | 3259 |
return 0; |
3260 | 3260 |
} |
3261 |
+ |
|
3262 |
+/* |
|
3263 |
+ * David Champion <dgc@uchicago.edu> |
|
3264 |
+ * |
|
3265 |
+ * Check whether addr is on network by applying netmasks. |
|
3266 |
+ * addr must be a 32-bit integer-packed IPv4 address in network order. |
|
3267 |
+ * For example: |
|
3268 |
+ * struct in_addr IPAddress; |
|
3269 |
+ * isLocal = isLocalAddr(IPAddress.s_addr); |
|
3270 |
+ */ |
|
3271 |
+static int |
|
3272 |
+isLocalAddr(in_addr_t addr) |
|
3273 |
+{ |
|
3274 |
+ const struct cidr_net *net; |
|
3275 |
+ |
|
3276 |
+ for(net = localNets; net->base; net++) |
|
3277 |
+ if(htonl(net->base & net->mask) == (addr & htonl(net->mask))) |
|
3278 |
+ return 1; |
|
3279 |
+ |
|
3280 |
+ return 0; /* is non-local */ |
|
3281 |
+} |