Browse code

win32#2

aCaB authored on 2009/09/24 23:21:51
Showing 44 changed files
... ...
@@ -1,3 +1,7 @@
1
+Thu Sep 24 16:22:25 CEST 2009 (acab)
2
+------------------------------------
3
+ * merge initial set of win32 patches from Gianluigi Tiesi <sherpya*netfarm.it>
4
+
1 5
 Thu Sep 24 01:14:50 CEST 2009 (acab)
2 6
 ------------------------------------
3 7
  * clamav-milter: Add option ReportHostname to mangle the host name in X headers
... ...
@@ -33,10 +33,10 @@
33 33
 #include <sys/stat.h>
34 34
 #include <fcntl.h>
35 35
 #include <time.h>
36
-#ifdef C_WINDOWS
37
-#include <direct.h>	/* for chdir */
38
-#else
36
+#ifdef HAVE_PWD_H
39 37
 #include <pwd.h>
38
+#endif
39
+#ifdef HAVE_GRP_H
40 40
 #include <grp.h>
41 41
 #endif
42 42
 #include <signal.h>
... ...
@@ -114,7 +114,7 @@ static int isremote(const struct optstruct *opts) {
114 114
     testsock.sin_port = htons(INADDR_ANY);
115 115
     if(!(s = socket(testsock.sin_family, SOCK_STREAM, 0))) return 0;
116 116
     ret = (bind(s, (struct sockaddr *)&testsock, sizeof(testsock)) != 0);
117
-    close(s);
117
+    closesocket(s);
118 118
     return ret;
119 119
 }
120 120
 
... ...
@@ -173,7 +173,7 @@ int get_clamd_version(const struct optstruct *opts)
173 173
     recvlninit(&rcv, sockd);
174 174
 
175 175
     if(sendln(sockd, "zVERSION", 9)) {
176
-	close(sockd);
176
+	closesocket(sockd);
177 177
 	return 2;
178 178
     }
179 179
 
... ...
@@ -185,7 +185,7 @@ int get_clamd_version(const struct optstruct *opts)
185 185
 	printf("%s\n", buff);
186 186
     }
187 187
 
188
-    close(sockd);
188
+    closesocket(sockd);
189 189
     return 0;
190 190
 }
191 191
 
... ...
@@ -201,16 +201,16 @@ int reload_clamd_database(const struct optstruct *opts)
201 201
     recvlninit(&rcv, sockd);
202 202
 
203 203
     if(sendln(sockd, "zRELOAD", 8)) {
204
-	close(sockd);
204
+	closesocket(sockd);
205 205
 	return 2;
206 206
     }
207 207
 
208 208
     if(!(len = recvln(&rcv, &buff, NULL)) || len < 10 || memcmp(buff, "RELOADING", 9)) {
209 209
 	logg("!Clamd did not reload the database\n");
210
-	close(sockd);
210
+	closesocket(sockd);
211 211
 	return 2;
212 212
     }
213
-    close(sockd);
213
+    closesocket(sockd);
214 214
     return 0;
215 215
 }
216 216
 
... ...
@@ -265,7 +265,7 @@ int client(const struct optstruct *opts, int *infected)
265 265
 	    *infected = ret;
266 266
 	else
267 267
 	    errors = 1;
268
-	if(sockd >= 0) close(sockd);
268
+	if(sockd >= 0) closesocket(sockd);
269 269
     } else if(opts->filename || optget(opts, "file-list")->enabled) {
270 270
 	if(opts->filename && optget(opts, "file-list")->enabled)
271 271
 	    logg("^Only scanning files from --file-list (files passed at cmdline are ignored)\n");
... ...
@@ -64,7 +64,7 @@ int dconnect() {
64 64
     }
65 65
 
66 66
     if(connect(sockd, (struct sockaddr *)mainsa, mainsasz) < 0) {
67
-	close(sockd);
67
+	closesocket(sockd);
68 68
 	logg("!Can't connect to clamd: %s\n", strerror(errno));
69 69
 	return -1;
70 70
     }
... ...
@@ -162,7 +162,7 @@ static int send_stream(int sockd, const char *filename) {
162 162
     unsigned long int todo = maxstream;
163 163
 
164 164
     if(filename) {
165
-	if((fd = open(filename, O_RDONLY))<0) {
165
+	if((fd = open(filename, O_RDONLY | O_BINARY))<0) {
166 166
 	    logg("~%s: Access denied. ERROR\n", filename);
167 167
 	    return 0;
168 168
 	}
... ...
@@ -361,7 +361,7 @@ static int serial_callback(struct stat *sb, char *filename, const char *path, en
361 361
     }
362 362
     ret = dsresult(sockd, c->scantype, f, &c->printok);
363 363
     if(filename) free(filename);
364
-    close(sockd);
364
+    closesocket(sockd);
365 365
     if(ret < 0) return CL_EOPEN;
366 366
     c->infected += ret;
367 367
     if(reason == visit_directory_toplev)
... ...
@@ -553,7 +553,7 @@ int parallel_client_scan(char *file, int scantype, int *infected, int maxlevel,
553 553
 	return 1;
554 554
 
555 555
     if(sendln(cdata.sockd, "zIDSESSION", 11)) {
556
-	close(cdata.sockd);
556
+	closesocket(cdata.sockd);
557 557
 	return 1;
558 558
     }
559 559
 
... ...
@@ -568,13 +568,13 @@ int parallel_client_scan(char *file, int scantype, int *infected, int maxlevel,
568 568
 
569 569
     if(ftw != CL_SUCCESS) {
570 570
 	*infected += cdata.infected;
571
-	close(cdata.sockd);
571
+	closesocket(cdata.sockd);
572 572
 	return 1;
573 573
     }
574 574
 
575 575
     sendln(cdata.sockd, "zEND", 5);
576 576
     while(cdata.ids && !dspresult(&cdata));
577
-    close(cdata.sockd);
577
+    closesocket(cdata.sockd);
578 578
 
579 579
     *infected += cdata.infected;
580 580
 
... ...
@@ -68,15 +68,6 @@
68 68
 dev_t procdev;
69 69
 #endif
70 70
 
71
-#ifdef C_WINDOWS
72
-#undef P_tmpdir
73
-#define P_tmpdir    "C:\\WINDOWS\\TEMP"
74
-#endif
75
-
76
-#ifndef	O_BINARY
77
-#define	O_BINARY    0
78
-#endif
79
-
80 71
 static int scanfile(const char *filename, struct cl_engine *engine, const struct optstruct *opts, unsigned int options)
81 72
 {
82 73
   int ret = 0, fd, included, printclean = 1, fsize;
... ...
@@ -272,17 +263,9 @@ static int scanstdin(const struct cl_engine *engine, const struct optstruct *opt
272 272
 
273 273
     if(optget(opts, "tempdir")->enabled) {
274 274
 	tmpdir = optget(opts, "tempdir")->strarg;
275
-    } else {
275
+    } else
276 276
 	/* check write access */
277
-	tmpdir = getenv("TMPDIR");
278
-
279
-	if(tmpdir == NULL)
280
-#ifdef P_tmpdir
281
-	    tmpdir = P_tmpdir;
282
-#else
283
-	    tmpdir = "/tmp";
284
-#endif
285
-    }
277
+	tmpdir = cli_gettmpdir();
286 278
 
287 279
     if(checkaccess(tmpdir, CLAMAVUSER, W_OK) != 1) {
288 280
 	logg("!Can't write to temporary directory\n");
... ...
@@ -35,8 +35,10 @@
35 35
 #endif
36 36
 #include <sys/stat.h>
37 37
 #include <fcntl.h>
38
-#ifndef	C_WINDOWS
38
+#ifdef	HAVE_PWD_H
39 39
 #include <pwd.h>
40
+#endif
41
+#ifdef HAVE_GRP_H
40 42
 #include <grp.h>
41 43
 #endif
42 44
 
... ...
@@ -675,11 +675,7 @@ int submitstats(const char *clamdcfg, const struct optstruct *opts)
675 675
 	*pt2 = 0;
676 676
 	pt2 += 2;
677 677
 
678
-#ifdef C_WINDOWS
679
-	if((pt = strrchr(pt, '\\')))
680
-#else
681
-	if((pt = strrchr(pt, '/')))
682
-#endif
678
+	if((pt = strrchr(pt, *PATHSEP)))
683 679
 	    *pt++ = 0;
684 680
 	if(!pt)
685 681
 	    pt = (char*) "NOFNAME";
... ...
@@ -48,10 +48,6 @@
48 48
 
49 49
 #include "shared/output.h"
50 50
 
51
-#ifndef O_BINARY
52
-#define O_BINARY    0
53
-#endif
54
-
55 51
 #ifndef HAVE_GETADDRINFO
56 52
 #ifndef AF_INET6
57 53
 #define AF_INET6    0xbeef  /* foo */
... ...
@@ -27,7 +27,7 @@
27 27
 #include <unistd.h>
28 28
 #endif
29 29
 #include <sys/types.h>
30
-#ifndef	C_WINDOWS
30
+#ifndef	_WIN32
31 31
 #include <sys/socket.h>
32 32
 #include <sys/un.h>
33 33
 #include <netinet/in.h>
... ...
@@ -37,10 +37,6 @@
37 37
 #include "7z/Archive/7z/7zIn.h"
38 38
 #include "7z/Archive/7z/7zExtract.h"
39 39
 
40
-#ifndef O_BINARY
41
-#define O_BINARY 0
42
-#endif
43
-
44 40
 static ISzAlloc allocImp = { __lzma_wrap_alloc, __lzma_wrap_free}, allocTempImp = { __lzma_wrap_alloc, __lzma_wrap_free};
45 41
 
46 42
 int cli_7unz (int fd, cli_ctx *ctx) {
... ...
@@ -35,10 +35,6 @@
35 35
 #include <unistd.h>
36 36
 #endif
37 37
 
38
-#ifndef O_BINARY
39
-#define O_BINARY        0
40
-#endif
41
-
42 38
 #include "others.h"
43 39
 #include "scanners.h"
44 40
 #include "autoit.h"
... ...
@@ -13,6 +13,10 @@
13 13
  * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
14 14
  */
15 15
 
16
+#if HAVE_CONFIG_H
17
+#include "clamav-config.h"
18
+#endif
19
+
16 20
 /* Start: bn_error.c */
17 21
 #include <bignum.h>
18 22
 #include "others.h"
... ...
@@ -44,14 +44,6 @@
44 44
 #define LTM_ALL /* FIXME: tk: limit to the above class */
45 45
 #include "bignum_class.h"
46 46
 
47
-#ifndef MIN
48
-   #define MIN(x,y) ((x)<(y)?(x):(y))
49
-#endif
50
-
51
-#ifndef MAX
52
-   #define MAX(x,y) ((x)>(y)?(x):(y))
53
-#endif
54
-
55 47
 #ifdef __cplusplus
56 48
 extern "C" {
57 49
 
... ...
@@ -48,10 +48,6 @@ static	char	const	rcsid[] = "$Id: blob.c,v 1.64 2007/02/12 22:25:14 njh Exp $";
48 48
 #include "scanners.h"
49 49
 #include "filetypes.h"
50 50
 
51
-#ifndef	O_BINARY
52
-#define	O_BINARY	0
53
-#endif
54
-
55 51
 #include <assert.h>
56 52
 
57 53
 /* Scehduled for rewite in 0.94 (bb#804). Disabling for now */
... ...
@@ -40,10 +40,6 @@
40 40
 #define EC32(x) le32_to_host(x) /* Convert little endian to host */
41 41
 #define EC16(x) le16_to_host(x)
42 42
 
43
-#ifndef O_BINARY
44
-#define O_BINARY        0
45
-#endif
46
-
47 43
 /* hard limits */
48 44
 #define CAB_FOLDER_LIMIT    5000
49 45
 #define CAB_FILE_LIMIT	    5000
... ...
@@ -63,10 +63,6 @@
63 63
 #pragma pack 1
64 64
 #endif
65 65
 
66
-#ifndef	O_BINARY
67
-#define	O_BINARY	0
68
-#endif
69
-
70 66
 #define CHM_CHUNK_HDR_LEN (0x14)
71 67
 
72 68
 #define CHM_CONTROL_LEN (0x18)
... ...
@@ -45,10 +45,6 @@
45 45
 
46 46
 #define TAR_BLOCKSIZE 512
47 47
 
48
-#ifndef	O_BINARY
49
-#define	O_BINARY	0
50
-#endif
51
-
52 48
 static int cli_untgz(int fd, const char *destdir)
53 49
 {
54 50
 	char *path, osize[13], name[101], type;
... ...
@@ -51,10 +51,6 @@
51 51
 #include "others.h"
52 52
 #include "ishield.h"
53 53
 
54
-#ifndef O_BINARY
55
-#define O_BINARY 0
56
-#endif
57
-
58 54
 #ifndef LONG_MAX
59 55
 #define LONG_MAX ((-1UL)>>1)
60 56
 #endif
... ...
@@ -495,11 +495,6 @@ static int match_parameters(const yystype *tokens, const char ** param_names, si
495 495
 static const char *de_packer_3[] = {"p","a","c","k","e","r"};
496 496
 static const char *de_packer_2[] = {"p","a","c","k","e","d"};
497 497
 
498
-
499
-#ifndef MAX
500
-#define MAX(a, b) ((a)>(b) ? (a) : (b))
501
-#endif
502
-
503 498
 static inline char *textbuffer_done(yyscan_t scanner)
504 499
 {
505 500
 	/* free unusued memory */
... ...
@@ -1390,10 +1385,6 @@ static inline int parseId(YYSTYPE *lvalp, yyscan_t scanner)
1390 1390
 	return 0;
1391 1391
 }
1392 1392
 
1393
-#ifndef MIN
1394
-#define MIN(a,b) ((a)<(b) ? (a):(b))
1395
-#endif
1396
-
1397 1393
 static int parseOperator(YYSTYPE *lvalp, yyscan_t scanner)
1398 1394
 {
1399 1395
 	size_t len = MIN(5, scanner->insize - scanner->pos);
... ...
@@ -32,6 +32,7 @@ CLAMAV_PUBLIC {
32 32
 };
33 33
 CLAMAV_PRIVATE {
34 34
   global:
35
+    cli_gettmpdir;
35 36
     cli_strtok;
36 37
     cli_strtokenize;
37 38
     cli_cvdunpack;
... ...
@@ -136,6 +136,7 @@ typedef	enum {
136 136
 #include "phishcheck.h"
137 137
 
138 138
 #ifndef	_WIN32
139
+#include <sys/time.h>
139 140
 #include <netdb.h>
140 141
 #include <sys/socket.h>
141 142
 #include <netinet/in.h>
... ...
@@ -145,19 +146,7 @@ typedef	enum {
145 145
 #endif
146 146
 #endif
147 147
 
148
-
149 148
 #include <fcntl.h>
150
-#ifndef	C_WINDOWS
151
-#include <sys/time.h>
152
-#endif
153
-
154
-#ifndef HAVE_IN_PORT_T
155
-typedef	unsigned	short	in_port_t;
156
-#endif
157
-
158
-#ifndef HAVE_IN_ADDR_T
159
-typedef	unsigned	int	in_addr_t;
160
-#endif
161 149
 
162 150
 /*
163 151
  * Use CL_SCAN_PARTIAL_MESSAGE to handle messages covered by section 7.3.2 of RFC1341.
... ...
@@ -311,10 +300,6 @@ static	const	struct tableinit {
311 311
 static	pthread_mutex_t	tables_mutex = PTHREAD_MUTEX_INITIALIZER;
312 312
 #endif
313 313
 
314
-#ifndef	O_BINARY
315
-#define	O_BINARY	0
316
-#endif
317
-
318 314
 #ifdef	NEW_WORLD
319 315
 
320 316
 #include "matcher.h"
... ...
@@ -3666,22 +3651,7 @@ rfc1341(message *m, const char *dir)
3666 3666
 	if(id == NULL)
3667 3667
 		return -1;
3668 3668
 
3669
-/* do we need this for C_WINDOWS?
3670
-#ifdef  C_CYGWIN
3671
-	if((tmpdir = getenv("TEMP")) == (char *)NULL)
3672
-		if((tmpdir = getenv("TMP")) == (char *)NULL)
3673
-			if((tmpdir = getenv("TMPDIR")) == (char *)NULL)
3674
-				tmpdir = "C:\\";
3675
-#else
3676
-*/
3677
-	if((tmpdir = getenv("TMPDIR")) == (char *)NULL)
3678
-		if((tmpdir = getenv("TMP")) == (char *)NULL)
3679
-			if((tmpdir = getenv("TEMP")) == (char *)NULL)
3680
-#ifdef	P_tmpdir
3681
-				tmpdir = P_tmpdir;
3682
-#else
3683
-				tmpdir = "/tmp";
3684
-#endif
3669
+	tmpdir = cli_gettmpdir();
3685 3670
 
3686 3671
 	snprintf(pdir, sizeof(pdir) - 1, "%s/clamav-partial", tmpdir);
3687 3672
 
... ...
@@ -47,10 +47,6 @@
47 47
 #include "scanners.h"
48 48
 #include "nulsft.h" /* SHUT UP GCC -Wextra */
49 49
 
50
-#ifndef O_BINARY
51
-#define O_BINARY 0
52
-#endif
53
-
54 50
 #define EC32(x) le32_to_host(x)
55 51
 
56 52
 enum {
... ...
@@ -65,11 +65,6 @@
65 65
 #pragma pack 1
66 66
 #endif
67 67
 
68
-#ifndef	O_BINARY
69
-#define	O_BINARY	0
70
-#endif
71
-
72
-
73 68
 typedef struct ole2_header_tag
74 69
 {
75 70
 	unsigned char magic[8];		/* should be: 0xd0cf11e0a1b11ae1 */
... ...
@@ -33,21 +33,18 @@
33 33
 #endif
34 34
 #include <sys/types.h>
35 35
 #include <sys/stat.h>
36
-#ifndef	C_WINDOWS
36
+#include <dirent.h>
37
+#ifndef	_WIN32
37 38
 #include <sys/wait.h>
38 39
 #include <sys/time.h>
39
-#include <dirent.h>
40 40
 #endif
41 41
 #include <time.h>
42 42
 #include <fcntl.h>
43
-#ifndef	C_WINDOWS
43
+#ifdef HAVE_PWD_H
44 44
 #include <pwd.h>
45 45
 #endif
46 46
 #include <errno.h>
47 47
 #include "target.h"
48
-#ifndef	C_WINDOWS
49
-#include <sys/time.h>
50
-#endif
51 48
 #ifdef	HAVE_SYS_PARAM_H
52 49
 #include <sys/param.h>
53 50
 #endif
... ...
@@ -70,15 +67,6 @@
70 70
 #include "default.h"
71 71
 #include "scanners.h"
72 72
 
73
-#ifndef	O_BINARY
74
-#define	O_BINARY	0
75
-#endif
76
-
77
-#ifdef        C_WINDOWS
78
-#undef        P_tmpdir
79
-#define       P_tmpdir        "C:\\WINDOWS\\TEMP"
80
-#endif
81
-
82 73
 int (*cli_unrar_open)(int fd, const char *dirname, unrar_state_t *state);
83 74
 int (*cli_unrar_extract_next_prepare)(unrar_state_t *state, const char *dirname);
84 75
 int (*cli_unrar_extract_next)(unrar_state_t *state, const char *dirname);
... ...
@@ -382,6 +382,7 @@ char *cli_md5file(const char *filename);
382 382
 int cli_unlink(const char *pathname);
383 383
 int cli_readn(int fd, void *buff, unsigned int count);
384 384
 int cli_writen(int fd, const void *buff, unsigned int count);
385
+const char *cli_gettmpdir(void);
385 386
 char *cli_gentemp(const char *dir);
386 387
 int cli_gentempfd(const char *dir, char **name, int *fd);
387 388
 unsigned int cli_rndnum(unsigned int max);
... ...
@@ -33,21 +33,18 @@
33 33
 #endif
34 34
 #include <sys/types.h>
35 35
 #include <sys/stat.h>
36
-#ifndef	C_WINDOWS
36
+#include <dirent.h>
37
+#ifndef	_WIN32
37 38
 #include <sys/wait.h>
38 39
 #include <sys/time.h>
39
-#include <dirent.h>
40 40
 #endif
41 41
 #include <time.h>
42 42
 #include <fcntl.h>
43
-#ifndef	C_WINDOWS
43
+#ifdef	HAVE_PWD_H
44 44
 #include <pwd.h>
45 45
 #endif
46 46
 #include <errno.h>
47 47
 #include "target.h"
48
-#ifndef	C_WINDOWS
49
-#include <sys/time.h>
50
-#endif
51 48
 #ifdef	HAVE_SYS_PARAM_H
52 49
 #include <sys/param.h>
53 50
 #endif
... ...
@@ -64,10 +61,6 @@
64 64
 #include "matcher-ac.h"
65 65
 #include "md5.h"
66 66
 
67
-#ifndef	O_BINARY
68
-#define	O_BINARY	0
69
-#endif
70
-
71 67
 static unsigned char name_salt[16] = { 16, 38, 97, 12, 8, 4, 72, 196, 217, 144, 33, 124, 18, 11, 17, 253 };
72 68
 
73 69
 #ifdef CL_NOTHREADS
... ...
@@ -115,9 +108,11 @@ void cli_dbgmsg_internal(const char *str, ...)
115 115
 int cli_matchregex(const char *str, const char *regex)
116 116
 {
117 117
 	regex_t reg;
118
-	int match;
119
-
120
-    if(cli_regcomp(&reg, regex, REG_EXTENDED | REG_NOSUB) == 0) {
118
+	int match, flags = REG_EXTENDED | REG_NOSUB;
119
+#ifdef _WIN32
120
+    flags |= REG_ICASE;
121
+#endif
122
+    if(cli_regcomp(&reg, regex, flags) == 0) {
121 123
 	match = (cli_regexec(&reg, str, 0, NULL, 0) == REG_NOMATCH) ? 0 : 1;
122 124
 	cli_regfree(&reg);
123 125
 	return match;
... ...
@@ -337,6 +332,10 @@ int cli_writen(int fd, const void *buff, unsigned int count)
337 337
 
338 338
 int cli_filecopy(const char *src, const char *dest)
339 339
 {
340
+
341
+#ifdef _WIN32
342
+    return (!CopyFileA(src, dest, 0));
343
+#else
340 344
 	char *buffer;
341 345
 	int s, d, bytes;
342 346
 
... ...
@@ -362,7 +361,16 @@ int cli_filecopy(const char *src, const char *dest)
362 362
     close(s);
363 363
 
364 364
     return close(d);
365
+#endif
365 366
 }
367
+
368
+#ifndef _WIN32
369
+static const char tmpdir[] = "/tmp";
370
+const char *cli_gettmpdir(void) {
371
+    return tmpdir;
372
+}
373
+#endif /* _WIN32 */
374
+
366 375
 struct dirent_data {
367 376
     char *filename;
368 377
     const char *dirname;
... ...
@@ -742,18 +750,12 @@ char *cli_gentemp(const char *dir)
742 742
         const char *mdir;
743 743
 	unsigned char salt[16 + 32];
744 744
 	int i;
745
+    size_t len;
745 746
 
746
-    if(!dir) {
747
-	if((mdir = getenv("TMPDIR")) == NULL)
748
-#ifdef P_tmpdir
749
-	    mdir = P_tmpdir;
750
-#else
751
-	    mdir = "/tmp";
752
-#endif
753
-    } else
754
-	mdir = dir;
747
+    mdir = dir ? dir : cli_gettmpdir();
755 748
 
756
-    name = (char *) cli_calloc(strlen(mdir) + 1 + 32 + 1 + 7, sizeof(char));
749
+    len = strlen(mdir) + 42;
750
+    name = (char *) cli_calloc(len, sizeof(char));
757 751
     if(!name) {
758 752
 	cli_dbgmsg("cli_gentemp('%s'): out of memory\n", mdir);
759 753
 	return NULL;
... ...
@@ -780,12 +782,7 @@ char *cli_gentemp(const char *dir)
780 780
 	return NULL;
781 781
     }
782 782
 
783
-#ifdef	C_WINDOWS
784
-	sprintf(name, "%s\\clamav-", mdir);
785
-#else
786
-	sprintf(name, "%s/clamav-", mdir);
787
-#endif
788
-    strncat(name, tmp, 32);
783
+	snprintf(name, len, "%s"PATHSEP"clamav-%s", mdir, tmp);
789 784
     free(tmp);
790 785
 
791 786
     return(name);
... ...
@@ -59,10 +59,6 @@ static	char	const	rcsid[] = "$Id: pdf.c,v 1.61 2007/02/12 20:46:09 njh Exp $";
59 59
 #include "scanners.h"
60 60
 #include "str.h"
61 61
 
62
-#ifndef	O_BINARY
63
-#define	O_BINARY	0
64
-#endif
65
-
66 62
 #ifdef	CL_DEBUG
67 63
 /*#define	SAVE_TMP	
68 64
  *Save the file being worked on in tmp */
... ...
@@ -59,10 +59,6 @@
59 59
 #include "special.h"
60 60
 #include "ishield.h"
61 61
 
62
-#ifndef	O_BINARY
63
-#define	O_BINARY	0
64
-#endif
65
-
66 62
 #define DCONF ctx->dconf->pe
67 63
 
68 64
 #define IMAGE_DOS_SIGNATURE	    0x5a4d	    /* MZ */
... ...
@@ -1843,7 +1843,7 @@ int cl_statinidir(const char *dirname, struct cl_stat *dbstat)
1843 1843
 		    return CL_EMEM;
1844 1844
 		}
1845 1845
 
1846
-#if defined(C_INTERIX) || defined(C_OS2)
1846
+#if defined(C_INTERIX) || defined(C_OS2) || defined(_WIN32)
1847 1847
 		dbstat->statdname = (char **) cli_realloc2(dbstat->statdname, dbstat->entries * sizeof(char *));
1848 1848
 		if(!dbstat->statdname) {
1849 1849
 		    cl_statfree(dbstat);
... ...
@@ -1859,7 +1859,7 @@ int cl_statinidir(const char *dirname, struct cl_stat *dbstat)
1859 1859
 		    return CL_EMEM;
1860 1860
 		}
1861 1861
 		sprintf(fname, "%s/%s", dirname, dent->d_name);
1862
-#if defined(C_INTERIX) || defined(C_OS2)
1862
+#if defined(C_INTERIX) || defined(C_OS2) || defined(_WIN32)
1863 1863
 		dbstat->statdname[dbstat->entries - 1] = (char *) cli_malloc(strlen(dent->d_name) + 1);
1864 1864
 		if(!dbstat->statdname[dbstat->entries - 1]) {
1865 1865
 		    cl_statfree(dbstat);
... ...
@@ -1928,7 +1928,7 @@ int cl_statchkdir(const struct cl_stat *dbstat)
1928 1928
 
1929 1929
 		found = 0;
1930 1930
 		for(i = 0; i < dbstat->entries; i++)
1931
-#if defined(C_INTERIX) || defined(C_OS2)
1931
+#if defined(C_INTERIX) || defined(C_OS2) || defined(_WIN32)
1932 1932
 		    if(!strcmp(dbstat->statdname[i], dent->d_name)) {
1933 1933
 #else
1934 1934
 		    if(dbstat->stattab[i].st_ino == sb.st_ino) {
... ...
@@ -1957,7 +1957,7 @@ int cl_statfree(struct cl_stat *dbstat)
1957 1957
 
1958 1958
     if(dbstat) {
1959 1959
 
1960
-#if defined(C_INTERIX) || defined(C_OS2)
1960
+#if defined(C_INTERIX) || defined(C_OS2) || defined(_WIN32)
1961 1961
 	    int i;
1962 1962
 
1963 1963
 	if(dbstat->statdname) {
... ...
@@ -48,10 +48,6 @@
48 48
 #endif
49 49
 #endif
50 50
 
51
-#ifndef	O_BINARY
52
-#define	O_BINARY	0
53
-#endif
54
-
55 51
 #define DCONF_ARCH  ctx->dconf->archive
56 52
 #define DCONF_DOC   ctx->dconf->doc
57 53
 #define DCONF_MAIL  ctx->dconf->mail
... ...
@@ -46,11 +46,6 @@
46 46
 #define EC32(x) le32_to_host(x)
47 47
 #define EC16(x) le16_to_host(x)
48 48
 
49
-#ifndef O_BINARY
50
-#define O_BINARY 0
51
-#endif
52
-
53
-
54 49
 static int real_scansis(FILE *, cli_ctx *, const char *);
55 50
 static int real_scansis9x(FILE *, cli_ctx *, const char *);
56 51
 
... ...
@@ -182,11 +182,7 @@ cli_tnef(const char *dir, int desc, cli_ctx *ctx)
182 182
 					char buffer[BUFSIZ];
183 183
 
184 184
 					if(filename)
185
-#ifdef	O_BINARY
186 185
 						fout = open(filename, O_WRONLY|O_CREAT|O_EXCL|O_TRUNC|O_BINARY, 0600);
187
-#else
188
-						fout = open(filename, O_WRONLY|O_CREAT|O_EXCL|O_TRUNC, 0600);
189
-#endif
190 186
 
191 187
 					if(fout >= 0) {
192 188
 						int count;
... ...
@@ -81,10 +81,6 @@
81 81
 #define NPT NP
82 82
 #endif
83 83
 
84
-#ifndef MIN
85
-#define MIN(a,b) ((a < b) ? a : b)
86
-#endif
87
-
88 84
 #define GARBLE_FLAG     0x01
89 85
 
90 86
 #ifndef HAVE_ATTRIB_PACKED
... ...
@@ -99,10 +95,6 @@
99 99
 #pragma pack 1
100 100
 #endif
101 101
 
102
-#ifndef O_BINARY
103
-#define O_BINARY        0
104
-#endif
105
-
106 102
 typedef struct arj_main_hdr_tag {
107 103
 	uint8_t first_hdr_size;		/* must be 30 bytes */
108 104
 	uint8_t version;
... ...
@@ -45,10 +45,6 @@ static	char	const	rcsid[] = "$Id: untar.c,v 1.35 2007/02/12 20:46:09 njh Exp $";
45 45
 
46 46
 #define BLOCKSIZE 512
47 47
 
48
-#ifndef	O_BINARY
49
-#define	O_BINARY	0
50
-#endif
51
-
52 48
 static int
53 49
 octal(const char *str)
54 50
 {
... ...
@@ -58,11 +58,6 @@
58 58
 #define UNZIP_PRIVATE
59 59
 #include "unzip.h"
60 60
 
61
-#ifndef O_BINARY
62
-#define O_BINARY 0
63
-#endif
64
-
65
-
66 61
 static int wrap_inflateinit2(void *a, int b) {
67 62
   return inflateInit2(a, b);
68 63
 }
... ...
@@ -44,10 +44,6 @@
44 44
 #endif
45 45
 #include "blob.h"
46 46
 
47
-#ifndef	O_BINARY
48
-#define	O_BINARY	0
49
-#endif
50
-
51 47
 #define PPT_LZW_BUFFSIZE 8192
52 48
 #define VBA_COMPRESSION_WINDOW 4096
53 49
 #define	MIDDLE_SIZE	20
... ...
@@ -14,6 +14,10 @@
14 14
  *  not be used to develop a RAR (WinRAR) compatible archiver.
15 15
  */
16 16
 
17
+#if HAVE_CONFIG_H
18
+#include "clamav-config.h"
19
+#endif
20
+
17 21
 #include <stdio.h>
18 22
 #include <string.h>
19 23
 
... ...
@@ -26,7 +30,6 @@
26 26
 static void rar_dbgmsg(const char* fmt,...){}
27 27
 #endif
28 28
 
29
-#define MAX(a,b)    (((a) > (b)) ? (a) : (b))
30 29
 #define MAX_O 64
31 30
 
32 31
 const unsigned int UNIT_SIZE=MAX(sizeof(struct ppm_context), sizeof(struct rar_mem_blk_tag));
... ...
@@ -50,10 +50,6 @@ static uint32_t unrar_endian_convert_32(uint32_t v)
50 50
 }
51 51
 #endif
52 52
 
53
-#ifndef O_BINARY
54
-#define O_BINARY    0
55
-#endif
56
-
57 53
 /* FIXME: allow this to be controlled from unrar_open or so */
58 54
 #ifdef RAR_DEBUG_MODE
59 55
 #define unrar_dbgmsg printf
... ...
@@ -19,3 +19,18 @@
19 19
 #ifndef MAX
20 20
 #define MAX(a,b)	(((a) > (b)) ? (a) : (b))
21 21
 #endif
22
+
23
+#ifndef HAVE_IN_PORT_T
24
+typedef	unsigned	short	in_port_t;
25
+#endif
26
+
27
+#ifndef HAVE_IN_ADDR_T
28
+typedef	unsigned	int	in_addr_t;
29
+#endif
30
+
31
+#ifdef _WIN32
32
+#define PATHSEP "\\"
33
+#else
34
+#define PATHSEP "/"
35
+#endif
36
+
... ...
@@ -47,10 +47,6 @@
47 47
 #include "libclamav/version.h"
48 48
 #include "shared/misc.h"
49 49
 
50
-#ifndef	O_BINARY
51
-#define	O_BINARY	0
52
-#endif
53
-
54 50
 #ifndef REPO_VERSION
55 51
 #define REPO_VERSION "exported"
56 52
 #endif
... ...
@@ -198,7 +194,9 @@ const char *filelist(const struct optstruct *opts, int *err)
198 198
 
199 199
 int filecopy(const char *src, const char *dest)
200 200
 {
201
-#ifdef C_DARWIN
201
+#ifdef _WIN32
202
+    return (!CopyFileA(src, dest, 0));
203
+#elif defined(C_DARWIN)
202 204
 	pid_t pid;
203 205
 
204 206
     /* On Mac OS X use ditto and copy resource fork, too. */
... ...
@@ -47,7 +47,6 @@
47 47
 #include "getopt.h"
48 48
 
49 49
 #define MAXCMDOPTS  100
50
-#define MAX(a,b) (a > b ? a : b)
51 50
 
52 51
 #define MATCH_NUMBER "^[0-9]+$"
53 52
 #define MATCH_SIZE "^[0-9]+[KM]?$"
... ...
@@ -696,7 +695,7 @@ struct optstruct *optparse(const char *cfgfile, int argc, char **argv, int verbo
696 696
     }
697 697
 
698 698
     if(cfgfile) {
699
-	if((fs = fopen(cfgfile, "rb")) == NULL) {
699
+	if((fs = fopen(cfgfile, "r")) == NULL) {
700 700
 	    /* don't print error messages here! */
701 701
 	    optfree(opts);
702 702
 	    return NULL;
... ...
@@ -33,10 +33,6 @@
33 33
 
34 34
 #include "tar.h"
35 35
 
36
-#ifndef O_BINARY
37
-#define O_BINARY 0
38
-#endif
39
-
40 36
 struct tar_header {
41 37
     char name[100];	/* File name */
42 38
     char mode[8];	/* File mode */
... ...
@@ -34,10 +34,12 @@
34 34
 #include <sys/types.h>
35 35
 #include <sys/stat.h>
36 36
 #include <fcntl.h>
37
+#ifndef _WIN32
37 38
 #include <sys/socket.h>
38 39
 #include <sys/un.h>
39 40
 #include <netinet/in.h>
40 41
 #include <arpa/inet.h>
42
+#endif
41 43
 #include <sys/wait.h>
42 44
 #include <dirent.h>
43 45
 
... ...
@@ -325,7 +327,7 @@ static char *getdsig(const char *host, const char *user, const unsigned char *da
325 325
     server.sin_port = htons(33101);
326 326
 
327 327
     if(connect(sockd, (struct sockaddr *) &server, sizeof(struct sockaddr_in)) < 0) {
328
-        close(sockd);
328
+        closesocket(sockd);
329 329
 	perror("connect()");
330 330
 	mprintf("!getdsig: Can't connect to ClamAV Signing Service at %s\n", host);
331 331
 	memset(pass, 0, sizeof(pass));
... ...
@@ -343,9 +345,9 @@ static char *getdsig(const char *host, const char *user, const unsigned char *da
343 343
     memcpy(pt, data, datalen);
344 344
     len += datalen;
345 345
 
346
-    if(write(sockd, cmd, len) < 0) {
346
+    if(send(sockd, cmd, len, 0) < 0) {
347 347
 	mprintf("!getdsig: Can't write to socket\n");
348
-	close(sockd);
348
+	closesocket(sockd);
349 349
 	memset(cmd, 0, sizeof(cmd));
350 350
 	memset(pass, 0, sizeof(pass));
351 351
 	return NULL;
... ...
@@ -355,22 +357,22 @@ static char *getdsig(const char *host, const char *user, const unsigned char *da
355 355
     memset(pass, 0, sizeof(pass));
356 356
     memset(buff, 0, sizeof(buff));
357 357
 
358
-    if((bread = cli_readn(sockd, buff, sizeof(buff))) > 0) {
358
+    if((bread = recv(sockd, buff, sizeof(buff), 0)) > 0) {
359 359
 	if(!strstr(buff, "Signature:")) {
360 360
 	    mprintf("!getdsig: Error generating digital signature\n");
361 361
 	    mprintf("!getdsig: Answer from remote server: %s\n", buff);
362
-	    close(sockd);
362
+	    closesocket(sockd);
363 363
 	    return NULL;
364 364
 	} else {
365 365
 	    mprintf("Signature received (length = %lu)\n", strlen(buff) - 10);
366 366
 	}
367 367
     } else {
368 368
 	mprintf("!getdsig: Communication error with remote server\n");
369
-	close(sockd);
369
+	closesocket(sockd);
370 370
 	return NULL;
371 371
     }
372 372
 
373
-    close(sockd);
373
+    closesocket(sockd);
374 374
 
375 375
     pt = buff;
376 376
     pt += 10;
... ...
@@ -1059,15 +1061,7 @@ static int listdb(const char *filename)
1059 1059
 	free(buffer);
1060 1060
 	fclose(fh);
1061 1061
 
1062
-	tmpdir = getenv("TMPDIR");
1063
-	if(tmpdir == NULL)
1064
-#ifdef P_tmpdir
1065
-	    tmpdir = P_tmpdir;
1066
-#else
1067
-	    tmpdir = "/tmp";
1068
-#endif
1069
-
1070
-	if(!(dir = cli_gentemp(tmpdir))) {
1062
+	if(!(dir = cli_gentemp(NULL))) {
1071 1063
 	    mprintf("!listdb: Can't generate temporary name\n");
1072 1064
 	    return -1;
1073 1065
 	}
... ...
@@ -1217,7 +1211,7 @@ static int vbadump(const struct optstruct *opts)
1217 1217
 	pt = optget(opts, "vba")->strarg;
1218 1218
     }
1219 1219
  
1220
-    if((fd = open(pt, O_RDONLY)) == -1) {
1220
+    if((fd = open(pt, O_RDONLY|O_BINARY)) == -1) {
1221 1221
 	mprintf("!vbadump: Can't open file %s\n", pt);
1222 1222
 	return -1;
1223 1223
     }
... ...
@@ -37,10 +37,6 @@
37 37
 #include "libclamav/cltypes.h"
38 38
 #include "libclamav/ole2_extract.h"
39 39
 
40
-#ifndef	O_BINARY
41
-#define	O_BINARY	0
42
-#endif
43
-
44 40
 typedef struct mac_token_tag
45 41
 {
46 42
     unsigned char token;
... ...
@@ -991,14 +987,7 @@ static int sigtool_scandir (const char *dirname, int hex_output)
991 991
 			} else {
992 992
 			    if (S_ISREG (statbuf.st_mode)) {
993 993
 			        struct uniq *vba = NULL;
994
-				tmpdir = getenv ("TMPDIR");
995
-
996
-				if (tmpdir == NULL)
997
-#ifdef P_tmpdir
998
-				    tmpdir = P_tmpdir;
999
-#else
1000
-				    tmpdir = "/tmp";
1001
-#endif
994
+				tmpdir = cli_gettmpdir();
1002 995
 
1003 996
 				/* generate the temporary directory */
1004 997
 				dir = cli_gentemp (tmpdir);
... ...
@@ -1007,7 +996,7 @@ static int sigtool_scandir (const char *dirname, int hex_output)
1007 1007
 				    return CL_ETMPDIR;
1008 1008
 				}
1009 1009
 
1010
-				if ((desc = open (fname, O_RDONLY)) == -1) {
1010
+				if ((desc = open (fname, O_RDONLY|O_BINARY)) == -1) {
1011 1011
 				    printf ("Can't open file %s\n", fname);
1012 1012
 				    return 1;
1013 1013
 				}