Browse code

Added white list of recipients

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@72 77e5149b-7576-45b1-b177-96237e5ba77b

Nigel Horne authored on 2003/10/03 20:56:52
Showing 3 changed files
... ...
@@ -1,3 +1,7 @@
1
+Fri Oct  3 12:55:46 BST 2003 (njh)
2
+----------------------------------
3
+  * clamav-milter: added list of recipients who's email is not scanned
4
+
1 5
 Thu Oct  2 19:43:57 CEST 2003 (tk)
2 6
 ----------------------------------
3 7
   * clamd: set umask also in Foreground mode (thanks to Kelsey Cummings)
... ...
@@ -126,6 +126,9 @@ Changes
126 126
 0.60i	30/9/03	clamfi_envfrom() now correctly returns SMFIS_TEMPFAIL,
127 127
 		in a few circumstances it used to return EX_TEMPFAIL
128 128
 		Patch from Matt Sullivan <matt@sullivan.gen.nz>
129
+0.60j	1/10/03	strerror_r doesn't work on Linux, attempting workaround
130
+		Added support for hard-coded list of email addresses
131
+		who's e-mail is not scanned
129 132
 
130 133
 BUG REPORTS
131 134
 
... ...
@@ -131,9 +131,15 @@
131 131
  *	0.60i	30/9/03	clamfi_envfrom() now correctly returns SMFIS_TEMPFAIL,
132 132
  *			in a few circumstances it used to return EX_TEMPFAIL
133 133
  *			Patch from Matt Sullivan <matt@sullivan.gen.nz>
134
+ *	0.60j	1/10/03	strerror_r doesn't work on Linux, attempting workaround
135
+ *			Added support for hard-coded list of email addresses
136
+ *			who's e-mail is not scanned
134 137
  *
135 138
  * Change History:
136 139
  * $Log: clamav-milter.c,v $
140
+ * Revision 1.10  2003/10/03 11:54:53  nigelhorne
141
+ * Added white list of recipients
142
+ *
137 143
  * Revision 1.9  2003/09/30 11:53:55  nigelhorne
138 144
  * clamfi_envfrom was returning EX_TEMPFAIL in some places rather than SMFIS_TEMPFAIL
139 145
  *
... ...
@@ -147,9 +153,9 @@
147 147
  * Added -f flag use MaxThreads if --max-children not set
148 148
  *
149 149
  */
150
-static	char	const	rcsid[] = "$Id: clamav-milter.c,v 1.9 2003/09/30 11:53:55 nigelhorne Exp $";
150
+static	char	const	rcsid[] = "$Id: clamav-milter.c,v 1.10 2003/10/03 11:54:53 nigelhorne Exp $";
151 151
 
152
-#define	CM_VERSION	"0.60i"
152
+#define	CM_VERSION	"0.60j"
153 153
 
154 154
 /*#define	CONFDIR	"/usr/local/etc"*/
155 155
 
... ...
@@ -270,6 +276,13 @@ static	in_port_t	tcpSocket;
270 270
 static	const	char	*serverIP = "127.0.0.1";
271 271
 static	const	char	*postmaster = "postmaster";
272 272
 
273
+/* TODO: read in from a file */
274
+static	const	char	*ignoredEmailAddresses[] = {
275
+	/*"Mailer-Daemon@bandsman.co.uk",
276
+	"postmaster@bandsman.co.uk",*/
277
+	NULL
278
+};
279
+
273 280
 static void
274 281
 help(void)
275 282
 {
... ...
@@ -582,8 +595,8 @@ main(int argc, char **argv)
582 582
 	close(1);
583 583
 	close(2);
584 584
 	open("/dev/null", O_RDONLY);
585
-	open("/dev/console", O_WRONLY);
586
-	open("/dev/console", O_WRONLY);
585
+	if(open("/dev/console", O_WRONLY) == 1)
586
+		dup(1);
587 587
 
588 588
 	return smfi_main();
589 589
 }
... ...
@@ -706,7 +719,6 @@ clamfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr)
706 706
 			}
707 707
 		}
708 708
 	}
709
-
710 709
 	return SMFIS_CONTINUE;
711 710
 }
712 711
 
... ...
@@ -765,8 +777,19 @@ clamfi_envfrom(SMFICTX *ctx, char **argv)
765 765
 #ifdef TARGET_OS_SOLARIS	/* no strerror_r */
766 766
 				snprintf(message, sizeof(message), "pthread_cond_timedwait: %s", strerror(rc));
767 767
 #else
768
-				strerror_r(rc, buf, sizeof(buf));
769
-				snprintf(message, sizeof(message), "pthread_cond_timedwait: %s", buf);
768
+				if(strerror_r(rc, buf, sizeof(buf)) == NULL)
769
+					switch(rc) {
770
+						case EINTR:
771
+							strcpy(buf, "Interrupted system call");
772
+							break;
773
+						case ETIMEDOUT:
774
+							strcpy(buf, "Timedout");
775
+							break;
776
+						default:
777
+							strcpy(buf, "Unknown error");
778
+							break;
779
+						}
780
+				snprintf(message, sizeof(message), "pthread_cond_timedwait: (rc = %d) %s", rc, buf);
770 781
 #endif
771 782
 				if(use_syslog) {
772 783
 					if(rc == ETIMEDOUT)
... ...
@@ -984,6 +1007,7 @@ static sfsistat
984 984
 clamfi_eoh(SMFICTX *ctx)
985 985
 {
986 986
 	struct privdata *privdata = (struct privdata *)smfi_getpriv(ctx);
987
+	char **to;
987 988
 
988 989
 	if(logVerbose)
989 990
 		syslog(LOG_DEBUG, "clamfi_eoh");
... ...
@@ -996,7 +1020,48 @@ clamfi_eoh(SMFICTX *ctx)
996 996
 		return SMFIS_TEMPFAIL;
997 997
 	}
998 998
 
999
-	return SMFIS_CONTINUE;
999
+	/*
1000
+	 * See if the e-mail is only going to members of the list
1001
+	 * of users we don't scan for. If it is, don't scan, otherwise
1002
+	 * scan
1003
+	 *
1004
+	 * scan = false
1005
+	 * FORALL recipients
1006
+	 *	IF receipient NOT MEMBER OF white address list
1007
+	 *	THEN
1008
+	 *		scan = true
1009
+	 *	FI
1010
+	 * ENDFOR
1011
+	 */
1012
+	for(to = privdata->to; *to; to++) {
1013
+		const char **s;
1014
+
1015
+		for(s = ignoredEmailAddresses; *s; s++)
1016
+			if(strcasecmp(*s, *to) == 0)
1017
+				/*
1018
+				 * This recipient is on the whitelist
1019
+				 */
1020
+				break;
1021
+
1022
+		if(*s == NULL)
1023
+			/*
1024
+			 * This recipient is not on the whitelist,
1025
+			 * no need to check any further
1026
+			 */
1027
+			return SMFIS_CONTINUE;
1028
+	}
1029
+	/*
1030
+	 * Didn't find a recipient who is not on the white list, so all
1031
+	 * must be on the white list, so just accept the e-mail
1032
+	 */
1033
+	if(use_syslog)
1034
+		syslog(LOG_NOTICE, "clamfi_connect: ignoring whitelisted message");
1035
+#ifdef	CL_DEBUG
1036
+	puts("clamfi_connect: not scanning outgoing messages");
1037
+#endif
1038
+	clamfi_cleanup(ctx);
1039
+
1040
+	return SMFIS_ACCEPT;
1000 1041
 }
1001 1042
 
1002 1043
 static sfsistat