xp-sp2-fix-plus-20040810
authorJeffrey Altman <jaltman@mit.edu>
Tue, 10 Aug 2004 01:16:34 +0000 (01:16 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Tue, 10 Aug 2004 01:16:34 +0000 (01:16 +0000)
The XP SP2 problem was caused by attempting to call bind() from
within DllMain which is no longer permitted.  Added a new function
AfsLogonInit() which is called from every entry point to ensure
that the necessary initializaton is performed.

Cleaned up the prior fix to smb3.c to better test the invalid
conditions.

src/WINNT/afsd/afslogon.c
src/WINNT/afsd/smb3.c

index 15feb9b..3e63daa 100644 (file)
@@ -63,6 +63,47 @@ void DebugEvent(char *b,...)
        va_end(marker);
 }
 
+static HANDLE hInitMutex = NULL;
+static BOOL bInit = FALSE;
+
+BOOLEAN APIENTRY DllEntryPoint(HANDLE dll, DWORD reason, PVOID reserved)
+{
+       hDLL = dll;
+       switch (reason) {
+    case DLL_PROCESS_ATTACH:
+        /* Initialization Mutex */
+        hInitMutex = CreateMutex(NULL, FALSE, NULL);
+        break;
+
+    case DLL_PROCESS_DETACH:
+        CloseHandle(hInitMutex);
+        break;
+
+    case DLL_THREAD_ATTACH:
+    case DLL_THREAD_DETACH:
+    default:
+               /* Everything else succeeds but does nothing. */
+        break;
+       }
+
+       return TRUE;
+}
+
+void AfsLogonInit(void)
+{
+    if ( bInit == FALSE ) {
+         if ( WaitForSingleObject( hInitMutex, INFINITE ) == WAIT_OBJECT_0 ) {
+             if ( bInit == FALSE ) {
+                 rx_Init(0);
+                 initAFSDirPath();
+                 ka_Init(0);
+                 bInit = TRUE;
+             }
+             ReleaseMutex(hInitMutex);
+         }
+    }
+}
+
 CHAR *GenRandomName(CHAR *pbuf)
 {
        int i;
@@ -139,28 +180,6 @@ DWORD MapAuthError(DWORD code)
        }
 }
 
-BOOLEAN APIENTRY DllEntryPoint(HANDLE dll, DWORD reason, PVOID reserved)
-{
-       hDLL = dll;
-       switch (reason) {
-               case DLL_PROCESS_ATTACH:
-                       /* Initialize AFS libraries */
-                       rx_Init(0);
-            initAFSDirPath();
-                       ka_Init(0);
-                       break;
-
-               /* Everything else succeeds but does nothing. */
-               case DLL_PROCESS_DETACH:
-               case DLL_THREAD_ATTACH:
-               case DLL_THREAD_DETACH:
-               default:
-                       break;
-       }
-
-       return TRUE;
-}
-
 DWORD APIENTRY NPGetCaps(DWORD index)
 {
        switch (index) {
@@ -551,6 +570,9 @@ DWORD APIENTRY NPLogonNotify(
        int retryInterval;
        int sleepInterval;
 
+    /* Make sure the AFS Libraries are initialized */
+    AfsLogonInit();
+
     /* Initialize Logon Script to none */
        *lpLogonScript=NULL;
     
@@ -772,6 +794,9 @@ DWORD APIENTRY NPPasswordChangeNotify(
        LPVOID StationHandle,
        DWORD dwChangeInfo)
 {
+    /* Make sure the AFS Libraries are initialized */
+    AfsLogonInit();
+
        DebugEvent0("AFS AfsLogon - NPPasswordChangeNotify");
        return 0;
 }
@@ -815,6 +840,9 @@ VOID AFS_Startup_Event( PWLX_NOTIFICATION_INFO pInfo )
        DWORD LSPtype, LSPsize;
        HKEY NPKey;
 
+    /* Make sure the AFS Libraries are initialized */
+    AfsLogonInit();
+
     (void) RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_CLIENT_PARMS_KEY,
                         0, KEY_QUERY_VALUE, &NPKey);
        LSPsize=sizeof(TraceOption);
@@ -834,6 +862,9 @@ VOID AFS_Logoff_Event( PWLX_NOTIFICATION_INFO pInfo )
     DWORD  retLen;
     HANDLE hToken;
 
+    /* Make sure the AFS Libraries are initialized */
+    AfsLogonInit();
+
     DebugEvent0("AFS_Logoff_Event - Starting");
 
     if (!GetTokenInformation(pInfo->hToken, TokenUser, NULL, 0, &retLen))
index 2f8b324..8abd382 100644 (file)
@@ -1292,11 +1292,11 @@ long smb_ReceiveV3Trans(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp)
     }   
 
     /* now copy the parms and data */
-    if ( parmCount != 0 )
+    if ( asp->totalParms > 0 && parmCount != 0 )
     {
         memcpy(((char *)asp->parmsp) + parmDisp, inp->data + parmOffset, parmCount);
     }
-    if ( dataCount != 0 ) {
+    if ( asp->totalData > 0 && dataCount != 0 ) {
         memcpy(asp->datap + dataDisp, inp->data + dataOffset, dataCount);
     }
 
@@ -1305,8 +1305,9 @@ long smb_ReceiveV3Trans(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp)
     asp->curParms += parmCount;
 
     /* finally, if we're done, remove the packet from the queue and dispatch it */
-    if (asp->curData > 0 && asp->curParms > 0 && 
-        asp->totalData <= asp->curData && 
+    if (asp->totalParms > 0 &&
+        asp->curParms > 0 &&
+        asp->totalData <= asp->curData &&
         asp->totalParms <= asp->curParms) {
                /* we've received it all */
         lock_ObtainWrite(&smb_globalLock);