If Not AuthSeq.fInitialized Then AuthSeq.fInitialized = True End If
fDone = Not (ss = SEC_I_CONTINUE_NEEDED _ Or ss = SEC_I_COMPLETE_AND_CONTINUE)
GenServerContext = True
FreeResourcesAndExit:
If sbdOut.pBuffers <> 0 Then HeapFree GetProcessHeap(), 0, sbdOut.pBuffers End If
If sbdIn.pBuffers <> 0 Then HeapFree GetProcessHeap(), 0, sbdIn.pBuffers End If
End Function
Public Function SSPValidateUser(User As String, Domain As String, _ Password As String) As Boolean
Dim pSPI As Long Dim SPI As SecPkgInfo Dim cbMaxToken As Long
Dim pClientBuf As Long Dim pServerBuf As Long
Dim ai As SEC_WINNT_AUTH_IDENTITY
Dim asClient As AUTH_SEQ Dim asServer As AUTH_SEQ Dim cbIn As Long Dim cbOut As Long Dim fDone As Boolean
Dim osinfo As OSVERSIONINFO
SSPValidateUser = False
'''' Determine if system is Windows NT (version 4.0 or earlier) osinfo.dwOSVersionInfoSize = Len(osinfo) osinfo.szCSDVersion = Space$(128) GetVersionExA osinfo g_NT4 = (osinfo.dwPlatformId = VER_PLATFORM_WIN32_NT And _ osinfo.dwMajorVersion <= 4)
'''' Get max token size If g_NT4 Then NT4QuerySecurityPackageInfo "NTLM", pSPI Else QuerySecurityPackageInfo "NTLM", pSPI End If
If g_NT4 Then NT4FreeContextBuffer pSPI Else FreeContextBuffer pSPI End If
'''' Allocate buffers for client and server messages pClientBuf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, _ cbMaxToken) If pClientBuf = 0 Then GoTo FreeResourcesAndExit End If
pServerBuf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, _ cbMaxToken) If pServerBuf = 0 Then GoTo FreeResourcesAndExit End If
'''' Prepare client message (negotiate) . cbOut = cbMaxToken If Not GenClientContext(asClient, ai, 0, 0, pClientBuf, cbOut, _ fDone) Then GoTo FreeResourcesAndExit End If
'''' Prepare server message (challenge) . cbIn = cbOut cbOut = cbMaxToken If Not GenServerContext(asServer, pClientBuf, cbIn, pServerBuf, _ cbOut, fDone) Then '''' Most likely failure: AcceptServerContext fails with '''' SEC_E_LOGON_DENIED in the case of bad szUser or szPassword. '''' Unexpected Result: Logon will succeed if you pass in a bad '''' szUser and the guest account is enabled in the specified domain. GoTo FreeResourcesAndExit End If
'''' Prepare client message (authenticate) . cbIn = cbOut cbOut = cbMaxToken If Not GenClientContext(asClient, ai, pServerBuf, cbIn, pClientBuf, _ cbOut, fDone) Then GoTo FreeResourcesAndExit End If
'''' Prepare server message (authentication) . cbIn = cbOut cbOut = cbMaxToken If Not GenServerContext(asServer, pClientBuf, cbIn, pServerBuf, _