Browse code

Handle yEnc attachments

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

Nigel Horne authored on 2004/09/17 22:48:38
Showing 3 changed files
... ...
@@ -1,3 +1,7 @@
1
+Fri Sep 17 14:47:53 BST 2004 (njh)
2
+----------------------------------
3
+  * libclamav:	Scan  yEnc mime attachments
4
+
1 5
 Fri Sep 17 11:56:58 BST 2004 (njh)
2 6
 ----------------------------------
3 7
   * libclamav:	Handle even more attempts to falsify the mime type
... ...
@@ -17,6 +17,9 @@
17 17
  *
18 18
  * Change History:
19 19
  * $Log: message.c,v $
20
+ * Revision 1.85  2004/09/17 13:47:19  nigelhorne
21
+ * Handle yEnc attachments
22
+ *
20 23
  * Revision 1.84  2004/09/17 09:48:53  nigelhorne
21 24
  * Handle attempts to hide mime type
22 25
  *
... ...
@@ -249,7 +252,7 @@
249 249
  * uuencodebegin() no longer static
250 250
  *
251 251
  */
252
-static	char	const	rcsid[] = "$Id: message.c,v 1.84 2004/09/17 09:48:53 nigelhorne Exp $";
252
+static	char	const	rcsid[] = "$Id: message.c,v 1.85 2004/09/17 13:47:19 nigelhorne Exp $";
253 253
 
254 254
 #if HAVE_CONFIG_H
255 255
 #include "clamav-config.h"
... ...
@@ -326,6 +329,7 @@ static	const	struct	encoding_map {
326 326
 	{	"8bit",			EIGHTBIT	},
327 327
 	{	"8 bit",		EIGHTBIT	},	/* incorrect */
328 328
 	{	"x-uuencode",		UUENCODE	},
329
+	{	"x-yencode",		YENCODE		},
329 330
 	{	"binary",		BINARY		},
330 331
 	{	NULL,			NOENCODING	}
331 332
 };
... ...
@@ -1027,6 +1031,8 @@ messageIsEncoding(message *m)
1027 1027
 		(isdigit(line[8])) &&
1028 1028
 		(line[9] == ' ')))
1029 1029
 			m->uuencode = m->body_last;
1030
+	else if((m->yenc == NULL) && (strncmp(line, "=ybegin line=", 13) == 0))
1031
+		m->yenc = m->body_last;
1030 1032
 }
1031 1033
 
1032 1034
 /*
... ...
@@ -1402,6 +1408,27 @@ messageExport(message *m, const char *dir, void *(*create)(void), void (*destroy
1402 1402
 			(*setFilename)(ret, dir, filename);
1403 1403
 			t_line = t_line->t_next;
1404 1404
 			enctype = UUENCODE;
1405
+		} else if((enctype == YENCODE) || ((i == 0) && yEncBegin(m))) {
1406
+			/*
1407
+			 * TODO: handle multipart yEnc encoded files
1408
+			 */
1409
+			t_line = yEncBegin(m);
1410
+			filename = lineGetData(t_line->t_line);
1411
+
1412
+			if((filename = strstr(filename, " name=")) != NULL) {
1413
+				filename = strdup(&filename[6]);
1414
+				if(filename) {
1415
+					cli_chomp(filename);
1416
+					strstrip(filename);
1417
+					cli_dbgmsg("Set yEnc filename to \"%s\"\n", filename);
1418
+				}
1419
+			} else
1420
+				filename = strdup("attachment");
1421
+
1422
+			if(filename)
1423
+				(*setFilename)(ret, dir, filename);
1424
+			t_line = t_line->t_next;
1425
+			enctype = YENCODE;
1405 1426
 		} else {
1406 1427
 			filename = (char *)messageFindArgument(m, "filename");
1407 1428
 			if(filename == NULL) {
... ...
@@ -1423,7 +1450,8 @@ messageExport(message *m, const char *dir, void *(*create)(void), void (*destroy
1423 1423
 
1424 1424
 			t_line = messageGetBody(m);
1425 1425
 		}
1426
-		free((char *)filename);
1426
+		if(filename)
1427
+			free((char *)filename);
1427 1428
 
1428 1429
 		/*
1429 1430
 		 * t_line should now point to the first (encoded) line of the message
... ...
@@ -1455,6 +1483,11 @@ messageExport(message *m, const char *dir, void *(*create)(void), void (*destroy
1455 1455
 					continue;
1456 1456
 				if(strcasecmp(line, "end") == 0)
1457 1457
 					break;
1458
+			} else if(enctype == YENCODE) {
1459
+				if(line == NULL)
1460
+					continue;
1461
+				if(strncmp(line, "=end ", 5) == 0)
1462
+					break;
1458 1463
 			}
1459 1464
 
1460 1465
 			uptr = decodeLine(m, enctype, line, data, sizeof(data));
... ...
@@ -1593,6 +1626,16 @@ messageToText(message *m)
1593 1593
 				return NULL;
1594 1594
 			}
1595 1595
 			t_line = t_line->t_next;
1596
+		} else if(enctype == YENCODE) {
1597
+			t_line = yEncBegin(m);
1598
+
1599
+			if(t_line == NULL) {
1600
+				/*cli_warnmsg("YENCODED attachment is missing begin statement\n");*/
1601
+				if(first)
1602
+					textDestroy(first);
1603
+				return NULL;
1604
+			}
1605
+			t_line = t_line->t_next;
1596 1606
 		} else {
1597 1607
 			if((i == 0) && binhexBegin(m))
1598 1608
 				cli_warnmsg("Binhex messages not supported yet.\n");
... ...
@@ -1698,6 +1741,12 @@ uuencodeBegin(const message *m)
1698 1698
 }
1699 1699
 #endif
1700 1700
 
1701
+const text *
1702
+yEncBegin(const message *m)
1703
+{
1704
+	return m->yenc;
1705
+}
1706
+
1701 1707
 /*
1702 1708
  * Scan to find the BINHEX message (if any)
1703 1709
  */
... ...
@@ -1910,6 +1959,20 @@ decodeLine(message *m, encoding_type et, const char *line, unsigned char *buf, s
1910 1910
 			else
1911 1911
 				buf = decode(m, line, buf, uudecode, (len & 3) == 0);
1912 1912
 			break;
1913
+		case YENCODE:
1914
+			if((line == NULL) || (*line == '\0'))	/* empty line */
1915
+				break;
1916
+			if(strncmp(line, "=yend ", 6) == 0)
1917
+				break;
1918
+
1919
+			while(*line)
1920
+				if(*line == '=') {
1921
+					if(*++line == '\0')
1922
+						break;
1923
+					*buf++ = ((*line++ - 64) & 255);
1924
+				} else
1925
+					*buf++ = ((*line++ - 42) & 255);
1926
+			break;
1913 1927
 	}
1914 1928
 
1915 1929
 	*buf = '\0';
... ...
@@ -16,6 +16,9 @@
16 16
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 17
  *
18 18
  * $Log: message.h,v $
19
+ * Revision 1.19  2004/09/17 13:47:19  nigelhorne
20
+ * Handle yEnc attachments
21
+ *
19 22
  * Revision 1.18  2004/09/17 09:48:53  nigelhorne
20 23
  * Handle attempts to hide mime type
21 24
  *
... ...
@@ -85,6 +88,7 @@ typedef struct message {
85 85
 	text	*bounce;	/* start of a bounced message */
86 86
 	text	*binhex;	/* start of a binhex message */
87 87
 	text	*uuencode;	/* start of a uuencoded message */
88
+	text	*yenc;		/* start of a yEnc message */
88 89
 	text	*encoding;	/* is the non MIME message encoded? */
89 90
 } message;
90 91
 
... ...
@@ -111,6 +115,7 @@ fileblob	*messageToFileblob(message *m, const char *dir);
111 111
 blob	*messageToBlob(message *m);
112 112
 text	*messageToText(message *m);
113 113
 const	text	*uuencodeBegin(const message *m);
114
+const	text	*yEncBegin(const message *m);
114 115
 const	text	*bounceBegin(const message *m);
115 116
 const	text	*encodingLine(const message *m);
116 117
 void	messageClearMarkers(message *m);