Browse code

use reentrant version of gethostbyname when available

git-svn: trunk@1701

Tomasz Kojm authored on 2005/08/21 08:09:11
Showing 6 changed files
... ...
@@ -1,3 +1,7 @@
1
+Sun Aug 21 01:06:54 CEST 2005 (tk)
2
+----------------------------------
3
+  * clamd: use reentrant version of gethostbyname when available
4
+
1 5
 Sun Aug 21 00:32:10 CEST 2005 (tk)
2 6
 ----------------------------------
3 7
   * shared/network.[ch]: new files (include r_gethostbyname by NJH)
... ...
@@ -30,6 +30,8 @@ clamd_SOURCES = \
30 30
     $(top_srcdir)/shared/memory.h \
31 31
     $(top_srcdir)/shared/misc.c \
32 32
     $(top_srcdir)/shared/misc.h \
33
+    $(top_srcdir)/shared/network.c \
34
+    $(top_srcdir)/shared/network.h \
33 35
     options.c \
34 36
     options.h \
35 37
     clamd.c \
... ...
@@ -75,7 +75,8 @@ am__clamd_SOURCES_DIST = $(top_srcdir)/shared/output.c \
75 75
 	$(top_srcdir)/shared/cfgparser.h $(top_srcdir)/shared/getopt.c \
76 76
 	$(top_srcdir)/shared/getopt.h $(top_srcdir)/shared/memory.c \
77 77
 	$(top_srcdir)/shared/memory.h $(top_srcdir)/shared/misc.c \
78
-	$(top_srcdir)/shared/misc.h options.c options.h clamd.c \
78
+	$(top_srcdir)/shared/misc.h $(top_srcdir)/shared/network.c \
79
+	$(top_srcdir)/shared/network.h options.c options.h clamd.c \
79 80
 	tcpserver.c tcpserver.h localserver.c localserver.h session.c \
80 81
 	session.h thrmgr.c thrmgr.h server-th.c server.h scanner.c \
81 82
 	scanner.h others.c others.h clamuko.c clamuko.h \
... ...
@@ -84,11 +85,12 @@ am__clamd_SOURCES_DIST = $(top_srcdir)/shared/output.c \
84 84
 @BUILD_CLAMD_TRUE@am_clamd_OBJECTS = output.$(OBJEXT) \
85 85
 @BUILD_CLAMD_TRUE@	cfgparser.$(OBJEXT) getopt.$(OBJEXT) \
86 86
 @BUILD_CLAMD_TRUE@	memory.$(OBJEXT) misc.$(OBJEXT) \
87
-@BUILD_CLAMD_TRUE@	options.$(OBJEXT) clamd.$(OBJEXT) \
88
-@BUILD_CLAMD_TRUE@	tcpserver.$(OBJEXT) localserver.$(OBJEXT) \
89
-@BUILD_CLAMD_TRUE@	session.$(OBJEXT) thrmgr.$(OBJEXT) \
90
-@BUILD_CLAMD_TRUE@	server-th.$(OBJEXT) scanner.$(OBJEXT) \
91
-@BUILD_CLAMD_TRUE@	others.$(OBJEXT) clamuko.$(OBJEXT) \
87
+@BUILD_CLAMD_TRUE@	network.$(OBJEXT) options.$(OBJEXT) \
88
+@BUILD_CLAMD_TRUE@	clamd.$(OBJEXT) tcpserver.$(OBJEXT) \
89
+@BUILD_CLAMD_TRUE@	localserver.$(OBJEXT) session.$(OBJEXT) \
90
+@BUILD_CLAMD_TRUE@	thrmgr.$(OBJEXT) server-th.$(OBJEXT) \
91
+@BUILD_CLAMD_TRUE@	scanner.$(OBJEXT) others.$(OBJEXT) \
92
+@BUILD_CLAMD_TRUE@	clamuko.$(OBJEXT) \
92 93
 @BUILD_CLAMD_TRUE@	dazukoio_compat12.$(OBJEXT) \
93 94
 @BUILD_CLAMD_TRUE@	dazukoio.$(OBJEXT)
94 95
 clamd_OBJECTS = $(am_clamd_OBJECTS)
... ...
@@ -228,6 +230,8 @@ target_vendor = @target_vendor@
228 228
 @BUILD_CLAMD_TRUE@    $(top_srcdir)/shared/memory.h \
229 229
 @BUILD_CLAMD_TRUE@    $(top_srcdir)/shared/misc.c \
230 230
 @BUILD_CLAMD_TRUE@    $(top_srcdir)/shared/misc.h \
231
+@BUILD_CLAMD_TRUE@    $(top_srcdir)/shared/network.c \
232
+@BUILD_CLAMD_TRUE@    $(top_srcdir)/shared/network.h \
231 233
 @BUILD_CLAMD_TRUE@    options.c \
232 234
 @BUILD_CLAMD_TRUE@    options.h \
233 235
 @BUILD_CLAMD_TRUE@    clamd.c \
... ...
@@ -336,6 +340,7 @@ distclean-compile:
336 336
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/localserver.Po@am__quote@
337 337
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/memory.Po@am__quote@
338 338
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/misc.Po@am__quote@
339
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/network.Po@am__quote@
339 340
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/options.Po@am__quote@
340 341
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/others.Po@am__quote@
341 342
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/output.Po@am__quote@
... ...
@@ -436,6 +441,20 @@ misc.obj: $(top_srcdir)/shared/misc.c
436 436
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
437 437
 @am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o misc.obj `if test -f '$(top_srcdir)/shared/misc.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/misc.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/misc.c'; fi`
438 438
 
439
+network.o: $(top_srcdir)/shared/network.c
440
+@am__fastdepCC_TRUE@	if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT network.o -MD -MP -MF "$(DEPDIR)/network.Tpo" -c -o network.o `test -f '$(top_srcdir)/shared/network.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/network.c; \
441
+@am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/network.Tpo" "$(DEPDIR)/network.Po"; else rm -f "$(DEPDIR)/network.Tpo"; exit 1; fi
442
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$(top_srcdir)/shared/network.c' object='network.o' libtool=no @AMDEPBACKSLASH@
443
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
444
+@am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o network.o `test -f '$(top_srcdir)/shared/network.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/network.c
445
+
446
+network.obj: $(top_srcdir)/shared/network.c
447
+@am__fastdepCC_TRUE@	if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT network.obj -MD -MP -MF "$(DEPDIR)/network.Tpo" -c -o network.obj `if test -f '$(top_srcdir)/shared/network.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/network.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/network.c'; fi`; \
448
+@am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/network.Tpo" "$(DEPDIR)/network.Po"; else rm -f "$(DEPDIR)/network.Tpo"; exit 1; fi
449
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$(top_srcdir)/shared/network.c' object='network.obj' libtool=no @AMDEPBACKSLASH@
450
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
451
+@am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o network.obj `if test -f '$(top_srcdir)/shared/network.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/network.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/network.c'; fi`
452
+
439 453
 mostlyclean-libtool:
440 454
 	-rm -f *.lo
441 455
 
... ...
@@ -24,6 +24,7 @@
24 24
 #include <stdlib.h>
25 25
 #include <string.h>
26 26
 #include <unistd.h>
27
+#include <errno.h>
27 28
 #include <sys/stat.h>
28 29
 #include <sys/types.h>
29 30
 #include <sys/time.h>
... ...
@@ -48,6 +49,7 @@
48 48
 #include "memory.h"
49 49
 #include "shared.h"
50 50
 #include "output.h"
51
+#include "network.h"
51 52
 
52 53
 #include "../libclamav/others.h"
53 54
 
... ...
@@ -66,8 +68,6 @@ dev_t procdev; /* /proc device */
66 66
 # endif
67 67
 #endif
68 68
 
69
-pthread_mutex_t gh_mutex = PTHREAD_MUTEX_INITIALIZER;
70
-
71 69
 int checksymlink(const char *path)
72 70
 {
73 71
 	struct stat statbuf;
... ...
@@ -299,7 +299,7 @@ int scanstream(int odesc, unsigned long int *scanned, const struct cl_node *root
299 299
 	const char *virname;
300 300
 	char buff[FILEBUFF];
301 301
 	struct sockaddr_in server;
302
-	struct hostent *he;
302
+	struct hostent he;
303 303
 	struct cfgstruct *cpt;
304 304
 	char *tmpname;
305 305
 
... ...
@@ -331,15 +331,12 @@ int scanstream(int odesc, unsigned long int *scanned, const struct cl_node *root
331 331
 	server.sin_port = htons(port);
332 332
 
333 333
 	if((cpt = cfgopt(copt, "TCPAddr"))->enabled) {
334
-	    pthread_mutex_lock(&gh_mutex);
335
-	    if((he = gethostbyname(cpt->strarg)) == 0) {
336
-		logg("!gethostbyname(%s) error: %s\n", cpt->strarg);
337
-		mdprintf(odesc, "gethostbyname(%s) ERROR\n", cpt->strarg);
338
-		pthread_mutex_unlock(&gh_mutex);
334
+	    if(r_gethostbyname(cpt->strarg, &he, buff, sizeof(buff)) == -1) {
335
+		logg("!r_gethostbyname(%s) error: %s\n", cpt->strarg, strerror(errno));
336
+		mdprintf(odesc, "r_gethostbyname(%s) ERROR\n", cpt->strarg);
339 337
 		return -1;
340 338
 	    }
341
-	    server.sin_addr = *(struct in_addr *) he->h_addr_list[0];
342
-	    pthread_mutex_unlock(&gh_mutex);
339
+	    server.sin_addr = *(struct in_addr *) he.h_addr_list[0];
343 340
 	} else
344 341
 	    server.sin_addr.s_addr = INADDR_ANY;
345 342
 
... ...
@@ -42,8 +42,8 @@ int tcpserver(const struct cfgstruct *copt, struct cl_node *root)
42 42
 	int sockfd, backlog;
43 43
 	struct cfgstruct *cpt;
44 44
 	struct cfgstruct *taddr;
45
-	struct hostent *he;
46
-	char *estr;
45
+	struct hostent he;
46
+	char *estr, buf[1024];
47 47
 	int true = 1;
48 48
 
49 49
     memset((char *) &server, 0, sizeof(server));
... ...
@@ -51,11 +51,11 @@ int tcpserver(const struct cfgstruct *copt, struct cl_node *root)
51 51
     server.sin_port = htons(cfgopt(copt, "TCPSocket")->numarg);
52 52
 
53 53
     if((taddr = cfgopt(copt, "TCPAddr"))->enabled) {
54
-	if ((he = gethostbyname(taddr->strarg)) == 0) {
55
-	    logg("!gethostbyname(%s) error: %s\n", taddr->strarg, strerror(errno));
54
+	if(r_gethostbyname(taddr->strarg, &he, buf, sizeof(buf)) == -1) {
55
+	    logg("!r_gethostbyname(%s) error: %s\n", taddr->strarg, strerror(errno));
56 56
 	    exit(1);
57 57
 	}
58
-	server.sin_addr = *(struct in_addr *) he->h_addr_list[0];
58
+	server.sin_addr = *(struct in_addr *) he.h_addr_list[0];
59 59
     } else
60 60
 	server.sin_addr.s_addr = INADDR_ANY;
61 61
 
... ...
@@ -85,4 +85,5 @@ int r_gethostbyname(const char *hostname, struct hostent *hp, char *buf, size_t
85 85
 #endif
86 86
 
87 87
 	return 0;
88
+#endif
88 89
 }