[Pkg-clamav-commits] [SCM] Debian repository for ClamAV branch, debian/unstable, updated. debian/0.95+dfsg-1-6156-g094ec9b
aCaB
acab at clamav.net
Sun Apr 4 01:05:23 UTC 2010
The following commit has been merged in the debian/unstable branch:
commit 081f64735d8ad0e3a15850d1341f4f93cb1eed50
Author: aCaB <acab at clamav.net>
Date: Thu Sep 24 16:21:51 2009 +0200
win32#2
diff --git a/ChangeLog b/ChangeLog
index a7b906f..b7ac171 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Thu Sep 24 16:22:25 CEST 2009 (acab)
+------------------------------------
+ * merge initial set of win32 patches from Gianluigi Tiesi <sherpya*netfarm.it>
+
Thu Sep 24 01:14:50 CEST 2009 (acab)
------------------------------------
* clamav-milter: Add option ReportHostname to mangle the host name in X headers
diff --git a/clamd/clamd.c b/clamd/clamd.c
index 968cd78..59faeb7 100644
--- a/clamd/clamd.c
+++ b/clamd/clamd.c
@@ -33,10 +33,10 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
-#ifdef C_WINDOWS
-#include <direct.h> /* for chdir */
-#else
+#ifdef HAVE_PWD_H
#include <pwd.h>
+#endif
+#ifdef HAVE_GRP_H
#include <grp.h>
#endif
#include <signal.h>
diff --git a/clamdscan/client.c b/clamdscan/client.c
index 0264764..937e946 100644
--- a/clamdscan/client.c
+++ b/clamdscan/client.c
@@ -114,7 +114,7 @@ static int isremote(const struct optstruct *opts) {
testsock.sin_port = htons(INADDR_ANY);
if(!(s = socket(testsock.sin_family, SOCK_STREAM, 0))) return 0;
ret = (bind(s, (struct sockaddr *)&testsock, sizeof(testsock)) != 0);
- close(s);
+ closesocket(s);
return ret;
}
@@ -173,7 +173,7 @@ int get_clamd_version(const struct optstruct *opts)
recvlninit(&rcv, sockd);
if(sendln(sockd, "zVERSION", 9)) {
- close(sockd);
+ closesocket(sockd);
return 2;
}
@@ -185,7 +185,7 @@ int get_clamd_version(const struct optstruct *opts)
printf("%s\n", buff);
}
- close(sockd);
+ closesocket(sockd);
return 0;
}
@@ -201,16 +201,16 @@ int reload_clamd_database(const struct optstruct *opts)
recvlninit(&rcv, sockd);
if(sendln(sockd, "zRELOAD", 8)) {
- close(sockd);
+ closesocket(sockd);
return 2;
}
if(!(len = recvln(&rcv, &buff, NULL)) || len < 10 || memcmp(buff, "RELOADING", 9)) {
logg("!Clamd did not reload the database\n");
- close(sockd);
+ closesocket(sockd);
return 2;
}
- close(sockd);
+ closesocket(sockd);
return 0;
}
@@ -265,7 +265,7 @@ int client(const struct optstruct *opts, int *infected)
*infected = ret;
else
errors = 1;
- if(sockd >= 0) close(sockd);
+ if(sockd >= 0) closesocket(sockd);
} else if(opts->filename || optget(opts, "file-list")->enabled) {
if(opts->filename && optget(opts, "file-list")->enabled)
logg("^Only scanning files from --file-list (files passed at cmdline are ignored)\n");
diff --git a/clamdscan/proto.c b/clamdscan/proto.c
index a1b23bf..f37de07 100644
--- a/clamdscan/proto.c
+++ b/clamdscan/proto.c
@@ -64,7 +64,7 @@ int dconnect() {
}
if(connect(sockd, (struct sockaddr *)mainsa, mainsasz) < 0) {
- close(sockd);
+ closesocket(sockd);
logg("!Can't connect to clamd: %s\n", strerror(errno));
return -1;
}
@@ -162,7 +162,7 @@ static int send_stream(int sockd, const char *filename) {
unsigned long int todo = maxstream;
if(filename) {
- if((fd = open(filename, O_RDONLY))<0) {
+ if((fd = open(filename, O_RDONLY | O_BINARY))<0) {
logg("~%s: Access denied. ERROR\n", filename);
return 0;
}
@@ -361,7 +361,7 @@ static int serial_callback(struct stat *sb, char *filename, const char *path, en
}
ret = dsresult(sockd, c->scantype, f, &c->printok);
if(filename) free(filename);
- close(sockd);
+ closesocket(sockd);
if(ret < 0) return CL_EOPEN;
c->infected += ret;
if(reason == visit_directory_toplev)
@@ -553,7 +553,7 @@ int parallel_client_scan(char *file, int scantype, int *infected, int maxlevel,
return 1;
if(sendln(cdata.sockd, "zIDSESSION", 11)) {
- close(cdata.sockd);
+ closesocket(cdata.sockd);
return 1;
}
@@ -568,13 +568,13 @@ int parallel_client_scan(char *file, int scantype, int *infected, int maxlevel,
if(ftw != CL_SUCCESS) {
*infected += cdata.infected;
- close(cdata.sockd);
+ closesocket(cdata.sockd);
return 1;
}
sendln(cdata.sockd, "zEND", 5);
while(cdata.ids && !dspresult(&cdata));
- close(cdata.sockd);
+ closesocket(cdata.sockd);
*infected += cdata.infected;
diff --git a/clamscan/manager.c b/clamscan/manager.c
index a86c1ce..5a0f273 100644
--- a/clamscan/manager.c
+++ b/clamscan/manager.c
@@ -68,15 +68,6 @@
dev_t procdev;
#endif
-#ifdef C_WINDOWS
-#undef P_tmpdir
-#define P_tmpdir "C:\\WINDOWS\\TEMP"
-#endif
-
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
static int scanfile(const char *filename, struct cl_engine *engine, const struct optstruct *opts, unsigned int options)
{
int ret = 0, fd, included, printclean = 1, fsize;
@@ -272,17 +263,9 @@ static int scanstdin(const struct cl_engine *engine, const struct optstruct *opt
if(optget(opts, "tempdir")->enabled) {
tmpdir = optget(opts, "tempdir")->strarg;
- } else {
+ } else
/* check write access */
- tmpdir = getenv("TMPDIR");
-
- if(tmpdir == NULL)
-#ifdef P_tmpdir
- tmpdir = P_tmpdir;
-#else
- tmpdir = "/tmp";
-#endif
- }
+ tmpdir = cli_gettmpdir();
if(checkaccess(tmpdir, CLAMAVUSER, W_OK) != 1) {
logg("!Can't write to temporary directory\n");
diff --git a/freshclam/freshclam.c b/freshclam/freshclam.c
index 86e0bae..a133e38 100644
--- a/freshclam/freshclam.c
+++ b/freshclam/freshclam.c
@@ -35,8 +35,10 @@
#endif
#include <sys/stat.h>
#include <fcntl.h>
-#ifndef C_WINDOWS
+#ifdef HAVE_PWD_H
#include <pwd.h>
+#endif
+#ifdef HAVE_GRP_H
#include <grp.h>
#endif
diff --git a/freshclam/manager.c b/freshclam/manager.c
index 05fcbc2..3173961 100644
--- a/freshclam/manager.c
+++ b/freshclam/manager.c
@@ -675,11 +675,7 @@ int submitstats(const char *clamdcfg, const struct optstruct *opts)
*pt2 = 0;
pt2 += 2;
-#ifdef C_WINDOWS
- if((pt = strrchr(pt, '\\')))
-#else
- if((pt = strrchr(pt, '/')))
-#endif
+ if((pt = strrchr(pt, *PATHSEP)))
*pt++ = 0;
if(!pt)
pt = (char*) "NOFNAME";
diff --git a/freshclam/mirman.c b/freshclam/mirman.c
index 034bd0f..c971cfa 100644
--- a/freshclam/mirman.c
+++ b/freshclam/mirman.c
@@ -48,10 +48,6 @@
#include "shared/output.h"
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
#ifndef HAVE_GETADDRINFO
#ifndef AF_INET6
#define AF_INET6 0xbeef /* foo */
diff --git a/freshclam/notify.c b/freshclam/notify.c
index 211b977..d1d7690 100644
--- a/freshclam/notify.c
+++ b/freshclam/notify.c
@@ -27,7 +27,7 @@
#include <unistd.h>
#endif
#include <sys/types.h>
-#ifndef C_WINDOWS
+#ifndef _WIN32
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
diff --git a/libclamav/7z.c b/libclamav/7z.c
index 5d3c75d..43c9611 100644
--- a/libclamav/7z.c
+++ b/libclamav/7z.c
@@ -37,10 +37,6 @@
#include "7z/Archive/7z/7zIn.h"
#include "7z/Archive/7z/7zExtract.h"
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
static ISzAlloc allocImp = { __lzma_wrap_alloc, __lzma_wrap_free}, allocTempImp = { __lzma_wrap_alloc, __lzma_wrap_free};
int cli_7unz (int fd, cli_ctx *ctx) {
diff --git a/libclamav/autoit.c b/libclamav/autoit.c
index 4298648..78bf62d 100644
--- a/libclamav/autoit.c
+++ b/libclamav/autoit.c
@@ -35,10 +35,6 @@
#include <unistd.h>
#endif
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
#include "others.h"
#include "scanners.h"
#include "autoit.h"
diff --git a/libclamav/bignum.c b/libclamav/bignum.c
index b46be20..fb9f84d 100644
--- a/libclamav/bignum.c
+++ b/libclamav/bignum.c
@@ -13,6 +13,10 @@
* Tom St Denis, tomstdenis at gmail.com, http://math.libtomcrypt.com
*/
+#if HAVE_CONFIG_H
+#include "clamav-config.h"
+#endif
+
/* Start: bn_error.c */
#include <bignum.h>
#include "others.h"
diff --git a/libclamav/bignum.h b/libclamav/bignum.h
index 3e3f35a..5da2cce 100644
--- a/libclamav/bignum.h
+++ b/libclamav/bignum.h
@@ -44,14 +44,6 @@
#define LTM_ALL /* FIXME: tk: limit to the above class */
#include "bignum_class.h"
-#ifndef MIN
- #define MIN(x,y) ((x)<(y)?(x):(y))
-#endif
-
-#ifndef MAX
- #define MAX(x,y) ((x)>(y)?(x):(y))
-#endif
-
#ifdef __cplusplus
extern "C" {
diff --git a/libclamav/blob.c b/libclamav/blob.c
index 891efa5..49e2644 100644
--- a/libclamav/blob.c
+++ b/libclamav/blob.c
@@ -48,10 +48,6 @@ static char const rcsid[] = "$Id: blob.c,v 1.64 2007/02/12 22:25:14 njh Exp $";
#include "scanners.h"
#include "filetypes.h"
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
#include <assert.h>
/* Scehduled for rewite in 0.94 (bb#804). Disabling for now */
diff --git a/libclamav/cab.c b/libclamav/cab.c
index 76cf847..3ab4812 100644
--- a/libclamav/cab.c
+++ b/libclamav/cab.c
@@ -40,10 +40,6 @@
#define EC32(x) le32_to_host(x) /* Convert little endian to host */
#define EC16(x) le16_to_host(x)
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
/* hard limits */
#define CAB_FOLDER_LIMIT 5000
#define CAB_FILE_LIMIT 5000
diff --git a/libclamav/chmunpack.c b/libclamav/chmunpack.c
index 7c3896c..5c4d9f1 100644
--- a/libclamav/chmunpack.c
+++ b/libclamav/chmunpack.c
@@ -63,10 +63,6 @@
#pragma pack 1
#endif
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
#define CHM_CHUNK_HDR_LEN (0x14)
#define CHM_CONTROL_LEN (0x18)
diff --git a/libclamav/cvd.c b/libclamav/cvd.c
index 928e65e..4e9bc79 100644
--- a/libclamav/cvd.c
+++ b/libclamav/cvd.c
@@ -45,10 +45,6 @@
#define TAR_BLOCKSIZE 512
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
static int cli_untgz(int fd, const char *destdir)
{
char *path, osize[13], name[101], type;
diff --git a/libclamav/ishield.c b/libclamav/ishield.c
index d51f314..361e93a 100644
--- a/libclamav/ishield.c
+++ b/libclamav/ishield.c
@@ -51,10 +51,6 @@
#include "others.h"
#include "ishield.h"
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
#ifndef LONG_MAX
#define LONG_MAX ((-1UL)>>1)
#endif
diff --git a/libclamav/jsparse/js-norm.c b/libclamav/jsparse/js-norm.c
index 4264836..24cf297 100644
--- a/libclamav/jsparse/js-norm.c
+++ b/libclamav/jsparse/js-norm.c
@@ -495,11 +495,6 @@ static int match_parameters(const yystype *tokens, const char ** param_names, si
static const char *de_packer_3[] = {"p","a","c","k","e","r"};
static const char *de_packer_2[] = {"p","a","c","k","e","d"};
-
-#ifndef MAX
-#define MAX(a, b) ((a)>(b) ? (a) : (b))
-#endif
-
static inline char *textbuffer_done(yyscan_t scanner)
{
/* free unusued memory */
@@ -1390,10 +1385,6 @@ static inline int parseId(YYSTYPE *lvalp, yyscan_t scanner)
return 0;
}
-#ifndef MIN
-#define MIN(a,b) ((a)<(b) ? (a):(b))
-#endif
-
static int parseOperator(YYSTYPE *lvalp, yyscan_t scanner)
{
size_t len = MIN(5, scanner->insize - scanner->pos);
diff --git a/libclamav/libclamav.map b/libclamav/libclamav.map
index 870c19e..0654dbc 100644
--- a/libclamav/libclamav.map
+++ b/libclamav/libclamav.map
@@ -32,6 +32,7 @@ CLAMAV_PUBLIC {
};
CLAMAV_PRIVATE {
global:
+ cli_gettmpdir;
cli_strtok;
cli_strtokenize;
cli_cvdunpack;
diff --git a/libclamav/mbox.c b/libclamav/mbox.c
index 46a352f..3f3c2a3 100644
--- a/libclamav/mbox.c
+++ b/libclamav/mbox.c
@@ -136,6 +136,7 @@ typedef enum {
#include "phishcheck.h"
#ifndef _WIN32
+#include <sys/time.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
@@ -145,19 +146,7 @@ typedef enum {
#endif
#endif
-
#include <fcntl.h>
-#ifndef C_WINDOWS
-#include <sys/time.h>
-#endif
-
-#ifndef HAVE_IN_PORT_T
-typedef unsigned short in_port_t;
-#endif
-
-#ifndef HAVE_IN_ADDR_T
-typedef unsigned int in_addr_t;
-#endif
/*
* Use CL_SCAN_PARTIAL_MESSAGE to handle messages covered by section 7.3.2 of RFC1341.
@@ -311,10 +300,6 @@ static const struct tableinit {
static pthread_mutex_t tables_mutex = PTHREAD_MUTEX_INITIALIZER;
#endif
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
#ifdef NEW_WORLD
#include "matcher.h"
@@ -3666,22 +3651,7 @@ rfc1341(message *m, const char *dir)
if(id == NULL)
return -1;
-/* do we need this for C_WINDOWS?
-#ifdef C_CYGWIN
- if((tmpdir = getenv("TEMP")) == (char *)NULL)
- if((tmpdir = getenv("TMP")) == (char *)NULL)
- if((tmpdir = getenv("TMPDIR")) == (char *)NULL)
- tmpdir = "C:\\";
-#else
-*/
- if((tmpdir = getenv("TMPDIR")) == (char *)NULL)
- if((tmpdir = getenv("TMP")) == (char *)NULL)
- if((tmpdir = getenv("TEMP")) == (char *)NULL)
-#ifdef P_tmpdir
- tmpdir = P_tmpdir;
-#else
- tmpdir = "/tmp";
-#endif
+ tmpdir = cli_gettmpdir();
snprintf(pdir, sizeof(pdir) - 1, "%s/clamav-partial", tmpdir);
diff --git a/libclamav/nsis/nulsft.c b/libclamav/nsis/nulsft.c
index db1b7c5..f2d6ca5 100644
--- a/libclamav/nsis/nulsft.c
+++ b/libclamav/nsis/nulsft.c
@@ -47,10 +47,6 @@
#include "scanners.h"
#include "nulsft.h" /* SHUT UP GCC -Wextra */
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
#define EC32(x) le32_to_host(x)
enum {
diff --git a/libclamav/ole2_extract.c b/libclamav/ole2_extract.c
index 9766ac8..d823c44 100644
--- a/libclamav/ole2_extract.c
+++ b/libclamav/ole2_extract.c
@@ -65,11 +65,6 @@
#pragma pack 1
#endif
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
-
typedef struct ole2_header_tag
{
unsigned char magic[8]; /* should be: 0xd0cf11e0a1b11ae1 */
diff --git a/libclamav/others.c b/libclamav/others.c
index c53b376..bed7b03 100644
--- a/libclamav/others.c
+++ b/libclamav/others.c
@@ -33,21 +33,18 @@
#endif
#include <sys/types.h>
#include <sys/stat.h>
-#ifndef C_WINDOWS
+#include <dirent.h>
+#ifndef _WIN32
#include <sys/wait.h>
#include <sys/time.h>
-#include <dirent.h>
#endif
#include <time.h>
#include <fcntl.h>
-#ifndef C_WINDOWS
+#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
#include <errno.h>
#include "target.h"
-#ifndef C_WINDOWS
-#include <sys/time.h>
-#endif
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
@@ -70,15 +67,6 @@
#include "default.h"
#include "scanners.h"
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
-#ifdef C_WINDOWS
-#undef P_tmpdir
-#define P_tmpdir "C:\\WINDOWS\\TEMP"
-#endif
-
int (*cli_unrar_open)(int fd, const char *dirname, unrar_state_t *state);
int (*cli_unrar_extract_next_prepare)(unrar_state_t *state, const char *dirname);
int (*cli_unrar_extract_next)(unrar_state_t *state, const char *dirname);
diff --git a/libclamav/others.h b/libclamav/others.h
index 7425edd..09a48ce 100644
--- a/libclamav/others.h
+++ b/libclamav/others.h
@@ -382,6 +382,7 @@ char *cli_md5file(const char *filename);
int cli_unlink(const char *pathname);
int cli_readn(int fd, void *buff, unsigned int count);
int cli_writen(int fd, const void *buff, unsigned int count);
+const char *cli_gettmpdir(void);
char *cli_gentemp(const char *dir);
int cli_gentempfd(const char *dir, char **name, int *fd);
unsigned int cli_rndnum(unsigned int max);
diff --git a/libclamav/others_common.c b/libclamav/others_common.c
index 5d9c965..52399c2 100644
--- a/libclamav/others_common.c
+++ b/libclamav/others_common.c
@@ -33,21 +33,18 @@
#endif
#include <sys/types.h>
#include <sys/stat.h>
-#ifndef C_WINDOWS
+#include <dirent.h>
+#ifndef _WIN32
#include <sys/wait.h>
#include <sys/time.h>
-#include <dirent.h>
#endif
#include <time.h>
#include <fcntl.h>
-#ifndef C_WINDOWS
+#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
#include <errno.h>
#include "target.h"
-#ifndef C_WINDOWS
-#include <sys/time.h>
-#endif
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
@@ -64,10 +61,6 @@
#include "matcher-ac.h"
#include "md5.h"
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
static unsigned char name_salt[16] = { 16, 38, 97, 12, 8, 4, 72, 196, 217, 144, 33, 124, 18, 11, 17, 253 };
#ifdef CL_NOTHREADS
@@ -115,9 +108,11 @@ void cli_dbgmsg_internal(const char *str, ...)
int cli_matchregex(const char *str, const char *regex)
{
regex_t reg;
- int match;
-
- if(cli_regcomp(®, regex, REG_EXTENDED | REG_NOSUB) == 0) {
+ int match, flags = REG_EXTENDED | REG_NOSUB;
+#ifdef _WIN32
+ flags |= REG_ICASE;
+#endif
+ if(cli_regcomp(®, regex, flags) == 0) {
match = (cli_regexec(®, str, 0, NULL, 0) == REG_NOMATCH) ? 0 : 1;
cli_regfree(®);
return match;
@@ -337,6 +332,10 @@ int cli_writen(int fd, const void *buff, unsigned int count)
int cli_filecopy(const char *src, const char *dest)
{
+
+#ifdef _WIN32
+ return (!CopyFileA(src, dest, 0));
+#else
char *buffer;
int s, d, bytes;
@@ -362,7 +361,16 @@ int cli_filecopy(const char *src, const char *dest)
close(s);
return close(d);
+#endif
}
+
+#ifndef _WIN32
+static const char tmpdir[] = "/tmp";
+const char *cli_gettmpdir(void) {
+ return tmpdir;
+}
+#endif /* _WIN32 */
+
struct dirent_data {
char *filename;
const char *dirname;
@@ -742,18 +750,12 @@ char *cli_gentemp(const char *dir)
const char *mdir;
unsigned char salt[16 + 32];
int i;
+ size_t len;
- if(!dir) {
- if((mdir = getenv("TMPDIR")) == NULL)
-#ifdef P_tmpdir
- mdir = P_tmpdir;
-#else
- mdir = "/tmp";
-#endif
- } else
- mdir = dir;
+ mdir = dir ? dir : cli_gettmpdir();
- name = (char *) cli_calloc(strlen(mdir) + 1 + 32 + 1 + 7, sizeof(char));
+ len = strlen(mdir) + 42;
+ name = (char *) cli_calloc(len, sizeof(char));
if(!name) {
cli_dbgmsg("cli_gentemp('%s'): out of memory\n", mdir);
return NULL;
@@ -780,12 +782,7 @@ char *cli_gentemp(const char *dir)
return NULL;
}
-#ifdef C_WINDOWS
- sprintf(name, "%s\\clamav-", mdir);
-#else
- sprintf(name, "%s/clamav-", mdir);
-#endif
- strncat(name, tmp, 32);
+ snprintf(name, len, "%s"PATHSEP"clamav-%s", mdir, tmp);
free(tmp);
return(name);
diff --git a/libclamav/pdf.c b/libclamav/pdf.c
index 51c1e44..d0b8331 100644
--- a/libclamav/pdf.c
+++ b/libclamav/pdf.c
@@ -59,10 +59,6 @@ static char const rcsid[] = "$Id: pdf.c,v 1.61 2007/02/12 20:46:09 njh Exp $";
#include "scanners.h"
#include "str.h"
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
#ifdef CL_DEBUG
/*#define SAVE_TMP
*Save the file being worked on in tmp */
diff --git a/libclamav/pe.c b/libclamav/pe.c
index 9b80936..c8b1029 100644
--- a/libclamav/pe.c
+++ b/libclamav/pe.c
@@ -59,10 +59,6 @@
#include "special.h"
#include "ishield.h"
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
#define DCONF ctx->dconf->pe
#define IMAGE_DOS_SIGNATURE 0x5a4d /* MZ */
diff --git a/libclamav/readdb.c b/libclamav/readdb.c
index 8fa04e0..534f9f7 100644
--- a/libclamav/readdb.c
+++ b/libclamav/readdb.c
@@ -1843,7 +1843,7 @@ int cl_statinidir(const char *dirname, struct cl_stat *dbstat)
return CL_EMEM;
}
-#if defined(C_INTERIX) || defined(C_OS2)
+#if defined(C_INTERIX) || defined(C_OS2) || defined(_WIN32)
dbstat->statdname = (char **) cli_realloc2(dbstat->statdname, dbstat->entries * sizeof(char *));
if(!dbstat->statdname) {
cl_statfree(dbstat);
@@ -1859,7 +1859,7 @@ int cl_statinidir(const char *dirname, struct cl_stat *dbstat)
return CL_EMEM;
}
sprintf(fname, "%s/%s", dirname, dent->d_name);
-#if defined(C_INTERIX) || defined(C_OS2)
+#if defined(C_INTERIX) || defined(C_OS2) || defined(_WIN32)
dbstat->statdname[dbstat->entries - 1] = (char *) cli_malloc(strlen(dent->d_name) + 1);
if(!dbstat->statdname[dbstat->entries - 1]) {
cl_statfree(dbstat);
@@ -1928,7 +1928,7 @@ int cl_statchkdir(const struct cl_stat *dbstat)
found = 0;
for(i = 0; i < dbstat->entries; i++)
-#if defined(C_INTERIX) || defined(C_OS2)
+#if defined(C_INTERIX) || defined(C_OS2) || defined(_WIN32)
if(!strcmp(dbstat->statdname[i], dent->d_name)) {
#else
if(dbstat->stattab[i].st_ino == sb.st_ino) {
@@ -1957,7 +1957,7 @@ int cl_statfree(struct cl_stat *dbstat)
if(dbstat) {
-#if defined(C_INTERIX) || defined(C_OS2)
+#if defined(C_INTERIX) || defined(C_OS2) || defined(_WIN32)
int i;
if(dbstat->statdname) {
diff --git a/libclamav/scanners.c b/libclamav/scanners.c
index 9a29ffd..60a8df8 100644
--- a/libclamav/scanners.c
+++ b/libclamav/scanners.c
@@ -48,10 +48,6 @@
#endif
#endif
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
#define DCONF_ARCH ctx->dconf->archive
#define DCONF_DOC ctx->dconf->doc
#define DCONF_MAIL ctx->dconf->mail
diff --git a/libclamav/sis.c b/libclamav/sis.c
index 3b02142..49c1996 100644
--- a/libclamav/sis.c
+++ b/libclamav/sis.c
@@ -46,11 +46,6 @@
#define EC32(x) le32_to_host(x)
#define EC16(x) le16_to_host(x)
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
-
static int real_scansis(FILE *, cli_ctx *, const char *);
static int real_scansis9x(FILE *, cli_ctx *, const char *);
diff --git a/libclamav/tnef.c b/libclamav/tnef.c
index 46861d4..8e405ed 100644
--- a/libclamav/tnef.c
+++ b/libclamav/tnef.c
@@ -182,11 +182,7 @@ cli_tnef(const char *dir, int desc, cli_ctx *ctx)
char buffer[BUFSIZ];
if(filename)
-#ifdef O_BINARY
fout = open(filename, O_WRONLY|O_CREAT|O_EXCL|O_TRUNC|O_BINARY, 0600);
-#else
- fout = open(filename, O_WRONLY|O_CREAT|O_EXCL|O_TRUNC, 0600);
-#endif
if(fout >= 0) {
int count;
diff --git a/libclamav/unarj.c b/libclamav/unarj.c
index faa3247..65b9c87 100644
--- a/libclamav/unarj.c
+++ b/libclamav/unarj.c
@@ -81,10 +81,6 @@
#define NPT NP
#endif
-#ifndef MIN
-#define MIN(a,b) ((a < b) ? a : b)
-#endif
-
#define GARBLE_FLAG 0x01
#ifndef HAVE_ATTRIB_PACKED
@@ -99,10 +95,6 @@
#pragma pack 1
#endif
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
typedef struct arj_main_hdr_tag {
uint8_t first_hdr_size; /* must be 30 bytes */
uint8_t version;
diff --git a/libclamav/untar.c b/libclamav/untar.c
index 9ca38ed..4432f99 100644
--- a/libclamav/untar.c
+++ b/libclamav/untar.c
@@ -45,10 +45,6 @@ static char const rcsid[] = "$Id: untar.c,v 1.35 2007/02/12 20:46:09 njh Exp $";
#define BLOCKSIZE 512
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
static int
octal(const char *str)
{
diff --git a/libclamav/unzip.c b/libclamav/unzip.c
index de17bf9..286bb85 100644
--- a/libclamav/unzip.c
+++ b/libclamav/unzip.c
@@ -58,11 +58,6 @@
#define UNZIP_PRIVATE
#include "unzip.h"
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
-
static int wrap_inflateinit2(void *a, int b) {
return inflateInit2(a, b);
}
diff --git a/libclamav/vba_extract.c b/libclamav/vba_extract.c
index 3597a76..0bebd84 100644
--- a/libclamav/vba_extract.c
+++ b/libclamav/vba_extract.c
@@ -44,10 +44,6 @@
#endif
#include "blob.h"
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
#define PPT_LZW_BUFFSIZE 8192
#define VBA_COMPRESSION_WINDOW 4096
#define MIDDLE_SIZE 20
diff --git a/libclamunrar/unrarppm.c b/libclamunrar/unrarppm.c
index 2c9a5f5..a58b47c 100644
--- a/libclamunrar/unrarppm.c
+++ b/libclamunrar/unrarppm.c
@@ -14,6 +14,10 @@
* not be used to develop a RAR (WinRAR) compatible archiver.
*/
+#if HAVE_CONFIG_H
+#include "clamav-config.h"
+#endif
+
#include <stdio.h>
#include <string.h>
@@ -26,7 +30,6 @@
static void rar_dbgmsg(const char* fmt,...){}
#endif
-#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MAX_O 64
const unsigned int UNIT_SIZE=MAX(sizeof(struct ppm_context), sizeof(struct rar_mem_blk_tag));
diff --git a/libclamunrar_iface/unrar_iface.c b/libclamunrar_iface/unrar_iface.c
index bedc1a9..3ec7cad 100644
--- a/libclamunrar_iface/unrar_iface.c
+++ b/libclamunrar_iface/unrar_iface.c
@@ -50,10 +50,6 @@ static uint32_t unrar_endian_convert_32(uint32_t v)
}
#endif
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
/* FIXME: allow this to be controlled from unrar_open or so */
#ifdef RAR_DEBUG_MODE
#define unrar_dbgmsg printf
diff --git a/platform.h b/platform.h
index 6445507..ea2b482 100644
--- a/platform.h
+++ b/platform.h
@@ -19,3 +19,18 @@
#ifndef MAX
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#endif
+
+#ifndef HAVE_IN_PORT_T
+typedef unsigned short in_port_t;
+#endif
+
+#ifndef HAVE_IN_ADDR_T
+typedef unsigned int in_addr_t;
+#endif
+
+#ifdef _WIN32
+#define PATHSEP "\\"
+#else
+#define PATHSEP "/"
+#endif
+
diff --git a/shared/misc.c b/shared/misc.c
index 74690af..60030c8 100644
--- a/shared/misc.c
+++ b/shared/misc.c
@@ -47,10 +47,6 @@
#include "libclamav/version.h"
#include "shared/misc.h"
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
#ifndef REPO_VERSION
#define REPO_VERSION "exported"
#endif
@@ -198,7 +194,9 @@ const char *filelist(const struct optstruct *opts, int *err)
int filecopy(const char *src, const char *dest)
{
-#ifdef C_DARWIN
+#ifdef _WIN32
+ return (!CopyFileA(src, dest, 0));
+#elif defined(C_DARWIN)
pid_t pid;
/* On Mac OS X use ditto and copy resource fork, too. */
diff --git a/shared/optparser.c b/shared/optparser.c
index d873b8c..aef17b4 100644
--- a/shared/optparser.c
+++ b/shared/optparser.c
@@ -47,7 +47,6 @@
#include "getopt.h"
#define MAXCMDOPTS 100
-#define MAX(a,b) (a > b ? a : b)
#define MATCH_NUMBER "^[0-9]+$"
#define MATCH_SIZE "^[0-9]+[KM]?$"
@@ -696,7 +695,7 @@ struct optstruct *optparse(const char *cfgfile, int argc, char **argv, int verbo
}
if(cfgfile) {
- if((fs = fopen(cfgfile, "rb")) == NULL) {
+ if((fs = fopen(cfgfile, "r")) == NULL) {
/* don't print error messages here! */
optfree(opts);
return NULL;
diff --git a/shared/tar.c b/shared/tar.c
index 047dec4..700929e 100644
--- a/shared/tar.c
+++ b/shared/tar.c
@@ -33,10 +33,6 @@
#include "tar.h"
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
struct tar_header {
char name[100]; /* File name */
char mode[8]; /* File mode */
diff --git a/sigtool/sigtool.c b/sigtool/sigtool.c
index 70e8af5..27f4526 100644
--- a/sigtool/sigtool.c
+++ b/sigtool/sigtool.c
@@ -34,10 +34,12 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#ifndef _WIN32
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#endif
#include <sys/wait.h>
#include <dirent.h>
@@ -325,7 +327,7 @@ static char *getdsig(const char *host, const char *user, const unsigned char *da
server.sin_port = htons(33101);
if(connect(sockd, (struct sockaddr *) &server, sizeof(struct sockaddr_in)) < 0) {
- close(sockd);
+ closesocket(sockd);
perror("connect()");
mprintf("!getdsig: Can't connect to ClamAV Signing Service at %s\n", host);
memset(pass, 0, sizeof(pass));
@@ -343,9 +345,9 @@ static char *getdsig(const char *host, const char *user, const unsigned char *da
memcpy(pt, data, datalen);
len += datalen;
- if(write(sockd, cmd, len) < 0) {
+ if(send(sockd, cmd, len, 0) < 0) {
mprintf("!getdsig: Can't write to socket\n");
- close(sockd);
+ closesocket(sockd);
memset(cmd, 0, sizeof(cmd));
memset(pass, 0, sizeof(pass));
return NULL;
@@ -355,22 +357,22 @@ static char *getdsig(const char *host, const char *user, const unsigned char *da
memset(pass, 0, sizeof(pass));
memset(buff, 0, sizeof(buff));
- if((bread = cli_readn(sockd, buff, sizeof(buff))) > 0) {
+ if((bread = recv(sockd, buff, sizeof(buff), 0)) > 0) {
if(!strstr(buff, "Signature:")) {
mprintf("!getdsig: Error generating digital signature\n");
mprintf("!getdsig: Answer from remote server: %s\n", buff);
- close(sockd);
+ closesocket(sockd);
return NULL;
} else {
mprintf("Signature received (length = %lu)\n", strlen(buff) - 10);
}
} else {
mprintf("!getdsig: Communication error with remote server\n");
- close(sockd);
+ closesocket(sockd);
return NULL;
}
- close(sockd);
+ closesocket(sockd);
pt = buff;
pt += 10;
@@ -1059,15 +1061,7 @@ static int listdb(const char *filename)
free(buffer);
fclose(fh);
- tmpdir = getenv("TMPDIR");
- if(tmpdir == NULL)
-#ifdef P_tmpdir
- tmpdir = P_tmpdir;
-#else
- tmpdir = "/tmp";
-#endif
-
- if(!(dir = cli_gentemp(tmpdir))) {
+ if(!(dir = cli_gentemp(NULL))) {
mprintf("!listdb: Can't generate temporary name\n");
return -1;
}
@@ -1217,7 +1211,7 @@ static int vbadump(const struct optstruct *opts)
pt = optget(opts, "vba")->strarg;
}
- if((fd = open(pt, O_RDONLY)) == -1) {
+ if((fd = open(pt, O_RDONLY|O_BINARY)) == -1) {
mprintf("!vbadump: Can't open file %s\n", pt);
return -1;
}
diff --git a/sigtool/vba.c b/sigtool/vba.c
index 5532b6a..13bfade 100644
--- a/sigtool/vba.c
+++ b/sigtool/vba.c
@@ -37,10 +37,6 @@
#include "libclamav/cltypes.h"
#include "libclamav/ole2_extract.h"
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
typedef struct mac_token_tag
{
unsigned char token;
@@ -991,14 +987,7 @@ static int sigtool_scandir (const char *dirname, int hex_output)
} else {
if (S_ISREG (statbuf.st_mode)) {
struct uniq *vba = NULL;
- tmpdir = getenv ("TMPDIR");
-
- if (tmpdir == NULL)
-#ifdef P_tmpdir
- tmpdir = P_tmpdir;
-#else
- tmpdir = "/tmp";
-#endif
+ tmpdir = cli_gettmpdir();
/* generate the temporary directory */
dir = cli_gentemp (tmpdir);
@@ -1007,7 +996,7 @@ static int sigtool_scandir (const char *dirname, int hex_output)
return CL_ETMPDIR;
}
- if ((desc = open (fname, O_RDONLY)) == -1) {
+ if ((desc = open (fname, O_RDONLY|O_BINARY)) == -1) {
printf ("Can't open file %s\n", fname);
return 1;
}
--
Debian repository for ClamAV
More information about the Pkg-clamav-commits
mailing list