Browse code

* libclamav/vba_extract.c: remove unused PowerPoint functions.

* libclamav/ole2_extract.c: cleanup some warnings. Apply patch for
clean 64bit compile (originally from Martin Brulisauer)


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

Trog authored on 2004/07/06 22:29:07
Showing 3 changed files
... ...
@@ -1,3 +1,10 @@
1
+Tue Jul  6 14:26:19 BST 2004 (trog)
2
+-----------------------------------
3
+  * libclamav/vba_extract.c: remove unused PowerPoint functions.
4
+                                                                                                                                                 
5
+  * libclamav/ole2_extract.c: cleanup some warnings. Apply patch for
6
+	clean 64bit compile (originally from Martin Brulisauer)
7
+
1 8
 Tue Jul  6 15:15:18 CEST 2004 (tk)
2 9
 ----------------------------------
3 10
   * configure: improve libmilter test (patch by Tom G. Christensen
... ...
@@ -461,7 +461,7 @@ static void ole2_walk_property_tree(int fd, ole2_header_t *hdr, const char *dir,
461 461
 				int rec_level, int *file_count, const struct cl_limits *limits)
462 462
 {
463 463
 	property_t prop_block[4];
464
-	int32_t index, current_block, count=0, i;
464
+	int32_t index, current_block, i;
465 465
 	unsigned char *dirname;
466 466
 	current_block = hdr->prop_start;
467 467
 	
... ...
@@ -584,14 +584,14 @@ static int handler_writefile(int fd, ole2_header_t *hdr, property_t *prop, const
584 584
 
585 585
 	if (! (name = get_property_name(prop->name, prop->name_size))) {
586 586
 		/* File without a name - create a name for it */
587
-		int i;
587
+		off_t i;
588 588
                                                                                                                             
589 589
 		i = lseek(fd, 0, SEEK_CUR);
590 590
 		name = (char *) cli_malloc(11);
591 591
 		if (!name) {
592 592
 			return FALSE;
593 593
 		}
594
-		snprintf(name, 11, "%.10d", i + (int) prop);
594
+		snprintf(name, 11, "%.10ld", i + (long int) prop);
595 595
 	}
596 596
 
597 597
 	newname = (char *) cli_malloc(strlen(name) + strlen(dir) + 2);
... ...
@@ -290,6 +290,7 @@ vba_project_t *vba56_dir_read(const char *dir)
290 290
         if (fd == -1) {
291 291
                 cli_dbgmsg("Can't open %s\n", fullname);
292 292
 		free(fullname);
293
+		/* vba56_old_dir_read(dir); */
293 294
                 return NULL;
294 295
         }
295 296
 	free(fullname);
... ...
@@ -672,7 +673,7 @@ unsigned char *vba_decompress(int fd, uint32_t offset, int *size)
672 672
 }
673 673
 
674 674
 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
675
-/* Code to extract Power Point Embedded OLE2 Objects
675
+/* Code to extract Power Point Embedded OLE2 Objects		     */
676 676
 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
677 677
 
678 678
 #define MIN(a, b)  (((a) < (b)) ? (a) : (b))
... ...
@@ -686,24 +687,6 @@ typedef struct atom_header_tag {
686 686
 	uint32_t length;
687 687
 } atom_header_t;
688 688
 
689
-typedef struct ppt_currentuser_tag {
690
-	atom_header_t atom_hdr;
691
-	uint32_t len;
692
-	uint32_t magic;
693
-	uint32_t current_edit_offset;
694
-} ppt_currentuser_t;
695
-
696
-typedef struct ppt_useredit_tag {
697
-	atom_header_t atom_hdr;
698
-	int32_t last_slide_id;
699
-	uint32_t version;
700
-	uint32_t last_edit_offset;
701
-	uint32_t persist_dir_offset;
702
-	uint32_t document_ref;
703
-	uint32_t max_persist;
704
-	int16_t	 last_view_type;
705
-} ppt_useredit_t;
706
-
707 689
 static int ppt_read_atom_header(int fd, atom_header_t *atom_header)
708 690
 {
709 691
 	atom_header->foffset = lseek(fd, 0, SEEK_CUR);
... ...
@@ -736,168 +719,6 @@ static void ppt_print_atom_header(atom_header_t *atom_header)
736 736
 	cli_dbgmsg("  Length: 0x%.8x\n", atom_header->length);
737 737
 }
738 738
 
739
-static void ppt_print_useredit(ppt_useredit_t *ppt_useredit)
740
-{
741
-	ppt_print_atom_header(&ppt_useredit->atom_hdr);
742
-	cli_dbgmsg("Last Slide ID: 0x%.4x\n", ppt_useredit->last_slide_id);
743
-	cli_dbgmsg("Version: 0x%.4x\n", ppt_useredit->version);
744
-	cli_dbgmsg("Last Edit Offset: 0x%.4x\n", ppt_useredit->last_edit_offset);
745
-	cli_dbgmsg("Persist Dir Offset: 0x%.4x\n", ppt_useredit->persist_dir_offset);
746
-	cli_dbgmsg("Document Ref: 0x%.4x\n", ppt_useredit->document_ref);
747
-	cli_dbgmsg("Max Persist: 0x%.4x\n", ppt_useredit->max_persist);
748
-	cli_dbgmsg("Last view type: 0x%.4x\n\n", ppt_useredit->last_view_type);
749
-}
750
-
751
-static int ppt_read_useredit(int fd, ppt_useredit_t *ppt_useredit)
752
-{
753
-	if (!ppt_read_atom_header(fd, &ppt_useredit->atom_hdr)) {
754
-		return FALSE;
755
-	}
756
-	if (ppt_useredit->atom_hdr.type != 0x0FF5) {
757
-		cli_dbgmsg("read ppt_useredit failed, wrong atom type\n");
758
-		return FALSE;
759
-	}
760
-	if (cli_readn(fd, &ppt_useredit->last_slide_id, 4) != 4) {
761
-		cli_dbgmsg("read ppt_useredit failed\n");
762
-		return FALSE;
763
-	}
764
-	if (cli_readn(fd, &ppt_useredit->version, 4) != 4) {
765
-		cli_dbgmsg("read ppt_useredit failed\n");
766
-		return FALSE;
767
-	}
768
-	if (cli_readn(fd, &ppt_useredit->last_edit_offset, 4) != 4) {
769
-		cli_dbgmsg("read ppt_useredit failed\n");
770
-		return FALSE;
771
-	}
772
-	if (cli_readn(fd, &ppt_useredit->persist_dir_offset, 4) != 4) {
773
-		cli_dbgmsg("read ppt_useredit failed\n");
774
-		return FALSE;
775
-	}
776
-	if (cli_readn(fd, &ppt_useredit->document_ref, 4) != 4) {
777
-		cli_dbgmsg("read ppt_useredit failed\n");
778
-		return FALSE;
779
-	}
780
-	if (cli_readn(fd, &ppt_useredit->max_persist, 4) != 4) {
781
-		cli_dbgmsg("read ppt_useredit failed\n");
782
-		return FALSE;
783
-	}
784
-	if (cli_readn(fd, &ppt_useredit->last_view_type, 2) != 2) {
785
-		cli_dbgmsg("read ppt_useredit failed\n");
786
-		return FALSE;
787
-	}
788
-	ppt_useredit->last_slide_id = vba_endian_convert_32(ppt_useredit->last_slide_id, FALSE);
789
-	ppt_useredit->version = vba_endian_convert_32(ppt_useredit->version, FALSE);
790
-	ppt_useredit->last_edit_offset = vba_endian_convert_32(ppt_useredit->last_edit_offset, FALSE);
791
-	ppt_useredit->persist_dir_offset = vba_endian_convert_32(ppt_useredit->persist_dir_offset, FALSE);
792
-	ppt_useredit->document_ref = vba_endian_convert_32(ppt_useredit->document_ref, FALSE);
793
-	ppt_useredit->max_persist = vba_endian_convert_32(ppt_useredit->max_persist, FALSE);
794
-	ppt_useredit->last_view_type = vba_endian_convert_16(ppt_useredit->last_view_type, FALSE);
795
-	return TRUE;
796
-}
797
-
798
-static void ppt_print_current_user(ppt_currentuser_t *ppt_current_user)
799
-{
800
-	ppt_print_atom_header(&ppt_current_user->atom_hdr);
801
-	cli_dbgmsg("Magic: 0x%.8x\n", ppt_current_user->magic);
802
-	cli_dbgmsg("Curr Edit Offset: 0x%.8x\n", ppt_current_user->current_edit_offset);
803
-}
804
-
805
-static int ppt_read_current_user(int fd, ppt_currentuser_t *ppt_current_user)
806
-{
807
-	if (!ppt_read_atom_header(fd, &ppt_current_user->atom_hdr)) {
808
-		return FALSE;
809
-	}
810
-	if (ppt_current_user->atom_hdr.type != 0x0FF6) {
811
-		cli_dbgmsg("read ppt_current_user failed, wrong atom type\n");
812
-		return FALSE;
813
-	}
814
-	if (cli_readn(fd, &ppt_current_user->len, 4) != 4) {
815
-		cli_dbgmsg("read ppt_current_user failed\n");
816
-		return FALSE;
817
-	}
818
-	
819
-	if (cli_readn(fd, &ppt_current_user->magic, 4) != 4) {
820
-		cli_dbgmsg("read ppt_current_user 1 failed\n");
821
-		return FALSE;
822
-	}
823
-	if (cli_readn(fd, &ppt_current_user->current_edit_offset, 4) != 4) {
824
-		cli_dbgmsg("read ppt_current_user 2 failed\n");
825
-		return FALSE;
826
-	}
827
-	
828
-	/* Don't need to read the rest of the Current User file in order
829
-		to extract what we need */
830
-	
831
-	ppt_current_user->len = vba_endian_convert_32(ppt_current_user->len, FALSE);
832
-	ppt_current_user->magic = vba_endian_convert_32(ppt_current_user->magic, FALSE);
833
-	ppt_current_user->current_edit_offset = vba_endian_convert_32(ppt_current_user->current_edit_offset, FALSE);
834
-	if (ppt_current_user->magic != 0xE391C05F) {
835
-		cli_dbgmsg("read ppt_current_user failed, wrong magic\n");
836
-		return FALSE;
837
-	}
838
-	return TRUE;
839
-}
840
-
841
-static uint32_t *ppt_read_persist_dir(int fd, ppt_useredit_t *ppt_useredit)
842
-{
843
-	uint32_t *persist_dir, noffsets, off_index;
844
-	atom_header_t atom_header;
845
-	int size, i, off_count=0;
846
-	
847
-	if (lseek(fd, ppt_useredit->persist_dir_offset, SEEK_SET) != 
848
-			ppt_useredit->persist_dir_offset) {
849
-		return NULL;
850
-	}
851
-
852
-	if (!ppt_read_atom_header(fd, &atom_header)) {
853
-		return NULL;
854
-	}
855
-	ppt_print_atom_header(&atom_header);
856
-	if (atom_header.type != 0x1772) {
857
-		cli_dbgmsg("read ppt_current_user failed, wrong atom type\n");
858
-		return NULL;
859
-	}
860
-	size = sizeof(uint32_t) * (ppt_useredit->max_persist+1);
861
-	persist_dir = cli_malloc(size);
862
-	if (!persist_dir) {
863
-		return NULL;
864
-	}
865
-	memset(persist_dir, 0xFF, size);
866
-	
867
-	while ((off_count < ppt_useredit->max_persist) && 
868
-			(lseek(fd, 0, SEEK_CUR) < atom_header.foffset+atom_header.length)) {
869
-		if (cli_readn(fd, &noffsets, 4) != 4) {
870
-			cli_dbgmsg("read ppt_current_user failed\n");
871
-			free(persist_dir);
872
-			return NULL;
873
-		}
874
-		noffsets = vba_endian_convert_32(noffsets, FALSE);
875
-		off_index = noffsets & 0x000FFFFF;
876
-		noffsets = noffsets >> 20;
877
-		cli_dbgmsg("nOffsets: %d\n", noffsets);
878
-		cli_dbgmsg("Offset index: %d\n",off_index);
879
-		for (i=0 ; i<noffsets; i++) {
880
-			if ((off_index+i-1) > ppt_useredit->max_persist)
881
-			{
882
-				cli_dbgmsg("ppt_read_persist_dir overflow\n");
883
-				free(persist_dir);
884
-				return NULL;
885
-			}
886
-			if (cli_readn(fd, &persist_dir[off_index+i-1], 4) != 4) {
887
-				cli_dbgmsg("read ppt_read_persist_dir failed\n");
888
-				free(persist_dir);
889
-				return NULL;
890
-			}
891
-			persist_dir[off_index+i-1] = vba_endian_convert_32(persist_dir[off_index+i-1], FALSE);
892
-			cli_dbgmsg("persist_dir[%d] = 0x%.8x\n", off_index+i-1, persist_dir[off_index+i-1]);
893
-			off_count++;
894
-		}
895
-	}
896
-	cli_dbgmsg("File offset: 0x%.8x\n\n", lseek(fd, 0, SEEK_CUR));
897
-	
898
-	return persist_dir;
899
-}
900
-
901 739
 #define PPT_LZW_BUFFSIZE 8192
902 740
 static int ppt_unlzw(const char *dir, int fd, uint32_t length)
903 741
 {
... ...
@@ -911,7 +732,7 @@ static int ppt_unlzw(const char *dir, int fd, uint32_t length)
911 911
 	if (!fullname) {
912 912
 		return FALSE;
913 913
 	}
914
-	sprintf(fullname, "%s/ppt%.8x.doc", dir, lseek(fd, 0, SEEK_CUR));
914
+	sprintf(fullname, "%s/ppt%.8lx.doc", dir, lseek(fd, 0, SEEK_CUR));
915 915
 	
916 916
 	ofd = open(fullname, O_WRONLY|O_CREAT|O_TRUNC, 0600);
917 917
 	free(fullname);
... ...
@@ -1035,8 +856,6 @@ char *ppt_vba_read(const char *dir)
1035 1035
 {
1036 1036
 	char *fullname, *out_dir;
1037 1037
 	int fd;
1038
-	atom_header_t atom_header;
1039
-	uint32_t ole_id;
1040 1038
 
1041 1039
 	fullname = (char *) cli_malloc(strlen(dir) + 21);
1042 1040
 	if (!fullname) {
... ...
@@ -1054,148 +873,10 @@ char *ppt_vba_read(const char *dir)
1054 1054
 	close(fd);
1055 1055
 	return out_dir;
1056 1056
 }
1057
-	
1058
-	
1059
-/* Strictly speaking, the method below is the correct way to access the
1060
-	componenets of a PowerPoint file. However, it appears Microsoft
1061
-	don't do it that way.
1062
-	
1063
-char *ppt_vba_read_strict(const char *dir)
1064
-{
1065
-	ppt_currentuser_t ppt_current_user;
1066
-	ppt_useredit_t ppt_useredit;
1067
-	uint32_t *persist_dir;
1068
-	char *fullname, *out_dir, *tmpdir;
1069
-	int fd, i, ofd;
1070
-	unsigned char *buffer;
1071
-	atom_header_t atom_header;
1072
-	uint32_t ole_id;
1073
-	
1074
-	fullname = (char *) cli_malloc(strlen(dir) + 14);
1075
-	if (!fullname) {
1076
-		return NULL;
1077
-	}
1078
-	sprintf(fullname, "%s/Current User", dir);
1079
-	fd = open(fullname, O_RDONLY);
1080
-	free(fullname);
1081
-	if (fd == -1) {
1082
-		cli_dbgmsg("Open Current User failed\n");
1083
-		return NULL;
1084
-	}
1085
-	
1086
-	if (!ppt_read_current_user(fd, &ppt_current_user)) {
1087
-		close(fd);
1088
-		return NULL;
1089
-	}
1090
-	
1091
-	ppt_print_current_user(&ppt_current_user);
1092
-	close(fd);
1093
-
1094
-	fullname = (char *) cli_malloc(strlen(dir) + 21);
1095
-	if (!fullname) {
1096
-		return NULL;
1097
-	}
1098
-	sprintf(fullname, "%s/PowerPoint Document", dir);
1099
-	fd = open(fullname, O_RDONLY);
1100
-	free(fullname);
1101
-	if (fd == -1) {
1102
-		cli_dbgmsg("Open PowerPoint Document failed\n");
1103
-		return NULL;
1104
-	}
1105
-		
1106
-	if (lseek(fd, ppt_current_user.current_edit_offset, SEEK_SET) !=
1107
-					ppt_current_user.current_edit_offset) {
1108
-		cli_dbgmsg("lseek cli_ppt_vbaread failed\n");
1109
-		close(fd);
1110
-		return FALSE;
1111
-	}
1112
-
1113
-	tmpdir = getenv("TMPDIR");
1114
-
1115
-	if(tmpdir == NULL)
1116
-#ifdef P_tmpdir
1117
-		tmpdir = P_tmpdir;
1118
-#else
1119
-		tmpdir = "/tmp";
1120
-#endif
1121
-
1122
-	out_dir = cl_gentemp(tmpdir);
1123
-	if(mkdir(out_dir, 0700)) {
1124
-	    printf("ScanOLE2 -> Can't create temporary directory %s\n", dir);
1125
-	    close(fd);
1126
-	    return NULL;
1127
-	}
1128
-
1129
-	do {	
1130
-		if (!ppt_read_useredit(fd, &ppt_useredit)) {
1131
-			close(fd);
1132
-			cli_rmdirs(out_dir);
1133
-			free(out_dir);
1134
-			return NULL;
1135
-		}
1136
-		ppt_print_useredit(&ppt_useredit);
1137
-		
1138
-		persist_dir = ppt_read_persist_dir(fd, &ppt_useredit);
1139
-		if (!persist_dir) {
1140
-			close(fd);
1141
-			cli_rmdirs(out_dir);
1142
-			free(out_dir);
1143
-			return NULL;
1144
-		}
1145
-		for (i=0 ; i < ppt_useredit.max_persist ; i++) {
1146
-			if (persist_dir[i] != 0xFFFFFFFF) {
1147
-				if (lseek(fd, persist_dir[i], SEEK_SET) == persist_dir[i]) {				
1148
-					if (!ppt_read_atom_header(fd, &atom_header)) {
1149
-						close(fd);
1150
-						free(persist_dir);
1151
-						cli_rmdirs(out_dir);
1152
-						free(out_dir);
1153
-						return NULL;
1154
-					}
1155
-					ppt_print_atom_header(&atom_header);
1156
-					if (atom_header.type == 0x1011) {
1157
-						if (cli_readn(fd, &ole_id, 4) != 4) {
1158
-							cli_dbgmsg("read ole_id failed\n");
1159
-							close(fd);
1160
-							free(persist_dir);
1161
-							cli_rmdirs(out_dir);
1162
-							free(out_dir);
1163
-							return NULL;
1164
-						}
1165
-						ole_id = vba_endian_convert_32(ole_id, FALSE);
1166
-						cli_dbgmsg("OleID: %d, length: %d\n",
1167
-								ole_id, atom_header.length-4);
1168
-						if (!ppt_unlzw(out_dir, fd, atom_header.length-4)) {
1169
-							cli_dbgmsg("ppt_unlzw failed\n");
1170
-							close(fd);
1171
-							free(persist_dir);
1172
-							cli_rmdirs(out_dir);
1173
-							free(out_dir);
1174
-							return NULL;
1175
-						}
1176
-							
1177
-					}	
1178
-				}
1179
-			}
1180
-		}
1181
-		free(persist_dir);
1182
-		
1183
-		if (lseek(fd, ppt_useredit.last_edit_offset, SEEK_SET) !=
1184
-					ppt_useredit.last_edit_offset) {
1185
-			cli_dbgmsg("lseek cli_ppt_vbaread failed\n");
1186
-			close(fd);
1187
-			return NULL;
1188
-		}
1189
-	} while (ppt_useredit.last_edit_offset != 0);
1190
-	
1191
-	close(fd);
1192
-	return out_dir;
1193
-}	
1194
-*/
1195 1057
 
1196 1058
 
1197 1059
 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
1198
-/* Code to extract Word6 macros
1060
+/* Code to extract Word6 macros					     */
1199 1061
 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
1200 1062
 
1201 1063
 typedef struct mso_fib_tag {
... ...
@@ -1543,7 +1224,6 @@ static macro_extnames_t *wm_read_macro_extnames(int fd)
1543 1543
 {
1544 1544
 	int i, is_unicode=0;
1545 1545
 	int16_t size;
1546
-	uint8_t length_tmp;
1547 1546
 	off_t offset_end;	
1548 1547
 	macro_extnames_t *macro_extnames;
1549 1548
 	macro_extname_t *macro_extname;