1
diff -ur clamav-orig/clamdtop/clamdtop.c clamav-new/clamdtop/clamdtop.c
2
--- clamav-orig/clamdtop/clamdtop.c 2009-03-16 11:37:28.000000000 +1100
3
+++ clamav-new/clamdtop/clamdtop.c 2009-03-16 16:30:26.000000000 +1100
6
#include <netinet/in.h>
7
#include <sys/socket.h>
20
+#if defined(_WIN32) || defined(__DJGPP__)
23
if(soname[0] == '/' || (access(soname, F_OK) == 0)) {
24
diff -ur clamav-orig/clamscan/clamscan.c clamav-new/clamscan/clamscan.c
25
--- clamav-orig/clamscan/clamscan.c 2009-03-16 11:37:26.000000000 +1100
26
+++ clamav-new/clamscan/clamscan.c 2009-03-16 16:30:26.000000000 +1100
31
-#if !defined(C_WINDOWS) && !defined(C_BEOS)
32
+#if !defined(C_WINDOWS) && !defined(C_BEOS) && !defined(__DJGPP__)
34
sigaddset(&sigset, SIGXFSZ);
35
sigprocmask(SIG_SETMASK, &sigset, NULL);
36
diff -ur clamav-orig/clamscan/manager.c clamav-new/clamscan/manager.c
37
--- clamav-orig/clamscan/manager.c 2009-03-16 11:37:26.000000000 +1100
38
+++ clamav-new/clamscan/manager.c 2009-03-16 17:15:46.000000000 +1100
40
#define P_tmpdir "C:\\WINDOWS\\TEMP"
45
+#define P_tmpdir "/dev/env/TEMP"
54
info.rblocks += fsize / CL_COUNT_PRECISION;
56
+#if !defined(C_WINDOWS) && !defined(__DJGPP__)
58
if(checkaccess(filename, NULL, R_OK) != 1) {
62
if((dd = opendir(dirname)) != NULL) {
63
while((dent = readdir(dd))) {
64
-#if !defined(C_INTERIX) && !defined(C_WINDOWS)
65
+#if !defined(C_INTERIX) && !defined(C_WINDOWS) && !defined(__DJGPP__)
71
char *file, cwd[1024], *pua_cats = NULL;
72
const struct optstruct *opt;
74
+#if !defined(C_WINDOWS) && !defined(__DJGPP__)
83
+#if !defined(C_WINDOWS) && !defined(__DJGPP__)
84
if(getrlimit(RLIMIT_FSIZE, &rlim) == 0) {
85
if(rlim.rlim_max < (rlim_t) cl_engine_get_num(engine, CL_ENGINE_MAX_FILESIZE, NULL))
86
logg("^System limit for file size is lower than engine->maxfilesize\n");
87
diff -ur clamav-orig/freshclam/freshclam.c clamav-new/freshclam/freshclam.c
88
--- clamav-orig/freshclam/freshclam.c 2009-03-16 11:37:26.000000000 +1100
89
+++ clamav-new/freshclam/freshclam.c 2009-03-16 16:30:26.000000000 +1100
92
logg("#freshclam daemon %s (OS: "TARGET_OS_TYPE", ARCH: "TARGET_ARCH_TYPE", CPU: "TARGET_CPU_TYPE")\n", get_version());
95
+#if defined(C_WINDOWS) || defined(__DJGPP__)
96
signal(SIGINT, daemon_sighandler);
99
diff -ur clamav-orig/freshclam/manager.c clamav-new/freshclam/manager.c
100
--- clamav-orig/freshclam/manager.c 2009-03-16 11:37:26.000000000 +1100
101
+++ clamav-new/freshclam/manager.c 2009-03-16 16:30:26.000000000 +1100
102
@@ -1412,7 +1412,7 @@
105
while((dent = readdir(dir))) {
106
-#if !defined(C_INTERIX) && !defined(C_WINDOWS)
107
+#if !defined(C_INTERIX) && !defined(C_WINDOWS) && !defined(__DJGPP__)
111
diff -ur clamav-orig/libclamav/binhex.c clamav-new/libclamav/binhex.c
112
--- clamav-orig/libclamav/binhex.c 2009-03-16 11:37:28.000000000 +1100
113
+++ clamav-new/libclamav/binhex.c 2009-03-16 16:31:12.000000000 +1100
116
cli_binhex(const char *dir, int desc)
119
- cli_warnmsg("File not decoded - binhex decoding needs mmap() (for now)\n");
123
char *buf, *start, *line;
130
+ start = buf = cli_copy_file_to_mem(desc, size, 0);
132
start = buf = mmap(NULL, size, PROT_READ, MAP_PRIVATE, desc, 0);
134
if(buf == MAP_FAILED) {
150
return CL_CLEAN; /* a lie - but it gets things going */
151
/* return CL_EIO; */ /* probably CL_EMEM, but we can't tell at this layer */
155
diff -ur clamav-orig/libclamav/mbox.c clamav-new/libclamav/mbox.c
156
--- clamav-orig/libclamav/mbox.c 2009-03-16 11:37:28.000000000 +1100
157
+++ clamav-new/libclamav/mbox.c 2009-03-16 16:30:26.000000000 +1100
158
@@ -3857,7 +3857,7 @@
161
const char *dentry_idpart;
163
+#if (!defined(C_WINDOWS)) && (!defined(__DJGPP__))
167
diff -ur clamav-orig/libclamav/others.c clamav-new/libclamav/others.c
168
--- clamav-orig/libclamav/others.c 2009-03-16 11:37:28.000000000 +1100
169
+++ clamav-new/libclamav/others.c 2009-03-16 16:37:12.000000000 +1100
171
#define P_tmpdir "C:\\WINDOWS\\TEMP"
176
+#define P_tmpdir "/dev/env/TEMP"
178
+/* DJGPP is missing pread/pwrite */
179
+ssize_t pread(int fd, void *data, size_t length, off_t offset )
185
+ save_offset = lseek(fd,offset,SEEK_SET);
186
+ if(save_offset==-1) return -1;
188
+ result = read(fd,data,length);
190
+ save_errno = errno;
191
+ lseek(fd, save_offset, SEEK_SET);
192
+ errno = save_errno;
200
+/* A partial mmap replacement for binhex and pdf scanning */
201
+void *cli_copy_file_to_mem( int fildes, size_t size, off_t offset )
203
+ char *buf = malloc( size );
205
+ if( buf == NULL ) return( NULL );
206
+ if( pread( fildes, buf, size, offset ) == -1 ) {
215
int (*cli_unrar_open)(int fd, const char *dirname, unrar_state_t *state);
216
int (*cli_unrar_extract_next_prepare)(unrar_state_t *state, const char *dirname);
217
int (*cli_unrar_extract_next)(unrar_state_t *state, const char *dirname);
220
rhandle = lt_dlopenext("libclamunrar_iface");
223
+ cli_unrar_open = unrar_open;
224
+ cli_unrar_extract_next_prepare = unrar_extract_next_prepare;
225
+ cli_unrar_extract_next = unrar_extract_next;
226
+ cli_unrar_close = unrar_close;
229
#ifdef WARN_DLOPEN_FAIL
230
cli_warnmsg("Cannot dlopen: %s - unrar support unavailable\n", lt_dlerror());
232
cli_dbgmsg("Cannot dlopen: %s - unrar support unavailable\n", lt_dlerror());
237
if (!(cli_unrar_open = (int(*)(int, const char *, unrar_state_t *))lt_dlsym(rhandle, "unrar_open")) ||
243
+#if defined(C_WINDOWS) || defined(__DJGPP__)
245
* Windows doesn't allow you to delete a directory while it is still open
249
while((dent = readdir(dd))) {
251
-#if (!defined(C_INTERIX)) && (!defined(C_WINDOWS))
252
+#if (!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(__DJGPP__))
256
diff -ur clamav-orig/libclamav/others.h clamav-new/libclamav/others.h
257
--- clamav-orig/libclamav/others.h 2009-03-16 11:03:10.000000000 +1100
258
+++ clamav-new/libclamav/others.h 2009-03-16 16:31:12.000000000 +1100
260
void cli_dbgmsg_internal(const char *str, ...);
264
+void *cli_copy_file_to_mem(int fildes, size_t size, off_t offset);
265
+#define MAP_FAILED NULL
268
void *cli_malloc(size_t nmemb);
269
void *cli_calloc(size_t nmemb, size_t size);
270
void *cli_realloc(void *ptr, size_t size);
271
diff -ur clamav-orig/libclamav/others_common.c clamav-new/libclamav/others_common.c
272
--- clamav-orig/libclamav/others_common.c 2009-03-16 11:37:28.000000000 +1100
273
+++ clamav-new/libclamav/others_common.c 2009-03-16 16:44:08.000000000 +1100
274
@@ -100,6 +100,221 @@
275
fputs(buff, stderr); \
280
+ * DJGPP is missing strptime (needed by freshclam)
281
+ * This is my own implementation
285
+static char *__day[] = {
286
+ "Sunday", "Monday", "Tuesday", "Wednesday",
287
+ "Thursday", "Friday", "Saturday"
290
+static char *__month[] = {
291
+ "January", "February", "March", "April", "May", "June",
292
+ "July", "August", "September", "October", "November", "December"
295
+static char *__ampm[] = {
299
+static int _strton( const char *nptr, const char * restrict *endptr, int max )
305
+ if( *nptr == '0' && !x ) {
309
+ if( isdigit( *nptr ) ) {
310
+ x = x * 10 + ( *nptr - '0' );
317
+ *endptr = ( char * )nptr;
322
+char *strptime( const char * restrict buf, const char * restrict format,
323
+ struct tm * restrict tm )
330
+ if( *format == '%' ) {
332
+ if( *format == 'E' || *format == 'O' ) format++;
333
+ switch( *format ) {
338
+ case 'A': /* Day of week full or abbreviated */
339
+ for( w = 0; w < 7; w++ ) {
343
+ if( strnicmp( buf, p, len ) == 0 ) stri = len;
344
+ else if( strnicmp( buf, p, 3 ) == 0 ) stri = 3;
351
+ if( w == 7 ) return( NULL );
356
+ for( w = 0; w < 12; w++ ) {
360
+ if( strnicmp( buf, p, len ) == 0 ) stri = len;
361
+ else if( strnicmp( buf, p, 3 ) == 0 ) stri = 3;
368
+ if( w == 12 ) return( NULL );
371
+ buf = strptime( buf, "%a %b %d %R:%S %Y", tm );
372
+ if( buf == NULL ) return( NULL );
376
+ stri = _strton( buf, &buf, 2 );
377
+ if( stri == 0 || stri > 31 ) return( NULL );
378
+ tm->tm_mday = stri;
381
+ if( ( buf = strptime( buf, "%m/%d/%y", tm ) ) == NULL )
385
+ if( !isdigit( *buf ) ||
386
+ ( stri = _strton( buf, &buf, 2 ) ) > 23 )
388
+ tm->tm_hour = stri;
391
+ stri = _strton( buf, &buf, 2 );
392
+ if( stri < 1 || stri > 12 ) return( NULL );
393
+ tm->tm_hour = stri - 1;
396
+ stri = _strton( buf, &buf, 3 );
397
+ if( stri < 1 || stri > 366 ) return( NULL );
398
+ tm->tm_yday = stri;
401
+ stri = _strton( buf, &buf, 2 );
402
+ if( stri < 1 || stri > 12 ) return( NULL );
403
+ tm->tm_mon = stri - 1;
406
+ if( !isdigit( *buf ) ||
407
+ ( stri = _strton( buf, &buf, 2 ) ) > 59 ) {
414
+ if( !isspace( *buf ) ) return( NULL );
418
+ for( w = 0; w < 2; w++ ) {
419
+ if( strnicmp( buf, __ampm[ w ], 2 ) == 0 ) break;
421
+ if( w == 2 ) return( NULL );
422
+ if( w == 0 && tm->tm_hour > 11 ) tm->tm_hour -= 12;
423
+ if( w == 1 && tm->tm_hour < 12 ) tm->tm_hour += 12;
427
+ if( ( buf = strptime( buf, "%I:%M:%S%p", tm ) ) == NULL )
431
+ if( ( buf = strptime( buf, "%H:%M", tm ) ) == NULL )
435
+ if( !isdigit( *buf ) ||
436
+ ( stri = _strton( buf, &buf, 2 ) ) > 60 )
441
+ if( !isdigit( *buf ) ||
442
+ ( stri = _strton( buf, &buf, 2 ) ) > 53 )
445
+ if( stri % 7 > tm->tm_wday ) w++;
449
+ if( !isdigit( *buf ) ||
450
+ ( stri = _strton( buf, &buf, 2 ) ) > 6 ) return( NULL );
451
+ tm->tm_wday = stri;
454
+ if( !isdigit( *buf ) ||
455
+ ( stri = _strton( buf, &buf, 2 ) ) > 53 )
458
+ if( stri % 7 > ( tm->tm_wday + 6 ) % 7 ) w++;
462
+ if( ( buf = strptime( buf, "%a %b %d %Y", tm ) ) == NULL )
466
+ if( ( buf = strptime( buf, "%H:%M:%S", tm ) ) == NULL )
470
+ stri = _strton( buf, &buf, 2 );
471
+ if( stri > 99 ) return( NULL );
472
+ tm->tm_year = ( stri < 69 ) ? 100 + stri : stri;
475
+ stri = _strton( buf, &buf, 4 );
476
+ if( stri < 1969 || stri > 2068 ) return( NULL );
477
+ tm->tm_year = stri - 1900;
483
+ if( isspace( *format ) ) while( isspace( *buf ) ) buf++;
484
+ else if( *buf++ != *format ) return( NULL );
489
+ return( ( char * )buf );
493
void cli_warnmsg(const char *str, ...)
495
MSGCODE("LibClamAV Warning: ");
500
- if((mdir = getenv("TMPDIR")) == NULL)
501
+ mdir = getenv("TMPDIR");
503
+ if( mdir == NULL ) mdir = getenv("TEMP");
504
+ if( mdir == NULL ) mdir = getenv("TMP");
510
@@ -789,12 +1009,17 @@
514
+#ifdef __DJGPP__ /* Support systems that don't have an lfn driver/interface */
515
+ sprintf(name, "%s/c", mdir);
516
+ strncat(name, tmp, 7);
519
sprintf(name, "%s\\clamav-", mdir);
521
sprintf(name, "%s/clamav-", mdir);
523
strncat(name, tmp, 32);
528
diff -ur clamav-orig/libclamav/pdf.c clamav-new/libclamav/pdf.c
529
--- clamav-orig/libclamav/pdf.c 2009-03-16 11:37:28.000000000 +1100
530
+++ clamav-new/libclamav/pdf.c 2009-03-16 16:31:12.000000000 +1100
532
#include "clamav-config.h"
537
#include <sys/types.h>
538
#include <sys/stat.h>
540
if(size <= 7) /* doesn't even include the file header */
544
+ p = buf = cli_copy_file_to_mem(desc, size, offset);
546
p = buf = mmap(NULL, size, PROT_READ, MAP_PRIVATE, desc, offset);
548
if(buf == MAP_FAILED) {
549
cli_errmsg("cli_pdf: mmap() failed\n");
560
cli_dbgmsg("cli_pdf: file header not found\n");
572
cli_dbgmsg("cli_pdf: trailer not found\n");
576
* http://www.cs.cmu.edu/~dst/Adobe/Gallery/anon21jul01-pdf-encryption.txt
577
* http://www.adobe.com/devnet/pdf/
584
cli_dbgmsg("cli_pdf: Encrypted PDF files not yet supported\n");
596
cli_dbgmsg("cli_pdf: xref not found\n");
600
if(rc != CL_CLEAN) break;
609
tableDestroy(md5table);
615
-#else /*!HAVE_MMAP*/
622
-cli_pdf(const char *dir, int desc, cli_ctx *ctx, off_t offset)
624
- cli_dbgmsg("File not decoded - PDF decoding needs mmap() (for now)\n");
628
diff -ur clamav-orig/libclamav/readdb.c clamav-new/libclamav/readdb.c
629
--- clamav-orig/libclamav/readdb.c 2009-03-16 11:37:28.000000000 +1100
630
+++ clamav-new/libclamav/readdb.c 2009-03-16 16:30:26.000000000 +1100
631
@@ -1605,7 +1605,7 @@
633
while((dent = readdir(dd))) {
635
-#if (!defined(C_INTERIX)) && (!defined(C_WINDOWS))
636
+#if (!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(__DJGPP__))
640
@@ -1719,7 +1719,7 @@
642
while((dent = readdir(dd))) {
644
-#if (!defined(C_INTERIX)) && (!defined(C_WINDOWS))
645
+#if (!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(__DJGPP__))
649
@@ -1802,7 +1802,7 @@
651
while((dent = readdir(dd))) {
653
-#if (!defined(C_INTERIX)) && (!defined(C_WINDOWS))
654
+#if (!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(__DJGPP__))
658
@@ -1909,6 +1909,16 @@
659
#ifdef CL_THREAD_SAFE
660
pthread_mutex_unlock(&cli_ref_mutex);
663
+ * I know that disabling this for DJGPP causes a GIANT memory leak if an app
664
+ * were to free the database and load it again, but if we let if free each
665
+ * tiny memory block, it literally takes at least 5-10min if not more to
666
+ * finish. And in DOS all of the memory will automatically be freed when
667
+ * the app terminates, so the leak isn't permanent. If mempool were to be
668
+ * available for systems without mmap, this would likely be a much better
673
for(i = 0; i < CLI_MTARGETS; i++) {
674
if((root = engine->root[i])) {
675
@@ -1981,6 +1991,7 @@
681
if(engine->mempool) mpool_destroy(engine->mempool);
683
diff -ur clamav-orig/libclamav/scanners.c clamav-new/libclamav/scanners.c
684
--- clamav-orig/libclamav/scanners.c 2009-03-16 11:37:28.000000000 +1100
685
+++ clamav-new/libclamav/scanners.c 2009-03-16 16:30:26.000000000 +1100
688
while((dent = readdir(dd))) {
690
-#if (!defined(C_INTERIX)) && (!defined(C_WINDOWS))
691
+#if (!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(__DJGPP__))
697
while((dent = readdir(dd))) {
699
-#if (!defined(C_INTERIX)) && (!defined(C_WINDOWS))
700
+#if (!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(__DJGPP__))
704
diff -ur clamav-orig/shared/actions.c clamav-new/shared/actions.c
705
--- clamav-orig/shared/actions.c 2009-03-16 11:37:26.000000000 +1100
706
+++ clamav-new/shared/actions.c 2009-03-16 16:30:26.000000000 +1100
715
#include "shared/optparser.h"
716
#include "shared/output.h"
717
diff -ur clamav-orig/shared/misc.h clamav-new/shared/misc.h
718
--- clamav-orig/shared/misc.h 2009-03-16 11:37:26.000000000 +1100
719
+++ clamav-new/shared/misc.h 2009-03-16 17:13:22.000000000 +1100
722
#include <netinet/in.h>
723
#include "optparser.h"
725
/* Maximum filenames under various systems - njh */
726
#ifndef NAME_MAX /* e.g. Linux */
727
# ifdef MAXNAMELEN /* e.g. Solaris */
728
diff -ur clamav-orig/shared/optparser.c clamav-new/shared/optparser.c
729
--- clamav-orig/shared/optparser.c 2009-03-16 11:48:00.000000000 +1100
730
+++ clamav-new/shared/optparser.c 2009-03-16 17:21:28.000000000 +1100
732
#define FLAG_REQUIRED 2 /* arg is required, even if there's a default value */
733
#define FLAG_HIDDEN 4 /* don't print in clamconf --generate-config */
736
+#define FRESHCLAM_CONF CONFDIR"/clamav.cnf"
738
+#define FRESHCLAM_CONF CONFDIR"/freshclam.conf"
741
const struct clam_option clam_options[] = {
742
/* name, longopt, sopt, argtype, regex, num, str, mul, owner, description, suggested */
745
{ NULL, "help", 'h', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL | OPT_MILTER | OPT_CLAMCONF | OPT_CLAMDTOP, "", "" },
746
{ NULL, "config-file", 'c', TYPE_STRING, NULL, 0, CONFDIR"/clamd.conf", FLAG_REQUIRED, OPT_CLAMD | OPT_CLAMDSCAN | OPT_CLAMDTOP, "", "" },
747
- { NULL, "config-file", 0, TYPE_STRING, NULL, 0, CONFDIR"/freshclam.conf", FLAG_REQUIRED, OPT_FRESHCLAM, "", "" },
748
+ { NULL, "config-file", 0, TYPE_STRING, NULL, 0, FRESHCLAM_CONF, FLAG_REQUIRED, OPT_FRESHCLAM, "", "" },
749
{ NULL, "config-file", 'c', TYPE_STRING, NULL, 0, CONFDIR"/clamav-milter.conf", FLAG_REQUIRED, OPT_MILTER, "", "" },
750
{ NULL, "version", 'V', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL | OPT_MILTER | OPT_CLAMCONF | OPT_CLAMDTOP, "", "" },
751
{ NULL, "debug", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_SIGTOOL, "", "" },
752
diff -ur clamav-orig/sigtool/sigtool.c clamav-new/sigtool/sigtool.c
753
--- clamav-orig/sigtool/sigtool.c 2009-03-16 11:37:26.000000000 +1100
754
+++ clamav-new/sigtool/sigtool.c 2009-03-16 16:30:26.000000000 +1100
756
#include <sys/stat.h>
758
#include <sys/socket.h>
762
#include <netinet/in.h>
763
#include <arpa/inet.h>
764
#include <sys/wait.h>
768
while((dent = readdir(dd))) {
770
+#if !defined(C_INTERIX) && !defined(__DJGPP__)
774
@@ -1469,7 +1471,7 @@
777
while((dent = readdir(dd))) {
778
-#if (!defined(C_INTERIX)) && (!defined(C_WINDOWS))
779
+#if (!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(__DJGPP__))
783
@@ -1617,7 +1619,7 @@
786
while((dent = readdir(dd))) {
788
+#if !defined(C_INTERIX) && !defined(__DJGPP__)
792
@@ -1645,7 +1647,7 @@
795
while((dent = readdir(dd))) {
797
+#if !defined(C_INTERIX) && !defined(__DJGPP__)
801
diff -ur clamav-orig/sigtool/vba.c clamav-new/sigtool/vba.c
802
--- clamav-orig/sigtool/vba.c 2009-03-16 11:37:26.000000000 +1100
803
+++ clamav-new/sigtool/vba.c 2009-03-16 16:30:26.000000000 +1100
806
if ((dd = opendir (dirname)) != NULL) {
807
while ((dent = readdir (dd))) {
813
if (strcmp (dent->d_name, ".") && strcmp (dent->d_name, "..")) {
814
/* build the full name */
815
fname = (char *) cli_calloc (strlen (dirname) + strlen (dent->d_name) + 2, sizeof (char));
816
@@ -1130,7 +1133,10 @@
818
if ((dd = opendir (dirname)) != NULL) {
819
while ((dent = readdir (dd))) {
825
if (strcmp (dent->d_name, ".") && strcmp (dent->d_name, "..")) {
826
/* build the full name */
827
fullname = calloc (strlen (dirname) + strlen (dent->d_name) + 2, sizeof (char));