git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@836 77e5149b-7576-45b1-b177-96237e5ba77b
Tomasz Kojm authored on 2004/09/08 06:19:02... | ... |
@@ -1,3 +1,9 @@ |
1 |
+Tue Sep 7 23:14:42 CEST 2004 (tk) |
|
2 |
+---------------------------------- |
|
3 |
+ * libclamav/filetypes.c: add rule for "PK00PK" Zip archives (thanks to |
|
4 |
+ Tomasz Papszun) |
|
5 |
+ * libclamav: enable support for POSIX tar files (patch by Nigel) |
|
6 |
+ |
|
1 | 7 |
Mon Sep 6 12:04:08 BST 2004 (njh) |
2 | 8 |
---------------------------------- |
3 | 9 |
* libclamav/mbox.c: Normalise the HTML before looking for URLs to scan |
... | ... |
@@ -209,7 +209,7 @@ void register_char_option(struct optstruct *opt, char ch, const char *longname) |
209 | 209 |
void register_long_option(struct optstruct *opt, const char *optname) |
210 | 210 |
{ |
211 | 211 |
struct optnode *newnode; |
212 |
- int i, found; |
|
212 |
+ int i, found = 0; |
|
213 | 213 |
|
214 | 214 |
|
215 | 215 |
if(clamdscan_mode) { |
... | ... |
@@ -79,7 +79,7 @@ am_libclamav_la_OBJECTS = matcher-ac.lo matcher-bm.lo matcher.lo \ |
79 | 79 |
blob.lo mbox.lo message.lo snprintf.lo strrcpy.lo table.lo \ |
80 | 80 |
text.lo ole2_extract.lo vba_extract.lo msexpand.lo pe.lo \ |
81 | 81 |
cabd.lo lzxd.lo mszipd.lo qtmd.lo system.lo upx.lo htmlnorm.lo \ |
82 |
- chmunpack.lo rebuildpe.lo petite.lo fsg.lo line.lo |
|
82 |
+ chmunpack.lo rebuildpe.lo petite.lo fsg.lo line.lo untar.lo |
|
83 | 83 |
libclamav_la_OBJECTS = $(am_libclamav_la_OBJECTS) |
84 | 84 |
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) |
85 | 85 |
depcomp = $(SHELL) $(top_srcdir)/depcomp |
... | ... |
@@ -102,8 +102,8 @@ am__depfiles_maybe = depfiles |
102 | 102 |
@AMDEP_TRUE@ ./$(DEPDIR)/str.Plo ./$(DEPDIR)/strc.Plo \ |
103 | 103 |
@AMDEP_TRUE@ ./$(DEPDIR)/strrcpy.Plo ./$(DEPDIR)/system.Plo \ |
104 | 104 |
@AMDEP_TRUE@ ./$(DEPDIR)/table.Plo ./$(DEPDIR)/text.Plo \ |
105 |
-@AMDEP_TRUE@ ./$(DEPDIR)/unrarlib.Plo ./$(DEPDIR)/upx.Plo \ |
|
106 |
-@AMDEP_TRUE@ ./$(DEPDIR)/vba_extract.Plo \ |
|
105 |
+@AMDEP_TRUE@ ./$(DEPDIR)/unrarlib.Plo ./$(DEPDIR)/untar.Plo \ |
|
106 |
+@AMDEP_TRUE@ ./$(DEPDIR)/upx.Plo ./$(DEPDIR)/vba_extract.Plo \ |
|
107 | 107 |
@AMDEP_TRUE@ ./$(DEPDIR)/zzip-dir.Plo ./$(DEPDIR)/zzip-err.Plo \ |
108 | 108 |
@AMDEP_TRUE@ ./$(DEPDIR)/zzip-file.Plo \ |
109 | 109 |
@AMDEP_TRUE@ ./$(DEPDIR)/zzip-info.Plo ./$(DEPDIR)/zzip-io.Plo \ |
... | ... |
@@ -324,7 +324,9 @@ libclamav_la_SOURCES = \ |
324 | 324 |
fsg.c \ |
325 | 325 |
fsg.h \ |
326 | 326 |
line.c \ |
327 |
- line.h |
|
327 |
+ line.h \ |
|
328 |
+ untar.c \ |
|
329 |
+ untar.h |
|
328 | 330 |
|
329 | 331 |
lib_LTLIBRARIES = libclamav.la |
330 | 332 |
all: all-am |
... | ... |
@@ -430,6 +432,7 @@ distclean-compile: |
430 | 430 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/table.Plo@am__quote@ |
431 | 431 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/text.Plo@am__quote@ |
432 | 432 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/unrarlib.Plo@am__quote@ |
433 |
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/untar.Plo@am__quote@ |
|
433 | 434 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/upx.Plo@am__quote@ |
434 | 435 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vba_extract.Plo@am__quote@ |
435 | 436 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zzip-dir.Plo@am__quote@ |
... | ... |
@@ -53,13 +53,15 @@ static const struct cli_magic_s cli_magic[] = { |
53 | 53 |
|
54 | 54 |
/* Archives */ |
55 | 55 |
|
56 |
- {0, "Rar!", 4, "RAR", CL_RARFILE}, |
|
57 |
- {0, "PK\003\004", 4, "ZIP", CL_ZIPFILE}, |
|
58 |
- {0, "\037\213", 2, "GZip", CL_GZFILE}, |
|
59 |
- {0, "BZh", 3, "BZip", CL_BZFILE}, |
|
60 |
- {0, "SZDD", 4, "compress.exe'd", CL_MSCFILE}, |
|
61 |
- {0, "MSCF", 4, "MS CAB", CL_MSCABFILE}, |
|
62 |
- {0, "ITSF", 4, "MS CHM", CL_MSCHMFILE}, |
|
56 |
+ {0, "Rar!", 4, "RAR", CL_RARFILE}, |
|
57 |
+ {0, "PK\003\004", 4, "ZIP", CL_ZIPFILE}, |
|
58 |
+ {0, "PK00PK\003\004", 4, "ZIP", CL_ZIPFILE}, |
|
59 |
+ {0, "\037\213", 2, "GZip", CL_GZFILE}, |
|
60 |
+ {0, "BZh", 3, "BZip", CL_BZFILE}, |
|
61 |
+ {0, "SZDD", 4, "compress.exe'd", CL_MSCFILE}, |
|
62 |
+ {0, "MSCF", 4, "MS CAB", CL_MSCABFILE}, |
|
63 |
+ {0, "ITSF", 4, "MS CHM", CL_MSCHMFILE}, |
|
64 |
+ {257, "ustar", 5, "POSIX tar", CL_TARFILE}, |
|
63 | 65 |
|
64 | 66 |
/* Mail */ |
65 | 67 |
|
... | ... |
@@ -20,7 +20,7 @@ |
20 | 20 |
#ifndef __FILETYPES_H |
21 | 21 |
#define __FILETYPES_H |
22 | 22 |
|
23 |
-#define MAGIC_BUFFER_SIZE 26 |
|
23 |
+#define MAGIC_BUFFER_SIZE 262 |
|
24 | 24 |
#define CL_TYPENO 500 |
25 | 25 |
|
26 | 26 |
typedef enum { |
... | ... |
@@ -28,6 +28,7 @@ typedef enum { |
28 | 28 |
CL_UNKNOWN_DATA_TYPE, |
29 | 29 |
CL_DOSEXE, |
30 | 30 |
CL_DATAFILE, |
31 |
+ CL_TARFILE, |
|
31 | 32 |
CL_GZFILE, |
32 | 33 |
CL_ZIPFILE, |
33 | 34 |
CL_BZFILE, |
... | ... |
@@ -65,6 +65,7 @@ extern int cli_mbox(const char *dir, int desc, unsigned int options); /* FIXME * |
65 | 65 |
#include "pe.h" |
66 | 66 |
#include "filetypes.h" |
67 | 67 |
#include "htmlnorm.h" |
68 |
+#include "untar.h" |
|
68 | 69 |
|
69 | 70 |
#ifdef HAVE_ZLIB_H |
70 | 71 |
#include <zlib.h> |
... | ... |
@@ -106,7 +107,8 @@ static int cli_scanrar(int desc, const char **virname, long int *scanned, const |
106 | 106 |
char *rar_data_ptr; |
107 | 107 |
unsigned long rar_data_size; |
108 | 108 |
|
109 |
- cli_dbgmsg("Starting scanrar()\n"); |
|
109 |
+ |
|
110 |
+ cli_dbgmsg("in scanrar()\n"); |
|
110 | 111 |
|
111 | 112 |
|
112 | 113 |
#ifdef CL_THREAD_SAFE |
... | ... |
@@ -123,14 +125,14 @@ static int cli_scanrar(int desc, const char **virname, long int *scanned, const |
123 | 123 |
return CL_ERAR; |
124 | 124 |
} |
125 | 125 |
|
126 |
- cli_dbgmsg("Rar -> Number of archived files: %d\n", afiles); |
|
126 |
+ cli_dbgmsg("RAR: Number of archived files: %d\n", afiles); |
|
127 | 127 |
|
128 | 128 |
rarlist_head = rarlist; |
129 | 129 |
|
130 | 130 |
while(rarlist) { |
131 | 131 |
if(DETECT_ENCRYPTED && (rarlist->item.Flags & 4)) { |
132 | 132 |
files++; |
133 |
- cli_dbgmsg("Rar -> Encrypted files found in archive.\n"); |
|
133 |
+ cli_dbgmsg("RAR: Encrypted files found in archive.\n"); |
|
134 | 134 |
lseek(desc, 0, SEEK_SET); |
135 | 135 |
if(cli_scandesc(desc, virname, scanned, root, 0) != CL_VIRUS) |
136 | 136 |
*virname = "Encrypted.RAR"; |
... | ... |
@@ -140,7 +142,7 @@ static int cli_scanrar(int desc, const char **virname, long int *scanned, const |
140 | 140 |
|
141 | 141 |
if(limits) { |
142 | 142 |
if(limits->maxfilesize && (rarlist->item.UnpSize > (unsigned int) limits->maxfilesize)) { |
143 |
- cli_dbgmsg("RAR->%s: Size exceeded (%u, max: %lu)\n", rarlist->item.Name, (unsigned int) rarlist->item.UnpSize, limits->maxfilesize); |
|
143 |
+ cli_dbgmsg("RAR: %s: Size exceeded (%u, max: %lu)\n", rarlist->item.Name, (unsigned int) rarlist->item.UnpSize, limits->maxfilesize); |
|
144 | 144 |
rarlist = rarlist->next; |
145 | 145 |
files++; |
146 | 146 |
/* ret = CL_EMAXSIZE; */ |
... | ... |
@@ -161,7 +163,7 @@ static int cli_scanrar(int desc, const char **virname, long int *scanned, const |
161 | 161 |
} |
162 | 162 |
|
163 | 163 |
if((tmp = tmpfile()) == NULL) { |
164 |
- cli_dbgmsg("RAR -> Can't generate tmpfile().\n"); |
|
164 |
+ cli_dbgmsg("RAR: Can't generate temporary file.\n"); |
|
165 | 165 |
#ifdef CL_THREAD_SAFE |
166 | 166 |
pthread_mutex_unlock(&cli_scanrar_mutex); |
167 | 167 |
cli_scanrar_inuse = 0; |
... | ... |
@@ -171,9 +173,9 @@ static int cli_scanrar(int desc, const char **virname, long int *scanned, const |
171 | 171 |
fd = fileno(tmp); |
172 | 172 |
|
173 | 173 |
if( urarlib_get(&rar_data_ptr, &rar_data_size, rarlist->item.Name, desc, "clam")) { |
174 |
- cli_dbgmsg("RAR -> Extracted: %s, size: %lu\n", rarlist->item.Name, rar_data_size); |
|
174 |
+ cli_dbgmsg("RAR: Extracted: %s, size: %lu\n", rarlist->item.Name, rar_data_size); |
|
175 | 175 |
if(fwrite(rar_data_ptr, 1, rar_data_size, tmp) != rar_data_size) { |
176 |
- cli_dbgmsg("RAR -> Can't write() file.\n"); |
|
176 |
+ cli_dbgmsg("RAR: Can't write to file.\n"); |
|
177 | 177 |
fclose(tmp); |
178 | 178 |
tmp = NULL; |
179 | 179 |
ret = CL_ERAR; |
... | ... |
@@ -189,7 +191,7 @@ static int cli_scanrar(int desc, const char **virname, long int *scanned, const |
189 | 189 |
rar_data_ptr = NULL; |
190 | 190 |
} |
191 | 191 |
if(fflush(tmp) != 0) { |
192 |
- cli_dbgmsg("fflush() failed: %s\n", strerror(errno)); |
|
192 |
+ cli_dbgmsg("RAR: fflush() failed: %s\n", strerror(errno)); |
|
193 | 193 |
fclose(tmp); |
194 | 194 |
urarlib_freelist(rarlist_head); |
195 | 195 |
#ifdef CL_THREAD_SAFE |
... | ... |
@@ -201,7 +203,7 @@ static int cli_scanrar(int desc, const char **virname, long int *scanned, const |
201 | 201 |
|
202 | 202 |
lseek(fd, 0, SEEK_SET); |
203 | 203 |
if((ret = cli_magic_scandesc(fd, virname, scanned, root, limits, options, arec, mrec)) == CL_VIRUS ) { |
204 |
- cli_dbgmsg("RAR -> Found %s virus.\n", *virname); |
|
204 |
+ cli_dbgmsg("RAR: Infected with %s\n", *virname); |
|
205 | 205 |
|
206 | 206 |
fclose(tmp); |
207 | 207 |
urarlib_freelist(rarlist); |
... | ... |
@@ -213,7 +215,7 @@ static int cli_scanrar(int desc, const char **virname, long int *scanned, const |
213 | 213 |
} |
214 | 214 |
|
215 | 215 |
} else { |
216 |
- cli_dbgmsg("RAR -> Can't decompress file %s\n", rarlist->item.Name); |
|
216 |
+ cli_dbgmsg("RAR: Can't decompress file %s\n", rarlist->item.Name); |
|
217 | 217 |
fclose(tmp); |
218 | 218 |
tmp = NULL; |
219 | 219 |
ret = CL_ERAR; /* WinRAR 3.0 ? */ |
... | ... |
@@ -233,7 +235,7 @@ static int cli_scanrar(int desc, const char **virname, long int *scanned, const |
233 | 233 |
pthread_cleanup_pop(0); |
234 | 234 |
#endif |
235 | 235 |
|
236 |
- cli_dbgmsg("RAR -> Exit code: %d\n", ret); |
|
236 |
+ cli_dbgmsg("RAR: Exit code: %d\n", ret); |
|
237 | 237 |
|
238 | 238 |
return ret; |
239 | 239 |
} |
... | ... |
@@ -250,11 +252,12 @@ static int cli_scanzip(int desc, const char **virname, long int *scanned, const |
250 | 250 |
struct stat source; |
251 | 251 |
zzip_error_t err; |
252 | 252 |
|
253 |
- cli_dbgmsg("Starting scanzip()\n"); |
|
253 |
+ |
|
254 |
+ cli_dbgmsg("in scanzip()\n"); |
|
254 | 255 |
|
255 | 256 |
if((zdir = zzip_dir_fdopen(dup(desc), &err)) == NULL) { |
256 |
- cli_dbgmsg("Zip -> Not supported file format ?.\n"); |
|
257 |
- cli_dbgmsg("zzip_dir_fdopen() return code: %d\n", err); |
|
257 |
+ cli_dbgmsg("Zip: Not supported file format ?.\n"); |
|
258 |
+ cli_dbgmsg("Zip: zzip_dir_fdopen() return code: %d\n", err); |
|
258 | 259 |
/* no return with CL_EZIP due to password protected zips */ |
259 | 260 |
return CL_CLEAN; |
260 | 261 |
} |
... | ... |
@@ -262,7 +265,7 @@ static int cli_scanzip(int desc, const char **virname, long int *scanned, const |
262 | 262 |
fstat(desc, &source); |
263 | 263 |
|
264 | 264 |
if(!(buff = (char *) cli_malloc(FILEBUFF))) { |
265 |
- cli_dbgmsg("cli_scanzip(): unable to malloc(%d)\n", FILEBUFF); |
|
265 |
+ cli_dbgmsg("Zip: unable to malloc(%d)\n", FILEBUFF); |
|
266 | 266 |
zzip_dir_close(zdir); |
267 | 267 |
return CL_EMEM; |
268 | 268 |
} |
... | ... |
@@ -270,13 +273,13 @@ static int cli_scanzip(int desc, const char **virname, long int *scanned, const |
270 | 270 |
while(zzip_dir_read(zdir, &zdirent)) { |
271 | 271 |
|
272 | 272 |
if(!zdirent.d_name || !strlen(zdirent.d_name)) { /* Mimail fix */ |
273 |
- cli_dbgmsg("strlen(zdirent.d_name) == %d\n", strlen(zdirent.d_name)); |
|
273 |
+ cli_dbgmsg("Zip: strlen(zdirent.d_name) == %d\n", strlen(zdirent.d_name)); |
|
274 | 274 |
*virname = "Suspected.Zip"; |
275 | 275 |
ret = CL_VIRUS; |
276 | 276 |
break; |
277 | 277 |
} |
278 | 278 |
|
279 |
- cli_dbgmsg("Zip -> %s, compressed: %u, normal: %u, ratio: %d (max: %d)\n", zdirent.d_name, zdirent.d_csize, zdirent.st_size, zdirent.st_size / (zdirent.d_csize+1), limits ? limits->maxratio : -1 ); |
|
279 |
+ cli_dbgmsg("Zip: %s, compressed: %u, normal: %u, ratio: %d (max: %d)\n", zdirent.d_name, zdirent.d_csize, zdirent.st_size, zdirent.st_size / (zdirent.d_csize+1), limits ? limits->maxratio : -1 ); |
|
280 | 280 |
|
281 | 281 |
if(!zdirent.st_size) { /* omit directories and empty files */ |
282 | 282 |
files++; |
... | ... |
@@ -286,7 +289,7 @@ static int cli_scanzip(int desc, const char **virname, long int *scanned, const |
286 | 286 |
/* work-around for problematic zips (zziplib crashes with them) */ |
287 | 287 |
if(zdirent.d_csize <= 0 || zdirent.st_size < 0) { |
288 | 288 |
files++; |
289 |
- cli_dbgmsg("Zip -> Malformed archive detected.\n"); |
|
289 |
+ cli_dbgmsg("Zip: Malformed archive detected.\n"); |
|
290 | 290 |
/* ret = CL_EMALFZIP; */ |
291 | 291 |
/* report it as a virus */ |
292 | 292 |
*virname = "Suspected.Zip"; |
... | ... |
@@ -302,7 +305,7 @@ static int cli_scanzip(int desc, const char **virname, long int *scanned, const |
302 | 302 |
|
303 | 303 |
if(DETECT_ENCRYPTED && (zdirent.d_flags & 1 )) { |
304 | 304 |
files++; |
305 |
- cli_dbgmsg("Zip -> Encrypted files found in archive.\n"); |
|
305 |
+ cli_dbgmsg("Zip: Encrypted files found in archive.\n"); |
|
306 | 306 |
lseek(desc, 0, SEEK_SET); |
307 | 307 |
if(cli_scandesc(desc, virname, scanned, root, 0) != CL_VIRUS) |
308 | 308 |
*virname = "Encrypted.Zip"; |
... | ... |
@@ -312,7 +315,7 @@ static int cli_scanzip(int desc, const char **virname, long int *scanned, const |
312 | 312 |
|
313 | 313 |
if(limits) { |
314 | 314 |
if(limits->maxfilesize && (zdirent.st_size > limits->maxfilesize)) { |
315 |
- cli_dbgmsg("Zip -> %s: Size exceeded (%d, max: %ld)\n", zdirent.d_name, zdirent.st_size, limits->maxfilesize); |
|
315 |
+ cli_dbgmsg("Zip: %s: Size exceeded (%d, max: %ld)\n", zdirent.d_name, zdirent.st_size, limits->maxfilesize); |
|
316 | 316 |
files++; |
317 | 317 |
/* ret = CL_EMAXSIZE; */ |
318 | 318 |
continue; /* this is not a bug */ |
... | ... |
@@ -327,20 +330,20 @@ static int cli_scanzip(int desc, const char **virname, long int *scanned, const |
327 | 327 |
|
328 | 328 |
/* generate temporary file and get its descriptor */ |
329 | 329 |
if((tmp = tmpfile()) == NULL) { |
330 |
- cli_dbgmsg("Zip -> Can't generate tmpfile().\n"); |
|
330 |
+ cli_dbgmsg("Zip: Can't generate tmpfile().\n"); |
|
331 | 331 |
ret = CL_ETMPFILE; |
332 | 332 |
break; |
333 | 333 |
} |
334 | 334 |
|
335 | 335 |
if((zfp = zzip_file_open(zdir, zdirent.d_name, 0)) == NULL) { |
336 |
- cli_dbgmsg("Zip -> %s: Can't open file.\n", zdirent.d_name); |
|
336 |
+ cli_dbgmsg("Zip: Can't open file %s\n", zdirent.d_name); |
|
337 | 337 |
ret = CL_EZIP; |
338 | 338 |
break; |
339 | 339 |
} |
340 | 340 |
|
341 | 341 |
while((bytes = zzip_file_read(zfp, buff, FILEBUFF)) > 0) { |
342 | 342 |
if(fwrite(buff, 1, bytes, tmp) != (size_t) bytes) { |
343 |
- cli_dbgmsg("Zip -> Can't fwrite() file: %s\n", strerror(errno)); |
|
343 |
+ cli_dbgmsg("Zip: Can't write to file.\n"); |
|
344 | 344 |
zzip_file_close(zfp); |
345 | 345 |
zzip_dir_close(zdir); |
346 | 346 |
fclose(tmp); |
... | ... |
@@ -353,7 +356,7 @@ static int cli_scanzip(int desc, const char **virname, long int *scanned, const |
353 | 353 |
|
354 | 354 |
|
355 | 355 |
if(fflush(tmp) != 0) { |
356 |
- cli_dbgmsg("fflush() failed: %s\n", strerror(errno)); |
|
356 |
+ cli_dbgmsg("Zip: fflush() failed: %s\n", strerror(errno)); |
|
357 | 357 |
ret = CL_EFSYNC; |
358 | 358 |
break; |
359 | 359 |
} |
... | ... |
@@ -362,7 +365,7 @@ static int cli_scanzip(int desc, const char **virname, long int *scanned, const |
362 | 362 |
|
363 | 363 |
lseek(fd, 0, SEEK_SET); |
364 | 364 |
if((ret = cli_magic_scandesc(fd, virname, scanned, root, limits, options, arec, mrec)) == CL_VIRUS ) { |
365 |
- cli_dbgmsg("Zip -> Found %s virus.\n", *virname); |
|
365 |
+ cli_dbgmsg("Zip: Infected with %s\n", *virname); |
|
366 | 366 |
ret = CL_VIRUS; |
367 | 367 |
break; |
368 | 368 |
} else if(ret == CL_EMALFZIP) { |
... | ... |
@@ -370,7 +373,7 @@ static int cli_scanzip(int desc, const char **virname, long int *scanned, const |
370 | 370 |
* The trick with detection of ZoD only works with higher (>= 5) |
371 | 371 |
* recursion limit level. |
372 | 372 |
*/ |
373 |
- cli_dbgmsg("Zip -> Malformed Zip, scanning stopped.\n"); |
|
373 |
+ cli_dbgmsg("Zip: Malformed Zip file, scanning stopped.\n"); |
|
374 | 374 |
*virname = "Suspected.Zip"; |
375 | 375 |
ret = CL_VIRUS; |
376 | 376 |
break; |
... | ... |
@@ -405,19 +408,19 @@ static int cli_scangzip(int desc, const char **virname, long int *scanned, const |
405 | 405 |
cli_dbgmsg("in cli_scangzip()\n"); |
406 | 406 |
|
407 | 407 |
if((gd = gzdopen(dup(desc), "rb")) == NULL) { |
408 |
- cli_dbgmsg("Can't gzdopen() descriptor %d.\n", desc); |
|
408 |
+ cli_dbgmsg("GZip: Can't open descriptor %d\n", desc); |
|
409 | 409 |
return CL_EGZIP; |
410 | 410 |
} |
411 | 411 |
|
412 | 412 |
if((tmp = tmpfile()) == NULL) { |
413 |
- cli_dbgmsg("Can't generate tmpfile().\n"); |
|
413 |
+ cli_dbgmsg("GZip: Can't generate temporary file.\n"); |
|
414 | 414 |
gzclose(gd); |
415 | 415 |
return CL_ETMPFILE; |
416 | 416 |
} |
417 | 417 |
fd = fileno(tmp); |
418 | 418 |
|
419 | 419 |
if(!(buff = (char *) cli_malloc(FILEBUFF))) { |
420 |
- cli_dbgmsg("cli_scangzip(): unable to malloc(%d)\n", FILEBUFF); |
|
420 |
+ cli_dbgmsg("GZip: Unable to malloc %d bytes.\n", FILEBUFF); |
|
421 | 421 |
gzclose(gd); |
422 | 422 |
return CL_EMEM; |
423 | 423 |
} |
... | ... |
@@ -427,13 +430,13 @@ static int cli_scangzip(int desc, const char **virname, long int *scanned, const |
427 | 427 |
|
428 | 428 |
if(limits) |
429 | 429 |
if(limits->maxfilesize && (size + FILEBUFF > limits->maxfilesize)) { |
430 |
- cli_dbgmsg("Gzip->desc(%d): Size exceeded (stopped at %ld, max: %ld)\n", desc, size, limits->maxfilesize); |
|
430 |
+ cli_dbgmsg("GZip: Size exceeded (stopped at %ld, max: %ld)\n", size, limits->maxfilesize); |
|
431 | 431 |
/* ret = CL_EMAXSIZE; */ |
432 | 432 |
break; |
433 | 433 |
} |
434 | 434 |
|
435 | 435 |
if(cli_writen(fd, buff, bytes) != bytes) { |
436 |
- cli_dbgmsg("Gzip -> Can't write() file.\n"); |
|
436 |
+ cli_dbgmsg("GZip: Can't write to file.\n"); |
|
437 | 437 |
fclose(tmp); |
438 | 438 |
gzclose(gd); |
439 | 439 |
free(buff); |
... | ... |
@@ -444,14 +447,14 @@ static int cli_scangzip(int desc, const char **virname, long int *scanned, const |
444 | 444 |
free(buff); |
445 | 445 |
gzclose(gd); |
446 | 446 |
if(fsync(fd) == -1) { |
447 |
- cli_dbgmsg("fsync() failed for descriptor %d\n", fd); |
|
447 |
+ cli_dbgmsg("GZip: Can't synchronise descriptor %d\n", fd); |
|
448 | 448 |
fclose(tmp); |
449 | 449 |
return CL_EFSYNC; |
450 | 450 |
} |
451 | 451 |
|
452 | 452 |
lseek(fd, 0, SEEK_SET); |
453 | 453 |
if((ret = cli_magic_scandesc(fd, virname, scanned, root, limits, options, arec, mrec)) == CL_VIRUS ) { |
454 |
- cli_dbgmsg("Gzip -> Found %s virus.\n", *virname); |
|
454 |
+ cli_dbgmsg("GZip: Infected with %s\n", *virname); |
|
455 | 455 |
fclose(tmp); |
456 | 456 |
return CL_VIRUS; |
457 | 457 |
} |
... | ... |
@@ -480,7 +483,7 @@ static int cli_scanbzip(int desc, const char **virname, long int *scanned, const |
480 | 480 |
|
481 | 481 |
|
482 | 482 |
if((fs = fdopen(dup(desc), "rb")) == NULL) { |
483 |
- cli_dbgmsg("Can't fdopen() descriptor %d.\n", desc); |
|
483 |
+ cli_dbgmsg("Bzip: Can't open descriptor %d.\n", desc); |
|
484 | 484 |
return CL_EBZIP; |
485 | 485 |
} |
486 | 486 |
|
... | ... |
@@ -489,13 +492,13 @@ static int cli_scanbzip(int desc, const char **virname, long int *scanned, const |
489 | 489 |
memlim = 1; |
490 | 490 |
|
491 | 491 |
if((bfd = BZ2_bzReadOpen(&bzerror, fs, 0, memlim, NULL, 0)) == NULL) { |
492 |
- cli_dbgmsg("Can't initialize bzip2 library (descriptor %d).\n", desc); |
|
492 |
+ cli_dbgmsg("Bzip: Can't initialize bzip2 library (descriptor: %d).\n", desc); |
|
493 | 493 |
fclose(fs); |
494 | 494 |
return CL_EBZIP; |
495 | 495 |
} |
496 | 496 |
|
497 | 497 |
if((tmp = tmpfile()) == NULL) { |
498 |
- cli_dbgmsg("Can't generate tmpfile().\n"); |
|
498 |
+ cli_dbgmsg("Bzip: Can't generate temporary file.\n"); |
|
499 | 499 |
BZ2_bzReadClose(&bzerror, bfd); |
500 | 500 |
fclose(fs); |
501 | 501 |
return CL_ETMPFILE; |
... | ... |
@@ -503,7 +506,7 @@ static int cli_scanbzip(int desc, const char **virname, long int *scanned, const |
503 | 503 |
fd = fileno(tmp); |
504 | 504 |
|
505 | 505 |
if(!(buff = (char *) malloc(FILEBUFF))) { |
506 |
- cli_dbgmsg("cli_scanbzip(): unable to malloc(%d)\n", FILEBUFF); |
|
506 |
+ cli_dbgmsg("Bzip: Unable to malloc %d bytes.\n", FILEBUFF); |
|
507 | 507 |
fclose(tmp); |
508 | 508 |
fclose(fs); |
509 | 509 |
BZ2_bzReadClose(&bzerror, bfd); |
... | ... |
@@ -515,13 +518,13 @@ static int cli_scanbzip(int desc, const char **virname, long int *scanned, const |
515 | 515 |
|
516 | 516 |
if(limits) |
517 | 517 |
if(limits->maxfilesize && (size + FILEBUFF > limits->maxfilesize)) { |
518 |
- cli_dbgmsg("Bzip2->desc(%d): Size exceeded (stopped at %ld, max: %ld)\n", desc, size, limits->maxfilesize); |
|
518 |
+ cli_dbgmsg("Bzip: Size exceeded (stopped at %ld, max: %ld)\n", size, limits->maxfilesize); |
|
519 | 519 |
/* ret = CL_EMAXSIZE; */ |
520 | 520 |
break; |
521 | 521 |
} |
522 | 522 |
|
523 | 523 |
if(cli_writen(fd, buff, bytes) != bytes) { |
524 |
- cli_dbgmsg("Bzip2 -> Can't write() file.\n"); |
|
524 |
+ cli_dbgmsg("Bzip: Can't write to file.\n"); |
|
525 | 525 |
BZ2_bzReadClose(&bzerror, bfd); |
526 | 526 |
fclose(tmp); |
527 | 527 |
free(buff); |
... | ... |
@@ -533,7 +536,7 @@ static int cli_scanbzip(int desc, const char **virname, long int *scanned, const |
533 | 533 |
free(buff); |
534 | 534 |
BZ2_bzReadClose(&bzerror, bfd); |
535 | 535 |
if(fsync(fd) == -1) { |
536 |
- cli_dbgmsg("fsync() failed for descriptor %d\n", fd); |
|
536 |
+ cli_dbgmsg("Bzip: Synchronisation failed for descriptor %d\n", fd); |
|
537 | 537 |
fclose(tmp); |
538 | 538 |
fclose(fs); |
539 | 539 |
return CL_EFSYNC; |
... | ... |
@@ -541,7 +544,7 @@ static int cli_scanbzip(int desc, const char **virname, long int *scanned, const |
541 | 541 |
|
542 | 542 |
lseek(fd, 0, SEEK_SET); |
543 | 543 |
if((ret = cli_magic_scandesc(fd, virname, scanned, root, limits, options, arec, mrec)) == CL_VIRUS ) { |
544 |
- cli_dbgmsg("Bzip2 -> Found %s virus.\n", *virname); |
|
544 |
+ cli_dbgmsg("Bzip: Infected with %s\n", *virname); |
|
545 | 545 |
} |
546 | 546 |
fclose(tmp); |
547 | 547 |
fclose(fs); |
... | ... |
@@ -555,27 +558,28 @@ static int cli_scanmscomp(int desc, const char **virname, long int *scanned, con |
555 | 555 |
int fd, ret = CL_CLEAN; |
556 | 556 |
FILE *tmp = NULL, *in; |
557 | 557 |
|
558 |
+ |
|
558 | 559 |
cli_dbgmsg("in cli_scanmscomp()\n"); |
559 | 560 |
|
560 | 561 |
if((in = fdopen(dup(desc), "rb")) == NULL) { |
561 |
- cli_dbgmsg("Can't fdopen() descriptor %d.\n", desc); |
|
562 |
+ cli_dbgmsg("SZDD: Can't open descriptor %d\n", desc); |
|
562 | 563 |
return CL_EMSCOMP; |
563 | 564 |
} |
564 | 565 |
|
565 | 566 |
if((tmp = tmpfile()) == NULL) { |
566 |
- cli_dbgmsg("Can't generate tmpfile().\n"); |
|
567 |
+ cli_dbgmsg("SZDD: Can't generate temporary file.\n"); |
|
567 | 568 |
fclose(in); |
568 | 569 |
return CL_ETMPFILE; |
569 | 570 |
} |
570 | 571 |
|
571 | 572 |
if(cli_msexpand(in, tmp) == -1) { |
572 |
- cli_dbgmsg("msexpand failed.\n"); |
|
573 |
+ cli_dbgmsg("SZDD: msexpand failed.\n"); |
|
573 | 574 |
return CL_EMSCOMP; |
574 | 575 |
} |
575 | 576 |
|
576 | 577 |
fclose(in); |
577 | 578 |
if(fflush(tmp)) { |
578 |
- cli_dbgmsg("fflush() failed\n"); |
|
579 |
+ cli_dbgmsg("SZDD: fflush() failed.\n"); |
|
579 | 580 |
fclose(tmp); |
580 | 581 |
return CL_EFSYNC; |
581 | 582 |
} |
... | ... |
@@ -583,7 +587,7 @@ static int cli_scanmscomp(int desc, const char **virname, long int *scanned, con |
583 | 583 |
fd = fileno(tmp); |
584 | 584 |
lseek(fd, 0, SEEK_SET); |
585 | 585 |
if((ret = cli_magic_scandesc(fd, virname, scanned, root, limits, options, arec, mrec)) == CL_VIRUS) { |
586 |
- cli_dbgmsg("MSCompress -> Found %s virus.\n", *virname); |
|
586 |
+ cli_dbgmsg("SZDD: Infected with %s\n", *virname); |
|
587 | 587 |
fclose(tmp); |
588 | 588 |
return CL_VIRUS; |
589 | 589 |
} |
... | ... |
@@ -605,12 +609,12 @@ static int cli_scanmscab(int desc, const char **virname, long int *scanned, cons |
605 | 605 |
cli_dbgmsg("in cli_scanmscab()\n"); |
606 | 606 |
|
607 | 607 |
if((cabd = mspack_create_cab_decompressor(NULL)) == NULL) { |
608 |
- cli_dbgmsg("Can't create libmspack CAB decompressor\n"); |
|
608 |
+ cli_dbgmsg("MSCAB: Can't create libmspack CAB decompressor\n"); |
|
609 | 609 |
return CL_EMSCAB; |
610 | 610 |
} |
611 | 611 |
|
612 | 612 |
if((base = cabd->dsearch(cabd, desc)) == NULL) { |
613 |
- cli_dbgmsg("I/O error or no valid cabinets found\n"); |
|
613 |
+ cli_dbgmsg("MSCAB: I/O error or no valid cabinets found\n"); |
|
614 | 614 |
mspack_destroy_cab_decompressor(cabd); |
615 | 615 |
return CL_EMSCAB; |
616 | 616 |
} |
... | ... |
@@ -625,9 +629,9 @@ static int cli_scanmscab(int desc, const char **virname, long int *scanned, cons |
625 | 625 |
for(cab = base; cab; cab = cab->next) { |
626 | 626 |
for(file = cab->files; file; file = file->next) { |
627 | 627 |
tempname = cli_gentemp(tmpdir); |
628 |
- cli_dbgmsg("Extracting data to %s\n", tempname); |
|
628 |
+ cli_dbgmsg("MSCAB: Extracting data to %s\n", tempname); |
|
629 | 629 |
if(cabd->extract(cabd, file, tempname)) { |
630 |
- cli_dbgmsg("libmscab error code: %d\n", cabd->last_error(cabd)); |
|
630 |
+ cli_dbgmsg("MSCAB: libmscab error code: %d\n", cabd->last_error(cabd)); |
|
631 | 631 |
} else { |
632 | 632 |
ret = cli_scanfile(tempname, virname, scanned, root, limits, options, arec, mrec); |
633 | 633 |
} |
... | ... |
@@ -658,12 +662,12 @@ static int cli_scanhtml(int desc, const char **virname, long int *scanned, const |
658 | 658 |
cli_dbgmsg("in cli_scanhtml()\n"); |
659 | 659 |
|
660 | 660 |
if(fstat(desc, &statbuf) != 0) { |
661 |
- cli_dbgmsg("fstat failed\n"); |
|
661 |
+ cli_dbgmsg("HTML: Can't stat descriptor %d\n", desc); |
|
662 | 662 |
return CL_EIO; |
663 | 663 |
} |
664 | 664 |
|
665 | 665 |
if(limits && limits->maxfilesize && (statbuf.st_size > limits->maxfilesize)) { |
666 |
- cli_dbgmsg("ScanHTML -> Size exceeded (%d, max: %ld)\n", statbuf.st_size, limits->maxfilesize); |
|
666 |
+ cli_dbgmsg("HTML: Size exceeded (%d, max: %ld)\n", statbuf.st_size, limits->maxfilesize); |
|
667 | 667 |
return CL_CLEAN; |
668 | 668 |
} |
669 | 669 |
|
... | ... |
@@ -671,7 +675,7 @@ static int cli_scanhtml(int desc, const char **virname, long int *scanned, const |
671 | 671 |
|
672 | 672 |
/* TODO: do file operations if mmap fails */ |
673 | 673 |
if(membuff == MAP_FAILED) { |
674 |
- cli_dbgmsg("mmap failed\n"); |
|
674 |
+ cli_dbgmsg("HTML: mmap failed\n"); |
|
675 | 675 |
return CL_EMEM; |
676 | 676 |
} |
677 | 677 |
|
... | ... |
@@ -705,7 +709,7 @@ static int cli_scan_mydoom_log(int desc, const char **virname, long int *scanne |
705 | 705 |
int32_t record[8], check; |
706 | 706 |
int i, retval=CL_VIRUS, j; |
707 | 707 |
|
708 |
- cli_dbgmsg("in mydoom_log\n"); |
|
708 |
+ cli_dbgmsg("in mydoom_log()\n"); |
|
709 | 709 |
|
710 | 710 |
/* Check upto the first five records in the file */ |
711 | 711 |
for (j=0 ; j<5 ; j++) { |
... | ... |
@@ -715,13 +719,13 @@ static int cli_scan_mydoom_log(int desc, const char **virname, long int *scanne |
715 | 715 |
|
716 | 716 |
/* Decode the key */ |
717 | 717 |
record[0] = ~ntohl(record[0]); |
718 |
- cli_dbgmsg("key: %lu\n", record[0]); |
|
718 |
+ cli_dbgmsg("Mydoom: key: %lu\n", record[0]); |
|
719 | 719 |
check = 0; |
720 | 720 |
for (i=1 ; i<8; i++) { |
721 | 721 |
record[i] = ntohl(record[i]) ^ record[0]; |
722 | 722 |
check += record[i]; |
723 | 723 |
} |
724 |
- cli_dbgmsg("check: %lu\n", ~check); |
|
724 |
+ cli_dbgmsg("Mydoom: check: %lu\n", ~check); |
|
725 | 725 |
if ((~check) != record[0]) { |
726 | 726 |
return CL_CLEAN; |
727 | 727 |
} |
... | ... |
@@ -731,7 +735,7 @@ static int cli_scan_mydoom_log(int desc, const char **virname, long int *scanne |
731 | 731 |
retval = CL_CLEAN; |
732 | 732 |
} else if (retval==CL_VIRUS) { |
733 | 733 |
if(virname) |
734 |
- *virname = "Mydoom.M.log"; |
|
734 |
+ *virname = "Worm.Mydoom.M.log"; |
|
735 | 735 |
} |
736 | 736 |
|
737 | 737 |
return retval; |
... | ... |
@@ -778,7 +782,7 @@ static int cli_scandir(const char *dirname, const char **virname, long int *scan |
778 | 778 |
} |
779 | 779 |
} |
780 | 780 |
} else { |
781 |
- cli_dbgmsg("ScanDir -> Can't open directory %s.\n", dirname); |
|
781 |
+ cli_dbgmsg("ScanDir: Can't open directory %s.\n", dirname); |
|
782 | 782 |
return CL_EOPEN; |
783 | 783 |
} |
784 | 784 |
|
... | ... |
@@ -796,7 +800,8 @@ static int cli_vba_scandir(const char *dirname, const char **virname, long int * |
796 | 796 |
char *fname, *fullname; |
797 | 797 |
unsigned char *data; |
798 | 798 |
|
799 |
- cli_dbgmsg("VBA scan dir: %s\n", dirname); |
|
799 |
+ |
|
800 |
+ cli_dbgmsg("VBADir: %s\n", dirname); |
|
800 | 801 |
if((vba_project = (vba_project_t *) vba56_dir_read(dirname))) { |
801 | 802 |
|
802 | 803 |
for(i = 0; i < vba_project->count; i++) { |
... | ... |
@@ -804,18 +809,18 @@ static int cli_vba_scandir(const char *dirname, const char **virname, long int * |
804 | 804 |
sprintf(fullname, "%s/%s", vba_project->dir, vba_project->name[i]); |
805 | 805 |
fd = open(fullname, O_RDONLY); |
806 | 806 |
if(fd == -1) { |
807 |
- cli_dbgmsg("Scan->OLE2 -> Can't open file %s\n", fullname); |
|
807 |
+ cli_dbgmsg("VBADir: Can't open file %s\n", fullname); |
|
808 | 808 |
free(fullname); |
809 | 809 |
ret = CL_EOPEN; |
810 | 810 |
break; |
811 | 811 |
} |
812 | 812 |
free(fullname); |
813 |
- cli_dbgmsg("decompress VBA project '%s'\n", vba_project->name[i]); |
|
813 |
+ cli_dbgmsg("VBADir: Decompress VBA project '%s'\n", vba_project->name[i]); |
|
814 | 814 |
data = (unsigned char *) vba_decompress(fd, vba_project->offset[i], &data_len); |
815 | 815 |
close(fd); |
816 | 816 |
|
817 | 817 |
if(!data) { |
818 |
- cli_dbgmsg("WARNING: VBA project '%s' decompressed to NULL\n", vba_project->name[i]); |
|
818 |
+ cli_dbgmsg("VBADir: WARNING: VBA project '%s' decompressed to NULL\n", vba_project->name[i]); |
|
819 | 819 |
} else { |
820 | 820 |
if(cl_scanbuff(data, data_len, virname, root) == CL_VIRUS) { |
821 | 821 |
free(data); |
... | ... |
@@ -845,18 +850,18 @@ static int cli_vba_scandir(const char *dirname, const char **virname, long int * |
845 | 845 |
sprintf(fullname, "%s/%s", vba_project->dir, vba_project->name[i]); |
846 | 846 |
fd = open(fullname, O_RDONLY); |
847 | 847 |
if(fd == -1) { |
848 |
- cli_dbgmsg("Scan->OLE2 -> Can't open file %s\n", fullname); |
|
848 |
+ cli_dbgmsg("VBADir: Can't open file %s\n", fullname); |
|
849 | 849 |
free(fullname); |
850 | 850 |
ret = CL_EOPEN; |
851 | 851 |
break; |
852 | 852 |
} |
853 | 853 |
free(fullname); |
854 |
- cli_dbgmsg("decompress WM project '%s' macro:%d key:%d\n", vba_project->name[i], i, vba_project->key[i]); |
|
854 |
+ cli_dbgmsg("VBADir: Decompress WM project '%s' macro:%d key:%d\n", vba_project->name[i], i, vba_project->key[i]); |
|
855 | 855 |
data = (unsigned char *) wm_decrypt_macro(fd, vba_project->offset[i], vba_project->length[i], vba_project->key[i]); |
856 | 856 |
close(fd); |
857 | 857 |
|
858 | 858 |
if(!data) { |
859 |
- cli_dbgmsg("WARNING: WM project '%s' macro %d decrypted to NULL\n", vba_project->name[i], i); |
|
859 |
+ cli_dbgmsg("VBADir: WARNING: WM project '%s' macro %d decrypted to NULL\n", vba_project->name[i], i); |
|
860 | 860 |
} else { |
861 | 861 |
if(cl_scanbuff(data, vba_project->length[i], virname, root) == CL_VIRUS) { |
862 | 862 |
free(data); |
... | ... |
@@ -904,7 +909,7 @@ static int cli_vba_scandir(const char *dirname, const char **virname, long int * |
904 | 904 |
} |
905 | 905 |
} |
906 | 906 |
} else { |
907 |
- cli_dbgmsg("ScanDir -> Can't open directory %s.\n", dirname); |
|
907 |
+ cli_dbgmsg("VBADir: Can't open directory %s.\n", dirname); |
|
908 | 908 |
return CL_EOPEN; |
909 | 909 |
} |
910 | 910 |
|
... | ... |
@@ -918,6 +923,7 @@ static int cli_scanole2(int desc, const char **virname, long int *scanned, const |
918 | 918 |
char *dir; |
919 | 919 |
int ret = CL_CLEAN; |
920 | 920 |
|
921 |
+ |
|
921 | 922 |
cli_dbgmsg("in cli_scanole2()\n"); |
922 | 923 |
|
923 | 924 |
if((tmpdir = getenv("TMPDIR")) == NULL) |
... | ... |
@@ -930,12 +936,12 @@ static int cli_scanole2(int desc, const char **virname, long int *scanned, const |
930 | 930 |
/* generate the temporary directory */ |
931 | 931 |
dir = cli_gentemp(tmpdir); |
932 | 932 |
if(mkdir(dir, 0700)) { |
933 |
- cli_dbgmsg("ScanOLE2 -> Can't create temporary directory %s\n", dir); |
|
933 |
+ cli_dbgmsg("OLE2: Can't create temporary directory %s\n", dir); |
|
934 | 934 |
return CL_ETMPDIR; |
935 | 935 |
} |
936 | 936 |
|
937 | 937 |
if((ret = cli_ole2_extract(desc, dir, limits))) { |
938 |
- cli_dbgmsg("ScanOLE2 -> %s\n", cl_strerror(ret)); |
|
938 |
+ cli_dbgmsg("OLE2: %s\n", cl_strerror(ret)); |
|
939 | 939 |
cli_rmdirs(dir); |
940 | 940 |
free(dir); |
941 | 941 |
return ret; |
... | ... |
@@ -952,6 +958,41 @@ static int cli_scanole2(int desc, const char **virname, long int *scanned, const |
952 | 952 |
return ret; |
953 | 953 |
} |
954 | 954 |
|
955 |
+static int cli_scantar(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options, int *arec, int *mrec) |
|
956 |
+{ |
|
957 |
+ const char *tmpdir; |
|
958 |
+ char *dir; |
|
959 |
+ int ret = CL_CLEAN; |
|
960 |
+ |
|
961 |
+ |
|
962 |
+ cli_dbgmsg("in cli_scantar()\n"); |
|
963 |
+ |
|
964 |
+ if((tmpdir = getenv("TMPDIR")) == NULL) |
|
965 |
+#ifdef P_tmpdir |
|
966 |
+ tmpdir = P_tmpdir; |
|
967 |
+#else |
|
968 |
+ tmpdir = "/tmp"; |
|
969 |
+#endif |
|
970 |
+ |
|
971 |
+ /* generate temporary directory */ |
|
972 |
+ dir = cli_gentemp(tmpdir); |
|
973 |
+ if(mkdir(dir, 0700)) { |
|
974 |
+ cli_errmsg("Tar: Can't create temporary directory %s\n", dir); |
|
975 |
+ return CL_ETMPDIR; |
|
976 |
+ } |
|
977 |
+ |
|
978 |
+ if((ret = cli_untar(dir, desc))) |
|
979 |
+ cli_dbgmsg("Tar: %s\n", cl_strerror(ret)); |
|
980 |
+ else |
|
981 |
+ ret = cli_scandir(dir, virname, scanned, root, limits, options, arec, mrec); |
|
982 |
+ |
|
983 |
+ if(!cli_leavetemps_flag) |
|
984 |
+ cli_rmdirs(dir); |
|
985 |
+ |
|
986 |
+ free(dir); |
|
987 |
+ return ret; |
|
988 |
+} |
|
989 |
+ |
|
955 | 990 |
static int cli_scanmschm(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options, int *arec, int *mrec) |
956 | 991 |
{ |
957 | 992 |
const char *tmpdir; |
... | ... |
@@ -971,7 +1012,7 @@ static int cli_scanmschm(int desc, const char **virname, long int *scanned, cons |
971 | 971 |
tempname = cli_gentemp(tmpdir); |
972 | 972 |
|
973 | 973 |
if(mkdir(tempname, 0700)) { |
974 |
- cli_dbgmsg("ScanCHM -> Can't create temporary directory %s\n", tempname); |
|
974 |
+ cli_dbgmsg("CHM: Can't create temporary directory %s\n", tempname); |
|
975 | 975 |
return CL_ETMPDIR; |
976 | 976 |
} |
977 | 977 |
|
... | ... |
@@ -1004,7 +1045,7 @@ static int cli_scanmail(int desc, const char **virname, long int *scanned, const |
1004 | 1004 |
/* generate the temporary directory */ |
1005 | 1005 |
dir = cli_gentemp(tmpdir); |
1006 | 1006 |
if(mkdir(dir, 0700)) { |
1007 |
- cli_dbgmsg("ScanMail -> Can't create temporary directory %s\n", dir); |
|
1007 |
+ cli_dbgmsg("Mail: Can't create temporary directory %s\n", dir); |
|
1008 | 1008 |
return CL_ETMPDIR; |
1009 | 1009 |
} |
1010 | 1010 |
|
... | ... |
@@ -1024,7 +1065,7 @@ static int cli_scanmail(int desc, const char **virname, long int *scanned, const |
1024 | 1024 |
|
1025 | 1025 |
int cli_magic_scandesc(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options, int *arec, int *mrec) |
1026 | 1026 |
{ |
1027 |
- char magic[MAGIC_BUFFER_SIZE+1]; |
|
1027 |
+ char magic[MAGIC_BUFFER_SIZE + 1]; |
|
1028 | 1028 |
int ret = CL_CLEAN, nret; |
1029 | 1029 |
int bread = 0; |
1030 | 1030 |
cli_file_t type; |
... | ... |
@@ -1038,7 +1079,7 @@ int cli_magic_scandesc(int desc, const char **virname, long int *scanned, const |
1038 | 1038 |
if(!options) { /* raw mode (stdin, etc.) */ |
1039 | 1039 |
cli_dbgmsg("Raw mode: no support for archives.\n"); |
1040 | 1040 |
if((ret = cli_scandesc(desc, virname, scanned, root, 0) == CL_VIRUS)) |
1041 |
- cli_dbgmsg("%s virus found in descriptor %d.\n", *virname, desc); |
|
1041 |
+ cli_dbgmsg("%s found in descriptor %d\n", *virname, desc); |
|
1042 | 1042 |
return ret; |
1043 | 1043 |
} |
1044 | 1044 |
|
... | ... |
@@ -1057,17 +1098,17 @@ int cli_magic_scandesc(int desc, const char **virname, long int *scanned, const |
1057 | 1057 |
} |
1058 | 1058 |
|
1059 | 1059 |
lseek(desc, 0, SEEK_SET); |
1060 |
- bread = read(desc, magic, MAGIC_BUFFER_SIZE); |
|
1061 |
- magic[MAGIC_BUFFER_SIZE] = '\0'; |
|
1062 |
- lseek(desc, 0, SEEK_SET); |
|
1060 |
+ memset(magic, 0, sizeof(magic)); |
|
1063 | 1061 |
|
1064 |
- if(bread != MAGIC_BUFFER_SIZE) { |
|
1065 |
- /* short read: No need to do magic */ |
|
1066 |
- if((ret = cli_scandesc(desc, virname, scanned, root, 0) == CL_VIRUS)) |
|
1067 |
- cli_dbgmsg("%s virus found in descriptor %d.\n", *virname, desc); |
|
1068 |
- return ret; |
|
1062 |
+ if((bread = read(desc, magic, MAGIC_BUFFER_SIZE)) == -1) { |
|
1063 |
+ cli_dbgmsg("Can't read from descriptor %d\n"); |
|
1064 |
+ return CL_EIO; |
|
1065 |
+ } else if(bread < 2) { |
|
1066 |
+ /* short read - no need to do magic */ |
|
1067 |
+ return CL_CLEAN; |
|
1069 | 1068 |
} |
1070 | 1069 |
|
1070 |
+ lseek(desc, 0, SEEK_SET); |
|
1071 | 1071 |
type = cli_filetype(magic, bread); |
1072 | 1072 |
|
1073 | 1073 |
type == CL_MAILFILE ? (*mrec)++ : (*arec)++; |
... | ... |
@@ -1120,6 +1161,11 @@ int cli_magic_scandesc(int desc, const char **virname, long int *scanned, const |
1120 | 1120 |
ret = cli_scanole2(desc, virname, scanned, root, limits, options, arec, mrec); |
1121 | 1121 |
break; |
1122 | 1122 |
|
1123 |
+ case CL_TARFILE: |
|
1124 |
+ if(SCAN_ARCHIVE) |
|
1125 |
+ ret = cli_scantar(desc, virname, scanned, root, limits, options, arec, mrec); |
|
1126 |
+ break; |
|
1127 |
+ |
|
1123 | 1128 |
case CL_DATAFILE: |
1124 | 1129 |
/* it could be a false positive and a standard DOS .COM file */ |
1125 | 1130 |
{ |
... | ... |
@@ -1145,7 +1191,7 @@ int cli_magic_scandesc(int desc, const char **virname, long int *scanned, const |
1145 | 1145 |
lseek(desc, 0, SEEK_SET); |
1146 | 1146 |
|
1147 | 1147 |
if((nret = cli_scandesc(desc, virname, scanned, root, typerec)) == CL_VIRUS) { |
1148 |
- cli_dbgmsg("%s virus found in descriptor %d.\n", *virname, desc); |
|
1148 |
+ cli_dbgmsg("%s found in descriptor %d.\n", *virname, desc); |
|
1149 | 1149 |
return CL_VIRUS; |
1150 | 1150 |
|
1151 | 1151 |
} else if(nret >= CL_TYPENO) { |
... | ... |
@@ -27,6 +27,8 @@ |
27 | 27 |
#include "clamav.h" |
28 | 28 |
#include "cfgparser.h" |
29 | 29 |
#include "memory.h" |
30 |
+#include "output.h" |
|
31 |
+ |
|
30 | 32 |
|
31 | 33 |
const char *freshdbdir(void) |
32 | 34 |
{ |
... | ... |
@@ -70,7 +72,7 @@ const char *freshdbdir(void) |
70 | 70 |
void print_version(void) |
71 | 71 |
{ |
72 | 72 |
const char *dbdir; |
73 |
- char *path, *timecpy; |
|
73 |
+ char *path; |
|
74 | 74 |
struct cl_cvd *daily; |
75 | 75 |
|
76 | 76 |
|