From 264b72d0c05b5b5c323b4d1ec4e8b86303685547 Mon Sep 17 00:00:00 2001 From: Tom Yu Date: Tue, 12 Jul 2005 21:45:01 +0000 Subject: [PATCH] pullup from trunk ticket: 2980 version_fixed: 1.4.2 git-svn-id: svn://anonsvn.mit.edu/krb5/branches/krb5-1-4@17302 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/ChangeLog | 5 ++++ src/lib/krb5/os/ChangeLog | 8 +++++++ src/lib/krb5/os/init_os_ctx.c | 25 ++++++++++++++++---- src/lib/win_glue.c | 43 ----------------------------------- 4 files changed, 34 insertions(+), 47 deletions(-) diff --git a/src/lib/ChangeLog b/src/lib/ChangeLog index a31df2652..210a11bc0 100644 --- a/src/lib/ChangeLog +++ b/src/lib/ChangeLog @@ -1,3 +1,8 @@ +2005-04-22 Jeffrey Altman + + * win_glue.c: Remove calls to WSAStartup/WSACleanup because + they can result in deadlocks when called from DllMain(). + 2005-02-16 Jeffrey Altman * gssapi32.def: export the missing DATA symbols diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog index 1823a2fcb..d3e7a8595 100644 --- a/src/lib/krb5/os/ChangeLog +++ b/src/lib/krb5/os/ChangeLog @@ -1,3 +1,11 @@ +2005-04-22 Jeffrey Altman + + * init_os_ctx.c: use krb5_init_ctx and krb5_free_ctx + to initialize and cleanup the winsock stack. WSAStartup/ + WSACleanup are only supposed to increment/decrement a + reference counter if they have been previously called + within the application. + 2005-03-22 Tom Yu * dnsglue.h: Define ns_rr_class to ns_rr_cl if ns_rr_class doesn't diff --git a/src/lib/krb5/os/init_os_ctx.c b/src/lib/krb5/os/init_os_ctx.c index 0dd7cccd6..f4f9b690a 100644 --- a/src/lib/krb5/os/init_os_ctx.c +++ b/src/lib/krb5/os/init_os_ctx.c @@ -36,6 +36,7 @@ #endif #if defined(_WIN32) +#include static krb5_error_code get_from_windows_dir( @@ -342,6 +343,10 @@ krb5_os_init_context(krb5_context ctx) { krb5_os_context os_ctx; krb5_error_code retval = 0; +#ifdef _WIN32 + WORD wVersionRequested; + WSADATA wsaData; +#endif /* _WIN32 */ os_ctx = ctx->os_context; os_ctx->magic = KV5M_OS_CONTEXT; @@ -350,15 +355,23 @@ krb5_os_init_context(krb5_context ctx) os_ctx->os_flags = 0; os_ctx->default_ccname = 0; - krb5_cc_set_default_name(ctx, NULL); - retval = os_init_paths(ctx); - /* * If there's an error in the profile, return an error. Just * ignoring the error is a Bad Thing (tm). */ - + + if (!retval) { + krb5_cc_set_default_name(ctx, NULL); + +#ifdef _WIN32 + /* We initialize winsock to version 1.1 but + * we do not care if we succeed or fail. + */ + wVersionRequested = 0x0101; + WSAStartup (wVersionRequested, &wsaData); +#endif /* _WIN32 */ + } return retval; } @@ -464,4 +477,8 @@ krb5_os_free_context(krb5_context ctx) profile_release(ctx->profile); ctx->profile = 0; } + +#ifdef _WIN32 + WSACleanup(); +#endif /* _WIN32 */ } diff --git a/src/lib/win_glue.c b/src/lib/win_glue.c index 05b2a8aa7..568ccc938 100644 --- a/src/lib/win_glue.c +++ b/src/lib/win_glue.c @@ -1,33 +1,9 @@ -/* - * WinSock support. - * - * Do the WinSock initialization call, keeping all the hair here. - * - * This routine is called by SOCKET_INITIALIZE in include/c-windows.h. - * The code is pretty much copied from winsock.txt from winsock-1.1, - * available from: - * ftp://sunsite.unc.edu/pub/micro/pc-stuff/ms-windows/winsock/winsock-1.1 - * - * Note: WSAStartup and WSACleanup is called here (and only here). - * This assumes that under Windows, we only use this library via the - * DLL. Note that calls to WSAStartup and WSACleanup must be in - * matched pairs. If there is a missing WSACleanup call when a - * program exits, under Lan Workplace, the name resolver will stop - * working. - */ - #ifdef KRB4 #include #endif #define NEED_SOCKETS #include "k5-int.h" -#ifndef NEED_WINSOCK -#if defined(KRB4) || defined(KRB5) || defined(GSSAPI) -#define NEED_WINSOCK 1 -#endif -#endif - #ifdef KRB4 #include #include @@ -366,32 +342,13 @@ HINSTANCE get_lib_instance() static int control(int mode) { -#ifdef NEED_WINSOCK - WORD wVersionRequested; - WSADATA wsaData; - int err; -#endif - switch(mode) { case DLL_STARTUP: -#ifdef NEED_WINSOCK - wVersionRequested = 0x0101; /* We need version 1.1 */ - if ((err = WSAStartup (wVersionRequested, &wsaData))) - return err; - if (wVersionRequested != wsaData.wVersion) { - /* DLL couldn't support our version of the spec */ - WSACleanup (); - return -104; /* FIXME -- better error? */ - } -#endif break; case DLL_SHUTDOWN: #ifdef KRB5 krb5_stdcc_shutdown(); -#endif -#ifdef NEED_WINSOCK - WSACleanup (); #endif break; -- 2.26.2