in MySQL.Data/src/Authentication/SSPI/SspiSecurityContext.cs [55:133]
internal ContextStatus InitializeSecurityContext(out byte[] clientBlob, byte[] serverBlob, string targetName)
{
clientBlob = null;
SecBufferDesc clientBufferDesc = new SecBufferDesc(Const.MAX_TOKEN_SIZE);
SECURITY_INTEGER initLifetime = new SECURITY_INTEGER(0);
SecStatus result = 0;
try
{
uint ContextAttributes = 0;
if (serverBlob == null)
{
result = InitializeSecurityContext_0(
ref credentials.credentialsHandle,
IntPtr.Zero,
targetName,
Const.STANDARD_CONTEXT_ATTRIBUTES,
0,
Const.SECURITY_NETWORK_DREP,
IntPtr.Zero, /* always zero first time around */
0,
out securityContext,
out clientBufferDesc,
out ContextAttributes,
out initLifetime);
}
else
{
SecBufferDesc serverBufferDesc = new SecBufferDesc(serverBlob);
try
{
result = InitializeSecurityContext_1(
ref credentials.credentialsHandle,
ref securityContext,
targetName,
Const.STANDARD_CONTEXT_ATTRIBUTES,
0,
Const.SECURITY_NETWORK_DREP,
ref serverBufferDesc,
0,
out securityContext,
out clientBufferDesc,
out ContextAttributes,
out initLifetime);
}
finally
{
serverBufferDesc.Dispose();
}
}
if ((SecStatus.SEC_I_COMPLETE_NEEDED == result)
|| (SecStatus.SEC_I_COMPLETE_AND_CONTINUE == result))
{
CompleteAuthToken(ref securityContext, ref clientBufferDesc);
}
if (result != SecStatus.SEC_E_OK &&
result != SecStatus.SEC_I_CONTINUE_NEEDED &&
result != SecStatus.SEC_I_COMPLETE_NEEDED &&
result != SecStatus.SEC_I_COMPLETE_AND_CONTINUE)
{
throw new MySqlException("InitializeSecurityContext() failed with errorcode " + result);
}
clientBlob = clientBufferDesc.GetSecBufferByteArray();
}
finally
{
clientBufferDesc.Dispose();
}
if (result == SecStatus.SEC_I_CONTINUE_NEEDED)
return ContextStatus.RequiresContinuation;
return ContextStatus.Accepted;
}