apply w32 patches from NJH

git-svn: trunk@2245
remotes/push_mirror/metadata
Tomasz Kojm 20 years ago
parent bd912dd866
commit 67118e923d
  1. 4
      clamav-devel/ChangeLog
  2. 39
      clamav-devel/clamd/clamd.c
  3. 10
      clamav-devel/clamd/localserver.c
  4. 35
      clamav-devel/clamd/others.c
  5. 28
      clamav-devel/clamd/scanner.c
  6. 39
      clamav-devel/clamd/server-th.c
  7. 17
      clamav-devel/clamd/session.c
  8. 8
      clamav-devel/clamd/tcpserver.c
  9. 4
      clamav-devel/clamd/thrmgr.c
  10. 3
      clamav-devel/clamd/thrmgr.h

@ -1,3 +1,7 @@
Tue Sep 12 22:52:14 CEST 2006 (tk)
----------------------------------
* clamd: apply w32 patches from NJH
Tue Sep 12 21:59:17 CEST 2006 (acab)
------------------------------------
* libclamav: Merge of the related part of the phishing module from

@ -21,17 +21,25 @@
#include "clamav-config.h"
#endif
#ifdef _MSC_VER
#include <winsock.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#include <sys/time.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#ifndef C_WINDOWS
#include <pwd.h>
#include <grp.h>
#endif
#if defined(USE_SYSLOG) && !defined(C_AIX)
#include <syslog.h>
@ -100,6 +108,12 @@ int main(int argc, char **argv)
{0, 0, 0, 0}
};
#ifdef C_WINDOWS
if(!pthread_win32_process_attach_np()) {
mprintf("!Can't start the win32 pthreads layer\n");
return 1;
}
#endif
opt = opt_parse(argc, argv, short_options, long_options, NULL);
if(!opt) {
@ -147,7 +161,7 @@ int main(int argc, char **argv)
umask(0);
/* drop privileges */
#ifndef C_OS2
#if (!defined(C_OS2)) && (!defined(C_WINDOWS))
if(geteuid() == 0 && (cpt = cfgopt(copt, "User"))->enabled) {
if((user = getpwnam(cpt->strarg)) == NULL) {
fprintf(stderr, "ERROR: Can't get information about user %s.\n", cpt->strarg);
@ -189,6 +203,7 @@ int main(int argc, char **argv)
return 1;
}
if(setuid(user->pw_uid)) {
fprintf(stderr, "ERROR: setuid(%d) failed.\n", (int) user->pw_uid);
logg("!setuid(%d) failed.\n", (int) user->pw_uid);
@ -330,6 +345,16 @@ int main(int argc, char **argv)
}
if(tcpsock) {
#ifdef C_WINDOWS
WSADATA wsaData;
if(WSAStartup(MAKEWORD(2,2), &wsaData) != NO_ERROR) {
logg("!Error at WSAStartup(): %d\n", WSAGetLastError());
logg_close();
freecfg(copt);
return 1;
}
#endif
lsockets[nlsockets] = tcpserver(copt);
if(lsockets[nlsockets] == -1) {
logg_close();
@ -353,6 +378,18 @@ int main(int argc, char **argv)
ret = acceptloop_th(lsockets, nlsockets, root, copt);
#ifdef C_WINDOWS
if(tcpsock)
WSACleanup();
if(!pthread_win32_process_detach_np()) {
logg("!Can't stop the win32 pthreads layer\n");
logg_close();
freecfg(copt);
return 1;
}
#endif
logg_close();
freecfg(copt);

@ -38,6 +38,15 @@
#include "server.h"
#include "output.h"
#ifdef C_WINDOWS
int localserver(const struct cfgstruct *copt, struct cl_node *root)
{
logg("!Localserver is not supported on this platform");
return -1;
}
#else
int localserver(const struct cfgstruct *copt)
{
struct sockaddr_un server;
@ -103,3 +112,4 @@ int localserver(const struct cfgstruct *copt)
return sockfd;
}
#endif /* C_WINDOWS */

@ -21,24 +21,34 @@
#include "clamav-config.h"
#endif
#ifdef _MSC_VER
#include <winsock.h>
#endif
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <fcntl.h>
#include <time.h>
#include <sys/stat.h>
#include <errno.h>
#ifndef C_WINDOWS
#include <sys/time.h>
#include <sys/wait.h>
#endif
#if HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#ifndef C_WINDOWS
#include <sys/socket.h>
#include <sys/ioctl.h>
#endif
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
@ -77,6 +87,15 @@
#define ENV_FILE "CLAM_VIRUSEVENT_FILENAME"
#define ENV_VIRUS "CLAM_VIRUSEVENT_VIRUSNAME"
#ifdef C_WINDOWS
void virusaction(const char *filename, const char *virname, const struct cfgstruct *copt)
{
if(cfgopt(copt, "VirusEvent")->enabled)
logg("^VirusEvent is not supported on this platform"); /* Yet */
}
#else
void virusaction(const char *filename, const char *virname, const struct cfgstruct *copt)
{
pid_t pid;
@ -130,6 +149,7 @@ void virusaction(const char *filename, const char *virname, const struct cfgstru
logg("!VirusAction: fork failed.\n");
}
}
#endif /* C_WINDOWS */
int poll_fds(int *fds, int nfds, int timeout_sec)
{
@ -186,9 +206,11 @@ int poll_fds(int *fds, int nfds, int timeout_sec)
int maxfd = 0;
for (i=0; i<nfds; i++) {
#ifndef C_WINDOWS
if (fds[i] >= DEFAULT_FD_SETSIZE) {
return -1;
}
#endif
if (fds[i] > maxfd)
maxfd = fds[i];
}
@ -262,9 +284,11 @@ int is_fd_connected(int fd)
struct timeval tv;
char buff[1];
#ifndef C_WINDOWS
if (fd >= DEFAULT_FD_SETSIZE) {
return 1;
}
#endif
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
@ -309,6 +333,16 @@ int writen(int fd, void *buff, unsigned int count)
return count;
}
#ifdef C_WINDOWS
/*
* The code is non-portable, please send patches to NJH
*/
int
readsock(int sockfd, char *buf, size_t size, unsigned char delim, int timeout_sec, int force_delim, int read_command)
{
return recv(sockfd, buf, size, 0);
}
#else
/* FD Support Submitted by Richard Lyons <frob-clamav*webcentral.com.au> */
/*
This procedure does timed clamd command and delimited input processing.
@ -456,3 +490,4 @@ int readsock(int sockfd, char *buf, size_t size, unsigned char delim, int timeou
}
return n;
}
#endif

@ -21,13 +21,20 @@
#include "clamav-config.h"
#endif
#ifdef _MSC_VER
#include <winsock.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#ifndef C_WINDOWS
#include <sys/time.h>
#include <sys/wait.h>
#include <sys/param.h>
@ -36,6 +43,7 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#endif
#include <pthread.h>
#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
@ -59,6 +67,10 @@
dev_t procdev; /* /proc device */
#endif
#ifndef C_WINDOWS
#define closesocket(s) close(s)
#endif
/* Maximum filenames under various systems - njh */
#ifndef NAME_MAX /* e.g. Linux */
# ifdef MAXNAMELEN /* e.g. Solaris */
@ -125,7 +137,7 @@ int dirscan(const char *dirname, const char **virname, unsigned long int *scanne
closedir(dd);
return 1;
}
#ifndef C_INTERIX
#if (!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(C_CYGWIN))
if(dent->d_ino)
#endif
{
@ -215,10 +227,12 @@ int scan(const char *filename, unsigned long int *scanned, const struct cl_node
}
switch(sb.st_mode & S_IFMT) {
#ifdef S_IFLNK
case S_IFLNK:
if(!cfgopt(copt, "FollowFileSymlinks")->enabled)
break;
/* else go to the next case */
#endif
case S_IFREG:
if(sb.st_size == 0) { /* empty file */
mdprintf(odesc, "%s: Empty file\n", filename);
@ -347,7 +361,7 @@ int scanstream(int odesc, unsigned long int *scanned, const struct cl_node *root
continue;
if(bind(sockfd, (struct sockaddr *) &server, sizeof(struct sockaddr_in)) == -1)
close(sockfd);
closesocket(sockfd);
else
bound = 1;
}
@ -406,15 +420,15 @@ int scanstream(int odesc, unsigned long int *scanned, const struct cl_node *root
btread = sizeof(buff);
while((retval = poll_fd(acceptd, timeout)) == 1) {
bread = read(acceptd, buff, btread);
bread = recv(acceptd, buff, btread, 0);
if(bread <= 0)
break;
size += bread;
if(writen(tmpd, buff, bread) != bread) {
shutdown(sockfd, 2);
close(sockfd);
close(acceptd);
closesocket(sockfd);
closesocket(acceptd);
mdprintf(odesc, "Temporary file -> write ERROR\n");
logg("!ScanStream %d: Can't write to temporary file.\n", port);
close(tmpd);
@ -456,8 +470,8 @@ int scanstream(int odesc, unsigned long int *scanned, const struct cl_node *root
unlink(tmpname);
free(tmpname);
close(acceptd);
close(sockfd);
closesocket(acceptd);
closesocket(sockfd);
if(ret == CL_VIRUS) {
mdprintf(odesc, "stream: %s FOUND\n", virname);

@ -22,6 +22,10 @@
#include "clamav-config.h"
#endif
#ifdef _MSC_VER
#include <winsock.h>
#endif
#include <pthread.h>
#include <errno.h>
#include <signal.h>
@ -29,8 +33,12 @@
#include <string.h>
#include <time.h>
#include <sys/types.h>
#ifndef C_WINDOWS
#include <sys/socket.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "libclamav/clamav.h"
@ -44,9 +52,17 @@
#include "others.h"
#include "shared.h"
#ifndef C_WINDOWS
#define closesocket(s) close(s)
#endif
#define BUFFSIZE 1024
#ifndef FALSE
#define FALSE (0)
#endif
#ifndef TRUE
#define TRUE (1)
#endif
int progexit = 0;
pthread_mutex_t exit_mutex;
@ -69,13 +85,17 @@ typedef struct client_conn_tag {
void scanner_thread(void *arg)
{
client_conn_t *conn = (client_conn_t *) arg;
#ifndef C_WINDOWS
sigset_t sigset;
#endif
int ret, timeout, i, session=FALSE;
#ifndef C_WINDOWS
/* ignore all signals */
sigfillset(&sigset);
pthread_sigmask(SIG_SETMASK, &sigset, NULL);
#endif
timeout = cfgopt(conn->copt, "ReadTimeout")->numarg;
if(!timeout)
@ -93,7 +113,7 @@ void scanner_thread(void *arg)
progexit = 1;
for(i = 0; i < conn->nsockets; i++) {
shutdown(conn->socketds[i], 2);
close(conn->socketds[i]);
closesocket(conn->socketds[i]);
}
pthread_mutex_unlock(&exit_mutex);
break;
@ -126,7 +146,7 @@ void scanner_thread(void *arg)
}
} while (session);
close(conn->sd);
closesocket(conn->sd);
cl_free(conn->root);
free(conn);
return;
@ -145,13 +165,17 @@ void sighandler_th(int sig)
_exit(11); /* probably not reached at all */
break; /* not reached */
#ifdef SIGHUP
case SIGHUP:
sighup = 1;
break;
#endif
#ifdef SIGUSR2
case SIGUSR2:
reload = 1;
break;
#endif
default:
break; /* Take no action on other signals - e.g. SIGPIPE */
@ -229,11 +253,15 @@ int acceptloop_th(int *socketds, int nsockets, struct cl_node *root, const struc
int new_sd, max_threads, i;
unsigned int options = 0;
threadpool_t *thr_pool;
#ifndef C_WINDOWS
struct sigaction sigact;
#endif
mode_t old_umask;
struct cl_limits limits;
pthread_attr_t thattr;
#ifndef C_WINDOWS
sigset_t sigset;
#endif
client_conn_t *client_conn;
struct cfgstruct *cpt;
#ifdef HAVE_STRERROR_R
@ -253,7 +281,10 @@ int acceptloop_th(int *socketds, int nsockets, struct cl_node *root, const struc
pthread_attr_t clamuko_attr;
struct thrarg *tharg = NULL; /* shut up gcc */
#endif
#ifndef C_WINDOWS
memset(&sigact, 0, sizeof(struct sigaction));
#endif
/* save the PID */
mainpid = getpid();
@ -402,6 +433,7 @@ int acceptloop_th(int *socketds, int nsockets, struct cl_node *root, const struc
logg("Clamuko is not available.\n");
#endif
#ifndef C_WINDOWS
/* set up signal handling */
sigfillset(&sigset);
sigdelset(&sigset, SIGINT);
@ -430,6 +462,7 @@ int acceptloop_th(int *socketds, int nsockets, struct cl_node *root, const struc
sigaddset(&sigact.sa_mask, SIGHUP);
sigaction(SIGSEGV, &sigact, NULL);
}
#endif
#if defined(C_BIGSTACK) || defined(C_BSD)
/*
@ -565,7 +598,7 @@ int acceptloop_th(int *socketds, int nsockets, struct cl_node *root, const struc
shutdown(socketds[i], 2);
logg("*Closing the main socket%s.\n", (nsockets > 1) ? "s" : "");
for (i = 0; i < nsockets; i++)
close(socketds[i]);
closesocket(socketds[i]);
#ifndef C_OS2
if((cpt = cfgopt(copt, "LocalSocket"))->enabled) {
if(unlink(cpt->strarg) == -1)

@ -21,18 +21,27 @@
#include "clamav-config.h"
#endif
#ifdef _MSC_VER
#include <winsock.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <sys/types.h>
#ifndef C_WINDOWS
#include <dirent.h>
#include <sys/socket.h>
#include <sys/time.h>
#endif
#include <pthread.h>
#include <time.h>
#include <signal.h>
#include <errno.h>
#include <stddef.h>
#include "libclamav/clamav.h"
#include "libclamav/str.h"
@ -65,13 +74,17 @@ void multiscanfile(void *arg)
{
struct multi_tag *tag = (struct multi_tag *) arg;
const char *virname;
#ifndef C_WINDOWS
sigset_t sigset;
#endif
int ret;
#ifndef C_WINDOWS
/* ignore all signals */
sigfillset(&sigset);
pthread_sigmask(SIG_SETMASK, &sigset, NULL);
#endif
ret = cl_scanfile(tag->fname, &virname, NULL, tag->root, tag->limits, tag->options);
@ -136,7 +149,7 @@ static int multiscan(const char *dirname, const struct cl_node *root, const stru
return -1;
}
#ifndef C_INTERIX
#if (!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(C_CYGWIN))
if(dent->d_ino)
#endif
{
@ -189,8 +202,10 @@ static int multiscan(const char *dirname, const struct cl_node *root, const stru
return -1;
}
#ifndef C_WINDOWS
while(!multi_pool->thr_idle) /* non-critical */
usleep(200);
#endif
}
}
}

@ -21,14 +21,22 @@
#include "clamav-config.h"
#endif
#ifdef _MSC_VER
#include <winsock.h>
#endif
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#ifndef C_WINDOWS
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif
#include <errno.h>
#ifndef C_WINDOWS
#include <netdb.h>
#endif
#include "libclamav/clamav.h"

@ -17,6 +17,10 @@
* MA 02110-1301, USA.
*/
#if HAVE_CONFIG_H
#include "clamav-config.h"
#endif
#include <stdio.h>
#include <pthread.h>
#include <time.h>

@ -21,7 +21,10 @@
#define __THRMGR_H__
#include <pthread.h>
#ifndef C_WINDOWS
#include <sys/time.h>
#endif
typedef struct work_item_tag {
struct work_item_tag *next;

Loading…
Cancel
Save