diff --git a/src/WINNT/afsd/afslogon.c b/src/WINNT/afsd/afslogon.c index 15feb9baab..3e63daa1fc 100644 --- a/src/WINNT/afsd/afslogon.c +++ b/src/WINNT/afsd/afslogon.c @@ -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)) diff --git a/src/WINNT/afsd/smb3.c b/src/WINNT/afsd/smb3.c index 2f8b3241de..8abd382152 100644 --- a/src/WINNT/afsd/smb3.c +++ b/src/WINNT/afsd/smb3.c @@ -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);