From a0283d44038f8b2f91746b7c3bb86538cfc56a02 Mon Sep 17 00:00:00 2001 From: Tomasz Kojm Date: Mon, 5 Apr 2004 13:30:09 +0000 Subject: [PATCH] respect TCPAddr git-svn: trunk@471 --- clamav-devel/ChangeLog | 5 +++++ clamav-devel/clamd/scanner.c | 24 +++++++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/clamav-devel/ChangeLog b/clamav-devel/ChangeLog index b3a98e60e..748e62d8a 100644 --- a/clamav-devel/ChangeLog +++ b/clamav-devel/ChangeLog @@ -1,3 +1,8 @@ +Mon Apr 5 15:39:55 CEST 2004 (tk) +---------------------------------- + * clamd: respect TCPAddr in stream scanner (problem reported by + Youza Youzovic ) + Mon Apr 5 13:19:02 BST 2004 (njh) ---------------------------------- * libclamav: Scan attachments with no filename (suggestion by Trog) diff --git a/clamav-devel/clamd/scanner.c b/clamav-devel/clamd/scanner.c index a19f7cc84..fe8d2f1b8 100644 --- a/clamav-devel/clamd/scanner.c +++ b/clamav-devel/clamd/scanner.c @@ -29,10 +29,10 @@ #include #include #include -#include #include #include -#include +#include +#include #include #include "cfgparser.h" @@ -198,8 +198,9 @@ int scanstream(int odesc, unsigned long int *scanned, const struct cl_node *root long int size = 0, maxsize = 0; short bound = 0; const char *virname; - char buff[32768]; + char buff[FILEBUFF]; struct sockaddr_in server; + struct hostent *he; struct cfgstruct *cpt; FILE *tmp = NULL; @@ -210,7 +211,16 @@ int scanstream(int odesc, unsigned long int *scanned, const struct cl_node *root memset((char *) &server, 0, sizeof(server)); server.sin_family = AF_INET; server.sin_port = htons(port); - server.sin_addr.s_addr = INADDR_ANY; + + if((cpt = cfgopt(copt, "TCPAddr"))) { + if ((he = gethostbyname(cpt->strarg)) == 0) { + logg("!gethostbyname(%s) error: %s\n", cpt->strarg); + mdprintf(odesc, "gethostbyname(%s) ERROR\n", cpt->strarg); + return -1; + } + server.sin_addr = *(struct in_addr *) he->h_addr_list[0]; + } else + server.sin_addr.s_addr = INADDR_ANY; if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) continue; @@ -232,8 +242,8 @@ int scanstream(int odesc, unsigned long int *scanned, const struct cl_node *root } if(!bound && !portscan) { - mdprintf(odesc, "ERROR\n"); logg("!ScanStream: Can't find any free port.\n"); + mdprintf(odesc, "Can't find any free port ERROR\n"); return -1; } else { listen(sockfd, 1); @@ -243,11 +253,11 @@ int scanstream(int odesc, unsigned long int *scanned, const struct cl_node *root retval = poll_fd(sockfd, timeout); switch (retval) { case 0: /* timeout */ - mdprintf(sockfd, "ERROR\n"); + mdprintf(sockfd, "Accept timeout ERROR\n"); logg("!ScanStream: accept timeout.\n"); return -1; case -1: - mdprintf(sockfd, "ERROR\n"); + mdprintf(sockfd, "accept poll ERROR\n"); logg("!ScanStream: accept poll failed.\n"); return -1; }