2003-07-29 15:48:06 +00:00
|
|
|
/*
|
2005-01-11 01:34:19 +00:00
|
|
|
* Copyright (C) 2002 - 2005 Tomasz Kojm <tkojm@clamav.net>
|
2003-07-29 15:48:06 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
2004-02-06 13:46:08 +00:00
|
|
|
#if HAVE_CONFIG_H
|
|
|
|
#include "clamav-config.h"
|
|
|
|
#endif
|
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2004-11-13 14:47:20 +00:00
|
|
|
#include <sys/param.h>
|
2003-07-29 15:48:06 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <dirent.h>
|
2004-08-05 18:01:20 +00:00
|
|
|
#include <netinet/in.h>
|
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2004-07-02 23:00:58 +00:00
|
|
|
#if HAVE_MMAP
|
|
|
|
#if HAVE_SYS_MMAN_H
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#else /* HAVE_SYS_MMAN_H */
|
|
|
|
#undef HAVE_MMAP
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2004-06-02 00:36:05 +00:00
|
|
|
#include <mspack.h>
|
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
#ifdef CL_THREAD_SAFE
|
|
|
|
# include <pthread.h>
|
|
|
|
pthread_mutex_t cli_scanrar_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
#endif
|
2004-02-06 13:46:08 +00:00
|
|
|
int cli_scanrar_inuse = 0;
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2004-06-02 00:36:05 +00:00
|
|
|
extern short cli_leavetemps_flag;
|
|
|
|
|
2004-08-09 21:37:21 +00:00
|
|
|
extern int cli_mbox(const char *dir, int desc, unsigned int options); /* FIXME */
|
2004-07-19 17:54:40 +00:00
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
#include "clamav.h"
|
|
|
|
#include "others.h"
|
2004-08-02 17:09:06 +00:00
|
|
|
#include "scanners.h"
|
2004-07-19 17:54:40 +00:00
|
|
|
#include "matcher-ac.h"
|
|
|
|
#include "matcher-bm.h"
|
2003-07-29 15:48:06 +00:00
|
|
|
#include "matcher.h"
|
|
|
|
#include "unrarlib.h"
|
2004-01-23 11:17:16 +00:00
|
|
|
#include "ole2_extract.h"
|
|
|
|
#include "vba_extract.h"
|
2004-05-02 00:51:01 +00:00
|
|
|
#include "msexpand.h"
|
2004-07-20 01:31:25 +00:00
|
|
|
#include "chmunpack.h"
|
2004-07-05 23:50:55 +00:00
|
|
|
#include "pe.h"
|
2004-07-02 23:00:58 +00:00
|
|
|
#include "filetypes.h"
|
|
|
|
#include "htmlnorm.h"
|
2004-09-07 21:19:02 +00:00
|
|
|
#include "untar.h"
|
2004-09-30 00:26:52 +00:00
|
|
|
#include "special.h"
|
2005-01-26 17:45:25 +00:00
|
|
|
#include "binhex.h"
|
2003-07-29 15:48:06 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_ZLIB_H
|
|
|
|
#include <zlib.h>
|
|
|
|
#include <zzip.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_BZLIB_H
|
|
|
|
#include <bzlib.h>
|
|
|
|
#endif
|
|
|
|
|
2004-10-20 20:20:20 +00:00
|
|
|
#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
|
|
|
|
#include <limits.h>
|
2004-11-02 04:08:09 +00:00
|
|
|
#include <stddef.h>
|
2004-10-20 20:20:20 +00:00
|
|
|
#endif
|
|
|
|
|
2004-11-13 14:47:20 +00:00
|
|
|
/* Maximum filenames under various systems - njh */
|
|
|
|
#ifndef NAME_MAX /* e.g. Linux */
|
|
|
|
# ifdef MAXNAMELEN /* e.g. Solaris */
|
|
|
|
# define NAME_MAX MAXNAMELEN
|
|
|
|
# else
|
|
|
|
# ifdef FILENAME_MAX /* e.g. SCO */
|
|
|
|
# define NAME_MAX FILENAME_MAX
|
|
|
|
# endif
|
|
|
|
# endif
|
|
|
|
#endif
|
2004-10-20 20:20:20 +00:00
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
#define SCAN_ARCHIVE (options & CL_SCAN_ARCHIVE)
|
|
|
|
#define SCAN_MAIL (options & CL_SCAN_MAIL)
|
|
|
|
#define SCAN_OLE2 (options & CL_SCAN_OLE2)
|
|
|
|
#define SCAN_HTML (options & CL_SCAN_HTML)
|
|
|
|
#define SCAN_PE (options & CL_SCAN_PE)
|
|
|
|
#define DISABLE_RAR (options & CL_SCAN_DISABLERAR)
|
2004-09-18 19:26:08 +00:00
|
|
|
#define DETECT_ENCRYPTED (options & CL_SCAN_BLOCKENCRYPTED)
|
2004-09-13 16:44:01 +00:00
|
|
|
#define BLOCKMAX (options & CL_SCAN_BLOCKMAX)
|
2004-02-06 13:46:08 +00:00
|
|
|
|
2004-07-06 02:27:22 +00:00
|
|
|
#define MAX_MAIL_RECURSION 15
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
static int cli_scanfile(const char *filename, const char **virname, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec);
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2004-07-13 03:30:49 +00:00
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
#ifdef CL_THREAD_SAFE
|
2004-03-11 08:33:45 +00:00
|
|
|
static void cli_unlock_mutex(void *mtx)
|
2003-07-29 15:48:06 +00:00
|
|
|
{
|
|
|
|
cli_dbgmsg("Pthread cancelled. Unlocking mutex.\n");
|
|
|
|
pthread_mutex_unlock(mtx);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
static int cli_scanrar(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec)
|
2003-07-29 15:48:06 +00:00
|
|
|
{
|
2003-11-09 19:26:44 +00:00
|
|
|
FILE *tmp = NULL;
|
2004-03-15 16:01:55 +00:00
|
|
|
int files = 0, fd, ret = CL_CLEAN, afiles;
|
2003-07-29 15:48:06 +00:00
|
|
|
ArchiveList_struct *rarlist = NULL;
|
2004-03-11 08:33:45 +00:00
|
|
|
ArchiveList_struct *rarlist_head = NULL;
|
2003-07-29 15:48:06 +00:00
|
|
|
char *rar_data_ptr;
|
|
|
|
unsigned long rar_data_size;
|
|
|
|
|
2004-09-07 21:19:02 +00:00
|
|
|
|
|
|
|
cli_dbgmsg("in scanrar()\n");
|
2003-07-29 15:48:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef CL_THREAD_SAFE
|
|
|
|
pthread_cleanup_push(cli_unlock_mutex, &cli_scanrar_mutex);
|
|
|
|
pthread_mutex_lock(&cli_scanrar_mutex);
|
|
|
|
cli_scanrar_inuse = 1;
|
|
|
|
#endif
|
|
|
|
|
2004-03-15 16:01:55 +00:00
|
|
|
if(! (afiles = urarlib_list(desc, (ArchiveList_struct *) &rarlist))) {
|
2003-07-29 15:48:06 +00:00
|
|
|
#ifdef CL_THREAD_SAFE
|
|
|
|
pthread_mutex_unlock(&cli_scanrar_mutex);
|
|
|
|
cli_scanrar_inuse = 0;
|
|
|
|
#endif
|
|
|
|
return CL_ERAR;
|
|
|
|
}
|
|
|
|
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("RAR: Number of archived files: %d\n", afiles);
|
2004-03-15 16:01:55 +00:00
|
|
|
|
2004-03-11 08:33:45 +00:00
|
|
|
rarlist_head = rarlist;
|
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
while(rarlist) {
|
2004-11-27 18:56:39 +00:00
|
|
|
if(DETECT_ENCRYPTED && (rarlist->item.Flags & 0x04)) {
|
2004-03-11 20:48:01 +00:00
|
|
|
files++;
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("RAR: Encrypted files found in archive.\n");
|
2004-05-01 19:33:05 +00:00
|
|
|
lseek(desc, 0, SEEK_SET);
|
2004-11-08 09:03:33 +00:00
|
|
|
ret = cli_scandesc(desc, virname, scanned, root, 0, 0);
|
|
|
|
if(ret < 0) {
|
|
|
|
break;
|
|
|
|
} else if(ret != CL_VIRUS) {
|
2004-05-01 19:33:05 +00:00
|
|
|
*virname = "Encrypted.RAR";
|
2004-11-08 09:03:33 +00:00
|
|
|
ret = CL_VIRUS;
|
|
|
|
}
|
2004-03-11 20:48:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2004-11-27 18:56:39 +00:00
|
|
|
if((rarlist->item.Flags & 0x03) != 0) {
|
|
|
|
cli_dbgmsg("RAR: Skipping %s (splitted)\n", rarlist->item.Name);
|
|
|
|
rarlist = rarlist->next;
|
|
|
|
files++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
if(limits) {
|
2004-09-13 01:43:57 +00:00
|
|
|
|
|
|
|
if(limits->maxratio && rarlist->item.UnpSize && rarlist->item.PackSize) {
|
|
|
|
if((unsigned int) rarlist->item.UnpSize / (unsigned int) rarlist->item.PackSize >= limits->maxratio) {
|
|
|
|
cli_dbgmsg("RAR: Max ratio reached (normal: %d, compressed: %d, max: %ld)\n", (int) rarlist->item.UnpSize, (int) rarlist->item.PackSize, limits->maxratio);
|
|
|
|
*virname = "Oversized.RAR";
|
|
|
|
ret = CL_VIRUS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-19 14:57:03 +00:00
|
|
|
if(limits->maxfilesize && (rarlist->item.UnpSize > (unsigned int) limits->maxfilesize)) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("RAR: %s: Size exceeded (%u, max: %lu)\n", rarlist->item.Name, (unsigned int) rarlist->item.UnpSize, limits->maxfilesize);
|
2003-07-29 15:48:06 +00:00
|
|
|
rarlist = rarlist->next;
|
|
|
|
files++;
|
2004-09-13 01:43:57 +00:00
|
|
|
if(BLOCKMAX) {
|
|
|
|
*virname = "RAR.ExceededFileSize";
|
|
|
|
ret = CL_VIRUS;
|
|
|
|
break;
|
|
|
|
}
|
2003-07-29 15:48:06 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(limits->maxfiles && (files > limits->maxfiles)) {
|
|
|
|
cli_dbgmsg("RAR: Files limit reached (max: %d)\n", limits->maxfiles);
|
2004-09-13 01:43:57 +00:00
|
|
|
if(BLOCKMAX) {
|
|
|
|
*virname = "RAR.ExceededFilesLimit";
|
|
|
|
ret = CL_VIRUS;
|
|
|
|
break;
|
|
|
|
}
|
2003-07-29 15:48:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-19 21:01:47 +00:00
|
|
|
if(rarlist->item.FileAttr & RAR_FENTRY_ATTR_DIRECTORY) {
|
2004-03-11 08:33:45 +00:00
|
|
|
rarlist = rarlist->next;
|
|
|
|
files++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
if((tmp = tmpfile()) == NULL) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("RAR: Can't generate temporary file.\n");
|
2003-07-29 15:48:06 +00:00
|
|
|
#ifdef CL_THREAD_SAFE
|
|
|
|
pthread_mutex_unlock(&cli_scanrar_mutex);
|
|
|
|
cli_scanrar_inuse = 0;
|
|
|
|
#endif
|
|
|
|
return CL_ETMPFILE;
|
|
|
|
}
|
|
|
|
fd = fileno(tmp);
|
|
|
|
|
2004-03-11 08:33:45 +00:00
|
|
|
if( urarlib_get(&rar_data_ptr, &rar_data_size, rarlist->item.Name, desc, "clam")) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("RAR: Extracted: %s, size: %lu\n", rarlist->item.Name, rar_data_size);
|
2004-03-11 08:33:45 +00:00
|
|
|
if(fwrite(rar_data_ptr, 1, rar_data_size, tmp) != rar_data_size) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("RAR: Can't write to file.\n");
|
2003-09-07 19:43:04 +00:00
|
|
|
fclose(tmp);
|
2003-07-29 15:48:06 +00:00
|
|
|
tmp = NULL;
|
|
|
|
ret = CL_ERAR;
|
2003-09-07 19:43:04 +00:00
|
|
|
if(rar_data_ptr) {
|
2003-07-29 15:48:06 +00:00
|
|
|
free(rar_data_ptr);
|
2003-09-07 19:43:04 +00:00
|
|
|
rar_data_ptr = NULL;
|
|
|
|
}
|
2003-09-21 20:02:01 +00:00
|
|
|
break;
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
2003-09-07 19:43:04 +00:00
|
|
|
if(rar_data_ptr) {
|
2003-07-29 15:48:06 +00:00
|
|
|
free(rar_data_ptr);
|
2003-09-07 19:43:04 +00:00
|
|
|
rar_data_ptr = NULL;
|
|
|
|
}
|
|
|
|
if(fflush(tmp) != 0) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("RAR: fflush() failed: %s\n", strerror(errno));
|
2003-09-07 19:43:04 +00:00
|
|
|
fclose(tmp);
|
2004-03-11 08:33:45 +00:00
|
|
|
urarlib_freelist(rarlist_head);
|
2003-07-29 15:48:06 +00:00
|
|
|
#ifdef CL_THREAD_SAFE
|
|
|
|
pthread_mutex_unlock(&cli_scanrar_mutex);
|
|
|
|
cli_scanrar_inuse = 0;
|
|
|
|
#endif
|
|
|
|
return CL_EFSYNC;
|
|
|
|
}
|
|
|
|
|
|
|
|
lseek(fd, 0, SEEK_SET);
|
2004-07-04 14:56:48 +00:00
|
|
|
if((ret = cli_magic_scandesc(fd, virname, scanned, root, limits, options, arec, mrec)) == CL_VIRUS ) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("RAR: Infected with %s\n", *virname);
|
2004-02-06 13:46:08 +00:00
|
|
|
|
2003-09-07 19:43:04 +00:00
|
|
|
fclose(tmp);
|
2003-07-29 15:48:06 +00:00
|
|
|
urarlib_freelist(rarlist);
|
|
|
|
#ifdef CL_THREAD_SAFE
|
|
|
|
pthread_mutex_unlock(&cli_scanrar_mutex);
|
|
|
|
cli_scanrar_inuse = 0;
|
|
|
|
#endif
|
2004-03-11 08:33:45 +00:00
|
|
|
return ret;
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("RAR: Can't decompress file %s\n", rarlist->item.Name);
|
2003-09-07 19:43:04 +00:00
|
|
|
fclose(tmp);
|
2004-03-16 19:39:49 +00:00
|
|
|
tmp = NULL;
|
2003-09-07 19:43:04 +00:00
|
|
|
ret = CL_ERAR; /* WinRAR 3.0 ? */
|
|
|
|
break;
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
2003-09-07 19:43:04 +00:00
|
|
|
fclose(tmp);
|
2003-07-29 15:48:06 +00:00
|
|
|
tmp = NULL;
|
|
|
|
rarlist = rarlist->next;
|
|
|
|
files++;
|
|
|
|
}
|
|
|
|
|
2004-03-11 08:33:45 +00:00
|
|
|
urarlib_freelist(rarlist_head);
|
2003-07-29 15:48:06 +00:00
|
|
|
#ifdef CL_THREAD_SAFE
|
|
|
|
pthread_mutex_unlock(&cli_scanrar_mutex);
|
|
|
|
cli_scanrar_inuse = 0;
|
|
|
|
pthread_cleanup_pop(0);
|
|
|
|
#endif
|
2004-03-16 19:39:49 +00:00
|
|
|
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("RAR: Exit code: %d\n", ret);
|
2004-03-16 19:39:49 +00:00
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_ZLIB_H
|
2004-09-13 16:44:01 +00:00
|
|
|
static int cli_scanzip(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec)
|
2003-07-29 15:48:06 +00:00
|
|
|
{
|
|
|
|
ZZIP_DIR *zdir;
|
|
|
|
ZZIP_DIRENT zdirent;
|
|
|
|
ZZIP_FILE *zfp;
|
2003-11-09 19:26:44 +00:00
|
|
|
FILE *tmp = NULL;
|
2003-11-09 02:29:23 +00:00
|
|
|
char *buff;
|
2005-02-20 04:14:06 +00:00
|
|
|
int fd, bytes, files = 0, ret = CL_CLEAN, encrypted;
|
2003-11-09 19:26:44 +00:00
|
|
|
struct stat source;
|
2005-02-20 04:14:06 +00:00
|
|
|
struct cli_zip_node *mdata;
|
2004-02-01 01:18:57 +00:00
|
|
|
zzip_error_t err;
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2004-09-07 21:19:02 +00:00
|
|
|
|
|
|
|
cli_dbgmsg("in scanzip()\n");
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2003-08-29 14:27:15 +00:00
|
|
|
if((zdir = zzip_dir_fdopen(dup(desc), &err)) == NULL) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("Zip: Not supported file format ?.\n");
|
|
|
|
cli_dbgmsg("Zip: zzip_dir_fdopen() return code: %d\n", err);
|
2003-12-30 03:36:47 +00:00
|
|
|
/* no return with CL_EZIP due to password protected zips */
|
|
|
|
return CL_CLEAN;
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
2003-11-09 19:26:44 +00:00
|
|
|
fstat(desc, &source);
|
|
|
|
|
2003-11-15 00:22:10 +00:00
|
|
|
if(!(buff = (char *) cli_malloc(FILEBUFF))) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("Zip: unable to malloc(%d)\n", FILEBUFF);
|
2003-11-15 00:22:10 +00:00
|
|
|
zzip_dir_close(zdir);
|
|
|
|
return CL_EMEM;
|
|
|
|
}
|
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
while(zzip_dir_read(zdir, &zdirent)) {
|
2005-02-27 01:31:02 +00:00
|
|
|
files++;
|
2003-11-09 19:26:44 +00:00
|
|
|
|
|
|
|
if(!zdirent.d_name || !strlen(zdirent.d_name)) { /* Mimail fix */
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("Zip: strlen(zdirent.d_name) == %d\n", strlen(zdirent.d_name));
|
2003-11-26 13:33:51 +00:00
|
|
|
*virname = "Suspected.Zip";
|
2003-11-09 19:26:44 +00:00
|
|
|
ret = CL_VIRUS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-02-20 04:14:06 +00:00
|
|
|
encrypted = zdirent.d_flags;
|
|
|
|
|
|
|
|
cli_dbgmsg("Zip: %s, crc32: 0x%x, encrypted: %d, compressed: %u, normal: %u, ratio: %d (max: %d)\n", zdirent.d_name, zdirent.d_crc32, encrypted, zdirent.d_csize, zdirent.st_size, zdirent.d_csize ? (zdirent.st_size / zdirent.d_csize) : 0, limits ? limits->maxratio : -1);
|
2003-11-09 19:26:44 +00:00
|
|
|
|
2004-11-15 22:58:03 +00:00
|
|
|
if(!zdirent.st_size) {
|
2004-11-18 10:05:58 +00:00
|
|
|
if(zdirent.d_crc32) {
|
|
|
|
cli_dbgmsg("Zip: Broken file or modified information in local header part of archive\n");
|
|
|
|
*virname = "Suspected.Zip";
|
|
|
|
ret = CL_VIRUS;
|
|
|
|
break;
|
|
|
|
}
|
2003-07-29 15:48:06 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2005-02-20 04:14:06 +00:00
|
|
|
/* Scan metadata */
|
|
|
|
mdata = root->zip_mlist;
|
2005-02-24 17:41:33 +00:00
|
|
|
if(mdata) do {
|
2005-02-20 04:14:06 +00:00
|
|
|
if(mdata->encrypted != encrypted)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(mdata->crc32 && mdata->crc32 != zdirent.d_crc32)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(mdata->csize > 0 && mdata->csize != zdirent.d_csize)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(mdata->size >= 0 && mdata->size != zdirent.st_size)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(mdata->compr >= 0 && mdata->compr != zdirent.d_compr)
|
|
|
|
continue;
|
|
|
|
|
2005-02-27 01:31:02 +00:00
|
|
|
if(mdata->fileno && mdata->fileno != files)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(mdata->maxdepth && *arec > mdata->maxdepth)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* TODO add support for regex */
|
2005-02-20 04:14:06 +00:00
|
|
|
/*if(mdata->filename && !strstr(zdirent.d_name, mdata->filename))*/
|
|
|
|
if(mdata->filename && strcmp(zdirent.d_name, mdata->filename))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
break; /* matched */
|
|
|
|
|
|
|
|
} while((mdata = mdata->next));
|
|
|
|
|
|
|
|
if(mdata) {
|
|
|
|
*virname = mdata->virname;
|
|
|
|
ret = CL_VIRUS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-02-05 15:22:31 +00:00
|
|
|
/*
|
|
|
|
* Workaround for archives created with ICEOWS.
|
|
|
|
* ZZIP_DIRENT does not contain information on file type
|
|
|
|
* so we try to determine a directory via a filename
|
|
|
|
*/
|
|
|
|
if(zdirent.d_name[strlen(zdirent.d_name) - 1] == '/') {
|
|
|
|
cli_dbgmsg("Zip: Directory entry with st_size != 0\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
/* work-around for problematic zips (zziplib crashes with them) */
|
2004-06-21 19:29:21 +00:00
|
|
|
if(zdirent.d_csize <= 0 || zdirent.st_size < 0) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("Zip: Malformed archive detected.\n");
|
2003-11-26 13:33:51 +00:00
|
|
|
*virname = "Suspected.Zip";
|
2003-11-09 19:26:44 +00:00
|
|
|
ret = CL_VIRUS;
|
2003-07-29 15:48:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-06-21 19:29:21 +00:00
|
|
|
if(limits && limits->maxratio > 0 && ((unsigned) zdirent.st_size / (unsigned) zdirent.d_csize) >= limits->maxratio) {
|
|
|
|
*virname = "Oversized.Zip";
|
|
|
|
ret = CL_VIRUS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-02-20 04:14:06 +00:00
|
|
|
if(DETECT_ENCRYPTED && encrypted) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("Zip: Encrypted files found in archive.\n");
|
2004-05-01 19:33:05 +00:00
|
|
|
lseek(desc, 0, SEEK_SET);
|
2004-11-08 09:03:33 +00:00
|
|
|
ret = cli_scandesc(desc, virname, scanned, root, 0, 0);
|
|
|
|
if(ret < 0) {
|
|
|
|
break;
|
|
|
|
} else if(ret != CL_VIRUS) {
|
2004-05-01 19:33:05 +00:00
|
|
|
*virname = "Encrypted.Zip";
|
2004-11-08 09:03:33 +00:00
|
|
|
ret = CL_VIRUS;
|
|
|
|
}
|
2004-03-04 02:27:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
if(limits) {
|
|
|
|
if(limits->maxfilesize && (zdirent.st_size > limits->maxfilesize)) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("Zip: %s: Size exceeded (%d, max: %ld)\n", zdirent.d_name, zdirent.st_size, limits->maxfilesize);
|
2004-02-03 01:35:25 +00:00
|
|
|
/* ret = CL_EMAXSIZE; */
|
2004-09-13 01:43:57 +00:00
|
|
|
if(BLOCKMAX) {
|
|
|
|
*virname = "Zip.ExceededFileSize";
|
|
|
|
ret = CL_VIRUS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
continue; /* continue scanning */
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(limits->maxfiles && (files > limits->maxfiles)) {
|
|
|
|
cli_dbgmsg("Zip: Files limit reached (max: %d)\n", limits->maxfiles);
|
2004-09-13 01:43:57 +00:00
|
|
|
if(BLOCKMAX) {
|
|
|
|
*virname = "Zip.ExceededFilesLimit";
|
|
|
|
ret = CL_VIRUS;
|
|
|
|
break;
|
|
|
|
}
|
2003-07-29 15:48:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-26 21:09:02 +00:00
|
|
|
if((zfp = zzip_file_open(zdir, zdirent.d_name, 0)) == NULL) {
|
|
|
|
cli_dbgmsg("Zip: Can't open file %s\n", zdirent.d_name);
|
|
|
|
ret = CL_EZIP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
/* generate temporary file and get its descriptor */
|
|
|
|
if((tmp = tmpfile()) == NULL) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("Zip: Can't generate tmpfile().\n");
|
2005-03-04 01:11:06 +00:00
|
|
|
zzip_file_close(zfp);
|
2003-11-09 19:26:44 +00:00
|
|
|
ret = CL_ETMPFILE;
|
|
|
|
break;
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
2003-11-09 02:29:23 +00:00
|
|
|
while((bytes = zzip_file_read(zfp, buff, FILEBUFF)) > 0) {
|
2004-04-20 22:33:42 +00:00
|
|
|
if(fwrite(buff, 1, bytes, tmp) != (size_t) bytes) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("Zip: Can't write to file.\n");
|
2003-07-29 15:48:06 +00:00
|
|
|
zzip_file_close(zfp);
|
2003-11-15 00:22:10 +00:00
|
|
|
zzip_dir_close(zdir);
|
|
|
|
fclose(tmp);
|
2003-11-09 02:29:23 +00:00
|
|
|
free(buff);
|
2004-11-26 21:09:02 +00:00
|
|
|
return CL_EIO;
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
zzip_file_close(zfp);
|
|
|
|
|
2003-09-07 19:43:04 +00:00
|
|
|
if(fflush(tmp) != 0) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("Zip: fflush() failed: %s\n", strerror(errno));
|
2003-11-09 19:26:44 +00:00
|
|
|
ret = CL_EFSYNC;
|
|
|
|
break;
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
2003-09-07 19:43:04 +00:00
|
|
|
fd = fileno(tmp);
|
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
lseek(fd, 0, SEEK_SET);
|
2004-07-04 14:56:48 +00:00
|
|
|
if((ret = cli_magic_scandesc(fd, virname, scanned, root, limits, options, arec, mrec)) == CL_VIRUS ) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("Zip: Infected with %s\n", *virname);
|
2003-07-29 15:48:06 +00:00
|
|
|
ret = CL_VIRUS;
|
|
|
|
break;
|
|
|
|
} else if(ret == CL_EMALFZIP) {
|
|
|
|
/*
|
2003-11-09 19:26:44 +00:00
|
|
|
* The trick with detection of ZoD only works with higher (>= 5)
|
2003-07-29 15:48:06 +00:00
|
|
|
* recursion limit level.
|
|
|
|
*/
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("Zip: Malformed Zip file, scanning stopped.\n");
|
2003-11-26 13:33:51 +00:00
|
|
|
*virname = "Suspected.Zip";
|
2003-07-29 15:48:06 +00:00
|
|
|
ret = CL_VIRUS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-09-07 19:43:04 +00:00
|
|
|
if (tmp) {
|
|
|
|
fclose(tmp);
|
|
|
|
tmp = NULL;
|
|
|
|
}
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
zzip_dir_close(zdir);
|
2003-09-07 19:43:04 +00:00
|
|
|
if (tmp) {
|
|
|
|
fclose(tmp);
|
|
|
|
tmp = NULL;
|
|
|
|
}
|
2003-11-15 00:22:10 +00:00
|
|
|
|
|
|
|
free(buff);
|
2003-07-29 15:48:06 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
static int cli_scangzip(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec)
|
2003-07-29 15:48:06 +00:00
|
|
|
{
|
|
|
|
int fd, bytes, ret = CL_CLEAN;
|
|
|
|
long int size = 0;
|
2003-11-09 02:29:23 +00:00
|
|
|
char *buff;
|
2003-11-09 19:26:44 +00:00
|
|
|
FILE *tmp = NULL;
|
2003-07-29 15:48:06 +00:00
|
|
|
gzFile gd;
|
|
|
|
|
|
|
|
|
2003-11-09 19:26:44 +00:00
|
|
|
cli_dbgmsg("in cli_scangzip()\n");
|
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
if((gd = gzdopen(dup(desc), "rb")) == NULL) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("GZip: Can't open descriptor %d\n", desc);
|
2003-07-29 15:48:06 +00:00
|
|
|
return CL_EGZIP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((tmp = tmpfile()) == NULL) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("GZip: Can't generate temporary file.\n");
|
2003-07-29 15:48:06 +00:00
|
|
|
gzclose(gd);
|
|
|
|
return CL_ETMPFILE;
|
|
|
|
}
|
|
|
|
fd = fileno(tmp);
|
|
|
|
|
2003-11-09 19:26:44 +00:00
|
|
|
if(!(buff = (char *) cli_malloc(FILEBUFF))) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("GZip: Unable to malloc %d bytes.\n", FILEBUFF);
|
2003-11-09 19:26:44 +00:00
|
|
|
gzclose(gd);
|
2003-11-09 02:29:23 +00:00
|
|
|
return CL_EMEM;
|
2003-11-09 19:26:44 +00:00
|
|
|
}
|
2003-11-09 02:29:23 +00:00
|
|
|
|
2003-11-09 19:26:44 +00:00
|
|
|
while((bytes = gzread(gd, buff, FILEBUFF)) > 0) {
|
2003-07-29 15:48:06 +00:00
|
|
|
size += bytes;
|
|
|
|
|
|
|
|
if(limits)
|
2003-11-09 19:26:44 +00:00
|
|
|
if(limits->maxfilesize && (size + FILEBUFF > limits->maxfilesize)) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("GZip: Size exceeded (stopped at %ld, max: %ld)\n", size, limits->maxfilesize);
|
2004-02-03 01:35:25 +00:00
|
|
|
/* ret = CL_EMAXSIZE; */
|
2003-07-29 15:48:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-03-26 15:31:01 +00:00
|
|
|
if(cli_writen(fd, buff, bytes) != bytes) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("GZip: Can't write to file.\n");
|
2003-09-07 19:43:04 +00:00
|
|
|
fclose(tmp);
|
2003-07-29 15:48:06 +00:00
|
|
|
gzclose(gd);
|
2003-11-09 02:29:23 +00:00
|
|
|
free(buff);
|
2003-07-29 15:48:06 +00:00
|
|
|
return CL_EGZIP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-09 02:29:23 +00:00
|
|
|
free(buff);
|
2003-07-29 15:48:06 +00:00
|
|
|
gzclose(gd);
|
|
|
|
if(fsync(fd) == -1) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("GZip: Can't synchronise descriptor %d\n", fd);
|
2003-09-07 19:43:04 +00:00
|
|
|
fclose(tmp);
|
2003-07-29 15:48:06 +00:00
|
|
|
return CL_EFSYNC;
|
|
|
|
}
|
|
|
|
|
|
|
|
lseek(fd, 0, SEEK_SET);
|
2004-07-04 14:56:48 +00:00
|
|
|
if((ret = cli_magic_scandesc(fd, virname, scanned, root, limits, options, arec, mrec)) == CL_VIRUS ) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("GZip: Infected with %s\n", *virname);
|
2003-09-07 19:43:04 +00:00
|
|
|
fclose(tmp);
|
2003-07-29 15:48:06 +00:00
|
|
|
return CL_VIRUS;
|
|
|
|
}
|
2003-09-07 19:43:04 +00:00
|
|
|
fclose(tmp);
|
2003-07-29 15:48:06 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_BZLIB_H
|
|
|
|
|
|
|
|
#ifdef NOBZ2PREFIX
|
|
|
|
#define BZ2_bzReadOpen bzReadOpen
|
|
|
|
#define BZ2_bzReadClose bzReadClose
|
|
|
|
#define BZ2_bzRead bzRead
|
|
|
|
#endif
|
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
static int cli_scanbzip(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec)
|
2003-07-29 15:48:06 +00:00
|
|
|
{
|
|
|
|
int fd, bytes, ret = CL_CLEAN, bzerror = 0;
|
|
|
|
short memlim = 0;
|
|
|
|
long int size = 0;
|
2003-11-09 02:29:23 +00:00
|
|
|
char *buff;
|
2003-11-09 19:26:44 +00:00
|
|
|
FILE *fs, *tmp = NULL;
|
2003-07-29 15:48:06 +00:00
|
|
|
BZFILE *bfd;
|
|
|
|
|
|
|
|
|
2003-12-01 19:28:40 +00:00
|
|
|
if((fs = fdopen(dup(desc), "rb")) == NULL) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("Bzip: Can't open descriptor %d.\n", desc);
|
2003-07-29 15:48:06 +00:00
|
|
|
return CL_EBZIP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(limits)
|
|
|
|
if(limits->archivememlim)
|
|
|
|
memlim = 1;
|
|
|
|
|
2003-12-20 12:27:44 +00:00
|
|
|
if((bfd = BZ2_bzReadOpen(&bzerror, fs, 0, memlim, NULL, 0)) == NULL) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("Bzip: Can't initialize bzip2 library (descriptor: %d).\n", desc);
|
2003-12-01 19:28:40 +00:00
|
|
|
fclose(fs);
|
2003-07-29 15:48:06 +00:00
|
|
|
return CL_EBZIP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((tmp = tmpfile()) == NULL) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("Bzip: Can't generate temporary file.\n");
|
2003-07-29 15:48:06 +00:00
|
|
|
BZ2_bzReadClose(&bzerror, bfd);
|
2003-12-01 19:28:40 +00:00
|
|
|
fclose(fs);
|
2003-07-29 15:48:06 +00:00
|
|
|
return CL_ETMPFILE;
|
|
|
|
}
|
|
|
|
fd = fileno(tmp);
|
|
|
|
|
2003-12-01 19:28:40 +00:00
|
|
|
if(!(buff = (char *) malloc(FILEBUFF))) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("Bzip: Unable to malloc %d bytes.\n", FILEBUFF);
|
2003-12-01 19:28:40 +00:00
|
|
|
fclose(tmp);
|
|
|
|
fclose(fs);
|
|
|
|
BZ2_bzReadClose(&bzerror, bfd);
|
2003-11-09 02:29:23 +00:00
|
|
|
return CL_EMEM;
|
2003-12-01 19:28:40 +00:00
|
|
|
}
|
2003-11-09 02:29:23 +00:00
|
|
|
|
2003-11-09 19:26:44 +00:00
|
|
|
while((bytes = BZ2_bzRead(&bzerror, bfd, buff, FILEBUFF)) > 0) {
|
2003-07-29 15:48:06 +00:00
|
|
|
size += bytes;
|
|
|
|
|
|
|
|
if(limits)
|
2003-11-09 19:26:44 +00:00
|
|
|
if(limits->maxfilesize && (size + FILEBUFF > limits->maxfilesize)) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("Bzip: Size exceeded (stopped at %ld, max: %ld)\n", size, limits->maxfilesize);
|
2004-02-03 01:35:25 +00:00
|
|
|
/* ret = CL_EMAXSIZE; */
|
2003-07-29 15:48:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-03-26 15:31:01 +00:00
|
|
|
if(cli_writen(fd, buff, bytes) != bytes) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("Bzip: Can't write to file.\n");
|
2003-07-29 15:48:06 +00:00
|
|
|
BZ2_bzReadClose(&bzerror, bfd);
|
2003-09-07 19:43:04 +00:00
|
|
|
fclose(tmp);
|
2003-11-09 02:29:23 +00:00
|
|
|
free(buff);
|
2003-12-01 19:28:40 +00:00
|
|
|
fclose(fs);
|
2003-07-29 15:48:06 +00:00
|
|
|
return CL_EGZIP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-09 02:29:23 +00:00
|
|
|
free(buff);
|
2003-07-29 15:48:06 +00:00
|
|
|
BZ2_bzReadClose(&bzerror, bfd);
|
|
|
|
if(fsync(fd) == -1) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("Bzip: Synchronisation failed for descriptor %d\n", fd);
|
2003-09-07 19:43:04 +00:00
|
|
|
fclose(tmp);
|
2003-12-01 19:28:40 +00:00
|
|
|
fclose(fs);
|
2003-07-29 15:48:06 +00:00
|
|
|
return CL_EFSYNC;
|
|
|
|
}
|
|
|
|
|
|
|
|
lseek(fd, 0, SEEK_SET);
|
2004-07-04 14:56:48 +00:00
|
|
|
if((ret = cli_magic_scandesc(fd, virname, scanned, root, limits, options, arec, mrec)) == CL_VIRUS ) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("Bzip: Infected with %s\n", *virname);
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
2003-09-07 19:43:04 +00:00
|
|
|
fclose(tmp);
|
2003-12-01 19:28:40 +00:00
|
|
|
fclose(fs);
|
2003-07-29 15:48:06 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
static int cli_scanszdd(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec)
|
2004-05-02 00:51:01 +00:00
|
|
|
{
|
|
|
|
int fd, ret = CL_CLEAN;
|
|
|
|
FILE *tmp = NULL, *in;
|
|
|
|
|
2004-09-07 21:19:02 +00:00
|
|
|
|
2004-05-02 00:51:01 +00:00
|
|
|
cli_dbgmsg("in cli_scanmscomp()\n");
|
|
|
|
|
|
|
|
if((in = fdopen(dup(desc), "rb")) == NULL) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("SZDD: Can't open descriptor %d\n", desc);
|
2004-05-02 00:51:01 +00:00
|
|
|
return CL_EMSCOMP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((tmp = tmpfile()) == NULL) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("SZDD: Can't generate temporary file.\n");
|
2004-05-02 00:51:01 +00:00
|
|
|
fclose(in);
|
|
|
|
return CL_ETMPFILE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(cli_msexpand(in, tmp) == -1) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("SZDD: msexpand failed.\n");
|
2004-05-02 00:51:01 +00:00
|
|
|
return CL_EMSCOMP;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(in);
|
|
|
|
if(fflush(tmp)) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("SZDD: fflush() failed.\n");
|
2004-05-02 00:51:01 +00:00
|
|
|
fclose(tmp);
|
|
|
|
return CL_EFSYNC;
|
|
|
|
}
|
|
|
|
|
|
|
|
fd = fileno(tmp);
|
|
|
|
lseek(fd, 0, SEEK_SET);
|
2004-07-04 14:56:48 +00:00
|
|
|
if((ret = cli_magic_scandesc(fd, virname, scanned, root, limits, options, arec, mrec)) == CL_VIRUS) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("SZDD: Infected with %s\n", *virname);
|
2004-05-02 00:51:01 +00:00
|
|
|
fclose(tmp);
|
|
|
|
return CL_VIRUS;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(tmp);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
static int cli_scanmscab(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec)
|
2004-06-02 00:36:05 +00:00
|
|
|
{
|
|
|
|
struct mscab_decompressor *cabd = NULL;
|
|
|
|
struct mscabd_cabinet *base, *cab;
|
|
|
|
struct mscabd_file *file;
|
|
|
|
char *tempname;
|
|
|
|
int ret = CL_CLEAN;
|
|
|
|
|
|
|
|
|
|
|
|
cli_dbgmsg("in cli_scanmscab()\n");
|
|
|
|
|
|
|
|
if((cabd = mspack_create_cab_decompressor(NULL)) == NULL) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("MSCAB: Can't create libmspack CAB decompressor\n");
|
2004-06-02 00:36:05 +00:00
|
|
|
return CL_EMSCAB;
|
|
|
|
}
|
|
|
|
|
2004-11-15 22:58:03 +00:00
|
|
|
if((base = cabd->dsearch(cabd, dup(desc))) == NULL) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("MSCAB: I/O error or no valid cabinets found\n");
|
2004-06-02 00:36:05 +00:00
|
|
|
mspack_destroy_cab_decompressor(cabd);
|
|
|
|
return CL_EMSCAB;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(cab = base; cab; cab = cab->next) {
|
|
|
|
for(file = cab->files; file; file = file->next) {
|
2004-10-04 01:15:12 +00:00
|
|
|
|
|
|
|
if(limits && limits->maxfilesize && (file->length > (unsigned int) limits->maxfilesize)) {
|
|
|
|
cli_dbgmsg("MSCAB: %s: Size exceeded (%u, max: %lu)\n", file->filename, file->length, limits->maxfilesize);
|
|
|
|
if(BLOCKMAX) {
|
|
|
|
*virname = "MSCAB.ExceededFileSize";
|
|
|
|
cabd->close(cabd, base);
|
|
|
|
mspack_destroy_cab_decompressor(cabd);
|
|
|
|
return CL_VIRUS;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-11-16 17:10:47 +00:00
|
|
|
tempname = cli_gentemp(NULL);
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("MSCAB: Extracting data to %s\n", tempname);
|
2004-06-02 00:36:05 +00:00
|
|
|
if(cabd->extract(cabd, file, tempname)) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("MSCAB: libmscab error code: %d\n", cabd->last_error(cabd));
|
2004-06-02 00:36:05 +00:00
|
|
|
} else {
|
2004-07-04 14:56:48 +00:00
|
|
|
ret = cli_scanfile(tempname, virname, scanned, root, limits, options, arec, mrec);
|
2004-06-02 00:36:05 +00:00
|
|
|
}
|
|
|
|
if(!cli_leavetemps_flag)
|
|
|
|
unlink(tempname);
|
|
|
|
free(tempname);
|
|
|
|
if(ret == CL_VIRUS)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(ret == CL_VIRUS)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
cabd->close(cabd, base);
|
|
|
|
mspack_destroy_cab_decompressor(cabd);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
static int cli_scandir(const char *dirname, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec)
|
2004-01-23 11:17:16 +00:00
|
|
|
{
|
2004-04-20 22:33:42 +00:00
|
|
|
DIR *dd;
|
|
|
|
struct dirent *dent;
|
2004-10-03 15:12:13 +00:00
|
|
|
#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
|
2004-11-02 04:08:09 +00:00
|
|
|
union {
|
|
|
|
struct dirent d;
|
|
|
|
char b[offsetof(struct dirent, d_name) + NAME_MAX + 1];
|
|
|
|
} result;
|
2004-10-03 15:12:13 +00:00
|
|
|
#endif
|
2004-04-20 22:33:42 +00:00
|
|
|
struct stat statbuf;
|
|
|
|
char *fname;
|
2004-01-23 11:17:16 +00:00
|
|
|
|
|
|
|
|
2004-04-20 22:33:42 +00:00
|
|
|
if((dd = opendir(dirname)) != NULL) {
|
2004-10-03 15:12:13 +00:00
|
|
|
#ifdef HAVE_READDIR_R_3
|
2004-11-02 04:08:09 +00:00
|
|
|
while(!readdir_r(dd, &result.d, &dent) && dent) {
|
2004-10-03 15:12:13 +00:00
|
|
|
#elif defined(HAVE_READDIR_R_2)
|
2004-11-02 04:08:09 +00:00
|
|
|
while((dent = (struct dirent *) readdir_r(dd, &result.d))) {
|
2004-10-03 15:12:13 +00:00
|
|
|
#else
|
2004-04-20 22:33:42 +00:00
|
|
|
while((dent = readdir(dd))) {
|
2004-10-03 15:12:13 +00:00
|
|
|
#endif
|
2004-06-27 07:22:19 +00:00
|
|
|
#ifndef C_INTERIX
|
|
|
|
if(dent->d_ino)
|
|
|
|
#endif
|
|
|
|
{
|
2004-04-20 22:33:42 +00:00
|
|
|
if(strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..")) {
|
|
|
|
/* build the full name */
|
|
|
|
fname = cli_calloc(strlen(dirname) + strlen(dent->d_name) + 2, sizeof(char));
|
|
|
|
sprintf(fname, "%s/%s", dirname, dent->d_name);
|
2004-01-23 11:17:16 +00:00
|
|
|
|
2004-04-20 22:33:42 +00:00
|
|
|
/* stat the file */
|
|
|
|
if(lstat(fname, &statbuf) != -1) {
|
|
|
|
if(S_ISDIR(statbuf.st_mode) && !S_ISLNK(statbuf.st_mode)) {
|
2004-07-04 14:56:48 +00:00
|
|
|
if (cli_scandir(fname, virname, scanned, root, limits, options, arec, mrec) == CL_VIRUS) {
|
2004-04-20 22:33:42 +00:00
|
|
|
free(fname);
|
|
|
|
closedir(dd);
|
|
|
|
return CL_VIRUS;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
if(S_ISREG(statbuf.st_mode))
|
2004-07-04 14:56:48 +00:00
|
|
|
if(cli_scanfile(fname, virname, scanned, root, limits, options, arec, mrec) == CL_VIRUS) {
|
2004-04-20 22:33:42 +00:00
|
|
|
free(fname);
|
|
|
|
closedir(dd);
|
|
|
|
return CL_VIRUS;
|
|
|
|
}
|
2004-01-23 11:17:16 +00:00
|
|
|
|
2004-02-06 19:52:13 +00:00
|
|
|
}
|
2004-04-20 22:33:42 +00:00
|
|
|
free(fname);
|
2004-01-23 11:17:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-04-20 22:33:42 +00:00
|
|
|
} else {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("ScanDir: Can't open directory %s.\n", dirname);
|
2004-04-20 22:33:42 +00:00
|
|
|
return CL_EOPEN;
|
|
|
|
}
|
2004-01-23 11:17:16 +00:00
|
|
|
|
2004-04-20 22:33:42 +00:00
|
|
|
closedir(dd);
|
|
|
|
return 0;
|
2004-01-23 11:17:16 +00:00
|
|
|
}
|
2004-04-20 22:33:42 +00:00
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
static int cli_vba_scandir(const char *dirname, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec)
|
2003-07-29 15:48:06 +00:00
|
|
|
{
|
2004-04-20 22:33:42 +00:00
|
|
|
int ret = CL_CLEAN, i, fd, data_len;
|
|
|
|
vba_project_t *vba_project;
|
2003-07-29 15:48:06 +00:00
|
|
|
DIR *dd;
|
|
|
|
struct dirent *dent;
|
2004-10-03 15:12:13 +00:00
|
|
|
#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
|
2004-11-02 04:08:09 +00:00
|
|
|
union {
|
|
|
|
struct dirent d;
|
|
|
|
char b[offsetof(struct dirent, d_name) + NAME_MAX + 1];
|
|
|
|
} result;
|
2004-10-03 15:12:13 +00:00
|
|
|
#endif
|
2003-07-29 15:48:06 +00:00
|
|
|
struct stat statbuf;
|
2004-04-27 12:55:18 +00:00
|
|
|
char *fname, *fullname;
|
2004-04-20 22:33:42 +00:00
|
|
|
unsigned char *data;
|
|
|
|
|
2004-09-07 21:19:02 +00:00
|
|
|
|
|
|
|
cli_dbgmsg("VBADir: %s\n", dirname);
|
2004-04-20 22:33:42 +00:00
|
|
|
if((vba_project = (vba_project_t *) vba56_dir_read(dirname))) {
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2004-04-20 22:33:42 +00:00
|
|
|
for(i = 0; i < vba_project->count; i++) {
|
|
|
|
fullname = (char *) cli_malloc(strlen(vba_project->dir) + strlen(vba_project->name[i]) + 2);
|
|
|
|
sprintf(fullname, "%s/%s", vba_project->dir, vba_project->name[i]);
|
|
|
|
fd = open(fullname, O_RDONLY);
|
|
|
|
if(fd == -1) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("VBADir: Can't open file %s\n", fullname);
|
2004-04-20 22:33:42 +00:00
|
|
|
free(fullname);
|
|
|
|
ret = CL_EOPEN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free(fullname);
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("VBADir: Decompress VBA project '%s'\n", vba_project->name[i]);
|
2004-04-20 22:33:42 +00:00
|
|
|
data = (unsigned char *) vba_decompress(fd, vba_project->offset[i], &data_len);
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
if(!data) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("VBADir: WARNING: VBA project '%s' decompressed to NULL\n", vba_project->name[i]);
|
2004-04-20 22:33:42 +00:00
|
|
|
} else {
|
2004-10-16 23:32:38 +00:00
|
|
|
if(scanned)
|
|
|
|
*scanned += data_len / CL_COUNT_PRECISION;
|
|
|
|
|
2004-09-17 23:29:44 +00:00
|
|
|
if(cli_scanbuff(data, data_len, virname, root, CL_TYPE_MSOLE2) == CL_VIRUS) {
|
2004-04-20 22:33:42 +00:00
|
|
|
free(data);
|
|
|
|
ret = CL_VIRUS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < vba_project->count; i++)
|
|
|
|
free(vba_project->name[i]);
|
|
|
|
free(vba_project->name);
|
|
|
|
free(vba_project->dir);
|
|
|
|
free(vba_project->offset);
|
|
|
|
free(vba_project);
|
2004-05-29 23:42:42 +00:00
|
|
|
} else if ((fullname = ppt_vba_read(dirname))) {
|
2004-07-04 14:56:48 +00:00
|
|
|
if(cli_scandir(fullname, virname, scanned, root, limits, options, arec, mrec) == CL_VIRUS) {
|
2004-05-29 23:42:42 +00:00
|
|
|
ret = CL_VIRUS;
|
|
|
|
}
|
2004-10-11 02:15:29 +00:00
|
|
|
if(!cli_leavetemps_flag)
|
|
|
|
cli_rmdirs(fullname);
|
2004-05-29 23:42:42 +00:00
|
|
|
free(fullname);
|
2004-05-06 20:16:54 +00:00
|
|
|
} else if ((vba_project = (vba_project_t *) wm_dir_read(dirname))) {
|
|
|
|
for (i = 0; i < vba_project->count; i++) {
|
|
|
|
fullname = (char *) cli_malloc(strlen(vba_project->dir) + strlen(vba_project->name[i]) + 2);
|
|
|
|
sprintf(fullname, "%s/%s", vba_project->dir, vba_project->name[i]);
|
|
|
|
fd = open(fullname, O_RDONLY);
|
|
|
|
if(fd == -1) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("VBADir: Can't open file %s\n", fullname);
|
2004-05-06 20:16:54 +00:00
|
|
|
free(fullname);
|
|
|
|
ret = CL_EOPEN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free(fullname);
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("VBADir: Decompress WM project '%s' macro:%d key:%d\n", vba_project->name[i], i, vba_project->key[i]);
|
2004-05-06 20:16:54 +00:00
|
|
|
data = (unsigned char *) wm_decrypt_macro(fd, vba_project->offset[i], vba_project->length[i], vba_project->key[i]);
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
if(!data) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("VBADir: WARNING: WM project '%s' macro %d decrypted to NULL\n", vba_project->name[i], i);
|
2004-05-06 20:16:54 +00:00
|
|
|
} else {
|
2004-10-16 23:32:38 +00:00
|
|
|
if(scanned)
|
|
|
|
*scanned += vba_project->length[i] / CL_COUNT_PRECISION;
|
2004-09-17 23:29:44 +00:00
|
|
|
if(cli_scanbuff(data, vba_project->length[i], virname, root, CL_TYPE_MSOLE2) == CL_VIRUS) {
|
2004-05-06 20:16:54 +00:00
|
|
|
free(data);
|
|
|
|
ret = CL_VIRUS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(i = 0; i < vba_project->count; i++)
|
|
|
|
free(vba_project->name[i]);
|
|
|
|
free(vba_project->key);
|
|
|
|
free(vba_project->length);
|
|
|
|
free(vba_project->offset);
|
|
|
|
free(vba_project->name);
|
|
|
|
free(vba_project->dir);
|
|
|
|
free(vba_project);
|
2004-04-20 22:33:42 +00:00
|
|
|
}
|
2004-05-06 20:16:54 +00:00
|
|
|
|
2004-04-20 22:33:42 +00:00
|
|
|
if(ret != CL_CLEAN)
|
|
|
|
return ret;
|
2003-07-29 15:48:06 +00:00
|
|
|
|
|
|
|
if((dd = opendir(dirname)) != NULL) {
|
2004-10-03 15:12:13 +00:00
|
|
|
#ifdef HAVE_READDIR_R_3
|
2004-11-02 04:08:09 +00:00
|
|
|
while(!readdir_r(dd, &result.d, &dent) && dent) {
|
2004-10-03 15:12:13 +00:00
|
|
|
#elif defined(HAVE_READDIR_R_2)
|
2004-11-02 04:08:09 +00:00
|
|
|
while((dent = (struct dirent *) readdir_r(dd, &result.d))) {
|
2004-10-03 15:12:13 +00:00
|
|
|
#else
|
2003-07-29 15:48:06 +00:00
|
|
|
while((dent = readdir(dd))) {
|
2004-10-03 15:12:13 +00:00
|
|
|
#endif
|
2004-06-27 07:22:19 +00:00
|
|
|
#ifndef C_INTERIX
|
|
|
|
if(dent->d_ino)
|
|
|
|
#endif
|
|
|
|
{
|
2003-07-29 15:48:06 +00:00
|
|
|
if(strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..")) {
|
|
|
|
/* build the full name */
|
|
|
|
fname = cli_calloc(strlen(dirname) + strlen(dent->d_name) + 2, sizeof(char));
|
|
|
|
sprintf(fname, "%s/%s", dirname, dent->d_name);
|
|
|
|
|
|
|
|
/* stat the file */
|
|
|
|
if(lstat(fname, &statbuf) != -1) {
|
|
|
|
if(S_ISDIR(statbuf.st_mode) && !S_ISLNK(statbuf.st_mode))
|
2004-07-04 14:56:48 +00:00
|
|
|
if (cli_vba_scandir(fname, virname, scanned, root, limits, options, arec, mrec) == CL_VIRUS) {
|
2004-04-20 22:33:42 +00:00
|
|
|
ret = CL_VIRUS;
|
|
|
|
free(fname);
|
|
|
|
break;
|
|
|
|
}
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
free(fname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("VBADir: Can't open directory %s.\n", dirname);
|
2003-07-29 15:48:06 +00:00
|
|
|
return CL_EOPEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
closedir(dd);
|
2004-04-20 22:33:42 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-01-14 14:56:09 +00:00
|
|
|
static int cli_scanhtml(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec)
|
|
|
|
{
|
|
|
|
char *tempname, fullname[1024];
|
|
|
|
int ret=CL_CLEAN, fd;
|
|
|
|
|
|
|
|
|
|
|
|
cli_dbgmsg("in cli_scanhtml()\n");
|
|
|
|
|
|
|
|
tempname = cli_gentemp(NULL);
|
|
|
|
if(mkdir(tempname, 0700)) {
|
|
|
|
cli_dbgmsg("ScanHTML -> Can't create temporary directory %s\n", tempname);
|
|
|
|
return CL_ETMPDIR;
|
|
|
|
}
|
|
|
|
|
|
|
|
html_normalise_fd(desc, tempname, NULL);
|
|
|
|
snprintf(fullname, 1024, "%s/comment.html", tempname);
|
|
|
|
fd = open(fullname, O_RDONLY);
|
|
|
|
if (fd >= 0) {
|
|
|
|
ret = cli_scandesc(fd, virname, scanned, root, 0, CL_TYPE_HTML);
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ret < 0 || ret == CL_VIRUS) {
|
|
|
|
if(!cli_leavetemps_flag)
|
|
|
|
cli_rmdirs(tempname);
|
|
|
|
free(tempname);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == CL_CLEAN) {
|
|
|
|
snprintf(fullname, 1024, "%s/nocomment.html", tempname);
|
|
|
|
fd = open(fullname, O_RDONLY);
|
|
|
|
if (fd >= 0) {
|
|
|
|
ret = cli_scandesc(fd, virname, scanned, root, 0, CL_TYPE_HTML);
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ret < 0 || ret == CL_VIRUS) {
|
|
|
|
if(!cli_leavetemps_flag)
|
|
|
|
cli_rmdirs(tempname);
|
|
|
|
free(tempname);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == CL_CLEAN) {
|
|
|
|
snprintf(fullname, 1024, "%s/script.html", tempname);
|
|
|
|
fd = open(fullname, O_RDONLY);
|
|
|
|
if (fd >= 0) {
|
|
|
|
ret = cli_scandesc(fd, virname, scanned, root, 0, CL_TYPE_HTML);
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ret < 0 || ret == CL_VIRUS) {
|
|
|
|
if(!cli_leavetemps_flag)
|
|
|
|
cli_rmdirs(tempname);
|
|
|
|
free(tempname);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == CL_CLEAN) {
|
|
|
|
snprintf(fullname, 1024, "%s/rfc2397", tempname);
|
|
|
|
ret = cli_scandir(fullname, virname, scanned, root, limits, options, arec, mrec);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!cli_leavetemps_flag)
|
|
|
|
cli_rmdirs(tempname);
|
|
|
|
|
|
|
|
free(tempname);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
static int cli_scanole2(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec)
|
2004-04-20 22:33:42 +00:00
|
|
|
{
|
2004-04-27 12:55:18 +00:00
|
|
|
char *dir;
|
|
|
|
int ret = CL_CLEAN;
|
2004-04-20 22:33:42 +00:00
|
|
|
|
2004-09-07 21:19:02 +00:00
|
|
|
|
2004-04-20 22:33:42 +00:00
|
|
|
cli_dbgmsg("in cli_scanole2()\n");
|
|
|
|
|
|
|
|
/* generate the temporary directory */
|
2004-11-16 17:10:47 +00:00
|
|
|
dir = cli_gentemp(NULL);
|
2004-04-20 22:33:42 +00:00
|
|
|
if(mkdir(dir, 0700)) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("OLE2: Can't create temporary directory %s\n", dir);
|
2004-04-20 22:33:42 +00:00
|
|
|
return CL_ETMPDIR;
|
|
|
|
}
|
|
|
|
|
2004-06-24 08:11:13 +00:00
|
|
|
if((ret = cli_ole2_extract(desc, dir, limits))) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("OLE2: %s\n", cl_strerror(ret));
|
2004-10-11 02:15:29 +00:00
|
|
|
if(!cli_leavetemps_flag)
|
|
|
|
cli_rmdirs(dir);
|
2004-04-20 22:33:42 +00:00
|
|
|
free(dir);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-07-04 14:56:48 +00:00
|
|
|
if((ret = cli_vba_scandir(dir, virname, scanned, root, limits, options, arec, mrec)) != CL_VIRUS) {
|
|
|
|
if(cli_scandir(dir, virname, scanned, root, limits, options, arec, mrec) == CL_VIRUS) {
|
2004-04-27 12:55:18 +00:00
|
|
|
ret = CL_VIRUS;
|
2004-04-20 22:33:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-11 02:15:29 +00:00
|
|
|
if(!cli_leavetemps_flag)
|
|
|
|
cli_rmdirs(dir);
|
2004-04-20 22:33:42 +00:00
|
|
|
free(dir);
|
|
|
|
return ret;
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
static int cli_scantar(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec)
|
2004-09-07 21:19:02 +00:00
|
|
|
{
|
|
|
|
char *dir;
|
|
|
|
int ret = CL_CLEAN;
|
|
|
|
|
|
|
|
|
|
|
|
cli_dbgmsg("in cli_scantar()\n");
|
|
|
|
|
|
|
|
/* generate temporary directory */
|
2004-11-16 17:10:47 +00:00
|
|
|
dir = cli_gentemp(NULL);
|
2004-09-07 21:19:02 +00:00
|
|
|
if(mkdir(dir, 0700)) {
|
|
|
|
cli_errmsg("Tar: Can't create temporary directory %s\n", dir);
|
|
|
|
return CL_ETMPDIR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((ret = cli_untar(dir, desc)))
|
|
|
|
cli_dbgmsg("Tar: %s\n", cl_strerror(ret));
|
|
|
|
else
|
|
|
|
ret = cli_scandir(dir, virname, scanned, root, limits, options, arec, mrec);
|
|
|
|
|
|
|
|
if(!cli_leavetemps_flag)
|
|
|
|
cli_rmdirs(dir);
|
|
|
|
|
|
|
|
free(dir);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-11-18 19:30:29 +00:00
|
|
|
static int cli_scanbinhex(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec)
|
|
|
|
{
|
|
|
|
char *dir;
|
|
|
|
int ret = CL_CLEAN;
|
|
|
|
|
|
|
|
|
|
|
|
cli_dbgmsg("in cli_scanbinhex()\n");
|
|
|
|
|
|
|
|
/* generate temporary directory */
|
|
|
|
dir = cli_gentemp(NULL);
|
|
|
|
|
|
|
|
if(mkdir(dir, 0700)) {
|
|
|
|
cli_errmsg("Binhex: Can't create temporary directory %s\n", dir);
|
|
|
|
return CL_ETMPDIR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((ret = cli_binhex(dir, desc)))
|
|
|
|
cli_dbgmsg("Binhex: %s\n", cl_strerror(ret));
|
|
|
|
else
|
|
|
|
ret = cli_scandir(dir, virname, scanned, root, limits, options, arec, mrec);
|
|
|
|
|
|
|
|
if(!cli_leavetemps_flag)
|
|
|
|
cli_rmdirs(dir);
|
|
|
|
|
|
|
|
free(dir);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
static int cli_scanmschm(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec)
|
2004-07-20 01:31:25 +00:00
|
|
|
{
|
|
|
|
char *tempname;
|
|
|
|
int ret = CL_CLEAN;
|
|
|
|
|
|
|
|
|
|
|
|
cli_dbgmsg("in cli_scanmschm()\n");
|
|
|
|
|
2004-11-16 17:10:47 +00:00
|
|
|
tempname = cli_gentemp(NULL);
|
2004-07-20 01:31:25 +00:00
|
|
|
if(mkdir(tempname, 0700)) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("CHM: Can't create temporary directory %s\n", tempname);
|
2004-07-20 01:31:25 +00:00
|
|
|
return CL_ETMPDIR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(chm_unpack(desc, tempname))
|
|
|
|
ret = cli_scandir(tempname, virname, scanned, root, limits, options, arec, mrec);
|
|
|
|
|
|
|
|
if(!cli_leavetemps_flag)
|
|
|
|
cli_rmdirs(tempname);
|
|
|
|
|
|
|
|
free(tempname);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
static int cli_scanscrenc(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec)
|
2004-09-13 10:30:14 +00:00
|
|
|
{
|
|
|
|
char *tempname;
|
|
|
|
int ret = CL_CLEAN;
|
|
|
|
|
|
|
|
cli_dbgmsg("in cli_scanscrenc()\n");
|
|
|
|
|
2004-11-16 17:10:47 +00:00
|
|
|
tempname = cli_gentemp(NULL);
|
2004-09-13 10:30:14 +00:00
|
|
|
if(mkdir(tempname, 0700)) {
|
|
|
|
cli_dbgmsg("CHM: Can't create temporary directory %s\n", tempname);
|
|
|
|
return CL_ETMPDIR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (html_screnc_decode(desc, tempname))
|
|
|
|
ret = cli_scandir(tempname, virname, scanned, root, limits, options, arec, mrec);
|
|
|
|
|
|
|
|
if(!cli_leavetemps_flag)
|
|
|
|
cli_rmdirs(tempname);
|
|
|
|
|
|
|
|
free(tempname);
|
|
|
|
return ret;
|
|
|
|
}
|
2004-09-18 00:14:00 +00:00
|
|
|
|
2005-02-05 15:50:18 +00:00
|
|
|
static int cli_scanriff(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec)
|
|
|
|
{
|
|
|
|
int ret = CL_CLEAN;
|
|
|
|
|
|
|
|
if(cli_check_riff_exploit(desc) == 2) {
|
|
|
|
ret = CL_VIRUS;
|
|
|
|
*virname = "Exploit.W32.MS05-002";
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
static int cli_scanmail(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec)
|
2003-07-29 15:48:06 +00:00
|
|
|
{
|
|
|
|
char *dir;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
2004-07-06 02:27:22 +00:00
|
|
|
cli_dbgmsg("Starting cli_scanmail(), mrec == %d, arec == %d\n", *mrec, *arec);
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2004-11-16 17:10:47 +00:00
|
|
|
/* generate the temporary directory */
|
|
|
|
dir = cli_gentemp(NULL);
|
|
|
|
if(mkdir(dir, 0700)) {
|
|
|
|
cli_dbgmsg("Mail: Can't create temporary directory %s\n", dir);
|
|
|
|
free(dir);
|
|
|
|
return CL_ETMPDIR;
|
|
|
|
}
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2004-11-16 17:10:47 +00:00
|
|
|
/*
|
|
|
|
* Extract the attachments into the temporary directory
|
|
|
|
*/
|
|
|
|
if((ret = cli_mbox(dir, desc, options))) {
|
2004-10-11 02:15:29 +00:00
|
|
|
if(!cli_leavetemps_flag)
|
|
|
|
cli_rmdirs(dir);
|
2003-07-29 15:48:06 +00:00
|
|
|
free(dir);
|
|
|
|
return ret;
|
2004-11-16 17:10:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = cli_scandir(dir, virname, scanned, root, limits, options, arec, mrec);
|
|
|
|
|
|
|
|
if(!cli_leavetemps_flag)
|
|
|
|
cli_rmdirs(dir);
|
|
|
|
|
|
|
|
free(dir);
|
|
|
|
return ret;
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
int cli_magic_scandesc(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec)
|
2003-07-29 15:48:06 +00:00
|
|
|
{
|
2004-09-07 21:19:02 +00:00
|
|
|
char magic[MAGIC_BUFFER_SIZE + 1];
|
2004-07-02 23:00:58 +00:00
|
|
|
int ret = CL_CLEAN, nret;
|
2003-09-07 19:43:04 +00:00
|
|
|
int bread = 0;
|
2004-03-20 14:49:22 +00:00
|
|
|
cli_file_t type;
|
2003-07-29 15:48:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
if(!root) {
|
2004-06-02 00:36:05 +00:00
|
|
|
cli_errmsg("CRITICAL: root == NULL\n");
|
2004-10-14 23:56:30 +00:00
|
|
|
return CL_EMALFDB;
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
2004-05-25 20:38:25 +00:00
|
|
|
if(!options) { /* raw mode (stdin, etc.) */
|
2004-09-14 01:33:32 +00:00
|
|
|
cli_dbgmsg("Raw mode: No support for special files\n");
|
|
|
|
if((ret = cli_scandesc(desc, virname, scanned, root, 0, 0) == CL_VIRUS))
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("%s found in descriptor %d\n", *virname, desc);
|
2004-05-25 20:38:25 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-04-20 22:33:42 +00:00
|
|
|
if(SCAN_ARCHIVE && limits && limits->maxreclevel)
|
2004-07-04 14:56:48 +00:00
|
|
|
if(*arec > limits->maxreclevel) {
|
|
|
|
cli_dbgmsg("Archive recursion limit exceeded (arec == %d).\n", *arec);
|
2004-12-27 00:13:00 +00:00
|
|
|
if(BLOCKMAX) {
|
|
|
|
*virname = "Archive.ExceededRecursionLimit";
|
|
|
|
return CL_VIRUS;
|
|
|
|
}
|
2004-04-20 22:33:42 +00:00
|
|
|
return CL_CLEAN;
|
2004-07-04 14:56:48 +00:00
|
|
|
}
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2004-07-04 14:56:48 +00:00
|
|
|
if(SCAN_MAIL)
|
|
|
|
if(*mrec > MAX_MAIL_RECURSION) {
|
|
|
|
cli_dbgmsg("Mail recursion level exceeded (mrec == %d).\n", *mrec);
|
|
|
|
/* return CL_EMAXREC; */
|
|
|
|
return CL_CLEAN;
|
|
|
|
}
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2004-04-20 22:33:42 +00:00
|
|
|
lseek(desc, 0, SEEK_SET);
|
2004-09-07 21:19:02 +00:00
|
|
|
memset(magic, 0, sizeof(magic));
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2004-09-07 21:19:02 +00:00
|
|
|
if((bread = read(desc, magic, MAGIC_BUFFER_SIZE)) == -1) {
|
|
|
|
cli_dbgmsg("Can't read from descriptor %d\n");
|
|
|
|
return CL_EIO;
|
|
|
|
} else if(bread < 2) {
|
|
|
|
/* short read - no need to do magic */
|
|
|
|
return CL_CLEAN;
|
2004-04-20 22:33:42 +00:00
|
|
|
}
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2004-09-07 21:19:02 +00:00
|
|
|
lseek(desc, 0, SEEK_SET);
|
2004-04-20 22:33:42 +00:00
|
|
|
type = cli_filetype(magic, bread);
|
2004-02-06 13:46:08 +00:00
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
type == CL_TYPE_MAIL ? (*mrec)++ : (*arec)++;
|
2004-07-02 23:00:58 +00:00
|
|
|
|
2004-04-20 22:33:42 +00:00
|
|
|
switch(type) {
|
2004-09-13 16:44:01 +00:00
|
|
|
case CL_TYPE_RAR:
|
2004-04-20 22:33:42 +00:00
|
|
|
if(!DISABLE_RAR && SCAN_ARCHIVE && !cli_scanrar_inuse)
|
2004-07-04 14:56:48 +00:00
|
|
|
ret = cli_scanrar(desc, virname, scanned, root, limits, options, arec, mrec);
|
2004-04-20 22:33:42 +00:00
|
|
|
break;
|
2004-02-06 13:46:08 +00:00
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
case CL_TYPE_ZIP:
|
2004-04-20 22:33:42 +00:00
|
|
|
if(SCAN_ARCHIVE)
|
2004-07-04 14:56:48 +00:00
|
|
|
ret = cli_scanzip(desc, virname, scanned, root, limits, options, arec, mrec);
|
2004-04-20 22:33:42 +00:00
|
|
|
break;
|
2004-02-06 13:46:08 +00:00
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
case CL_TYPE_GZ:
|
2004-04-20 22:33:42 +00:00
|
|
|
if(SCAN_ARCHIVE)
|
2004-07-04 14:56:48 +00:00
|
|
|
ret = cli_scangzip(desc, virname, scanned, root, limits, options, arec, mrec);
|
2004-04-20 22:33:42 +00:00
|
|
|
break;
|
2004-02-06 13:46:08 +00:00
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
case CL_TYPE_BZ:
|
2004-03-11 08:33:45 +00:00
|
|
|
#ifdef HAVE_BZLIB_H
|
2004-04-20 22:33:42 +00:00
|
|
|
if(SCAN_ARCHIVE)
|
2004-07-04 14:56:48 +00:00
|
|
|
ret = cli_scanbzip(desc, virname, scanned, root, limits, options, arec, mrec);
|
2003-07-29 15:48:06 +00:00
|
|
|
#endif
|
2004-04-20 22:33:42 +00:00
|
|
|
break;
|
2004-02-06 13:46:08 +00:00
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
case CL_TYPE_MSSZDD:
|
2004-05-02 00:51:01 +00:00
|
|
|
if(SCAN_ARCHIVE)
|
2004-09-13 16:44:01 +00:00
|
|
|
ret = cli_scanszdd(desc, virname, scanned, root, limits, options, arec, mrec);
|
2004-05-02 00:51:01 +00:00
|
|
|
break;
|
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
case CL_TYPE_MSCAB:
|
2004-06-02 00:36:05 +00:00
|
|
|
if(SCAN_ARCHIVE)
|
2004-07-04 14:56:48 +00:00
|
|
|
ret = cli_scanmscab(desc, virname, scanned, root, limits, options, arec, mrec);
|
2004-06-02 00:36:05 +00:00
|
|
|
break;
|
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
case CL_TYPE_MAIL:
|
2004-04-20 22:33:42 +00:00
|
|
|
if(SCAN_MAIL)
|
2004-07-04 14:56:48 +00:00
|
|
|
ret = cli_scanmail(desc, virname, scanned, root, limits, options, arec, mrec);
|
2004-04-20 22:33:42 +00:00
|
|
|
break;
|
2004-02-06 13:46:08 +00:00
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
case CL_TYPE_MSCHM:
|
2004-07-20 01:31:25 +00:00
|
|
|
if(SCAN_ARCHIVE)
|
|
|
|
ret = cli_scanmschm(desc, virname, scanned, root, limits, options, arec, mrec);
|
|
|
|
break;
|
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
case CL_TYPE_MSOLE2:
|
2004-04-20 22:33:42 +00:00
|
|
|
if(SCAN_OLE2)
|
2004-07-04 14:56:48 +00:00
|
|
|
ret = cli_scanole2(desc, virname, scanned, root, limits, options, arec, mrec);
|
2004-04-20 22:33:42 +00:00
|
|
|
break;
|
2004-02-06 13:46:08 +00:00
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
case CL_TYPE_TAR:
|
2004-09-07 21:19:02 +00:00
|
|
|
if(SCAN_ARCHIVE)
|
|
|
|
ret = cli_scantar(desc, virname, scanned, root, limits, options, arec, mrec);
|
2004-11-18 19:30:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CL_TYPE_BINHEX:
|
|
|
|
if(SCAN_ARCHIVE)
|
|
|
|
ret = cli_scanbinhex(desc, virname, scanned, root, limits, options, arec, mrec);
|
2004-09-07 21:19:02 +00:00
|
|
|
break;
|
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
case CL_TYPE_SCRENC:
|
2004-09-13 10:30:14 +00:00
|
|
|
ret = cli_scanscrenc(desc, virname, scanned, root, limits, options, arec, mrec);
|
2005-02-05 15:50:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CL_TYPE_RIFF:
|
|
|
|
ret = cli_scanriff(desc, virname, scanned, root, limits, options, arec, mrec);
|
2004-09-13 10:30:14 +00:00
|
|
|
break;
|
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
case CL_TYPE_DATA:
|
2004-04-20 22:33:42 +00:00
|
|
|
/* it could be a false positive and a standard DOS .COM file */
|
|
|
|
{
|
|
|
|
struct stat s;
|
|
|
|
if(fstat(desc, &s) == 0 && S_ISREG(s.st_mode) && s.st_size < 65536)
|
2004-09-13 16:44:01 +00:00
|
|
|
type = CL_TYPE_UNKNOWN_DATA;
|
2004-04-20 22:33:42 +00:00
|
|
|
}
|
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
case CL_TYPE_UNKNOWN_DATA:
|
2004-09-30 00:26:52 +00:00
|
|
|
ret = cli_check_mydoom_log(desc, virname);
|
2004-04-20 22:33:42 +00:00
|
|
|
break;
|
2004-08-24 00:50:29 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
type == CL_TYPE_MAIL ? (*mrec)-- : (*arec)--;
|
2004-04-20 22:33:42 +00:00
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
if(type != CL_TYPE_DATA && ret != CL_VIRUS) { /* scan the raw file */
|
2004-07-11 14:50:25 +00:00
|
|
|
int typerec;
|
2004-07-02 23:00:58 +00:00
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
type == CL_TYPE_UNKNOWN_TEXT ? (typerec = 1) : (typerec = 0);
|
2004-11-15 22:58:03 +00:00
|
|
|
if(lseek(desc, 0, SEEK_SET) < 0)
|
|
|
|
cli_errmsg("lseek() failed, trying to continue anyway...\n");
|
2004-07-04 14:56:48 +00:00
|
|
|
|
2004-09-14 01:33:32 +00:00
|
|
|
if((nret = cli_scandesc(desc, virname, scanned, root, typerec, type)) == CL_VIRUS) {
|
2004-09-07 21:19:02 +00:00
|
|
|
cli_dbgmsg("%s found in descriptor %d.\n", *virname, desc);
|
2003-07-29 15:48:06 +00:00
|
|
|
return CL_VIRUS;
|
2004-07-02 23:00:58 +00:00
|
|
|
|
2004-11-08 09:03:33 +00:00
|
|
|
} else if(nret < 0) {
|
|
|
|
return nret;
|
|
|
|
|
2004-07-02 23:00:58 +00:00
|
|
|
} else if(nret >= CL_TYPENO) {
|
|
|
|
lseek(desc, 0, SEEK_SET);
|
|
|
|
|
2004-12-01 20:11:17 +00:00
|
|
|
nret == CL_TYPE_MAIL ? (*mrec)++ : (*arec)++;
|
2004-07-02 23:00:58 +00:00
|
|
|
switch(nret) {
|
2004-09-13 16:44:01 +00:00
|
|
|
case CL_TYPE_HTML:
|
2004-07-02 23:00:58 +00:00
|
|
|
if(SCAN_HTML)
|
2004-07-04 14:56:48 +00:00
|
|
|
if(cli_scanhtml(desc, virname, scanned, root, limits, options, arec, mrec) == CL_VIRUS)
|
2004-07-02 23:00:58 +00:00
|
|
|
return CL_VIRUS;
|
|
|
|
break;
|
2004-07-03 15:24:43 +00:00
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
case CL_TYPE_MAIL:
|
2004-07-03 15:24:43 +00:00
|
|
|
if(SCAN_MAIL)
|
2004-07-04 14:56:48 +00:00
|
|
|
if(cli_scanmail(desc, virname, scanned, root, limits, options, arec, mrec) == CL_VIRUS)
|
2004-07-03 15:24:43 +00:00
|
|
|
return CL_VIRUS;
|
|
|
|
break;
|
2004-07-02 23:00:58 +00:00
|
|
|
}
|
2004-12-01 20:11:17 +00:00
|
|
|
nret == CL_TYPE_MAIL ? (*mrec)-- : (*arec)--;
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
2003-12-12 17:48:47 +00:00
|
|
|
}
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2004-07-11 14:50:25 +00:00
|
|
|
(*arec)++;
|
|
|
|
lseek(desc, 0, SEEK_SET);
|
|
|
|
switch(type) {
|
|
|
|
/* Due to performance reasons all executables were first scanned
|
|
|
|
* in raw mode. Now we will try to unpack them
|
|
|
|
*/
|
2004-09-13 16:44:01 +00:00
|
|
|
case CL_TYPE_MSEXE:
|
2004-07-11 14:50:25 +00:00
|
|
|
if(SCAN_PE)
|
|
|
|
ret = cli_scanpe(desc, virname, scanned, root, limits, options, arec, mrec);
|
|
|
|
break;
|
2004-07-19 17:54:40 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2004-07-11 14:50:25 +00:00
|
|
|
}
|
|
|
|
(*arec)--;
|
|
|
|
|
2004-10-14 23:56:30 +00:00
|
|
|
if(ret == CL_EFORMAT) {
|
2004-12-01 20:11:17 +00:00
|
|
|
cli_dbgmsg("Descriptor[%d]: %s\n", desc, cl_strerror(CL_EFORMAT));
|
2004-10-14 23:56:30 +00:00
|
|
|
return CL_CLEAN;
|
|
|
|
} else {
|
|
|
|
return ret;
|
|
|
|
}
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
int cl_scandesc(int desc, const char **virname, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options)
|
2003-07-29 15:48:06 +00:00
|
|
|
{
|
2004-07-04 14:56:48 +00:00
|
|
|
int arec = 0, mrec = 0;
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2004-07-04 14:56:48 +00:00
|
|
|
return cli_magic_scandesc(desc, virname, scanned, root, limits, options, &arec, &mrec);
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
static int cli_scanfile(const char *filename, const char **virname, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec)
|
2004-04-14 22:55:44 +00:00
|
|
|
{
|
|
|
|
int fd, ret;
|
|
|
|
|
2004-07-05 23:50:55 +00:00
|
|
|
|
2004-07-04 14:56:48 +00:00
|
|
|
/* internal version of cl_scanfile with arec/mrec preserved */
|
2004-04-14 22:55:44 +00:00
|
|
|
if((fd = open(filename, O_RDONLY)) == -1)
|
|
|
|
return CL_EOPEN;
|
|
|
|
|
2004-07-04 14:56:48 +00:00
|
|
|
ret = cli_magic_scandesc(fd, virname, scanned, root, limits, options, arec, mrec);
|
2004-04-14 22:55:44 +00:00
|
|
|
|
|
|
|
close(fd);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-09-13 16:44:01 +00:00
|
|
|
int cl_scanfile(const char *filename, const char **virname, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options)
|
2003-07-29 15:48:06 +00:00
|
|
|
{
|
|
|
|
int fd, ret;
|
|
|
|
|
2004-07-03 15:24:43 +00:00
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
if((fd = open(filename, O_RDONLY)) == -1)
|
|
|
|
return CL_EOPEN;
|
|
|
|
|
|
|
|
ret = cl_scandesc(fd, virname, scanned, root, limits, options);
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|