Browse code

Various changes

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

Nigel Horne authored on 2004/04/22 00:27:47
Showing 2 changed files
... ...
@@ -335,6 +335,11 @@ Changes
335 335
 		Always add X-Virus-Scanned
336 336
 		If hostaddr is NULL assume it's a local connection. This
337 337
 		is probably a safe assumption but it should be verified
338
+0.70p	20/4/04	If /dev/console fails to open, open /dev/null instead on fds 1
339
+			and 2
340
+		TCP_WRAPPERS code now uses inet_ntop()
341
+		Simplify virus string
342
+		Sort out tabs in the hard coded e-mail message
338 343
 
339 344
 BUG REPORTS
340 345
 
... ...
@@ -336,9 +336,17 @@
336 336
  *			Always add X-Virus-Scanned
337 337
  *			If hostaddr is NULL assume it's a local connection. This
338 338
  *			is probably a safe assumption but it should be verified
339
+ *	0.70p	20/4/04	If /dev/console fails to open, open /dev/null instead on
340
+ *			fds 1 and 2
341
+ *			TCP_WRAPPERS code now uses inet_ntop()
342
+ *			Simplify virus string
343
+ *			Sort out tabs in the hard coded e-mail message
339 344
  *
340 345
  * Change History:
341 346
  * $Log: clamav-milter.c,v $
347
+ * Revision 1.80  2004/04/21 15:27:02  nigelhorne
348
+ * Various changes
349
+ *
342 350
  * Revision 1.79  2004/04/20 14:15:01  nigelhorne
343 351
  * Sorted out X- headers and handle hostaddr == NULL
344 352
  *
... ...
@@ -561,9 +569,9 @@
561 561
  * Revision 1.6  2003/09/28 16:37:23  nigelhorne
562 562
  * Added -f flag use MaxThreads if --max-children not set
563 563
  */
564
-static	char	const	rcsid[] = "$Id: clamav-milter.c,v 1.79 2004/04/20 14:15:01 nigelhorne Exp $";
564
+static	char	const	rcsid[] = "$Id: clamav-milter.c,v 1.80 2004/04/21 15:27:02 nigelhorne Exp $";
565 565
 
566
-#define	CM_VERSION	"0.70o"
566
+#define	CM_VERSION	"0.70p"
567 567
 
568 568
 /*#define	CONFDIR	"/usr/local/etc"*/
569 569
 
... ...
@@ -1291,7 +1299,8 @@ main(int argc, char **argv)
1291 1291
 		close(1);
1292 1292
 		close(2);
1293 1293
 		open("/dev/null", O_RDONLY);
1294
-		if(open("/dev/console", O_WRONLY) == 1)
1294
+		if((open("/dev/console", O_WRONLY) == 1) ||
1295
+		   (open("/dev/null", O_WRONLY) == 1))
1295 1296
 			dup(1);
1296 1297
 #ifdef HAVE_SETPGRP
1297 1298
 #ifdef SETPGRP_VOID
... ...
@@ -1635,11 +1644,14 @@ clamfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr)
1635 1635
 		if((hp = gethostbyname(hostmail)) == NULL) {
1636 1636
 			if(use_syslog)
1637 1637
 				syslog(LOG_WARNING, "Access Denied: Host Unknown (%s)", hostname);
1638
-			return SMFIS_TEMPFAIL;
1638
+			return cl_error;
1639 1639
 		}
1640 1640
 
1641
-		/* inet_ntop? */
1641
+#ifdef HAVE_INET_NTOP
1642
+		(void)inet_ntop(AF_INET, &((struct sockaddr_in *)(hp->h_addr))->sin_addr, ip, sizeof(ip));
1643
+#else
1642 1644
 		strcpy(ip, (char *)inet_ntoa(*(struct in_addr *)hp->h_addr));
1645
+#endif
1643 1646
 
1644 1647
 		/*
1645 1648
 		 * Ask is this is a allowed name or IP number
... ...
@@ -2097,7 +2109,7 @@ clamfi_eom(SMFICTX *ctx)
2097 2097
 		return cl_error;
2098 2098
 	}
2099 2099
 
2100
-	if(strstr(mess, "FOUND") == NULL) {
2100
+	if((ptr = strstr(mess, "FOUND")) == NULL) {
2101 2101
 		if(!nflag)
2102 2102
 			smfi_addheader(ctx, "X-Virus-Status", "Clean");
2103 2103
 
... ...
@@ -2127,55 +2139,58 @@ clamfi_eom(SMFICTX *ctx)
2127 2127
 			}
2128 2128
 		}
2129 2129
 	} else {
2130
-		int i;
2131
-		char **to, *err;
2132 2130
 		char reject[1024];
2131
+		char **to;
2132
+
2133
+		*ptr = '\0';	/* Remove the "FOUND" word */
2133 2134
 
2134 2135
 		if(!nflag)
2135 2136
 			smfi_addheader(ctx, "X-Virus-Status", "Infected");
2136 2137
 
2137
-		/*
2138
-		 * Setup err as a list of recipients
2139
-		 */
2140
-		err = (char *)cli_malloc(1024);
2138
+		if(use_syslog) {
2139
+			/*
2140
+			 * Setup err as a list of recipients
2141
+			 */
2142
+			char *err = (char *)cli_malloc(1024);
2143
+			int i;
2141 2144
 
2142
-		if(err == NULL) {
2143
-			clamfi_cleanup(ctx);
2144
-			return cl_error;
2145
-		}
2145
+			if(err == NULL) {
2146
+				clamfi_cleanup(ctx);
2147
+				return cl_error;
2148
+			}
2146 2149
 
2147
-		/*
2148
-		 * Use snprintf rather than printf since we don't know the
2149
-		 * length of privdata->from and may get a buffer overrun
2150
-		 */
2151
-		snprintf(err, 1023, "Intercepted virus from %s to",
2152
-			privdata->from);
2150
+			/*
2151
+			 * Use snprintf rather than printf since we don't know the
2152
+			 * length of privdata->from and may get a buffer overrun
2153
+			 */
2154
+			snprintf(err, 1023, "Intercepted virus from %s to",
2155
+				privdata->from);
2153 2156
 
2154
-		ptr = strchr(err, '\0');
2157
+			ptr = strchr(err, '\0');
2155 2158
 
2156
-		i = 1024;
2159
+			i = 1024;
2157 2160
 
2158
-		for(to = privdata->to; *to; to++) {
2159
-			/*
2160
-			 * Re-alloc if we are about run out of buffer space
2161
-			 */
2162
-			if(&ptr[strlen(*to) + 2] >= &err[i]) {
2163
-				i += 1024;
2164
-				err = realloc(err, i);
2165
-				ptr = strchr(err, '\0');
2161
+			for(to = privdata->to; *to; to++) {
2162
+				/*
2163
+				 * Re-alloc if we are about run out of buffer space
2164
+				 */
2165
+				if(&ptr[strlen(*to) + 2] >= &err[i]) {
2166
+					i += 1024;
2167
+					err = realloc(err, i);
2168
+					ptr = strchr(err, '\0');
2169
+				}
2170
+				ptr = strrcpy(ptr, " ");
2171
+				ptr = strrcpy(ptr, *to);
2166 2172
 			}
2167
-			ptr = strrcpy(ptr, " ");
2168
-			ptr = strrcpy(ptr, *to);
2169
-		}
2170
-		(void)strcpy(ptr, "\n");
2173
+			(void)strcpy(ptr, "\n");
2171 2174
 
2172
-		if(use_syslog)
2173 2175
 			/* Include the sendmail queue ID in the log */
2174 2176
 			syslog(LOG_NOTICE, "%s: %s %s", sendmailId, mess, err);
2175 2177
 #ifdef	CL_DEBUG
2176
-		cli_dbgmsg("%s\n", err);
2178
+			cli_dbgmsg("%s\n", err);
2177 2179
 #endif
2178
-		free(err);
2180
+			free(err);
2181
+		}
2179 2182
 
2180 2183
 		if(!qflag) {
2181 2184
 			char cmd[128];
... ...
@@ -2224,23 +2239,23 @@ clamfi_eom(SMFICTX *ctx)
2224 2224
 				if((templatefile == NULL) ||
2225 2225
 				   (sendtemplate(templatefile, sendmail, mess) < 0)) {
2226 2226
 					if(bflag)
2227
-						fputs("A message you sent to\n\t", sendmail);
2227
+						fputs("A message you sent to\n", sendmail);
2228 2228
 					else if(pflag)
2229 2229
 						/*
2230 2230
 						 * The message is only going to the
2231 2231
 						 * postmaster, so include some useful
2232 2232
 						 * information
2233 2233
 						 */
2234
-						fprintf(sendmail, "The message %s sent from %s to\n\t",
2234
+						fprintf(sendmail, "The message %s sent from %s to\n",
2235 2235
 							sendmailId, from);
2236 2236
 					else
2237
-						fprintf(sendmail, "A message sent from %s to\n\t",
2237
+						fprintf(sendmail, "A message sent from %s to\n",
2238 2238
 							from);
2239 2239
 
2240 2240
 					for(to = privdata->to; *to; to++)
2241
-						fprintf(sendmail, "%s\n", *to);
2242
-					fputs("contained a virus and has not been delivered.\n\t", sendmail);
2243
-					fputs(mess, sendmail);
2241
+						fprintf(sendmail, "\t%s\n", *to);
2242
+					/* skip over 'stream: ' at the start */
2243
+					fprintf(sendmail, "contained %sand has not been delivered.\n", &mess[8]);
2244 2244
 
2245 2245
 					if(privdata->filename != NULL)
2246 2246
 						fprintf(sendmail, "\nThe message in question has been quarantined as %s\n", privdata->filename);
... ...
@@ -2307,7 +2322,8 @@ clamfi_eom(SMFICTX *ctx)
2307 2307
 		else
2308 2308
 			rc = SMFIS_DISCARD;
2309 2309
 
2310
-		snprintf(reject, sizeof(reject) - 1, "Virus detected by ClamAV - http://www.clamav.net - %s", mess);
2310
+		/* skip over 'stream: ' at the start */
2311
+		snprintf(reject, sizeof(reject) - 1, "%sdetected by ClamAV - http://www.clamav.net", &mess[8]);
2311 2312
 		smfi_setreply(ctx, "550", "5.7.1", reject);
2312 2313
 	}
2313 2314
 	clamfi_cleanup(ctx);