Browse code

Add fast track to non-mbox files

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

Nigel Horne authored on 2005/03/28 20:06:21
Showing 3 changed files
... ...
@@ -1,3 +1,7 @@
1
+Mon Mar 28 12:05:17 BST 2005 (njh)
2
+----------------------------------
3
+ * libclamav:	Added fast track visa technology to files that are not mboxs
4
+
1 5
 Sat Mar 26 09:53:34 GMT 2005 (njh)
2 6
 ----------------------------------
3 7
   * libclamav/tnef.c:	Now works on PPC architecture
... ...
@@ -15,7 +15,7 @@
15 15
  *  along with this program; if not, write to the Free Software
16 16
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 17
  */
18
-static	char	const	rcsid[] = "$Id: mbox.c,v 1.232 2005/03/22 11:33:26 nigelhorne Exp $";
18
+static	char	const	rcsid[] = "$Id: mbox.c,v 1.233 2005/03/28 11:03:14 nigelhorne Exp $";
19 19
 
20 20
 #if HAVE_CONFIG_H
21 21
 #include "clamav-config.h"
... ...
@@ -169,7 +169,7 @@ typedef enum	{ FALSE = 0, TRUE = 1 } bool;
169 169
 /*#define	NEW_WORLD*/
170 170
 
171 171
 static	int	cli_parse_mbox(const char *dir, int desc, unsigned int options);
172
-static	message	*parseEmailFile(FILE *fin, const table_t *rfc821Table, const char *firstLine);
172
+static	message	*parseEmailFile(FILE *fin, const table_t *rfc821Table, const char *firstLine, const char *dir);
173 173
 static	message	*parseEmailHeaders(const message *m, const table_t *rfc821Table);
174 174
 static	int	parseEmailHeader(message *m, const char *line, const table_t *rfc821Table);
175 175
 static	int	parseEmailBody(message *messageIn, text *textIn, const char *dir, const table_t *rfc821Table, const table_t *subtypeTable, unsigned int options);
... ...
@@ -187,6 +187,7 @@ static	char	*rfc822comments(const char *in, char *out);
187 187
 static	int	rfc1341(message *m, const char *dir);
188 188
 #endif
189 189
 static	bool	usefulHeader(int commandNumber, const char *cmd);
190
+static	void	uufasttrack(message *m, const char *firstline, const char *dir, FILE *fin);
190 191
 #ifdef	NEW_WORLD
191 192
 static	const	char	*cli_pmemstr(const char *haystack, size_t hs, const char *needle, size_t ns);
192 193
 #endif
... ...
@@ -836,34 +837,13 @@ cli_parse_mbox(const char *dir, int desc, unsigned int options)
836 836
 			} else
837 837
 				lastLineWasEmpty = (bool)(buffer[0] == '\0');
838 838
 
839
-			if(isuuencodebegin(buffer)) {
839
+			if(isuuencodebegin(buffer))
840 840
 				/*
841 841
 				 * Fast track visa to uudecode.
842 842
 				 * TODO: binhex, yenc
843 843
 				 */
844
-				fileblob *fb = fileblobCreate();
845
-				char *filename = cli_strtok(buffer, 2, " ");
846
-
847
-				fileblobSetFilename(fb, dir, filename);
848
-				cli_dbgmsg("Fast track uuencode %s\n", filename);
849
-				free(filename);
850
-
851
-				while(fgets(buffer, sizeof(buffer) - 1, fd) != NULL) {
852
-					unsigned char data[1024];
853
-					const unsigned char *uptr;
854
-
855
-					cli_chomp(buffer);
856
-					if(strcasecmp(buffer, "end") == 0)
857
-						break;
858
-
859
-					uptr = decodeLine(m, UUENCODE, buffer, data, sizeof(data));
860
-					if(uptr == NULL)
861
-						break;
862
-					fileblobAddData(fb, data, (size_t)(uptr - data));
863
-				}
864
-
865
-				fileblobDestroy(fb);
866
-			} else
844
+				uufasttrack(m, buffer, dir, fd);
845
+			else
867 846
 				if(messageAddStr(m, buffer) < 0)
868 847
 					break;
869 848
 		} while(fgets(buffer, sizeof(buffer) - 1, fd) != NULL);
... ...
@@ -894,7 +874,7 @@ cli_parse_mbox(const char *dir, int desc, unsigned int options)
894 894
 
895 895
 		buffer[sizeof(buffer) - 1] = '\0';
896 896
 
897
-		body = parseEmailFile(fd, rfc821, buffer);
897
+		body = parseEmailFile(fd, rfc821, buffer, dir);
898 898
 		fclose(fd);
899 899
 	}
900 900
 
... ...
@@ -938,7 +918,7 @@ cli_parse_mbox(const char *dir, int desc, unsigned int options)
938 938
  * handled ungracefully...
939 939
  */
940 940
 static message *
941
-parseEmailFile(FILE *fin, const table_t *rfc821, const char *firstLine)
941
+parseEmailFile(FILE *fin, const table_t *rfc821, const char *firstLine, const char *dir)
942 942
 {
943 943
 	bool inHeader = TRUE;
944 944
 	bool contMarker = FALSE;
... ...
@@ -1131,8 +1111,13 @@ parseEmailFile(FILE *fin, const table_t *rfc821, const char *firstLine)
1131 1131
 				free(fullline);
1132 1132
 				fullline = NULL;
1133 1133
 			}
1134
-		} else
1135
-			/*cli_dbgmsg("Add line to body '%s'\n", start);*/
1134
+		} else if(start && isuuencodebegin(start))
1135
+			/*
1136
+			 * Fast track visa to uudecode.
1137
+			 * TODO: binhex, yenc
1138
+			 */
1139
+			uufasttrack(ret, start, dir, fin);
1140
+		else
1136 1141
 			if(messageAddStr(ret, start) < 0)
1137 1142
 				break;
1138 1143
 	} while(fgets(buffer, sizeof(buffer) - 1, fin) != NULL);
... ...
@@ -1450,7 +1435,7 @@ parseEmailBody(message *messageIn, text *textIn, const char *dir, const table_t
1450 1450
 			 */
1451 1451
 			cli_dbgmsg("assume no encoding\n");
1452 1452
 			mimeType = NOMIME;
1453
-			messageSetMimeSubtype(mainMessage, NULL);
1453
+			messageSetMimeSubtype(mainMessage, "");
1454 1454
 		} else if((mimeType == MESSAGE) &&
1455 1455
 			  (strcasecmp(mimeSubtype, "rfc822-headers") == 0)) {
1456 1456
 			/*
... ...
@@ -1461,6 +1446,7 @@ parseEmailBody(message *messageIn, text *textIn, const char *dir, const table_t
1461 1461
 			 */
1462 1462
 			cli_dbgmsg("Changing message/rfc822-headers to text/rfc822-headers\n");
1463 1463
 			mimeType = NOMIME;
1464
+			messageSetMimeSubtype(mainMessage, "");
1464 1465
 		}
1465 1466
 
1466 1467
 		cli_dbgmsg("mimeType = %d\n", mimeType);
... ...
@@ -2593,7 +2579,8 @@ parseEmailBody(message *messageIn, text *textIn, const char *dir, const table_t
2593 2593
 				 * has been found when it hasn't.
2594 2594
 				 */
2595 2595
 				if((fb = fileblobCreate()) != NULL) {
2596
-					cli_dbgmsg("Found a bounce message with no header\n");
2596
+					cli_dbgmsg("Found a bounce message with no header at '%s'\n",
2597
+						lineGetData(t_line->t_line));
2597 2598
 					fileblobSetFilename(fb, dir, "bounce");
2598 2599
 					fileblobAddData(fb,
2599 2600
 						(const unsigned char *)"Received: by clamd (bounce)\n",
... ...
@@ -3802,6 +3789,45 @@ usefulHeader(int commandNumber, const char *cmd)
3802 3802
 	return FALSE;
3803 3803
 }
3804 3804
 
3805
+/*
3806
+ * Save the uuencoded part of the file as it is read in
3807
+ */
3808
+static void
3809
+uufasttrack(message *m, const char *firstline, const char *dir, FILE *fin)
3810
+{
3811
+	fileblob *fb = fileblobCreate();
3812
+	char buffer[LINE_LENGTH + 1];
3813
+	char *filename = cli_strtok(firstline, 2, " ");
3814
+
3815
+	fileblobSetFilename(fb, dir, filename);
3816
+	cli_dbgmsg("Fast track uuencode %s\n", filename);
3817
+	free(filename);
3818
+
3819
+	while(fgets(buffer, sizeof(buffer) - 1, fin) != NULL) {
3820
+		unsigned char data[1024];
3821
+		const unsigned char *uptr;
3822
+		size_t len;
3823
+
3824
+		cli_chomp(buffer);
3825
+		if(strcasecmp(buffer, "end") == 0)
3826
+			break;
3827
+		if(buffer[0] == '\0')
3828
+			break;
3829
+
3830
+		uptr = decodeLine(m, UUENCODE, buffer, data, sizeof(data));
3831
+		if(uptr == NULL)
3832
+			break;
3833
+
3834
+		len = (size_t)(uptr - data);
3835
+		if((len > 62) || (len == 0))
3836
+			break;
3837
+
3838
+		fileblobAddData(fb, data, len);
3839
+	}
3840
+
3841
+	fileblobDestroy(fb);
3842
+}
3843
+
3805 3844
 #ifdef	NEW_WORLD
3806 3845
 /*
3807 3846
  * like cli_memstr - but returns the location of the match
... ...
@@ -15,7 +15,7 @@
15 15
  *  along with this program; if not, write to the Free Software
16 16
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 17
  */
18
-static	char	const	rcsid[] = "$Id: message.c,v 1.151 2005/03/18 18:12:24 nigelhorne Exp $";
18
+static	char	const	rcsid[] = "$Id: message.c,v 1.152 2005/03/28 11:03:15 nigelhorne Exp $";
19 19
 
20 20
 #if HAVE_CONFIG_H
21 21
 #include "clamav-config.h"
... ...
@@ -1951,6 +1951,8 @@ decodeLine(message *m, encoding_type et, const char *line, unsigned char *buf, s
1951 1951
 			break;
1952 1952
 
1953 1953
 		case UUENCODE:
1954
+			assert(m->base64chars == 0);
1955
+
1954 1956
 			if((line == NULL) || (*line == '\0'))	/* empty line */
1955 1957
 				break;
1956 1958
 			if(strcasecmp(line, "end") == 0)
... ...
@@ -1983,6 +1985,7 @@ decodeLine(message *m, encoding_type et, const char *line, unsigned char *buf, s
1983 1983
 				(void)decode(m, line, buf, uudecode, (len & 3) == 0);
1984 1984
 				buf = &buf[reallen];
1985 1985
 			}
1986
+			m->base64chars = 0;	/* this happens with broken uuencoded files */
1986 1987
 			break;
1987 1988
 		case YENCODE:
1988 1989
 			if((line == NULL) || (*line == '\0'))	/* empty line */