From 3b074c78780db38f251c8d50e474ea7d2701ed9d Mon Sep 17 00:00:00 2001 From: aCaB Date: Thu, 28 Jan 2010 23:36:37 +0100 Subject: [PATCH] clamd-win32 - WIP --- clamd/clamd.c | 2 +- clamd/localserver.c | 12 +- clamd/others.c | 4 +- clamd/scanner.c | 3 +- clamd/tcpserver.c | 2 +- win32/ClamAV.sln | 7 + win32/clamav-config.h | 6 +- win32/clambc.vcproj | 4 - win32/clamconf.vcproj | 6 +- win32/clamd.vcproj | 251 +++++++++++++++++++++++++++++++ win32/clamscan.vcproj | 4 - win32/compat/net.c | 24 +++ win32/compat/net.h | 3 + win32/compat/regen_errno_defs.sh | 2 +- win32/compat/setargv.c | 2 +- win32/compat/w32_errno.c | 19 ++- win32/compat/w32_errno.h | 3 + win32/compat/w32_errno_defs.c | 4 +- win32/freshclam.vcproj | 4 - win32/libclamav.def | 38 ++++- win32/platform.h | 5 + win32/update-win32.pl | 17 ++- 22 files changed, 373 insertions(+), 49 deletions(-) create mode 100644 win32/clamd.vcproj diff --git a/clamd/clamd.c b/clamd/clamd.c index cdb5e5937..097185eb0 100644 --- a/clamd/clamd.c +++ b/clamd/clamd.c @@ -104,7 +104,7 @@ int main(int argc, char **argv) { static struct cl_engine *engine = NULL; const struct optstruct *opt; -#ifndef C_WINDOWS +#ifndef _WIN32 struct passwd *user = NULL; struct sigaction sa; #endif diff --git a/clamd/localserver.c b/clamd/localserver.c index 693435136..6717e0b1a 100644 --- a/clamd/localserver.c +++ b/clamd/localserver.c @@ -25,13 +25,11 @@ #include #include #include -#ifndef C_WINDOWS +#ifndef _WIN32 #include -#endif -#include -#ifndef C_WINDOWS #include #endif +#include #include #ifdef HAVE_UNISTD_H #include @@ -40,13 +38,13 @@ #include "libclamav/clamav.h" #include "shared/optparser.h" +#include "shared/output.h" #include "others.h" #include "server.h" -#include "output.h" #include "localserver.h" -#ifdef C_WINDOWS +#ifdef _WIN32 int localserver(const struct optstruct *opts) { logg("!Localserver is not supported on this platform"); @@ -121,4 +119,4 @@ int localserver(const struct optstruct *opts) return sockfd; } -#endif /* C_WINDOWS */ +#endif diff --git a/clamd/others.c b/clamd/others.c index 91f9ffdeb..f0d838742 100644 --- a/clamd/others.c +++ b/clamd/others.c @@ -69,11 +69,11 @@ #include #include "shared/optparser.h" #include "shared/output.h" +#include "shared/misc.h" #include "libclamav/others.h" #include "session.h" #include "others.h" -#include "misc.h" #ifdef _WIN32 void virusaction(const char *filename, const char *virname, const struct optstruct *opts) @@ -551,6 +551,7 @@ int fds_poll_recv(struct fd_data *data, int timeout, int check_signals) } } while (retval == -1 && !check_signals && errno == EINTR); #else + { fd_set rfds; struct timeval tv; int maxfd = -1; @@ -628,6 +629,7 @@ int fds_poll_recv(struct fd_data *data, int timeout, int check_signals) continue; } } while (retval == -1 && !check_signals && errno == EINTR); + } #endif if (retval == -1 && errno != EINTR) { diff --git a/clamd/scanner.c b/clamd/scanner.c index 20bc68674..24b331c36 100644 --- a/clamd/scanner.c +++ b/clamd/scanner.c @@ -390,7 +390,8 @@ int scanstream(int odesc, unsigned long int *scanned, const struct cl_engine *en return -1; } - snprintf(peer_addr, sizeof(peer_addr), "%s", inet_ntoa(peer.sin_addr)); + *peer_addr = '\0'; + inet_ntop(peer.sin_family, &peer, peer_addr, sizeof(peer_addr)); logg("*Accepted connection from %s on port %u, fd %d\n", peer_addr, port, acceptd); if(cli_gentempfd(optget(opts, "TemporaryDirectory")->strarg, &tmpname, &tmpd)) { diff --git a/clamd/tcpserver.c b/clamd/tcpserver.c index 0afea86eb..a8f73d2cf 100644 --- a/clamd/tcpserver.c +++ b/clamd/tcpserver.c @@ -40,11 +40,11 @@ #include "shared/optparser.h" #include "shared/output.h" +#include "shared/misc.h" #include "others.h" #include "server.h" #include "tcpserver.h" -#include "misc.h" int tcpserver(const struct optstruct *opts) { diff --git a/win32/ClamAV.sln b/win32/ClamAV.sln index 790414843..7b62112cc 100644 --- a/win32/ClamAV.sln +++ b/win32/ClamAV.sln @@ -46,6 +46,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LLVMjit", "LLVMjit.vcproj", EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LLVMcodegen", "LLVMcodegen.vcproj", "{7472FD2F-DDE7-44B1-91FB-65C0BE81932B}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "clamd", "clamd.vcproj", "{B3CA73CF-E71E-42F3-95DE-43797A86C798}" + ProjectSection(ProjectDependencies) = postProject + {3AD5B16C-340A-40AC-96AD-6017B941A316} = {3AD5B16C-340A-40AC-96AD-6017B941A316} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -100,6 +105,8 @@ Global {7472FD2F-DDE7-44B1-91FB-65C0BE81932B}.Debug|Win32.Build.0 = Debug|Win32 {7472FD2F-DDE7-44B1-91FB-65C0BE81932B}.Release|Win32.ActiveCfg = Release|Win32 {7472FD2F-DDE7-44B1-91FB-65C0BE81932B}.Release|Win32.Build.0 = Release|Win32 + {B3CA73CF-E71E-42F3-95DE-43797A86C798}.Debug|Win32.ActiveCfg = Debug|Win32 + {B3CA73CF-E71E-42F3-95DE-43797A86C798}.Release|Win32.ActiveCfg = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/win32/clamav-config.h b/win32/clamav-config.h index 1d2a295b1..675144161 100644 --- a/win32/clamav-config.h +++ b/win32/clamav-config.h @@ -269,10 +269,10 @@ #define HAVE_OPENDIR 1 /* Define to 1 if you have the `poll' function. */ -#define HAVE_POLL 1 +/* #undef HAVE_POLL */ /* Define to 1 if you have the header file. */ -#define HAVE_POLL_H 1 +/* #undef HAVE_POLL_H */ /* "pragma pack" */ #define HAVE_PRAGMA_PACK 1 @@ -493,7 +493,7 @@ /* #undef USE_SYSLOG */ /* Version number of package */ -#define VERSION "devel-r5076-703-g0222ee6" +#define VERSION "devel-r5076-706-g0380088" /* Version suffix for package */ #define VERSION_SUFFIX "" diff --git a/win32/clambc.vcproj b/win32/clambc.vcproj index 51d360366..7ef60f181 100644 --- a/win32/clambc.vcproj +++ b/win32/clambc.vcproj @@ -184,10 +184,6 @@ RelativePath="..\clambc\bcrun.c" > - - diff --git a/win32/clamconf.vcproj b/win32/clamconf.vcproj index 611616026..fc7647330 100644 --- a/win32/clamconf.vcproj +++ b/win32/clamconf.vcproj @@ -6,7 +6,7 @@ ProjectType="Visual C++" RootNamespace="clamconf" TargetFrameworkVersion="196613" - Version="9.00" + Version="9,00" > - - diff --git a/win32/clamd.vcproj b/win32/clamd.vcproj new file mode 100644 index 000000000..f42c21fcd --- /dev/null +++ b/win32/clamd.vcproj @@ -0,0 +1,251 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/win32/clamscan.vcproj b/win32/clamscan.vcproj index c79095096..c3fa133fc 100644 --- a/win32/clamscan.vcproj +++ b/win32/clamscan.vcproj @@ -208,10 +208,6 @@ RelativePath="..\shared\actions.c" > - - diff --git a/win32/compat/net.c b/win32/compat/net.c index 73dc2d3bf..d46cac922 100644 --- a/win32/compat/net.c +++ b/win32/compat/net.c @@ -324,3 +324,27 @@ int w32_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, s } return ret; } + +int w32_accept(int sockfd, const struct sockaddr *addr, socklen_t *addrlen) { + if(accept((SOCKET)sockfd, addr, addrlen)) { + wsock2errno(); + return -1; + } + return 0; +} + +int w32_listen(int sockfd, int backlog) { + if(listen((SOCKET)sockfd, backlog)) { + wsock2errno(); + return -1; + } + return 0; +} + +int w32_shutdown(int sockfd, int how) { + if(shutdown((SOCKET)sockfd, how)) { + wsock2errno(); + return -1; + } + return 0; +} diff --git a/win32/compat/net.h b/win32/compat/net.h index 98e59f673..8f4ec7f3b 100644 --- a/win32/compat/net.h +++ b/win32/compat/net.h @@ -39,5 +39,8 @@ void w32_freeaddrinfo(struct addrinfo *res); const char *w32_inet_ntop(int af, const void *src, char *dst, socklen_t size); struct hostent *w32_gethostbyname(const char *name); int w32_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); +int w32_accept(int sockfd, const struct sockaddr *addr, socklen_t *addrlen); +int w32_listen(int sockfd, int backlog); +int w32_shutdown(int sockfd, int how); #endif diff --git a/win32/compat/regen_errno_defs.sh b/win32/compat/regen_errno_defs.sh index 762937fd9..4a35b1240 100644 --- a/win32/compat/regen_errno_defs.sh +++ b/win32/compat/regen_errno_defs.sh @@ -43,7 +43,7 @@ for pippo in `cat "$INFILE"`; do value=$((value+1000)) [ $value -gt $maxerr ] && maxerr=$value descr=`echo $pippo | cut -d'|' -f3` - git grep $symbol > /dev/null + git grep $symbol | egrep -v '(referrno|w32_errno_defs)' > /dev/null used=$? [ $used -ne 0 ] && echo "#ifdef __ERRNO_INCLUDE_UNUSED" >> "$OUTFILE" echo -e "#ifndef $symbol\n#define $symbol $value\n#endif\n{ $symbol, \"$descr\" }," >> "$OUTFILE" diff --git a/win32/compat/setargv.c b/win32/compat/setargv.c index c8ee67ab6..5585b5c18 100644 --- a/win32/compat/setargv.c +++ b/win32/compat/setargv.c @@ -46,7 +46,7 @@ int glob_add(const char *path, int *argc, char ***argv); int _setargv() { char *cur = GetCommandLineA(), *begparm = NULL, *endparm = NULL; char **argv = NULL, c; - int argc = 0, i, in_sq = 0, in_dq = 0, need_glob = 0, allarglen = 0; + int argc = 0, in_sq = 0, in_dq = 0, need_glob = 0, allarglen = 0; int *g_argc = __p___argc(); char ***g_argv = __p___argv(); diff --git a/win32/compat/w32_errno.c b/win32/compat/w32_errno.c index b51273c48..1375aea52 100644 --- a/win32/compat/w32_errno.c +++ b/win32/compat/w32_errno.c @@ -18,11 +18,20 @@ * MA 02110-1301, USA. */ -#if HAVE_CONFIG_H -#include "clamav-config.h" -#endif - +#include #include "w32_errno.h" +char *w32_strerror(int errnum) { + int i; + for(i=0; i #include "w32_errno_defs.c" +char *w32_strerror(int errnum); +int w32_strerror_r(int errnum, char *buf, size_t buflen); + #endif \ No newline at end of file diff --git a/win32/compat/w32_errno_defs.c b/win32/compat/w32_errno_defs.c index f68dba1b6..2e51a895a 100644 --- a/win32/compat/w32_errno_defs.c +++ b/win32/compat/w32_errno_defs.c @@ -1,4 +1,4 @@ -/* Automatically generated on Wed Oct 14 14:49:39 GMT 2009 */ +/* Automatically generated on Thu Jan 28 23:51:23 CET 2010 */ #include @@ -336,12 +336,10 @@ static const struct errno_struct { #endif { ESRMNT, "Srmount error" }, #endif /* __ERRNO_INCLUDE_UNUSED */ -#ifdef __ERRNO_INCLUDE_UNUSED #ifndef ECOMM #define ECOMM 1070 #endif { ECOMM, "Communication error on send" }, -#endif /* __ERRNO_INCLUDE_UNUSED */ #ifndef EPROTO #define EPROTO 1071 #endif diff --git a/win32/freshclam.vcproj b/win32/freshclam.vcproj index 435beabf4..6a564d302 100644 --- a/win32/freshclam.vcproj +++ b/win32/freshclam.vcproj @@ -214,10 +214,6 @@ RelativePath="..\shared\cdiff.c" > - - diff --git a/win32/libclamav.def b/win32/libclamav.def index 217ba2cc0..5ad4c6727 100644 --- a/win32/libclamav.def +++ b/win32/libclamav.def @@ -7,6 +7,10 @@ EXPORTS cl_engine_set_num EXPORTS cl_engine_set_str EXPORTS cl_engine_free EXPORTS cl_engine_new +EXPORTS cl_engine_settings_copy +EXPORTS cl_engine_settings_free +EXPORTS cl_engine_settings_apply +EXPORTS cl_engine_get_num EXPORTS cl_strerror EXPORTS cl_init EXPORTS cl_retdbdir @@ -18,9 +22,14 @@ EXPORTS cl_retflevel EXPORTS cl_cvdparse EXPORTS cl_cvdverify EXPORTS cl_retver +EXPORTS cl_engine_addref +EXPORTS cl_statinidir +EXPORTS cl_statchkdir +EXPORTS cl_statfree ; cli_stuff - should be mangled or exported by ordinal only EXPORTS cli_gentemp +EXPORTS cli_gentempfd EXPORTS cli_gettmpdir EXPORTS cli_regcomp EXPORTS cli_regexec @@ -33,6 +42,11 @@ EXPORTS cli_cvdunpack EXPORTS cli_chomp EXPORTS cli_strtokenize EXPORTS cli_versig2 +EXPORTS cli_strerror +EXPORTS cli_rndnum +EXPORTS cli_unlink +EXPORTS cli_writen +EXPORTS cli_ftw EXPORTS have_rar EXPORTS have_clamjit @@ -88,16 +102,37 @@ EXPORTS CONFDIR_MILTER DATA ; winsock - bridging for now EXPORTS htonl EXPORTS htons +EXPORTS ntohl EXPORTS ntohs EXPORTS gettimeofday EXPORTS pthread_mutex_lock EXPORTS pthread_mutex_unlock +EXPORTS pthread_mutex_destroy +EXPORTS pthread_once +EXPORTS pthread_getspecific +EXPORTS pthread_setspecific +EXPORTS pthread_create +EXPORTS pthread_cond_timedwait +EXPORTS pthread_cond_init +EXPORTS pthread_cond_broadcast +EXPORTS pthread_cond_signal +EXPORTS pthread_cond_destroy +EXPORTS pthread_join +EXPORTS pthread_key_create +EXPORTS pthread_cond_wait +EXPORTS pthread_attr_init +EXPORTS pthread_attr_setdetachstate +EXPORTS pthread_attr_destroy +EXPORTS pthread_mutex_init EXPORTS w32_socket EXPORTS w32_getsockopt EXPORTS w32_setsockopt EXPORTS w32_bind +EXPORTS w32_listen +EXPORTS w32_accept EXPORTS w32_connect +EXPORTS w32_shutdown EXPORTS w32_send EXPORTS w32_recv EXPORTS w32_closesocket @@ -107,5 +142,6 @@ EXPORTS w32_freeaddrinfo EXPORTS w32_inet_ntop EXPORTS w32_gethostbyname EXPORTS w32_select - EXPORTS w32_stat +EXPORTS w32_strerror +EXPORTS w32_strerror_r diff --git a/win32/platform.h b/win32/platform.h index 40cbf78aa..e1e42b25b 100644 --- a/win32/platform.h +++ b/win32/platform.h @@ -33,7 +33,10 @@ char *strptime(const char *s, const char *format, struct tm *tm); #define getsockopt w32_getsockopt #define setsockopt w32_setsockopt #define bind w32_bind +#define listen w32_listen +#define accept w32_accept #define connect w32_connect +#define shutdown w32_shutdown #define send w32_send #define recv w32_recv #define closesocket w32_closesocket @@ -43,6 +46,8 @@ char *strptime(const char *s, const char *format, struct tm *tm); #define inet_ntop w32_inet_ntop #define gethostbyname w32_gethostbyname #define select w32_select +#define strerror w32_strerror +#define strerror_r w32_strerror_r #define ftruncate _chsize #define getpid GetCurrentProcessId diff --git a/win32/update-win32.pl b/win32/update-win32.pl index 0116fb325..74184fd63 100755 --- a/win32/update-win32.pl +++ b/win32/update-win32.pl @@ -104,8 +104,8 @@ my %CONF = ( 'HAVE_MMAP' => -1, 'HAVE_NDIR_H' => -1, 'HAVE_OPENDIR' => '1', - 'HAVE_POLL' => '1', - 'HAVE_POLL_H' => '1', + 'HAVE_POLL' => -1, + 'HAVE_POLL_H' => -1, 'HAVE_PRAGMA_PACK' => '1', 'HAVE_PRAGMA_PACK_HPPA' => -1, 'HAVE_PRELOADED_SYMBOLS' => -1, @@ -215,16 +215,19 @@ my @PROJECTS = ( {makefile => 'libclamav/c++', sections => ['libclamavcxx'], output => 'win32/libclamavcxx.vcproj'}, # CLAMSCAN # - {makefile => 'clamscan', sections => ['clamscan'], output => 'win32/clamscan.vcproj', makefile_only => 'optparser\\.c$', vcproj_only => 'compat\\\\'}, + {makefile => 'clamscan', sections => ['clamscan'], output => 'win32/clamscan.vcproj', makefile_only => '(optparser\\.c|getopt\\.c)$', vcproj_only => 'compat\\\\'}, + + # CLAMD # + {makefile => 'clamd', sections => ['clamd'], output => 'win32/clamd.vcproj', makefile_only => '(optparser\\.c|getopt\\.c|(daz|clam)uko.*)$', vcproj_only => 'compat\\\\'}, # FRESHCLAM # - {makefile => 'freshclam', sections => ['freshclam'], output => 'win32/freshclam.vcproj', makefile_only => 'optparser\\.c$', vcproj_only => 'compat\\\\'}, + {makefile => 'freshclam', sections => ['freshclam'], output => 'win32/freshclam.vcproj', makefile_only => '(optparser\\.c|getopt\\.c)$', vcproj_only => 'compat\\\\'}, # CLAMCONF # - {makefile => 'clamconf', sections => ['clamconf'], output => 'win32/clamconf.vcproj', makefile_only => 'optparser\\.c$'}, + {makefile => 'clamconf', sections => ['clamconf'], output => 'win32/clamconf.vcproj', makefile_only => '(optparser\\.c$|getopt\\.c)$'}, # CLAMBC # - {makefile => 'clambc', sections => ['clambc'], output => 'win32/clambc.vcproj', makefile_only => 'optparser\\.c$'}, + {makefile => 'clambc', sections => ['clambc'], output => 'win32/clambc.vcproj', makefile_only => '(optparser\\.c|getopt\\.c)$'}, # LLVMsystem # {makefile => 'libclamav/c++', sections => ['libllvmsystem'], output => 'win32/LLVMsystem.vcproj'}, @@ -232,7 +235,7 @@ my @PROJECTS = ( # LLVMcodgen # {makefile => 'libclamav/c++', sections => ['libllvmcodegen'], output => 'win32/LLVMcodegen.vcproj'}, - # LLVMcodgen # + # LLVMx86codgen # {makefile => 'libclamav/c++', sections => ['libllvmx86codegen'], output => 'win32/LLVMx86codegen.vcproj'}, # LLVMjit #