summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorJeffrey Altman <jaltman@secure-endpoints.com>2005-04-23 00:39:18 +0000
committerJeffrey Altman <jaltman@secure-endpoints.com>2005-04-23 00:39:18 +0000
commit6e2d8b4ed34bb438fc8d02389fd1944c67aa70ac (patch)
treef0e59628e36f72471cf334231f6b8ed247e8788a /src/lib
parent52f23f0938f33ee0c5d5f20d3d6be8e84e03a308 (diff)
downloadkrb5-6e2d8b4ed34bb438fc8d02389fd1944c67aa70ac.tar.gz
krb5-6e2d8b4ed34bb438fc8d02389fd1944c67aa70ac.tar.xz
krb5-6e2d8b4ed34bb438fc8d02389fd1944c67aa70ac.zip
Move WSAStartup/WSACleanup from DllMain to krb5_init_ctx/krb5_free_ctx
WSAStartup/WSACleanup cannot be called from DllMain without risking a deadlock when FreeLibrary(). ticket:2980 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@17200 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ChangeLog5
-rw-r--r--src/lib/krb5/os/ChangeLog8
-rw-r--r--src/lib/krb5/os/init_os_ctx.c25
-rw-r--r--src/lib/win_glue.c43
4 files changed, 34 insertions, 47 deletions
diff --git a/src/lib/ChangeLog b/src/lib/ChangeLog
index 06d067515..4ef1d3109 100644
--- a/src/lib/ChangeLog
+++ b/src/lib/ChangeLog
@@ -1,3 +1,8 @@
+2005-04-22 Jeffrey Altman <jaltman@mit.edu>
+
+ * win_glue.c: Remove calls to WSAStartup/WSACleanup because
+ they can result in deadlocks when called from DllMain().
+
2005-04-13 Ken Raeburn <raeburn@mit.edu>
* win_glue.c (NEED_SOCKETS): Don't define.
diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog
index 294be82db..a082c4952 100644
--- a/src/lib/krb5/os/ChangeLog
+++ b/src/lib/krb5/os/ChangeLog
@@ -1,3 +1,11 @@
+2005-04-22 Jeffrey Altman <jaltman@mit.edu>
+
+ * 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-04-13 Ken Raeburn <raeburn@mit.edu>
* accessor.c (NEED_SOCKETS): Don't define.
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 <winsock.h>
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 4d1800a92..3b2cbc599 100644
--- a/src/lib/win_glue.c
+++ b/src/lib/win_glue.c
@@ -1,32 +1,8 @@
-/*
- * 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 <kerberosIV/krb.h>
#endif
#include "k5-int.h"
-#ifndef NEED_WINSOCK
-#if defined(KRB4) || defined(KRB5) || defined(GSSAPI)
-#define NEED_WINSOCK 1
-#endif
-#endif
-
#ifdef KRB4
#include <kerberosIV/krb_err.h>
#include <kerberosIV/kadm_err.h>
@@ -365,33 +341,14 @@ 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;
#if defined(ENABLE_THREADS) && defined(SUPPORTLIB)