From: Mark Andrews Date: Mon, 18 Jun 2007 03:30:31 +0000 (+0000) Subject: 2199. [bug] win32: don't call WSAStartup() while loading dlls. X-Git-Tag: v9.2.0b1^2~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f97a7411019620a4fd3998139342a3d5224d5bed;p=thirdparty%2Fbind9.git 2199. [bug] win32: don't call WSAStartup() while loading dlls. [RT #16911] --- diff --git a/CHANGES b/CHANGES index 2db02df30ce..724c1164050 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +2199. [bug] win32: don't call WSAStartup() while loading dlls. + [RT #16911] + 2198. [bug] win32: RegCloseKey() could be called when RegOpenKeyEx() failed. [RT #16911] diff --git a/lib/dns/win32/DLLMain.c b/lib/dns/win32/DLLMain.c index aa05e28f0f3..aed78c7038c 100644 --- a/lib/dns/win32/DLLMain.c +++ b/lib/dns/win32/DLLMain.c @@ -15,13 +15,11 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: DLLMain.c,v 1.3.2.1 2004/03/09 06:11:43 marka Exp $ */ +/* $Id: DLLMain.c,v 1.3.2.2 2007/06/18 03:30:31 marka Exp $ */ #include #include -BOOL InitSockets(void); - /* * Called when we enter the DLL */ diff --git a/lib/isc/win32/DLLMain.c b/lib/isc/win32/DLLMain.c index 1009912eeee..6767cef5b0a 100644 --- a/lib/isc/win32/DLLMain.c +++ b/lib/isc/win32/DLLMain.c @@ -15,13 +15,11 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: DLLMain.c,v 1.3.2.2 2004/03/09 06:12:16 marka Exp $ */ +/* $Id: DLLMain.c,v 1.3.2.3 2007/06/18 03:30:31 marka Exp $ */ #include #include -BOOL InitSockets(void); - /* * Called when we enter the DLL */ @@ -35,8 +33,6 @@ __declspec(dllexport) BOOL WINAPI DllMain(HINSTANCE hinstDLL, * initialization or a call to LoadLibrary. */ case DLL_PROCESS_ATTACH: - if (!InitSockets()) - return (FALSE); break; /* The attached process creates a new thread. */ diff --git a/lib/isc/win32/interfaceiter.c b/lib/isc/win32/interfaceiter.c index 550ba71922f..e7c8017ceb9 100644 --- a/lib/isc/win32/interfaceiter.c +++ b/lib/isc/win32/interfaceiter.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: interfaceiter.c,v 1.4.2.1 2004/03/09 06:12:18 marka Exp $ */ +/* $Id: interfaceiter.c,v 1.4.2.2 2007/06/18 03:30:31 marka Exp $ */ /* * Note that this code will need to be revisited to support IPv6 Interfaces. @@ -39,6 +39,8 @@ #include #include "errno2result.h" +void InitSockets(void); + /* Common utility functions */ /* @@ -114,6 +116,8 @@ isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) { if (iter == NULL) return (ISC_R_NOMEMORY); + InitSockets(); + iter->mctx = mctx; iter->buf = NULL; diff --git a/lib/isc/win32/net.c b/lib/isc/win32/net.c index 6abe5cfb12f..b58a3837b8e 100644 --- a/lib/isc/win32/net.c +++ b/lib/isc/win32/net.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: net.c,v 1.3.2.3 2004/03/09 06:12:18 marka Exp $ */ +/* $Id: net.c,v 1.3.2.4 2007/06/18 03:30:31 marka Exp $ */ #include @@ -37,6 +37,8 @@ static isc_once_t once = ISC_ONCE_INIT; static isc_result_t ipv4_result = ISC_R_NOTFOUND; static isc_result_t ipv6_result = ISC_R_NOTFOUND; +void InitSockets(void); + static isc_result_t try_proto(int domain) { SOCKET s; @@ -112,6 +114,7 @@ try_proto(int domain) { static void initialize_action(void) { + InitSockets(); ipv4_result = try_proto(PF_INET); #ifdef ISC_PLATFORM_HAVEIPV6 #ifdef WANT_IPV6 diff --git a/lib/isc/win32/socket.c b/lib/isc/win32/socket.c index 2068c4c7c95..72f7a7964f4 100644 --- a/lib/isc/win32/socket.c +++ b/lib/isc/win32/socket.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: socket.c,v 1.5.2.32 2007/02/01 23:55:18 marka Exp $ */ +/* $Id: socket.c,v 1.5.2.33 2007/06/18 03:30:31 marka Exp $ */ /* This code has been rewritten to take advantage of Windows Sockets * I/O Completion Ports and Events. I/O Completion Ports is ONLY @@ -77,6 +77,7 @@ #include #include #include +#include #include #include #include @@ -899,10 +900,11 @@ socket_close(isc_socket_t *sock) { } } -/* - * Initialize socket services - */ -BOOL InitSockets() { +static isc_once_t initialise_once = ISC_ONCE_INIT; +static isc_boolean_t initialised = ISC_FALSE; + +static void +initialise(void) { WORD wVersionRequested; WSADATA wsaData; int err; @@ -911,11 +913,26 @@ BOOL InitSockets() { wVersionRequested = MAKEWORD(2, 0); err = WSAStartup(wVersionRequested, &wsaData); - if ( err != 0 ) { - /* Tell the user that we could not find a usable Winsock DLL */ - return(FALSE); - } - return(TRUE); + if (err != 0) { + char strbuf[ISC_STRERRORSIZE]; + isc__strerror(err, strbuf, sizeof(strbuf)); + FATAL_ERROR(__FILE__, __LINE__, "WSAStartup() %s: %s", + isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL, + ISC_MSG_FAILED, "failed"), + strbuf); + } else + initialised = ISC_TRUE; +} + +/* + * Initialize socket services + */ +void +InitSockets(void) { + RUNTIME_CHECK(isc_once_do(&initialise_once, + initialise) == ISC_R_SUCCESS); + if (!initialised) + exit(1); } int @@ -2746,6 +2763,8 @@ isc_socketmgr_create(isc_mem_t *mctx, isc_socketmgr_t **managerp) { if (manager == NULL) return (ISC_R_NOMEMORY); + InitSockets(); + manager->magic = SOCKET_MANAGER_MAGIC; manager->mctx = NULL; ISC_LIST_INIT(manager->socklist); diff --git a/lib/isccc/win32/DLLMain.c b/lib/isccc/win32/DLLMain.c index 1d8d11d360d..b4a15c32055 100644 --- a/lib/isccc/win32/DLLMain.c +++ b/lib/isccc/win32/DLLMain.c @@ -15,13 +15,11 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: DLLMain.c,v 1.3.2.1 2004/03/09 06:12:29 marka Exp $ */ +/* $Id: DLLMain.c,v 1.3.2.2 2007/06/18 03:30:31 marka Exp $ */ #include #include -BOOL InitSockets(void); - /* * Called when we enter the DLL */ diff --git a/lib/isccfg/win32/DLLMain.c b/lib/isccfg/win32/DLLMain.c index 3ada9977f05..defb570e31b 100644 --- a/lib/isccfg/win32/DLLMain.c +++ b/lib/isccfg/win32/DLLMain.c @@ -15,13 +15,11 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: DLLMain.c,v 1.3.2.1 2004/03/09 06:12:32 marka Exp $ */ +/* $Id: DLLMain.c,v 1.3.2.2 2007/06/18 03:30:31 marka Exp $ */ #include #include -BOOL InitSockets(void); - /* * Called when we enter the DLL */ diff --git a/lib/lwres/context.c b/lib/lwres/context.c index f80f294f666..12d5afe75fb 100644 --- a/lib/lwres/context.c +++ b/lib/lwres/context.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: context.c,v 1.41.2.4 2004/09/17 05:57:20 marka Exp $ */ +/* $Id: context.c,v 1.41.2.5 2007/06/18 03:30:31 marka Exp $ */ #include @@ -128,6 +128,9 @@ lwres_context_destroy(lwres_context_t **contextp) { *contextp = NULL; if (ctx->sock != -1) { +#ifdef WIN32 + DestroySockets(); +#endif close(ctx->sock); ctx->sock = -1; } @@ -231,19 +234,34 @@ context_connect(lwres_context_t *ctx) { } else return (LWRES_R_IOERROR); +#ifdef WIN32 + InitSockets(); +#endif + s = socket(domain, SOCK_DGRAM, IPPROTO_UDP); - if (s < 0) + if (s < 0) { +#ifdef WIN32 + DestroySockets(); +#endif return (LWRES_R_IOERROR); + } ret = connect(s, sa, salen); if (ret != 0) { +#ifdef WIN32 + DestroySockets(); +#endif close(s); return (LWRES_R_IOERROR); } MAKE_NONBLOCKING(s, ret); - if (ret < 0) + if (ret < 0) { +#ifdef WIN32 + DestroySockets(); +#endif return (LWRES_R_IOERROR); + } ctx->sock = s; diff --git a/lib/lwres/getipnode.c b/lib/lwres/getipnode.c index fc5f61148db..6610bf79f0d 100644 --- a/lib/lwres/getipnode.c +++ b/lib/lwres/getipnode.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: getipnode.c,v 1.30.2.8 2005/04/28 23:59:13 marka Exp $ */ +/* $Id: getipnode.c,v 1.30.2.9 2007/06/18 03:30:31 marka Exp $ */ #include @@ -399,6 +399,9 @@ scan_interfaces(int *have_v4, int *have_v6) { static int bufsiz = 4095; int s, cpsize, n; +#ifdef WIN32 + InitSockets(); +#endif /* * Set to zero. Used as loop terminators below. */ @@ -519,13 +522,20 @@ scan_interfaces(int *have_v4, int *have_v6) { } if (buf != NULL) free(buf); +#ifdef WIN32 + DestroySockets(); +#endif close(s); return (0); + err_ret: if (buf != NULL) free(buf); if (s != -1) close(s); +#ifdef WIN32 + DestroySockets(); +#endif return (-1); #endif } diff --git a/lib/lwres/win32/DLLMain.c b/lib/lwres/win32/DLLMain.c index 0519bcaedfe..d613e80b0a1 100644 --- a/lib/lwres/win32/DLLMain.c +++ b/lib/lwres/win32/DLLMain.c @@ -15,13 +15,11 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: DLLMain.c,v 1.2.2.1 2004/03/09 06:12:42 marka Exp $ */ +/* $Id: DLLMain.c,v 1.2.2.2 2007/06/18 03:30:31 marka Exp $ */ #include #include -BOOL InitSockets(void); - /* * Called when we enter the DLL */ diff --git a/lib/lwres/win32/include/lwres/platform.h b/lib/lwres/win32/include/lwres/platform.h index 89539afce98..b2b32bd127f 100644 --- a/lib/lwres/win32/include/lwres/platform.h +++ b/lib/lwres/win32/include/lwres/platform.h @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: platform.h,v 1.4.2.1 2004/03/09 06:12:44 marka Exp $ */ +/* $Id: platform.h,v 1.4.2.2 2007/06/18 03:30:31 marka Exp $ */ #ifndef LWRES_PLATFORM_H #define LWRES_PLATFORM_H 1 @@ -92,4 +92,11 @@ do { \ #undef close #define close closesocket +/* + * Internal to liblwres. + */ +void InitSockets(void); + +void DestroySockets(void); + #endif /* LWRES_PLATFORM_H */ diff --git a/lib/lwres/win32/liblwres.dsp b/lib/lwres/win32/liblwres.dsp index b0a5b78e6cf..c6be9b74b46 100644 --- a/lib/lwres/win32/liblwres.dsp +++ b/lib/lwres/win32/liblwres.dsp @@ -174,6 +174,10 @@ SOURCE=..\lwresutil.c # End Source File # Begin Source File +SOURCE=.\socket.c +# End Source File +# Begin Source File + SOURCE=.\version.c # End Source File # End Group diff --git a/lib/lwres/win32/liblwres.mak b/lib/lwres/win32/liblwres.mak index b641a79a3b3..a0f16566550 100644 --- a/lib/lwres/win32/liblwres.mak +++ b/lib/lwres/win32/liblwres.mak @@ -129,7 +129,9 @@ CLEAN : -@erase "$(INTDIR)\lwres_grbn.obj" -@erase "$(INTDIR)\lwres_noop.obj" -@erase "$(INTDIR)\lwresutil.obj" + -@erase "$(INTDIR)\socket.obj" -@erase "$(INTDIR)\vc60.idb" + -@erase "$(INTDIR)\socket.obj" -@erase "$(INTDIR)\version.obj" -@erase "$(OUTDIR)\liblwres.exp" -@erase "$(OUTDIR)\liblwres.lib" @@ -204,6 +206,7 @@ LINK32_OBJS= \ "$(INTDIR)\lwres_grbn.obj" \ "$(INTDIR)\lwres_noop.obj" \ "$(INTDIR)\lwresutil.obj" \ + "$(INTDIR)\socket.obj" \ "$(INTDIR)\version.obj" "..\..\..\Build\Release\liblwres.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS) @@ -264,8 +267,12 @@ CLEAN : -@erase "$(INTDIR)\lwres_noop.sbr" -@erase "$(INTDIR)\lwresutil.obj" -@erase "$(INTDIR)\lwresutil.sbr" + -@erase "$(INTDIR)\socket.obj" + -@erase "$(INTDIR)\socket.sbr" -@erase "$(INTDIR)\vc60.idb" -@erase "$(INTDIR)\vc60.pdb" + -@erase "$(INTDIR)\socket.obj" + -@erase "$(INTDIR)\socket.sbr" -@erase "$(INTDIR)\version.obj" -@erase "$(INTDIR)\version.sbr" -@erase "$(OUTDIR)\liblwres.bsc" @@ -370,6 +377,7 @@ LINK32_OBJS= \ "$(INTDIR)\lwres_grbn.obj" \ "$(INTDIR)\lwres_noop.obj" \ "$(INTDIR)\lwresutil.obj" \ + "$(INTDIR)\socket.obj" \ "$(INTDIR)\version.obj" "..\..\..\Build\Debug\liblwres.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS) @@ -747,6 +755,22 @@ SOURCE=..\lwresutil.c $(CPP) $(CPP_PROJ) $(SOURCE) +!ENDIF + +SOURCE=.\socket.c + +!IF "$(CFG)" == "liblwres - Win32 Release" + + +"$(INTDIR)\socket.obj" : $(SOURCE) "$(INTDIR)" + + +!ELSEIF "$(CFG)" == "liblwres - Win32 Debug" + + +"$(INTDIR)\socket.obj" "$(INTDIR)\socket.sbr" : $(SOURCE) "$(INTDIR)" + + !ENDIF SOURCE=.\version.c