~ubuntu-branches/ubuntu/dapper/clamav/dapper-updates

« back to all changes in this revision

Viewing changes to contrib/DJGPP/djgpp_0.95.diff

  • Committer: Bazaar Package Importer
  • Author(s): Michael Tautschnig, Michael Tautschnig
  • Date: 2009-11-02 10:24:35 UTC
  • mfrom: (0.11.5 squeeze)
  • mto: (12.1.9 dapper-security)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20091102102435-yzkn3jdvo4gank3q
Tags: 0.95.3+dfsg-1
[ Michael Tautschnig ]
* New upstream version
* Should fix clamd segfault on startup (closes: #537629)
* Updated info in clamd.conf man page (closes: #534443)
* Proper socket ownership setup, no chgrp in make_dir (closes: #553333)

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
4
 
@@ -47,8 +47,10 @@
5
 
 #include <arpa/inet.h>
6
 
 #include <netinet/in.h>
7
 
 #include <sys/socket.h>
8
 
+#ifndef __DJGPP__
9
 
 #include <sys/un.h>
10
 
 #endif
11
 
+#endif
12
 
 #include <sys/time.h>
13
 
 #include <assert.h>
14
 
 #include <errno.h>
15
 
@@ -503,7 +505,7 @@
16
 
        int s;
17
 
        struct timeval tv;
18
 
        conn->tcp = 0;
19
 
-#ifdef _WIN32
20
 
+#if defined(_WIN32) || defined(__DJGPP__)
21
 
     {
22
 
 #else
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
27
 
@@ -80,7 +80,7 @@
28
 
     }
29
 
 #endif
30
 
 
31
 
-#if !defined(C_WINDOWS) && !defined(C_BEOS)
32
 
+#if !defined(C_WINDOWS) && !defined(C_BEOS) && !defined(__DJGPP__)
33
 
     sigemptyset(&sigset);
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
39
 
@@ -73,6 +73,11 @@
40
 
 #define P_tmpdir    "C:\\WINDOWS\\TEMP"
41
 
 #endif
42
 
 
43
 
+#ifdef __DJGPP__
44
 
+#undef P_tmpdir
45
 
+#define P_tmpdir    "/dev/env/TEMP"
46
 
+#endif
47
 
+
48
 
 #ifndef        O_BINARY
49
 
 #define        O_BINARY    0
50
 
 #endif
51
 
@@ -129,7 +134,7 @@
52
 
        return 0;
53
 
     }
54
 
     info.rblocks += fsize / CL_COUNT_PRECISION;
55
 
-#ifndef C_WINDOWS
56
 
+#if !defined(C_WINDOWS) && !defined(__DJGPP__)
57
 
     if(geteuid())
58
 
        if(checkaccess(filename, NULL, R_OK) != 1) {
59
 
            if(!printinfected)
60
 
@@ -214,7 +219,7 @@
61
 
 
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__)
66
 
            if(dent->d_ino)
67
 
 #endif
68
 
            {
69
 
@@ -334,7 +339,7 @@
70
 
        struct stat sb;
71
 
        char *file, cwd[1024], *pua_cats = NULL;
72
 
        const struct optstruct *opt;
73
 
-#ifndef C_WINDOWS
74
 
+#if !defined(C_WINDOWS) && !defined(__DJGPP__)
75
 
        struct rlimit rlim;
76
 
 #endif
77
 
 
78
 
@@ -468,7 +473,7 @@
79
 
        }
80
 
     }
81
 
 
82
 
-#ifndef C_WINDOWS
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
90
 
@@ -438,7 +438,7 @@
91
 
 
92
 
        logg("#freshclam daemon %s (OS: "TARGET_OS_TYPE", ARCH: "TARGET_ARCH_TYPE", CPU: "TARGET_CPU_TYPE")\n", get_version());
93
 
 
94
 
-#ifdef C_WINDOWS
95
 
+#if    defined(C_WINDOWS) || defined(__DJGPP__)
96
 
        signal(SIGINT, daemon_sighandler);
97
 
        terminate = 0;
98
 
 #else
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 @@
103
 
     }
104
 
 
105
 
     while((dent = readdir(dir))) {
106
 
-#if !defined(C_INTERIX) && !defined(C_WINDOWS)
107
 
+#if !defined(C_INTERIX) && !defined(C_WINDOWS) && !defined(__DJGPP__)
108
 
        if(dent->d_ino)
109
 
 #endif
110
 
        {
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
114
 
@@ -119,10 +119,6 @@
115
 
 int
116
 
 cli_binhex(const char *dir, int desc)
117
 
 {
118
 
-#ifndef HAVE_MMAP
119
 
-       cli_warnmsg("File not decoded - binhex decoding needs mmap() (for now)\n");
120
 
-       return CL_CLEAN;
121
 
-#else
122
 
        struct stat statb;
123
 
        char *buf, *start, *line;
124
 
        size_t size;
125
 
@@ -142,7 +138,11 @@
126
 
        if(m == NULL)
127
 
                return CL_EMEM;
128
 
 
129
 
+#ifndef HAVE_MMAP
130
 
+       start = buf = cli_copy_file_to_mem(desc, size, 0);
131
 
+#else
132
 
        start = buf = mmap(NULL, size, PROT_READ, MAP_PRIVATE, desc, 0);
133
 
+#endif
134
 
        if(buf == MAP_FAILED) {
135
 
                messageDestroy(m);
136
 
                return CL_EMAP;
137
 
@@ -187,7 +187,11 @@
138
 
                buf = ++ptr;
139
 
                bytesleft--;
140
 
        }
141
 
+#ifndef HAVE_MMAP
142
 
+       free(start);
143
 
+#else
144
 
        munmap(start, size);
145
 
+#endif
146
 
 
147
 
        if(line)
148
 
                free(line);
149
 
@@ -213,5 +217,4 @@
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 */
152
 
        return CL_EMEM;
153
 
-#endif
154
 
 }
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 @@
159
 
                                        int nblanks;
160
 
                                        struct stat statb;
161
 
                                        const char *dentry_idpart;
162
 
-#ifndef C_WINDOWS
163
 
+#if (!defined(C_WINDOWS)) && (!defined(__DJGPP__))
164
 
                                        if(dent->d_ino == 0)
165
 
                                                continue;
166
 
 #endif
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
170
 
@@ -81,6 +81,47 @@
171
 
 #define       P_tmpdir        "C:\\WINDOWS\\TEMP"
172
 
 #endif
173
 
 
174
 
+#ifdef               __DJGPP__
175
 
+#undef       P_tmpdir
176
 
+#define       P_tmpdir       "/dev/env/TEMP"
177
 
+
178
 
+/* DJGPP is missing pread/pwrite */
179
 
+ssize_t pread(int fd, void *data, size_t length, off_t offset )
180
 
+{
181
 
+        ssize_t result;
182
 
+        off_t save_offset;
183
 
+        int save_errno;
184
 
+
185
 
+        save_offset  = lseek(fd,offset,SEEK_SET);
186
 
+        if(save_offset==-1) return -1;
187
 
+
188
 
+        result = read(fd,data,length);
189
 
+
190
 
+        save_errno = errno;
191
 
+        lseek(fd, save_offset, SEEK_SET);
192
 
+        errno = save_errno;
193
 
+
194
 
+        return result;
195
 
+}
196
 
+
197
 
+#endif
198
 
+
199
 
+#ifndef HAVE_MMAP
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 )
202
 
+{
203
 
+       char *buf = malloc( size );
204
 
+
205
 
+       if( buf == NULL ) return( NULL );
206
 
+       if( pread( fildes, buf, size, offset ) == -1 ) {
207
 
+               free( buf );
208
 
+               return( NULL );
209
 
+       };
210
 
+
211
 
+       return( buf );
212
 
+}
213
 
+#endif
214
 
+
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);
218
 
@@ -99,11 +140,19 @@
219
 
     }
220
 
     rhandle = lt_dlopenext("libclamunrar_iface");
221
 
     if (!rhandle) {
222
 
+#ifdef __DJGPP__
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;
227
 
+    have_rar = 1;
228
 
+#else
229
 
 #ifdef WARN_DLOPEN_FAIL
230
 
         cli_warnmsg("Cannot dlopen: %s - unrar support unavailable\n", lt_dlerror());
231
 
 #else
232
 
         cli_dbgmsg("Cannot dlopen: %s - unrar support unavailable\n", lt_dlerror());
233
 
 #endif
234
 
+#endif
235
 
         return;
236
 
     }
237
 
     if (!(cli_unrar_open = (int(*)(int, const char *, unrar_state_t *))lt_dlsym(rhandle, "unrar_open")) ||
238
 
@@ -597,7 +646,7 @@
239
 
        return 0;
240
 
 }
241
 
 
242
 
-#ifdef C_WINDOWS
243
 
+#if defined(C_WINDOWS) || defined(__DJGPP__)
244
 
 /*
245
 
  * Windows doesn't allow you to delete a directory while it is still open
246
 
  */
247
 
@@ -702,7 +751,7 @@
248
 
 #else
249
 
            while((dent = readdir(dd))) {
250
 
 #endif
251
 
-#if    (!defined(C_INTERIX)) && (!defined(C_WINDOWS))
252
 
+#if    (!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(__DJGPP__))
253
 
                if(dent->d_ino)
254
 
 #endif
255
 
                {
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
259
 
@@ -358,6 +358,11 @@
260
 
 void cli_dbgmsg_internal(const char *str, ...);
261
 
 #endif
262
 
 
263
 
+#ifndef HAVE_MMAP
264
 
+void *cli_copy_file_to_mem(int fildes, size_t size, off_t offset);
265
 
+#define MAP_FAILED NULL
266
 
+#endif
267
 
+
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);                                   \
276
 
     va_end(args)
277
 
 
278
 
+#ifdef __DJGPP__
279
 
+/* 
280
 
+ * DJGPP is missing strptime (needed by freshclam)
281
 
+ * This is my own implementation
282
 
+ */
283
 
+
284
 
+
285
 
+static char *__day[] = {
286
 
+    "Sunday", "Monday", "Tuesday", "Wednesday",
287
 
+    "Thursday", "Friday", "Saturday"
288
 
+};
289
 
+
290
 
+static char *__month[] = {
291
 
+    "January", "February", "March", "April", "May", "June",
292
 
+    "July", "August", "September", "October", "November", "December"
293
 
+};
294
 
+
295
 
+static char *__ampm[] = {
296
 
+    "AM", "PM"
297
 
+};
298
 
+
299
 
+static int _strton( const char *nptr, const char * restrict *endptr, int max )
300
 
+{
301
 
+    int x = 0;
302
 
+
303
 
+    for( ;; ) {
304
 
+        if( !max ) break;
305
 
+        if( *nptr == '0' && !x ) {
306
 
+            nptr++;
307
 
+            continue;
308
 
+        }
309
 
+        if( isdigit( *nptr ) ) {
310
 
+            x = x * 10 + ( *nptr - '0' );
311
 
+            nptr++;
312
 
+            max--;
313
 
+        } else {
314
 
+            break;
315
 
+        }
316
 
+    }
317
 
+    *endptr = ( char * )nptr;
318
 
+
319
 
+    return( x );
320
 
+}
321
 
+
322
 
+char *strptime( const char * restrict buf, const char * restrict format,
323
 
+                struct tm * restrict tm )
324
 
+{
325
 
+    int w;
326
 
+    char *p;
327
 
+    int stri, len;
328
 
+
329
 
+    while( *format ) {
330
 
+        if( *format == '%' ) {
331
 
+            format++;
332
 
+            if( *format == 'E' || *format == 'O' ) format++;
333
 
+            switch( *format ) {
334
 
+                case '%':
335
 
+                    buf++;
336
 
+                    break;
337
 
+                case 'a':
338
 
+                case 'A':   /* Day of week full or abbreviated */
339
 
+                    for( w = 0; w < 7; w++ ) {
340
 
+                        p = __day[ w ];
341
 
+                        stri = 0;
342
 
+                        len = strlen( p );
343
 
+                        if( strnicmp( buf, p, len ) == 0 ) stri = len;
344
 
+                        else if( strnicmp( buf, p, 3 ) == 0 ) stri = 3;
345
 
+                        if( stri != 0 ) {
346
 
+                            tm->tm_wday = w;
347
 
+                            buf += stri;
348
 
+                            break;
349
 
+                        }
350
 
+                    }
351
 
+                    if( w == 7 ) return( NULL );
352
 
+                    break;
353
 
+                case 'b':
354
 
+                case 'B':
355
 
+                case 'h':
356
 
+                    for( w = 0; w < 12; w++ ) {
357
 
+                        p = __month[ w ];
358
 
+                        stri = 0;
359
 
+                        len = strlen( p );
360
 
+                        if( strnicmp( buf, p, len ) == 0 ) stri = len;
361
 
+                        else if( strnicmp( buf, p, 3 ) == 0 ) stri = 3;
362
 
+                        if( stri != 0 ) {
363
 
+                            tm->tm_mon = w;
364
 
+                            buf += stri;
365
 
+                            break;
366
 
+                        }
367
 
+                    }
368
 
+                    if( w == 12 ) return( NULL );
369
 
+                    break;
370
 
+                case 'c':
371
 
+                    buf = strptime( buf, "%a %b %d %R:%S %Y", tm );
372
 
+                    if( buf == NULL ) return( NULL );
373
 
+                    break;
374
 
+                case 'd':
375
 
+                case 'e':
376
 
+                    stri = _strton( buf, &buf, 2 );
377
 
+                    if( stri == 0 || stri > 31 ) return( NULL );
378
 
+                    tm->tm_mday = stri;
379
 
+                    break;
380
 
+                case 'D':
381
 
+                    if( ( buf = strptime( buf, "%m/%d/%y", tm ) ) == NULL )
382
 
+                        return( NULL );
383
 
+                    break;
384
 
+                case 'H':
385
 
+                    if( !isdigit( *buf ) ||
386
 
+                        ( stri = _strton( buf, &buf, 2 ) ) > 23 )
387
 
+                        return( NULL );
388
 
+                    tm->tm_hour = stri;
389
 
+                    break;
390
 
+                case 'I':
391
 
+                    stri = _strton( buf, &buf, 2 );
392
 
+                    if( stri < 1 || stri > 12 ) return( NULL );
393
 
+                    tm->tm_hour = stri - 1;
394
 
+                    break;
395
 
+                case 'j':
396
 
+                    stri = _strton( buf, &buf, 3 );
397
 
+                    if( stri < 1 || stri > 366 ) return( NULL );
398
 
+                    tm->tm_yday = stri;
399
 
+                    break;
400
 
+                case 'm':
401
 
+                    stri = _strton( buf, &buf, 2 );
402
 
+                    if( stri < 1 || stri > 12 ) return( NULL );
403
 
+                    tm->tm_mon = stri - 1;
404
 
+                    break;
405
 
+                case 'M':
406
 
+                    if( !isdigit( *buf ) ||
407
 
+                        ( stri = _strton( buf, &buf, 2 ) ) > 59 ) {
408
 
+                        return( NULL );
409
 
+                    }
410
 
+                    tm->tm_min = stri;
411
 
+                    break;
412
 
+                case 'n':
413
 
+                case 't':
414
 
+                    if( !isspace( *buf ) ) return( NULL );
415
 
+                    buf++;
416
 
+                    break;
417
 
+                case 'p':
418
 
+                    for( w = 0; w < 2; w++ ) {
419
 
+                        if( strnicmp( buf, __ampm[ w ], 2 ) == 0 ) break;
420
 
+                    }
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;
424
 
+                    buf += 2;
425
 
+                    break;
426
 
+                case 'r':
427
 
+                    if( ( buf = strptime( buf, "%I:%M:%S%p", tm ) ) == NULL )
428
 
+                        return( NULL );
429
 
+                    break;
430
 
+                case 'R':
431
 
+                    if( ( buf = strptime( buf, "%H:%M", tm ) ) == NULL )
432
 
+                        return( NULL );
433
 
+                    break;
434
 
+                case 'S':
435
 
+                    if( !isdigit( *buf ) ||
436
 
+                        ( stri = _strton( buf, &buf, 2 ) ) > 60 )
437
 
+                        return( NULL );
438
 
+                    tm->tm_sec = stri;
439
 
+                    break;
440
 
+                case 'U':
441
 
+                    if( !isdigit( *buf ) ||
442
 
+                        ( stri = _strton( buf, &buf, 2 ) ) > 53 )
443
 
+                        return( NULL );
444
 
+                    w = stri * 7;
445
 
+                    if( stri % 7 > tm->tm_wday ) w++;
446
 
+                    tm->tm_yday = w;
447
 
+                    break;
448
 
+                case 'w':
449
 
+                    if( !isdigit( *buf ) ||
450
 
+                        ( stri = _strton( buf, &buf, 2 ) ) > 6 ) return( NULL );
451
 
+                    tm->tm_wday = stri;
452
 
+                    break;
453
 
+                case 'W':
454
 
+                    if( !isdigit( *buf ) ||
455
 
+                        ( stri = _strton( buf, &buf, 2 ) ) > 53 )
456
 
+                        return( NULL );
457
 
+                    w = stri * 7;
458
 
+                    if( stri % 7 > ( tm->tm_wday + 6 ) % 7 ) w++;
459
 
+                    tm->tm_yday = w;
460
 
+                    break;
461
 
+                case 'x':
462
 
+                    if( ( buf = strptime( buf, "%a %b %d %Y", tm ) ) == NULL )
463
 
+                        return( NULL );
464
 
+                    break;
465
 
+                case 'X':
466
 
+                    if( ( buf = strptime( buf, "%H:%M:%S", tm ) ) == NULL )
467
 
+                        return( NULL );
468
 
+                    break;
469
 
+                case 'y':
470
 
+                    stri = _strton( buf, &buf, 2 );
471
 
+                    if( stri > 99 ) return( NULL );
472
 
+                    tm->tm_year = ( stri < 69 ) ? 100 + stri : stri;
473
 
+                    break;
474
 
+                case 'Y':
475
 
+                    stri = _strton( buf, &buf, 4 );
476
 
+                    if( stri < 1969 || stri > 2068 ) return( NULL );
477
 
+                    tm->tm_year = stri - 1900;
478
 
+                    break;
479
 
+                default:
480
 
+                    buf++;
481
 
+            }
482
 
+        } else {
483
 
+            if( isspace( *format ) ) while( isspace( *buf ) ) buf++;
484
 
+            else if( *buf++ != *format ) return( NULL );
485
 
+        }
486
 
+        format++;
487
 
+    }
488
 
+    
489
 
+    return( ( char * )buf );
490
 
+}
491
 
+#endif
492
 
+
493
 
 void cli_warnmsg(const char *str, ...)
494
 
 {
495
 
     MSGCODE("LibClamAV Warning: ");
496
 
@@ -753,7 +968,12 @@
497
 
        int i;
498
 
 
499
 
     if(!dir) {
500
 
-       if((mdir = getenv("TMPDIR")) == NULL)
501
 
+       mdir = getenv("TMPDIR");
502
 
+#ifdef __DJGPP__
503
 
+       if( mdir == NULL ) mdir = getenv("TEMP");
504
 
+       if( mdir == NULL ) mdir = getenv("TMP");
505
 
+#endif
506
 
+       if(mdir == NULL)
507
 
 #ifdef P_tmpdir
508
 
            mdir = P_tmpdir;
509
 
 #else
510
 
@@ -789,12 +1009,17 @@
511
 
        return NULL;
512
 
     }
513
 
 
514
 
+#ifdef __DJGPP__ /* Support systems that don't have an lfn driver/interface */
515
 
+       sprintf(name, "%s/c", mdir);
516
 
+       strncat(name, tmp, 7);
517
 
+#else
518
 
 #ifdef C_WINDOWS
519
 
        sprintf(name, "%s\\clamav-", mdir);
520
 
 #else
521
 
        sprintf(name, "%s/clamav-", mdir);
522
 
 #endif
523
 
     strncat(name, tmp, 32);
524
 
+#endif
525
 
     free(tmp);
526
 
 
527
 
     return(name);
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
531
 
@@ -26,7 +26,6 @@
532
 
 #include "clamav-config.h"
533
 
 #endif
534
 
 
535
 
-#ifdef HAVE_MMAP
536
 
 #include <stdio.h>
537
 
 #include <sys/types.h>
538
 
 #include <sys/stat.h>
539
 
@@ -105,7 +104,11 @@
540
 
        if(size <= 7)   /* doesn't even include the file header */
541
 
                return CL_CLEAN;
542
 
 
543
 
+#ifndef HAVE_MMAP
544
 
+       p = buf = cli_copy_file_to_mem(desc, size, offset);
545
 
+#else
546
 
        p = buf = mmap(NULL, size, PROT_READ, MAP_PRIVATE, desc, offset);
547
 
+#endif
548
 
        if(buf == MAP_FAILED) {
549
 
                cli_errmsg("cli_pdf: mmap() failed\n");
550
 
                return CL_EMAP;
551
 
@@ -126,7 +129,11 @@
552
 
        }
553
 
 
554
 
        if(!bytesleft) {
555
 
+#ifndef HAVE_MMAP
556
 
+           free(buf);
557
 
+#else
558
 
            munmap(buf, size);
559
 
+#endif
560
 
            cli_dbgmsg("cli_pdf: file header not found\n");
561
 
            return CL_CLEAN;
562
 
        }
563
 
@@ -137,7 +144,11 @@
564
 
                        break;
565
 
 
566
 
        if(q <= p) {
567
 
+#ifndef HAVE_MMAP
568
 
+               free(buf);
569
 
+#else
570
 
                munmap(buf, size);
571
 
+#endif
572
 
                cli_dbgmsg("cli_pdf: trailer not found\n");
573
 
                return CL_CLEAN;
574
 
        }
575
 
@@ -156,7 +167,11 @@
576
 
                 * http://www.cs.cmu.edu/~dst/Adobe/Gallery/anon21jul01-pdf-encryption.txt
577
 
                 * http://www.adobe.com/devnet/pdf/
578
 
                 */
579
 
+#ifndef HAVE_MMAP
580
 
+               free(buf);
581
 
+#else
582
 
                munmap(buf, size);
583
 
+#endif
584
 
                cli_dbgmsg("cli_pdf: Encrypted PDF files not yet supported\n");
585
 
                return CL_CLEAN;
586
 
        }
587
 
@@ -179,7 +194,11 @@
588
 
                                break;
589
 
 
590
 
        if(xrefstart == p) {
591
 
+#ifndef HAVE_MMAP
592
 
+               free(buf);
593
 
+#else
594
 
                munmap(buf, size);
595
 
+#endif
596
 
                cli_dbgmsg("cli_pdf: xref not found\n");
597
 
                return CL_CLEAN;
598
 
        }
599
 
@@ -550,7 +569,11 @@
600
 
                if(rc != CL_CLEAN) break;
601
 
        }
602
 
 
603
 
+#ifndef HAVE_MMAP
604
 
+       free(buf);
605
 
+#else
606
 
        munmap(buf, size);
607
 
+#endif
608
 
 
609
 
        tableDestroy(md5table);
610
 
 
611
 
@@ -886,16 +909,4 @@
612
 
 
613
 
        return NULL;
614
 
 }
615
 
-#else  /*!HAVE_MMAP*/
616
 
-
617
 
-#include "clamav.h"
618
 
-#include "others.h"
619
 
-#include "pdf.h"
620
 
 
621
 
-int
622
 
-cli_pdf(const char *dir, int desc, cli_ctx *ctx, off_t offset)
623
 
-{
624
 
-       cli_dbgmsg("File not decoded - PDF decoding needs mmap() (for now)\n");
625
 
-       return CL_CLEAN;
626
 
-}
627
 
-#endif
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 @@
632
 
 #else
633
 
     while((dent = readdir(dd))) {
634
 
 #endif
635
 
-#if    (!defined(C_INTERIX)) && (!defined(C_WINDOWS))
636
 
+#if    (!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(__DJGPP__))
637
 
        if(dent->d_ino)
638
 
 #endif
639
 
        {
640
 
@@ -1719,7 +1719,7 @@
641
 
 #else
642
 
     while((dent = readdir(dd))) {
643
 
 #endif
644
 
-#if    (!defined(C_INTERIX)) && (!defined(C_WINDOWS))
645
 
+#if    (!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(__DJGPP__))
646
 
        if(dent->d_ino)
647
 
 #endif
648
 
        {
649
 
@@ -1802,7 +1802,7 @@
650
 
 #else
651
 
     while((dent = readdir(dd))) {
652
 
 #endif
653
 
-#if    (!defined(C_INTERIX)) && (!defined(C_WINDOWS))
654
 
+#if    (!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(__DJGPP__))
655
 
        if(dent->d_ino)
656
 
 #endif
657
 
        {
658
 
@@ -1909,6 +1909,16 @@
659
 
 #ifdef CL_THREAD_SAFE
660
 
     pthread_mutex_unlock(&cli_ref_mutex);
661
 
 #endif
662
 
+/*
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
669
 
+ * solution
670
 
+ */
671
 
+#ifndef __DJGPP__
672
 
     if(engine->root) {
673
 
        for(i = 0; i < CLI_MTARGETS; i++) {
674
 
            if((root = engine->root[i])) {
675
 
@@ -1981,6 +1991,7 @@
676
 
 
677
 
     cli_ftfree(engine);
678
 
     cli_freeign(engine);
679
 
+#endif
680
 
 #ifdef USE_MPOOL
681
 
     if(engine->mempool) mpool_destroy(engine->mempool);
682
 
 #endif
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
686
 
@@ -128,7 +128,7 @@
687
 
 #else
688
 
        while((dent = readdir(dd))) {
689
 
 #endif
690
 
-#if    (!defined(C_INTERIX)) && (!defined(C_WINDOWS))
691
 
+#if    (!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(__DJGPP__))
692
 
            if(dent->d_ino)
693
 
 #endif
694
 
            {
695
 
@@ -885,7 +885,7 @@
696
 
 #else
697
 
        while((dent = readdir(dd))) {
698
 
 #endif
699
 
-#if    (!defined(C_INTERIX)) && (!defined(C_WINDOWS))
700
 
+#if    (!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(__DJGPP__))
701
 
            if(dent->d_ino)
702
 
 #endif
703
 
            {
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
707
 
@@ -30,7 +30,9 @@
708
 
 #include <fcntl.h>
709
 
 #include <utime.h>
710
 
 #include <errno.h>
711
 
+#ifndef __DJGPP__
712
 
 #include <libgen.h>
713
 
+#endif
714
 
 
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
720
 
@@ -23,6 +23,7 @@
721
 
 #include <netdb.h>
722
 
 #include <netinet/in.h>
723
 
 #include "optparser.h"
724
 
+
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
731
 
@@ -56,13 +56,19 @@
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 */
734
 
 
735
 
+#ifdef __DJGPP__
736
 
+#define FRESHCLAM_CONF CONFDIR"/clamav.cnf"
737
 
+#else
738
 
+#define FRESHCLAM_CONF CONFDIR"/freshclam.conf"
739
 
+#endif
740
 
+
741
 
 const struct clam_option clam_options[] = {
742
 
     /* name,   longopt, sopt, argtype, regex, num, str, mul, owner, description, suggested */
743
 
 
744
 
     /* cmdline only */
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
755
 
@@ -35,7 +35,9 @@
756
 
 #include <sys/stat.h>
757
 
 #include <fcntl.h>
758
 
 #include <sys/socket.h>
759
 
+#ifndef __DJGPP__
760
 
 #include <sys/un.h>
761
 
+#endif
762
 
 #include <netinet/in.h>
763
 
 #include <arpa/inet.h>
764
 
 #include <sys/wait.h>
765
 
@@ -987,7 +989,7 @@
766
 
     }
767
 
 
768
 
     while((dent = readdir(dd))) {
769
 
-#ifndef C_INTERIX
770
 
+#if !defined(C_INTERIX) && !defined(__DJGPP__)
771
 
        if(dent->d_ino)
772
 
 #endif
773
 
        {
774
 
@@ -1469,7 +1471,7 @@
775
 
     }
776
 
 
777
 
     while((dent = readdir(dd))) {
778
 
-#if (!defined(C_INTERIX)) && (!defined(C_WINDOWS))
779
 
+#if (!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(__DJGPP__))
780
 
        if(dent->d_ino)
781
 
 #endif
782
 
        {
783
 
@@ -1617,7 +1619,7 @@
784
 
     }
785
 
 
786
 
     while((dent = readdir(dd))) {
787
 
-#ifndef C_INTERIX
788
 
+#if !defined(C_INTERIX) && !defined(__DJGPP__)
789
 
        if(dent->d_ino)
790
 
 #endif
791
 
        {
792
 
@@ -1645,7 +1647,7 @@
793
 
     }
794
 
 
795
 
     while((dent = readdir(dd))) {
796
 
-#ifndef C_INTERIX
797
 
+#if !defined(C_INTERIX) && !defined(__DJGPP__)
798
 
        if(dent->d_ino)
799
 
 #endif
800
 
        {
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
804
 
@@ -970,7 +970,10 @@
805
 
 
806
 
     if ((dd = opendir (dirname)) != NULL) {
807
 
        while ((dent = readdir (dd))) {
808
 
-           if (dent->d_ino) {
809
 
+#ifndef __DJGPP__
810
 
+           if (dent->d_ino)
811
 
+#endif
812
 
+        {
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 @@
817
 
 
818
 
     if ((dd = opendir (dirname)) != NULL) {
819
 
        while ((dent = readdir (dd))) {
820
 
-           if (dent->d_ino) {
821
 
+#ifndef __DJGPP__
822
 
+           if (dent->d_ino)
823
 
+#endif
824
 
+        {
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));