2
* Copyright (C) 2007-2008 Sourcefire, Inc.
2
* Copyright (C) 2007-2010 Sourcefire, Inc.
4
4
* Authors: Tomasz Kojm, Trog
72
66
#include "matcher-ac.h"
73
67
#include "default.h"
81
#define P_tmpdir "C:\\WINDOWS\\TEMP"
84
71
int (*cli_unrar_open)(int fd, const char *dirname, unrar_state_t *state);
85
72
int (*cli_unrar_extract_next_prepare)(unrar_state_t *state, const char *dirname);
268
256
int cl_init(unsigned int initoptions)
270
259
struct timeval tv;
271
260
unsigned int pid = (unsigned int) getpid();
263
unrar_main_header_t x;
264
if (((char*)&x.flags - (char*)&x) != 3) {
265
cli_errmsg("Structure packing not working, got %u offset, expected %u\n",
266
(unsigned)((char*)&x.flags - (char*)&x), 3);
273
270
/* put dlopen() stuff here, etc. */
274
271
if (lt_init() == 0) {
277
274
gettimeofday(&tv, (struct timezone *) 0);
278
275
srand(pid + tv.tv_usec*(pid+1) + clock());
276
rc = bytecode_init();
279
279
return CL_SUCCESS;
380
381
case CL_ENGINE_KEEPTMP:
381
382
engine->keeptmp = num;
384
case CL_ENGINE_BYTECODE_SECURITY:
386
if (num == CL_BYTECODE_TRUST_ALL) {
387
cli_errmsg("cl_engine_set_num: CL_BYTECODE_TRUST_ALL is only supported when ClamAV is built in debug mode\n");
391
engine->bytecode_security = num;
384
394
cli_errmsg("cl_engine_set_num: Incorrect field number\n");
788
798
while((dent = readdir(dd))) {
790
#if (!defined(C_INTERIX)) && (!defined(C_WINDOWS))
794
802
if(strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..")) {
795
803
path = cli_malloc(strlen(dirname) + strlen(dent->d_name) + 2);
801
sprintf(path, "%s/%s", dirname, dent->d_name);
809
sprintf(path, "%s"PATHSEP"%s", dirname, dent->d_name);
803
811
/* stat the file */
804
812
if(lstat(path, &statbuf) != -1) {
852
int cli_dumpscan(int fd, off_t offset, size_t size, cli_ctx *ctx)
854
int newfd, bread, sum = 0, ret;
859
if(lseek(fd, offset, SEEK_SET) == -1) {
860
cli_dbgmsg("cli_dumpscan: Can't lseek to %u\n", (unsigned int) offset);
861
return CL_EFORMAT; /* most likely because of corrupted file */
865
if(!(name = cli_gentemp(ctx->engine->tmpdir)))
868
if((newfd = open(name, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU)) < 0) {
869
cli_errmsg("cli_dumpscan: Can't create file %s\n", name);
874
while((bread = cli_readn(fd, buff, FILEBUFF)) > 0) {
875
if((uint32_t) (sum + bread) >= size) {
876
if(write(newfd, buff, size - sum) == -1) {
877
cli_errmsg("cli_dumpscan: Can't write to %s\n", name);
885
if(write(newfd, buff, bread) == -1) {
886
cli_errmsg("cli_dumpscan: Can't write to %s\n", name);
895
cli_dbgmsg("DUMP&SCAN: File extracted to %s\n", name);
896
lseek(newfd, 0, SEEK_SET);
897
if((ret = cli_magic_scandesc(newfd, ctx)) == CL_VIRUS)
898
cli_dbgmsg("cli_dumpscan: Infected with %s\n", *ctx->virname);
901
if(!ctx->engine->keeptmp) {
902
if(cli_unlink(name)) {
844
911
/* Implement a generic bitset, trog@clamav.net */
846
913
#define BITS_PER_CHAR (8)
847
914
#define BITSET_DEFAULT_SIZE (1024)
851
916
static unsigned long nearest_power(unsigned long num)