Browse code

Added --sign option

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

Nigel Horne authored on 2003/12/22 23:09:37
Showing 4 changed files
... ...
@@ -1,3 +1,6 @@
1
+Mon Dec 22 14:06:09 GMT 2003 (njh)
2
+  * clamav-milter: Added --sign option
3
+
1 4
 Sun Dec 21 05:52:12 CET 2003 (tk)
2 5
 ---------------------------------
3 6
   * libclamav: fixed a mail recursion loop - problem reported by Alex Kah
... ...
@@ -177,6 +177,7 @@ Changes
177 177
 0.65k	12/12/03 A couple of calls to clamfi_cleanup were missing
178 178
 		before return cl_error
179 179
 0.66	13/12/03 Upissue
180
+0.66a	22/12/03 Added --sign
180 181
 
181 182
 BUG REPORTS
182 183
 
... ...
@@ -180,9 +180,13 @@
180 180
  *	0.65k	12/12/03 A couple of calls to clamfi_cleanup were missing
181 181
  *			before return cl_error
182 182
  *	0.66	13/12/03 Upissue
183
+ *	0.66a	22/12/03 Added --sign
183 184
  *
184 185
  * Change History:
185 186
  * $Log: clamav-milter.c,v $
187
+ * Revision 1.32  2003/12/22 14:05:31  nigelhorne
188
+ * Added --sign option
189
+ *
186 190
  * Revision 1.31  2003/12/13 16:43:21  nigelhorne
187 191
  * Upissue
188 192
  *
... ...
@@ -261,9 +265,9 @@
261 261
  * Revision 1.6  2003/09/28 16:37:23  nigelhorne
262 262
  * Added -f flag use MaxThreads if --max-children not set
263 263
  */
264
-static	char	const	rcsid[] = "$Id: clamav-milter.c,v 1.31 2003/12/13 16:43:21 nigelhorne Exp $";
264
+static	char	const	rcsid[] = "$Id: clamav-milter.c,v 1.32 2003/12/22 14:05:31 nigelhorne Exp $";
265 265
 
266
-#define	CM_VERSION	"0.66"
266
+#define	CM_VERSION	"0.66a"
267 267
 
268 268
 /*#define	CONFDIR	"/usr/local/etc"*/
269 269
 
... ...
@@ -318,7 +322,6 @@ static	char	const	rcsid[] = "$Id: clamav-milter.c,v 1.31 2003/12/13 16:43:21 nig
318 318
  * TODO: allow -s server to use a name as well as an IP address
319 319
  * TODO: build with libclamav.so rather than libclamav.a
320 320
  * TODO: bounce message should optionally be read from a file
321
- * TODO: optionally add a signature that the message has been scanned with ClamAV
322 321
  * TODO: Support ThreadTimeout, LogTime and Logfile from the conf
323 322
  *	 file
324 323
  * TODO: Allow more than one clamdscan server to be given
... ...
@@ -374,6 +377,10 @@ static	int	qflag = 0;	/*
374 374
 				 * found is the syslog, so it's best to
375 375
 				 * enable LogSyslog in clamav.conf
376 376
 				 */
377
+static	int	Sflag = 0;	/*
378
+				 * Add a signature to each message that
379
+				 * has been scanned
380
+				 */
377 381
 static	char	*quarantine;	/*
378 382
 				 * If a virus is found in an email redirect
379 383
 				 * it to this account
... ...
@@ -398,6 +405,10 @@ static	int	threadtimeout = CL_DEFAULT_SCANTIMEOUT; /*
398 398
 				 * number of seconds to wait for clamd to
399 399
 				 * respond
400 400
 				 */
401
+static	u_char	*body;		/* body of the message if Sflag is set */
402
+static	size_t	bodyLen;	/* number of bytes in body */
403
+static	const	char	signature[] =	/* TODO: read in from a file */
404
+	"-- \nScanned by ClamAv - http://clamav.elektrapro.com\n";
401 405
 
402 406
 #ifdef	CL_DEBUG
403 407
 static	int	debug_level = 0;
... ...
@@ -445,6 +456,7 @@ help(void)
445 445
 	puts("\t--quarantine=USER\t-Q EMAIL\tQuanrantine e-mail account.");
446 446
 	puts("\t--quarantine-dir=DIR\t-U DIR\tDirectory to store infected emails.");
447 447
 	puts("\t--server=ADDRESS\t-s ADDR\tIP address of server running clamd (when using TCPsocket).");
448
+	puts("\t--sign\t\t\t-S\tAdd a signature to each scanned message.");
448 449
 	puts("\t--version\t\t-V\tPrint the version number of this software.");
449 450
 #ifdef	CL_DEBUG
450 451
 	puts("\t--debug-level=n\t\t-x n\tSets the debug level to 'n'.");
... ...
@@ -486,9 +498,9 @@ main(int argc, char **argv)
486 486
 	for(;;) {
487 487
 		int opt_index = 0;
488 488
 #ifdef	CL_DEBUG
489
-		const char *args = "bc:flm:nop:PqQ:dhs:U:Vx:";
489
+		const char *args = "bc:flm:nop:PqQ:dhs:S:U:Vx:";
490 490
 #else
491
-		const char *args = "bc:flm:nop:PqQ:dhs:U:V";
491
+		const char *args = "bc:flm:nop:PqQ:dhs:S:U:V";
492 492
 #endif
493 493
 
494 494
 		static struct option long_options[] = {
... ...
@@ -538,6 +550,9 @@ main(int argc, char **argv)
538 538
 				"server", 1, NULL, 's'
539 539
 			},
540 540
 			{
541
+				"sign", 1, NULL, 'S'
542
+			},
543
+			{
541 544
 				"version", 0, NULL, 'V'
542 545
 			},
543 546
 #ifdef	CL_DEBUG
... ...
@@ -602,6 +617,10 @@ main(int argc, char **argv)
602 602
 			case 's':	/* server running clamd */
603 603
 				serverIP = optarg;
604 604
 				break;
605
+			case 'S':	/* sign */
606
+				smfilter.xxfi_flags |= SMFIF_CHGBODY;
607
+				Sflag++;
608
+				break;
605 609
 			case 'U':	/* quarantine path */
606 610
 				quarantine_dir = optarg;
607 611
 				break;
... ...
@@ -615,9 +634,9 @@ main(int argc, char **argv)
615 615
 #endif
616 616
 			default:
617 617
 #ifdef	CL_DEBUG
618
-				fprintf(stderr, "Usage: %s [-b] [-c FILE] [--max-children=num] [-l] [-o] [-p address] [-P] [-q] [-Q USER] [-x#] [-U PATH] socket-addr\n", argv[0]);
618
+				fprintf(stderr, "Usage: %s [-b] [-c FILE] [--max-children=num] [-l] [-o] [-p address] [-P] [-q] [-Q USER] [-S] [-x#] [-U PATH] socket-addr\n", argv[0]);
619 619
 #else
620
-				fprintf(stderr, "Usage: %s [-b] [-c FILE] [--max-children=num] [-l] [-o] [-p address] [-P] [-q] [-Q USER] [-U PATH] socket-addr\n", argv[0]);
620
+				fprintf(stderr, "Usage: %s [-b] [-c FILE] [--max-children=num] [-l] [-o] [-p address] [-P] [-q] [-Q USER] [-S] [-U PATH] socket-addr\n", argv[0]);
621 621
 #endif
622 622
 				return EX_USAGE;
623 623
 		}
... ...
@@ -1093,7 +1112,7 @@ clamfi_envfrom(SMFICTX *ctx, char **argv)
1093 1093
 			}
1094 1094
 			privdata->dataSocket = open(privdata->filename, O_CREAT|O_EXCL|O_WRONLY,0600);
1095 1095
 #endif
1096
-		} while(--ntries > 0 && privdata->dataSocket < 0);
1096
+		} while((--ntries > 0) && (privdata->dataSocket < 0));
1097 1097
 
1098 1098
 		if(privdata->dataSocket < 0) {
1099 1099
 			if(use_syslog)
... ...
@@ -1216,12 +1235,12 @@ clamfi_envfrom(SMFICTX *ctx, char **argv)
1216 1216
 
1217 1217
 			/* 0.4 - use better error message */
1218 1218
 			if(use_syslog) {
1219
-	#ifdef TARGET_OS_SOLARIS	/* no strerror_r */
1219
+#ifdef TARGET_OS_SOLARIS	/* no strerror_r */
1220 1220
 				syslog(LOG_ERR, "Failed to connect to port %d given by clamd: %s", port, strerror(rc));
1221
-	#else
1221
+#else
1222 1222
 				strerror_r(rc, buf, sizeof(buf));
1223 1223
 				syslog(LOG_ERR, "Failed to connect to port %d given by clamd: %s", port, buf);
1224
-	#endif
1224
+#endif
1225 1225
 			}
1226 1226
 
1227 1227
 			return cl_error;
... ...
@@ -1361,6 +1380,19 @@ clamfi_body(SMFICTX *ctx, u_char *bodyp, size_t len)
1361 1361
 		clamfi_cleanup(ctx);
1362 1362
 		return cl_error;
1363 1363
 	}
1364
+	if(Sflag) {
1365
+		if(body) {
1366
+			assert(bodyLen > 0);
1367
+			body = realloc(body, bodyLen + len);
1368
+			memcpy(&body[bodyLen], bodyp, len);
1369
+			bodyLen += len;
1370
+		} else {
1371
+			assert(bodyLen == 0);
1372
+			body = malloc(len);
1373
+			memcpy(body, bodyp, len);
1374
+			bodyLen = len;
1375
+		}
1376
+	}
1364 1377
 	return SMFIS_CONTINUE;
1365 1378
 }
1366 1379
 
... ...
@@ -1457,6 +1489,16 @@ clamfi_eom(SMFICTX *ctx)
1457 1457
 		if(use_syslog)
1458 1458
 			syslog(LOG_NOTICE, "clean message from %s",
1459 1459
 				(privdata->from) ? privdata->from : "an unknown sender");
1460
+
1461
+		if(body) {
1462
+			assert(Sflag != 0);
1463
+
1464
+			body = realloc(body, bodyLen + sizeof(signature));
1465
+			memcpy(&body[bodyLen], signature, sizeof(signature));
1466
+
1467
+			smfi_replacebody(ctx, body, bodyLen + sizeof(signature));
1468
+
1469
+		}
1460 1470
 	} else {
1461 1471
 		int i;
1462 1472
 		char **to, *err;
... ...
@@ -1631,6 +1673,12 @@ clamfi_cleanup(SMFICTX *ctx)
1631 1631
 {
1632 1632
 	struct privdata *privdata = (struct privdata *)smfi_getpriv(ctx);
1633 1633
 
1634
+	if(body) {
1635
+		free(body);
1636
+		body = NULL;
1637
+		bodyLen = 0;
1638
+	}
1639
+
1634 1640
 	if(privdata) {
1635 1641
 		if(privdata->dataSocket >= 0) {
1636 1642
 			close(privdata->dataSocket);
... ...
@@ -71,6 +71,9 @@ Note - this option only works when using LocalSocket.
71 71
 .TP 
72 72
 \fB\-\-server=ADDRESS, \-s ADDRESS\fR
73 73
 IP address of server running clamd (when using TCPsocket).
74
+.TP
75
+\fB\-\-sign, \-S\fR
76
+Add a signature to each scanned file.
74 77
 .TP 
75 78
 \fB\-\-max\-children=n, \-m n\fR
76 79
 Maximum number of children.