Dim sbIn As SecBuffer Dim fContextAttr As Long
GenServerContext = False
If Not AuthSeq.fInitialized Then
If g_NT4 Then ss = NT4AcquireCredentialsHandle2(0&, "NTLM", _ SECPKG_CRED_INBOUND, 0&, 0&, 0&, 0&, AuthSeq.hcred, _ tsExpiry) Else ss = AcquireCredentialsHandle2(0&, "NTLM", _ SECPKG_CRED_INBOUND, 0&, 0&, 0&, 0&, AuthSeq.hcred, _ tsExpiry) End If
If ss < 0 Then Exit Function End If
AuthSeq.fHaveCredHandle = True
End If
'''' Prepare output buffer sbdOut.ulVersion = 0 sbdOut.cBuffers = 1 sbdOut.pBuffers = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, _ Len(sbOut))
sbOut.cbBuffer = cbOut sbOut.BufferType = SECBUFFER_TOKEN sbOut.pvBuffer = pOut
CopyMemory ByVal sbdOut.pBuffers, sbOut, Len(sbOut)
'''' Prepare input buffer sbdIn.ulVersion = 0 sbdIn.cBuffers = 1 sbdIn.pBuffers = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, _ Len(sbIn))
sbIn.cbBuffer = cbIn sbIn.BufferType = SECBUFFER_TOKEN sbIn.pvBuffer = pIn
CopyMemory ByVal sbdIn.pBuffers, sbIn, Len(sbIn)
If AuthSeq.fInitialized Then
If g_NT4 Then ss = NT4AcceptSecurityContext(AuthSeq.hcred, AuthSeq.hctxt, _ sbdIn, 0, SECURITY_NATIVE_DREP, AuthSeq.hctxt, sbdOut, _ fContextAttr, tsExpiry) Else ss = AcceptSecurityContext(AuthSeq.hcred, AuthSeq.hctxt, _ sbdIn, 0, SECURITY_NATIVE_DREP, AuthSeq.hctxt, sbdOut, _ fContextAttr, tsExpiry) End If
Else
If g_NT4 Then ss = NT4AcceptSecurityContext2(AuthSeq.hcred, 0&, sbdIn, 0, _ SECURITY_NATIVE_DREP, AuthSeq.hctxt, sbdOut, _ fContextAttr, tsExpiry) Else ss = AcceptSecurityContext2(AuthSeq.hcred, 0&, sbdIn, 0, _ SECURITY_NATIVE_DREP, AuthSeq.hctxt, sbdOut, _ fContextAttr, tsExpiry) End If
End If
If ss < 0 Then GoTo FreeResourcesAndExit End If
AuthSeq.fHaveCtxtHandle = True
'''' If necessary, complete token If ss = SEC_I_COMPLETE_NEEDED _ Or ss = SEC_I_COMPLETE_AND_CONTINUE Then
If g_NT4 Then ss = NT4CompleteAuthToken(AuthSeq.hctxt, sbdOut) Else ss = CompleteAuthToken(AuthSeq.hctxt, sbdOut) End If
If ss < 0 Then GoTo FreeResourcesAndExit End If
End If
CopyMemory sbOut, ByVal sbdOut.pBuffers, Len(sbOut) cbOut = sbOut.cbBuffer
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
CopyMemory SPI, ByVal pSPI, Len(SPI) cbMaxToken = SPI.cbMaxToken
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
'''' Initialize auth identity structure ai.Domain = Domain ai.DomainLength = Len(Domain) ai.User = User ai.UserLength = Len(User) ai.Password = Password ai.PasswordLength = Len(Password) ai.Flags = SEC_WINNT_AUTH_IDENTITY_ANSI
'''' 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, _  上一页 [1] [2] [3] [4] 下一页 |