Browse code

Added Hflag

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

Nigel Horne authored on 2004/02/09 20:08:02
Showing 4 changed files
... ...
@@ -1,3 +1,8 @@
1
+Mon Feb  9 11:09:56 GMT 2004 (njh)
2
+----------------------------------
3
+  * clamav-milter:	Added --headers patch from "Leonid Zeitlin"
4
+	<lz@europe.com>, though a lot of people have requested it!
5
+
1 6
 Mon Feb  9 02:04:36 CET 2004 (tk)
2 7
 ---------------------------------
3 8
   * freshclam: work-around for potential database downgrade (subtle problem
... ...
@@ -220,6 +220,7 @@ Changes
220 220
 		<Jim.Allen@Heartsine.co.uk>
221 221
 0.66l	7/2/04	Updated URL reference
222 222
  		Added new config.h mechanism
223
+0.66m	9/2/04	Added Hflag from "Leonid Zeitlin" <lz@europe.com>
223 224
 
224 225
 BUG REPORTS
225 226
 
... ...
@@ -223,9 +223,13 @@
223 223
  *			<Jim.Allen@Heartsine.co.uk>
224 224
  *	0.66l	7/2/04	Updated URL reference
225 225
  *			Added new config.h mechanism
226
+ *	0.66m	9/2/04	Added Hflag from "Leonid Zeitlin" <lz@europe.com>
226 227
  *
227 228
  * Change History:
228 229
  * $Log: clamav-milter.c,v $
230
+ * Revision 1.44  2004/02/09 11:05:33  nigelhorne
231
+ * Added Hflag
232
+ *
229 233
  * Revision 1.43  2004/02/07 12:16:20  nigelhorne
230 234
  * Added config.h
231 235
  *
... ...
@@ -340,9 +344,9 @@
340 340
  * Revision 1.6  2003/09/28 16:37:23  nigelhorne
341 341
  * Added -f flag use MaxThreads if --max-children not set
342 342
  */
343
-static	char	const	rcsid[] = "$Id: clamav-milter.c,v 1.43 2004/02/07 12:16:20 nigelhorne Exp $";
343
+static	char	const	rcsid[] = "$Id: clamav-milter.c,v 1.44 2004/02/09 11:05:33 nigelhorne Exp $";
344 344
 
345
-#define	CM_VERSION	"0.66l"
345
+#define	CM_VERSION	"0.66m"
346 346
 
347 347
 /*#define	CONFDIR	"/usr/local/etc"*/
348 348
 
... ...
@@ -415,6 +419,18 @@ static	char	const	rcsid[] = "$Id: clamav-milter.c,v 1.43 2004/02/07 12:16:20 nig
415 415
  *	others could be bounced properly.
416 416
  */
417 417
 
418
+struct header_node_t {
419
+	char *header;
420
+	struct header_node_t *next;
421
+};
422
+
423
+struct header_list_struct {
424
+	struct header_node_t *first;
425
+	struct header_node_t *last;
426
+};
427
+
428
+typedef struct header_list_struct *header_list_t;
429
+
418 430
 /*
419 431
  * Each thread has one of these
420 432
  */
... ...
@@ -430,6 +446,7 @@ struct	privdata {
430 430
 	char	*filename;	/* Where to store the message in quarantine */
431 431
 	u_char	*body;		/* body of the message if Sflag is set */
432 432
 	size_t	bodyLen;	/* number of bytes in body */
433
+	header_list_t headers;	/* Message headers */
433 434
 };
434 435
 
435 436
 static	int		pingServer(int serverNumber);
... ...
@@ -448,6 +465,10 @@ static	int		clamfi_send(const struct privdata *privdata, size_t len, const char
448 448
 static	char		*strrcpy(char *dest, const char *source);
449 449
 static	int		clamd_recv(int sock, char *buf, size_t len);
450 450
 static	off_t		updateSigFile(void);
451
+static	header_list_t	header_list_new(void);
452
+static	void	header_list_free(header_list_t list);
453
+static	void	header_list_add(header_list_t list, const char *headerf, const char *headerv);
454
+static	void	header_list_print(header_list_t list, FILE *fp);
451 455
 
452 456
 static	char	clamav_version[128];
453 457
 static	int	fflag = 0;	/* force a scan, whatever */
... ...
@@ -493,6 +514,10 @@ static	int	rejectmail = 1;	/*
493 493
 				 * Send a 550 rejection when a virus is
494 494
 				 * found
495 495
 				 */
496
+static	int	hflag = 0;	/*
497
+				 * Include original message headers in
498
+				 * report
499
+				 */
496 500
 static	int	cl_error = SMFIS_TEMPFAIL; /*
497 501
 				 * If an error occurs, return
498 502
 				 * this status. Allows messages
... ...
@@ -548,6 +573,7 @@ help(void)
548 548
 	puts("\t--dont-scan-on-error\t-d\tPass e-mails through unscanned if a system error occurs.");
549 549
 	puts("\t--force-scan\t\t-f\tForce scan all messages (overrides (-o and -l).");
550 550
 	puts("\t--help\t\t\t-h\tThis message.");
551
+	puts("\t--headers\t\t-H\tInclude original message headers in the report.");
551 552
 	puts("\t--local\t\t\t-l\tScan messages sent from machines on our LAN.");
552 553
 	puts("\t--outgoing\t\t-o\tScan outgoing messages from this machine.");
553 554
 	puts("\t--noreject\t\t-N\tDon't reject viruses, silently throw them away.");
... ...
@@ -608,9 +634,9 @@ main(int argc, char **argv)
608 608
 	for(;;) {
609 609
 		int opt_index = 0;
610 610
 #ifdef	CL_DEBUG
611
-		const char *args = "bc:DfF:lm:nNop:PqQ:dhs:SU:Vx:";
611
+		const char *args = "bc:DfF:lm:nNop:PqQ:dhHs:SU:Vx:";
612 612
 #else
613
-		const char *args = "bc:DfF:lm:nNop:PqQ:dhs:SU:V";
613
+		const char *args = "bc:DfF:lm:nNop:PqQ:dhHs:SU:V";
614 614
 #endif
615 615
 
616 616
 		static struct option long_options[] = {
... ...
@@ -630,6 +656,9 @@ main(int argc, char **argv)
630 630
 				"force-scan", 0, NULL, 'f'
631 631
 			},
632 632
 			{
633
+			  	"headers", 0, NULL, 'H'
634
+			},
635
+			{
633 636
 				"help", 0, NULL, 'h'
634 637
 			},
635 638
 			{
... ...
@@ -710,6 +739,9 @@ main(int argc, char **argv)
710 710
 			case 'h':
711 711
 				help();
712 712
 				return EX_OK;
713
+			case 'H':
714
+				hflag++;
715
+				break;
713 716
 			case 'l':	/* scan mail from the lan */
714 717
 				lflag++;
715 718
 				break;
... ...
@@ -1561,6 +1593,10 @@ clamfi_envfrom(SMFICTX *ctx, char **argv)
1561 1561
 	privdata->from = strdup(argv[0]);
1562 1562
 	privdata->to = NULL;
1563 1563
 
1564
+	if (hflag) 
1565
+        	privdata->headers = header_list_new();
1566
+	else privdata->headers = NULL;
1567
+
1564 1568
 	return (smfi_setpriv(ctx, privdata) == MI_SUCCESS) ? SMFIS_CONTINUE : cl_error;
1565 1569
 }
1566 1570
 
... ...
@@ -1609,6 +1645,10 @@ clamfi_header(SMFICTX *ctx, char *headerf, char *headerv)
1609 1609
 		clamfi_cleanup(ctx);
1610 1610
 		return cl_error;
1611 1611
 	}
1612
+
1613
+	if(hflag)
1614
+		header_list_add(privdata->headers, headerf, headerv);	
1615
+
1612 1616
 	return SMFIS_CONTINUE;
1613 1617
 }
1614 1618
 
... ...
@@ -1897,10 +1937,15 @@ clamfi_eom(SMFICTX *ctx)
1897 1897
 					 */
1898 1898
 					fprintf(sendmail, "The message %s sent from %s to\n\t",
1899 1899
 						smfi_getsymval(ctx, "i"),
1900
-						privdata->from);
1900
+						/*privdata->from,*/
1901
+						smfi_getsymval(ctx, "_")
1902
+						);
1901 1903
 				else
1902 1904
 
1903
-					fprintf(sendmail, "A message sent from %s to\n\t", privdata->from);
1905
+					fprintf(sendmail, "A message sent from %s to\n\t",
1906
+						/*privdata->from,*/
1907
+						smfi_getsymval(ctx, "_")
1908
+						);
1904 1909
 
1905 1910
 				for(to = privdata->to; *to; to++)
1906 1911
 					fprintf(sendmail, "%s\n", *to);
... ...
@@ -1908,7 +1953,15 @@ clamfi_eom(SMFICTX *ctx)
1908 1908
 				fputs(mess, sendmail);
1909 1909
 
1910 1910
 				if(privdata->filename != NULL)
1911
-					fprintf(sendmail, "\nThe message in question is quarantined as %s\n", privdata->filename);
1911
+					fprintf(sendmail, "\nThe message in question has been quarantined as %s\n", privdata->filename);
1912
+
1913
+				if (hflag) {
1914
+					fprintf(sendmail, "\nThe message was received by %s from %s\n\n",
1915
+						smfi_getsymval(ctx, "j"),
1916
+						smfi_getsymval(ctx, "_"));
1917
+					fputs("For your information, the original message headers were:\n\n", sendmail);
1918
+					header_list_print(privdata->headers, sendmail);
1919
+				}
1912 1920
 
1913 1921
 				pclose(sendmail);
1914 1922
 			}
... ...
@@ -2053,6 +2106,8 @@ clamfi_cleanup(SMFICTX *ctx)
2053 2053
 			close(privdata->cmdSocket);
2054 2054
 			privdata->cmdSocket = -1;
2055 2055
 		}
2056
+		if(privdata->headers)
2057
+			header_list_free(privdata->headers);
2056 2058
 
2057 2059
 #ifdef	CL_DEBUG
2058 2060
 		if(debug_level >= 9)
... ...
@@ -2215,3 +2270,60 @@ updateSigFile(void)
2215 2215
 
2216 2216
 	return statb.st_size;
2217 2217
 }
2218
+
2219
+static header_list_t
2220
+header_list_new(void) 
2221
+{
2222
+	header_list_t ret;
2223
+
2224
+	ret = (header_list_t)cli_malloc(sizeof(struct header_list_struct));
2225
+	ret->first = NULL;
2226
+	ret->last = NULL;
2227
+	return ret;
2228
+}
2229
+
2230
+static void
2231
+header_list_free(header_list_t list)
2232
+{
2233
+	struct header_node_t *iter;
2234
+
2235
+	iter = list->first;
2236
+	while (iter) {
2237
+		struct header_node_t *iter2 = iter->next;
2238
+		free(iter->header);
2239
+		free(iter);
2240
+		iter = iter2;
2241
+	}
2242
+	free(list);
2243
+}
2244
+
2245
+static void
2246
+header_list_add(header_list_t list, const char *headerf, const char *headerv)
2247
+{
2248
+	char *header;
2249
+	size_t len;
2250
+	struct header_node_t *new_node;
2251
+
2252
+	len = strlen(headerf) + strlen(headerv) + 3;
2253
+
2254
+	header = (char *)cli_malloc(len);
2255
+	snprintf(header, len, "%s: %s", headerf, headerv);
2256
+	new_node = (struct header_node_t *) malloc(sizeof(struct header_node_t));
2257
+	new_node->header = header;
2258
+	new_node->next = NULL;
2259
+	if(!list->first)
2260
+		list->first = new_node;
2261
+	if(list->last)
2262
+		list->last->next = new_node;
2263
+
2264
+	list->last = new_node;
2265
+}
2266
+
2267
+static void
2268
+header_list_print(header_list_t list, FILE *fp)
2269
+{
2270
+	const struct header_node_t *iter;
2271
+
2272
+	for(iter = list->first; iter; iter = iter->next)
2273
+		fprintf(fp, "%s\n", iter->header);
2274
+}
... ...
@@ -18,6 +18,11 @@ if it cannot it terminates.
18 18
 .TP 
19 19
 \fB\-h, \-\-help\fR
20 20
 Output the help information and exit.
21
+.TP
22
+\fB\-H, \-\-headers\fR
23
+Include all headers in the content of emails generated by clamav\-milter.
24
+This is useful for systems administrators who may want to look at headers
25
+to check if any of their machines are infected.
21 26
 .TP 
22 27
 \fB\-V, \-\-version\fR
23 28
 Print the version number and exit.