git-svn: trunk@2845
Tomasz Kojm authored on 2007/02/23 05:00:21... | ... |
@@ -1,3 +1,7 @@ |
1 |
+Thu Feb 22 19:03:50 CET 2007 (tk) |
|
2 |
+--------------------------------- |
|
3 |
+ * freshclam: merge win32 patches from NJH |
|
4 |
+ |
|
1 | 5 |
Thu Feb 22 18:12:53 CET 2007 (tk) |
2 | 6 |
--------------------------------- |
3 | 7 |
* clamd/clamd.c: print some more information in Foreground mode (bb#317) |
... | ... |
@@ -1,5 +1,5 @@ |
1 | 1 |
/* |
2 |
- * By Per Jessen <per@computer.org> |
|
2 |
+ * By Per Jessen <per@computer.org> with changes by the ClamAV team |
|
3 | 3 |
* |
4 | 4 |
* This program is free software; you can redistribute it and/or modify |
5 | 5 |
* it under the terms of the GNU General Public License as published by |
... | ... |
@@ -23,9 +23,14 @@ |
23 | 23 |
|
24 | 24 |
#include <stdio.h> |
25 | 25 |
#include <stdlib.h> |
26 |
+#ifdef HAVE_UNISTD_H |
|
26 | 27 |
#include <unistd.h> |
28 |
+#endif |
|
27 | 29 |
#include <string.h> |
28 | 30 |
#include <errno.h> |
31 |
+#ifdef C_WINDOWS |
|
32 |
+#include <process.h> |
|
33 |
+#endif |
|
29 | 34 |
|
30 | 35 |
#include "shared/output.h" |
31 | 36 |
#include "execute.h" |
... | ... |
@@ -36,6 +41,16 @@ int active_children; |
36 | 36 |
|
37 | 37 |
void execute( const char *type, const char *text ) |
38 | 38 |
{ |
39 |
+#ifdef C_WINDOWS |
|
40 |
+ if(active_children < MAX_CHILDREN) { |
|
41 |
+ if(spawnlp(P_DETACH, text, text, NULL) == -1) { |
|
42 |
+ logg("^%s: couldn't execute \"%s\".\n", type, text); |
|
43 |
+ return; |
|
44 |
+ } |
|
45 |
+ active_children++; /* FIXME: this is never reduced */ |
|
46 |
+ } else |
|
47 |
+ logg("^%s: already %d processes active.\n", type, active_children); |
|
48 |
+#else |
|
39 | 49 |
pid_t pid; |
40 | 50 |
|
41 | 51 |
if ( active_children<MAX_CHILDREN ) |
... | ... |
@@ -56,4 +71,5 @@ void execute( const char *type, const char *text ) |
56 | 56 |
{ |
57 | 57 |
logg("^%s: already %d processes active.\n", type, active_children); |
58 | 58 |
} |
59 |
+#endif |
|
59 | 60 |
} |
... | ... |
@@ -20,6 +20,10 @@ |
20 | 20 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
21 | 21 |
* MA 02110-1301, USA. |
22 | 22 |
*/ |
23 |
+ |
|
24 |
+#ifdef _MSC_VER |
|
25 |
+#include <winsock.h> /* only needed in CL_EXPERIMENTAL */ |
|
26 |
+#endif |
|
23 | 27 |
|
24 | 28 |
#if HAVE_CONFIG_H |
25 | 29 |
#include "clamav-config.h" |
... | ... |
@@ -27,14 +31,20 @@ |
27 | 27 |
|
28 | 28 |
#include <stdio.h> |
29 | 29 |
#include <stdlib.h> |
30 |
+#ifdef HAVE_UNISTD_H |
|
30 | 31 |
#include <unistd.h> |
32 |
+#endif |
|
31 | 33 |
#include <string.h> |
32 | 34 |
#include <ctype.h> |
35 |
+#ifndef C_WINDOWS |
|
33 | 36 |
#include <netinet/in.h> |
34 | 37 |
#include <netdb.h> |
38 |
+#endif |
|
35 | 39 |
#include <sys/types.h> |
40 |
+#ifndef C_WINDOWS |
|
36 | 41 |
#include <sys/socket.h> |
37 | 42 |
#include <sys/time.h> |
43 |
+#endif |
|
38 | 44 |
#include <time.h> |
39 | 45 |
#include <fcntl.h> |
40 | 46 |
#include <sys/stat.h> |
... | ... |
@@ -64,6 +74,9 @@ |
64 | 64 |
#define O_BINARY 0 |
65 | 65 |
#endif |
66 | 66 |
|
67 |
+#ifndef C_WINDOWS |
|
68 |
+#define closesocket(s) close(s) |
|
69 |
+#endif |
|
67 | 70 |
|
68 | 71 |
static int wwwconnect(const char *server, const char *proxy, int pport, char *ip, const char *localip, int ctimeout, struct mirdat *mdat) |
69 | 72 |
{ |
... | ... |
@@ -144,7 +157,9 @@ static int wwwconnect(const char *server, const char *proxy, int pport, char *ip |
144 | 144 |
else |
145 | 145 |
port = 8080; |
146 | 146 |
|
147 |
+#ifndef C_WINDOWS |
|
147 | 148 |
endservent(); |
149 |
+#endif |
|
148 | 150 |
#else |
149 | 151 |
port = 8080; |
150 | 152 |
#endif |
... | ... |
@@ -156,7 +171,7 @@ static int wwwconnect(const char *server, const char *proxy, int pport, char *ip |
156 | 156 |
} |
157 | 157 |
|
158 | 158 |
if((host = gethostbyname(hostpt)) == NULL) { |
159 |
- const char *herr; |
|
159 |
+ char *herr; |
|
160 | 160 |
switch(h_errno) { |
161 | 161 |
case HOST_NOT_FOUND: |
162 | 162 |
herr = "Host not found"; |
... | ... |
@@ -376,9 +391,9 @@ static struct cl_cvd *remote_cvdhead(const char *file, const char *hostname, cha |
376 | 376 |
if(!ip[0]) |
377 | 377 |
strcpy(ip, ipaddr); |
378 | 378 |
|
379 |
- if(write(sd, cmd, strlen(cmd)) < 0) { |
|
379 |
+ if(send(sd, cmd, strlen(cmd), 0) < 0) { |
|
380 | 380 |
logg("!remote_cvdhead: write failed\n"); |
381 |
- close(sd); |
|
381 |
+ closesocket(sd); |
|
382 | 382 |
return NULL; |
383 | 383 |
} |
384 | 384 |
|
... | ... |
@@ -394,7 +409,7 @@ static struct cl_cvd *remote_cvdhead(const char *file, const char *hostname, cha |
394 | 394 |
if(cnt <= 0) |
395 | 395 |
break; |
396 | 396 |
} |
397 |
- close(sd); |
|
397 |
+ closesocket(sd); |
|
398 | 398 |
|
399 | 399 |
if(bread == -1) { |
400 | 400 |
logg("!remote_cvdhead: Error while reading CVD header from %s\n", hostname); |
... | ... |
@@ -525,7 +540,7 @@ static int getfile(const char *srcfile, const char *destfile, const char *hostna |
525 | 525 |
if(!ip[0]) |
526 | 526 |
strcpy(ip, ipaddr); |
527 | 527 |
|
528 |
- if(write(sd, cmd, strlen(cmd)) < 0) { |
|
528 |
+ if(send(sd, cmd, strlen(cmd), 0) < 0) { |
|
529 | 529 |
logg("!getfile: Can't write to socket\n"); |
530 | 530 |
return 52; |
531 | 531 |
} |
... | ... |
@@ -565,7 +580,7 @@ static int getfile(const char *srcfile, const char *destfile, const char *hostna |
565 | 565 |
if((strstr(buffer, "HTTP/1.1 404")) != NULL || (strstr(buffer, "HTTP/1.0 404")) != NULL) { |
566 | 566 |
logg("!getfile: %s not found on remote server (IP: %s)\n", srcfile, ipaddr); |
567 | 567 |
/* mirman_update(mdat->currip, mdat, 1); */ |
568 |
- close(sd); |
|
568 |
+ closesocket(sd); |
|
569 | 569 |
return 58; |
570 | 570 |
} |
571 | 571 |
|
... | ... |
@@ -573,7 +588,7 @@ static int getfile(const char *srcfile, const char *destfile, const char *hostna |
573 | 573 |
!strstr(buffer, "HTTP/1.1 206") && !strstr(buffer, "HTTP/1.0 206")) { |
574 | 574 |
logg("!getfile: Unknown response from remote server (IP: %s)\n", ipaddr); |
575 | 575 |
mirman_update(mdat->currip, mdat, 1); |
576 |
- close(sd); |
|
576 |
+ closesocket(sd); |
|
577 | 577 |
return 58; |
578 | 578 |
} |
579 | 579 |
|
... | ... |
@@ -596,7 +611,7 @@ static int getfile(const char *srcfile, const char *destfile, const char *hostna |
596 | 596 |
getcwd(currdir, sizeof(currdir)); |
597 | 597 |
logg("!getfile: Can't create new file %s in %s\n", destfile, currdir); |
598 | 598 |
logg("Hint: The database directory must be writable for UID %d or GID %d\n", getuid(), getgid()); |
599 |
- close(sd); |
|
599 |
+ closesocket(sd); |
|
600 | 600 |
return 57; |
601 | 601 |
} |
602 | 602 |
|
... | ... |
@@ -609,7 +624,7 @@ static int getfile(const char *srcfile, const char *destfile, const char *hostna |
609 | 609 |
logg("getfile: Can't write %d bytes to %s\n", bread, destfile); |
610 | 610 |
unlink(destfile); |
611 | 611 |
close(fd); |
612 |
- close(sd); |
|
612 |
+ closesocket(sd); |
|
613 | 613 |
return 57; /* FIXME */ |
614 | 614 |
} |
615 | 615 |
|
... | ... |
@@ -626,7 +641,7 @@ static int getfile(const char *srcfile, const char *destfile, const char *hostna |
626 | 626 |
fflush(stdout); |
627 | 627 |
} |
628 | 628 |
} |
629 |
- close(sd); |
|
629 |
+ closesocket(sd); |
|
630 | 630 |
close(fd); |
631 | 631 |
|
632 | 632 |
if(totalsize > 0) |
... | ... |
@@ -15,6 +15,9 @@ |
15 | 15 |
* along with this program; if not, write to the Free Software |
16 | 16 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
17 | 17 |
*/ |
18 |
+#ifdef _MSC_VER |
|
19 |
+#include <winsock.h> |
|
20 |
+#endif |
|
18 | 21 |
|
19 | 22 |
#if HAVE_CONFIG_H |
20 | 23 |
#include "clamav-config.h" |
... | ... |
@@ -24,14 +27,20 @@ |
24 | 24 |
|
25 | 25 |
#include <stdio.h> |
26 | 26 |
#include <stdlib.h> |
27 |
+#ifdef HAVE_UNISTD_H |
|
27 | 28 |
#include <unistd.h> |
29 |
+#endif |
|
28 | 30 |
#include <string.h> |
29 | 31 |
#include <ctype.h> |
32 |
+#ifndef C_WINDOWS |
|
30 | 33 |
#include <netinet/in.h> |
31 | 34 |
#include <netdb.h> |
35 |
+#endif |
|
32 | 36 |
#include <sys/types.h> |
33 |
-#include <sys/socket.h> |
|
37 |
+/*#include <sys/socket.h> /* in nonblock.h */ |
|
38 |
+#ifndef C_WINDOWS |
|
34 | 39 |
#include <sys/time.h> |
40 |
+#endif |
|
35 | 41 |
#include <time.h> |
36 | 42 |
#include <fcntl.h> |
37 | 43 |
#include <sys/stat.h> |
... | ... |
@@ -40,6 +49,16 @@ |
40 | 40 |
#include "shared/output.h" |
41 | 41 |
#include "libclamav/clamav.h" |
42 | 42 |
|
43 |
+#if (!defined(EALREADY)) && (defined(WSAEALREADY)) |
|
44 |
+#define EALREADY WSAEALREADY |
|
45 |
+#endif |
|
46 |
+#if (!defined(EINPROGRESS)) && (defined(WSAEINPROGRESS)) |
|
47 |
+#define EINPROGRESS WSAEINPROGRESS |
|
48 |
+#endif |
|
49 |
+#if (!defined(EISCONN)) && (defined(WSAEISCONN)) |
|
50 |
+#define EISCONN WSAEISCONN |
|
51 |
+#endif |
|
52 |
+ |
|
43 | 53 |
#ifdef SO_ERROR |
44 | 54 |
|
45 | 55 |
#ifndef timercmp |
... | ... |
@@ -229,6 +248,7 @@ static ssize_t nonblock_recv(int sock, void *buf, size_t len, int flags, int sec |
229 | 229 |
|
230 | 230 |
static long nonblock_fcntl(int sock) |
231 | 231 |
{ |
232 |
+#ifdef F_GETFL |
|
232 | 233 |
long fcntl_flags; /* Save fcntl() flags */ |
233 | 234 |
|
234 | 235 |
fcntl_flags = fcntl(sock, F_GETFL, 0); |
... | ... |
@@ -242,16 +262,21 @@ static long nonblock_fcntl(int sock) |
242 | 242 |
} |
243 | 243 |
|
244 | 244 |
return fcntl_flags; |
245 |
+#else |
|
246 |
+ return 0; |
|
247 |
+#endif |
|
245 | 248 |
} |
246 | 249 |
|
247 | 250 |
static void restore_fcntl(int sock, long fcntl_flags) |
248 | 251 |
{ |
252 |
+#ifdef F_SETFL |
|
249 | 253 |
if (fcntl_flags != -1) { |
250 | 254 |
if (fcntl(sock, F_SETFL, fcntl_flags)) { |
251 | 255 |
logg("restore_fcntl: restoring: fcntl(%d, F_SETFL): errno=%d: %s\n", |
252 | 256 |
sock, errno, strerror(errno)); |
253 | 257 |
} |
254 | 258 |
} |
259 |
+#endif |
|
255 | 260 |
} |
256 | 261 |
|
257 | 262 |
/* |
... | ... |
@@ -16,6 +16,11 @@ |
16 | 16 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
17 | 17 |
* MA 02110-1301, USA. |
18 | 18 |
*/ |
19 |
+#ifdef _MSC_VER |
|
20 |
+#include <windows.h> |
|
21 |
+#include <winsock.h> |
|
22 |
+#endif |
|
23 |
+ |
|
19 | 24 |
|
20 | 25 |
#if HAVE_CONFIG_H |
21 | 26 |
#include "clamav-config.h" |
... | ... |
@@ -24,23 +29,33 @@ |
24 | 24 |
#ifdef BUILD_CLAMD |
25 | 25 |
|
26 | 26 |
#include <stdio.h> |
27 |
+#ifdef HAVE_UNISTD_H |
|
27 | 28 |
#include <unistd.h> |
29 |
+#endif |
|
28 | 30 |
#include <sys/types.h> |
31 |
+#ifndef C_WINDOWS |
|
29 | 32 |
#include <sys/socket.h> |
30 | 33 |
#include <sys/un.h> |
31 | 34 |
#include <netinet/in.h> |
32 | 35 |
#include <arpa/inet.h> |
33 | 36 |
#include <netdb.h> |
37 |
+#endif |
|
34 | 38 |
#include <string.h> |
35 | 39 |
|
36 | 40 |
#include "shared/cfgparser.h" |
37 | 41 |
#include "shared/output.h" |
38 | 42 |
#include "notify.h" |
39 | 43 |
|
44 |
+#ifndef C_WINDOWS |
|
45 |
+#define closesocket(s) close(s) |
|
46 |
+#endif |
|
47 |
+ |
|
40 | 48 |
int notify(const char *cfgfile) |
41 | 49 |
{ |
42 | 50 |
char buff[20]; |
51 |
+#ifndef C_WINDOWS |
|
43 | 52 |
struct sockaddr_un server; |
53 |
+#endif |
|
44 | 54 |
struct sockaddr_in server2; |
45 | 55 |
struct hostent *he; |
46 | 56 |
struct cfgstruct *copt, *cpt; |
... | ... |
@@ -53,6 +68,7 @@ int notify(const char *cfgfile) |
53 | 53 |
return 1; |
54 | 54 |
} |
55 | 55 |
|
56 |
+#ifndef C_WINDOWS |
|
56 | 57 |
if((cpt = cfgopt(copt, "LocalSocket"))->enabled) { |
57 | 58 |
socktype = "UNIX"; |
58 | 59 |
server.sun_family = AF_UNIX; |
... | ... |
@@ -65,13 +81,15 @@ int notify(const char *cfgfile) |
65 | 65 |
} |
66 | 66 |
|
67 | 67 |
if(connect(sockd, (struct sockaddr *) &server, sizeof(struct sockaddr_un)) < 0) { |
68 |
- close(sockd); |
|
68 |
+ closesocket(sockd); |
|
69 | 69 |
logg("^Clamd was NOT notified: Can't connect to clamd through %s\n", cpt->strarg); |
70 | 70 |
perror("connect()"); |
71 | 71 |
return 1; |
72 | 72 |
} |
73 | 73 |
|
74 |
- } else if((cpt = cfgopt(copt, "TCPSocket"))->enabled) { |
|
74 |
+ } else |
|
75 |
+#endif |
|
76 |
+ if((cpt = cfgopt(copt, "TCPSocket"))->enabled) { |
|
75 | 77 |
|
76 | 78 |
socktype = "TCP"; |
77 | 79 |
#ifdef PF_INET |
... | ... |
@@ -99,7 +117,7 @@ int notify(const char *cfgfile) |
99 | 99 |
|
100 | 100 |
|
101 | 101 |
if(connect(sockd, (struct sockaddr *) &server2, sizeof(struct sockaddr_in)) < 0) { |
102 |
- close(sockd); |
|
102 |
+ closesocket(sockd); |
|
103 | 103 |
logg("^Clamd was NOT notified: Can't connect to clamd on %s:%d\n", |
104 | 104 |
inet_ntoa(server2.sin_addr), ntohs(server2.sin_port)); |
105 | 105 |
perror("connect()"); |
... | ... |
@@ -111,23 +129,23 @@ int notify(const char *cfgfile) |
111 | 111 |
return 1; |
112 | 112 |
} |
113 | 113 |
|
114 |
- if(write(sockd, "RELOAD", 6) < 0) { |
|
114 |
+ if(send(sockd, "RELOAD", 6, 0) < 0) { |
|
115 | 115 |
logg("^Clamd was NOT notified: Could not write to %s socket\n", socktype); |
116 | 116 |
perror("write()"); |
117 |
- close(sockd); |
|
117 |
+ closesocket(sockd); |
|
118 | 118 |
return 1; |
119 | 119 |
} |
120 | 120 |
|
121 | 121 |
/* TODO: Handle timeout */ |
122 | 122 |
memset(buff, 0, sizeof(buff)); |
123 |
- if((bread = read(sockd, buff, sizeof(buff))) > 0) |
|
123 |
+ if((bread = recv(sockd, buff, sizeof(buff), 0)) > 0) |
|
124 | 124 |
if(!strstr(buff, "RELOADING")) { |
125 | 125 |
logg("^Clamd was NOT notified: Unknown answer from clamd: '%s'\n", buff); |
126 |
- close(sockd); |
|
126 |
+ closesocket(sockd); |
|
127 | 127 |
return 1; |
128 | 128 |
} |
129 | 129 |
|
130 |
- close(sockd); |
|
130 |
+ closesocket(sockd); |
|
131 | 131 |
logg("Clamd successfully notified about the update.\n"); |
132 | 132 |
return 0; |
133 | 133 |
} |