pullup from trunk
authorTom Yu <tlyu@mit.edu>
Tue, 12 Jul 2005 21:45:01 +0000 (21:45 +0000)
committerTom Yu <tlyu@mit.edu>
Tue, 12 Jul 2005 21:45:01 +0000 (21:45 +0000)
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
src/lib/krb5/os/ChangeLog
src/lib/krb5/os/init_os_ctx.c
src/lib/win_glue.c

index a31df26523de170da62fec92997f5b396d3c300c..210a11bc0a42d9a13e334b2ebb0d321f53d7df1d 100644 (file)
@@ -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-02-16  Jeffrey Altman <jaltman@mit.edu>
 
         * gssapi32.def: export the missing DATA symbols
index 1823a2fcb3383cb0c743e3dd0b2d18874065c3ab..d3e7a8595b7c2d2cf73d355ac1268e9d0167f3cd 100644 (file)
@@ -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-03-22  Tom Yu  <tlyu@mit.edu>
 
        * dnsglue.h: Define ns_rr_class to ns_rr_cl if ns_rr_class doesn't
index 0dd7cccd62a3982063ea99107d2d3f09dec4c73e..f4f9b690a085e8f717f757629e96f2dd27f80239 100644 (file)
@@ -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 */
 }
index 05b2a8aa7ab2a56e55709fdc57f651322d517be3..568ccc93837f60f25228953e613d07a7e279a9bc 100644 (file)
@@ -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 <kerberosIV/krb.h>
 #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 <kerberosIV/krb_err.h>
 #include <kerberosIV/kadm_err.h>
@@ -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;