secur32: Cleanup InitializeSecurityContext (reduce indent and duplication).
This commit is contained in:
parent
d243b39c94
commit
4cd377d49c
|
@ -395,19 +395,29 @@ static SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextW(
|
||||||
PSecBufferDesc pOutput, ULONG *pfContextAttr, PTimeStamp ptsExpiry)
|
PSecBufferDesc pOutput, ULONG *pfContextAttr, PTimeStamp ptsExpiry)
|
||||||
{
|
{
|
||||||
SECURITY_STATUS ret;
|
SECURITY_STATUS ret;
|
||||||
|
PNegoHelper helper;
|
||||||
|
ULONG ctxt_attr = 0;
|
||||||
|
char* buffer;
|
||||||
|
PBYTE bin;
|
||||||
|
int buffer_len, bin_len, max_len = NTLM_MAX_BUF;
|
||||||
|
|
||||||
TRACE("%p %p %s %ld %ld %ld %p %ld %p %p %p %p\n", phCredential, phContext,
|
TRACE("%p %p %s %ld %ld %ld %p %ld %p %p %p %p\n", phCredential, phContext,
|
||||||
debugstr_w(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
|
debugstr_w(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
|
||||||
Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
|
Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
|
||||||
|
|
||||||
if(phCredential){
|
if(!phCredential)
|
||||||
|
return SEC_E_INVALID_HANDLE;
|
||||||
|
|
||||||
/* As the server side of sspi never calls this, make sure that
|
/* As the server side of sspi never calls this, make sure that
|
||||||
* the handler is a client handler.
|
* the handler is a client handler.
|
||||||
*/
|
*/
|
||||||
PNegoHelper helper = (PNegoHelper)phCredential->dwLower;
|
helper = (PNegoHelper)phCredential->dwLower;
|
||||||
ULONG ctxt_attr = 0;
|
if(helper->mode != NTLM_CLIENT)
|
||||||
if(helper->mode == NTLM_CLIENT)
|
|
||||||
{
|
{
|
||||||
|
TRACE("Helper mode = %d\n", helper->mode);
|
||||||
|
return SEC_E_INVALID_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************
|
/****************************************
|
||||||
* When communicating with the client, there can be the
|
* When communicating with the client, there can be the
|
||||||
* following reply packets:
|
* following reply packets:
|
||||||
|
@ -418,16 +428,8 @@ static SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextW(
|
||||||
* sent to server with KK prefixed
|
* sent to server with KK prefixed
|
||||||
* BH <char reason> something broke
|
* BH <char reason> something broke
|
||||||
*/
|
*/
|
||||||
BOOL first = FALSE;
|
|
||||||
/* The squid cache size is 2010 chars, and that's what ntlm_auth uses */
|
/* The squid cache size is 2010 chars, and that's what ntlm_auth uses */
|
||||||
char* buffer = HeapAlloc(GetProcessHeap(), 0,
|
|
||||||
sizeof(char) * NTLM_MAX_BUF);
|
|
||||||
PBYTE bin = HeapAlloc(GetProcessHeap(), 0, sizeof(BYTE) *
|
|
||||||
NTLM_MAX_BUF);
|
|
||||||
int buffer_len, bin_len, max_len = NTLM_MAX_BUF;
|
|
||||||
|
|
||||||
if((phContext == NULL) && (pInput == NULL))
|
|
||||||
first = TRUE;
|
|
||||||
if (pszTargetName)
|
if (pszTargetName)
|
||||||
{
|
{
|
||||||
TRACE("According to a MS whitepaper pszTargetName is ignored.\n");
|
TRACE("According to a MS whitepaper pszTargetName is ignored.\n");
|
||||||
|
@ -443,38 +445,28 @@ static SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextW(
|
||||||
ctxt_attr |= ISC_RET_CONNECTION;
|
ctxt_attr |= ISC_RET_CONNECTION;
|
||||||
}
|
}
|
||||||
if(fContextReq & ISC_REQ_EXTENDED_ERROR)
|
if(fContextReq & ISC_REQ_EXTENDED_ERROR)
|
||||||
{
|
FIXME("ISC_REQ_EXTENDED_ERROR\n");
|
||||||
FIXME("InitializeSecurityContext(): ISC_REQ_EXTENDED_ERROR stub\n");
|
|
||||||
}
|
|
||||||
if(fContextReq & ISC_REQ_INTEGRITY)
|
if(fContextReq & ISC_REQ_INTEGRITY)
|
||||||
{
|
FIXME("ISC_REQ_INTEGRITY\n");
|
||||||
FIXME("InitializeSecurityContext(): ISC_REQ_INTEGRITY stub\n");
|
|
||||||
}
|
|
||||||
if(fContextReq & ISC_REQ_MUTUAL_AUTH)
|
if(fContextReq & ISC_REQ_MUTUAL_AUTH)
|
||||||
{
|
FIXME("ISC_REQ_MUTUAL_AUTH\n");
|
||||||
FIXME("InitializeSecurityContext(): ISC_REQ_MUTUAL_AUTH stub\n");
|
|
||||||
}
|
|
||||||
if(fContextReq & ISC_REQ_REPLAY_DETECT)
|
if(fContextReq & ISC_REQ_REPLAY_DETECT)
|
||||||
{
|
FIXME("ISC_REQ_REPLAY_DETECT\n");
|
||||||
FIXME("InitializeSecurityContext(): ISC_REQ_REPLAY_DETECT stub\n");
|
|
||||||
}
|
|
||||||
if(fContextReq & ISC_REQ_SEQUENCE_DETECT)
|
if(fContextReq & ISC_REQ_SEQUENCE_DETECT)
|
||||||
{
|
FIXME("ISC_REQ_SEQUENCE_DETECT\n");
|
||||||
FIXME("InitializeSecurityContext(): ISC_REQ_SEQUENCE_DETECT stub\n");
|
|
||||||
}
|
|
||||||
if(fContextReq & ISC_REQ_STREAM)
|
if(fContextReq & ISC_REQ_STREAM)
|
||||||
{
|
FIXME("ISC_REQ_STREAM\n");
|
||||||
FIXME("InitializeSecurityContext(): ISC_REQ_STREAM stub\n");
|
|
||||||
}
|
|
||||||
/* Done with the flags */
|
/* Done with the flags */
|
||||||
if(TargetDataRep == SECURITY_NETWORK_DREP){
|
if(TargetDataRep == SECURITY_NETWORK_DREP){
|
||||||
FIXME("Don't know how to do SECURITY_NETWORK_DREP\n");
|
FIXME("Don't know how to do SECURITY_NETWORK_DREP\n");
|
||||||
HeapFree(GetProcessHeap(), 0, buffer);
|
|
||||||
HeapFree(GetProcessHeap(), 0, bin);
|
|
||||||
return SEC_E_UNSUPPORTED_FUNCTION;
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(first)
|
buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(char) * NTLM_MAX_BUF);
|
||||||
|
bin = HeapAlloc(GetProcessHeap(), 0, sizeof(BYTE) * NTLM_MAX_BUF);
|
||||||
|
|
||||||
|
if((phContext == NULL) && (pInput == NULL))
|
||||||
{
|
{
|
||||||
TRACE("First time in ISC()\n");
|
TRACE("First time in ISC()\n");
|
||||||
/* Request a challenge request from ntlm_auth */
|
/* Request a challenge request from ntlm_auth */
|
||||||
|
@ -493,83 +485,36 @@ static SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextW(
|
||||||
TRACE("Deleting password!\n");
|
TRACE("Deleting password!\n");
|
||||||
memset(helper->password, 0, helper->pwlen-2);
|
memset(helper->password, 0, helper->pwlen-2);
|
||||||
HeapFree(GetProcessHeap(), 0, helper->password);
|
HeapFree(GetProcessHeap(), 0, helper->password);
|
||||||
HeapFree(GetProcessHeap(), 0, buffer);
|
goto end;
|
||||||
HeapFree(GetProcessHeap(), 0, bin);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACE("Sending to helper: %s\n", debugstr_a(buffer));
|
TRACE("Sending to helper: %s\n", debugstr_a(buffer));
|
||||||
if((ret = run_helper(helper, buffer, max_len, &buffer_len)) !=
|
if((ret = run_helper(helper, buffer, max_len, &buffer_len)) != SEC_E_OK)
|
||||||
SEC_E_OK)
|
goto end;
|
||||||
{
|
|
||||||
HeapFree(GetProcessHeap(), 0, buffer);
|
|
||||||
HeapFree(GetProcessHeap(), 0, bin);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
TRACE("Helper returned %s\n", debugstr_a(buffer));
|
TRACE("Helper returned %s\n", debugstr_a(buffer));
|
||||||
lstrcpynA(buffer, "YR", max_len-1);
|
lstrcpynA(buffer, "YR", max_len-1);
|
||||||
|
|
||||||
if((ret = run_helper(helper, buffer, max_len, &buffer_len)) !=
|
if((ret = run_helper(helper, buffer, max_len, &buffer_len)) != SEC_E_OK)
|
||||||
SEC_E_OK)
|
goto end;
|
||||||
{
|
|
||||||
HeapFree(GetProcessHeap(), 0, buffer);
|
|
||||||
HeapFree(GetProcessHeap(), 0, bin);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
TRACE("%s\n", buffer);
|
TRACE("%s\n", buffer);
|
||||||
|
|
||||||
if(strncmp(buffer, "YR ", 3) != 0)
|
if(strncmp(buffer, "YR ", 3) != 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Something borked */
|
/* Something borked */
|
||||||
TRACE("Helper returned %c%c\n", buffer[0], buffer[1]);
|
TRACE("Helper returned %c%c\n", buffer[0], buffer[1]);
|
||||||
HeapFree(GetProcessHeap(), 0, buffer);
|
ret = SEC_E_INTERNAL_ERROR;
|
||||||
HeapFree(GetProcessHeap(), 0, bin);
|
goto end;
|
||||||
return SEC_E_INTERNAL_ERROR;
|
|
||||||
}
|
}
|
||||||
if((ret = decodeBase64(buffer+3, buffer_len-3, bin,
|
if((ret = decodeBase64(buffer+3, buffer_len-3, bin,
|
||||||
max_len-1, &bin_len)) != SEC_E_OK)
|
max_len-1, &bin_len)) != SEC_E_OK)
|
||||||
{
|
goto end;
|
||||||
HeapFree(GetProcessHeap(), 0, buffer);
|
|
||||||
HeapFree(GetProcessHeap(), 0, bin);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* put the decoded client blob into the out buffer */
|
/* put the decoded client blob into the out buffer */
|
||||||
|
|
||||||
if (fContextReq & ISC_REQ_ALLOCATE_MEMORY)
|
|
||||||
{
|
|
||||||
if (pOutput)
|
|
||||||
{
|
|
||||||
pOutput->cBuffers = 1;
|
|
||||||
pOutput->pBuffers[0].pvBuffer = SECUR32_ALLOC(bin_len);
|
|
||||||
pOutput->pBuffers[0].cbBuffer = bin_len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!pOutput || !pOutput->cBuffers || pOutput->pBuffers[0].cbBuffer < bin_len)
|
|
||||||
{
|
|
||||||
TRACE("out buffer is NULL or has not enough space\n");
|
|
||||||
HeapFree(GetProcessHeap(), 0, buffer);
|
|
||||||
HeapFree(GetProcessHeap(), 0, bin);
|
|
||||||
return SEC_E_BUFFER_TOO_SMALL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!pOutput->pBuffers[0].pvBuffer)
|
|
||||||
{
|
|
||||||
TRACE("out buffer is NULL\n");
|
|
||||||
HeapFree(GetProcessHeap(), 0, buffer);
|
|
||||||
HeapFree(GetProcessHeap(), 0, bin);
|
|
||||||
return SEC_E_INTERNAL_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
pOutput->pBuffers[0].cbBuffer = bin_len;
|
|
||||||
pOutput->pBuffers[0].BufferType = SECBUFFER_DATA;
|
|
||||||
memcpy(pOutput->pBuffers[0].pvBuffer, bin, bin_len);
|
|
||||||
|
|
||||||
ret = SEC_I_CONTINUE_NEEDED;
|
ret = SEC_I_CONTINUE_NEEDED;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -578,25 +523,22 @@ static SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextW(
|
||||||
/* encode server data to base64 */
|
/* encode server data to base64 */
|
||||||
if (!pInput || !pInput->cBuffers)
|
if (!pInput || !pInput->cBuffers)
|
||||||
{
|
{
|
||||||
HeapFree(GetProcessHeap(), 0, buffer);
|
ret = SEC_E_INCOMPLETE_MESSAGE;
|
||||||
HeapFree(GetProcessHeap(), 0, bin);
|
goto end;
|
||||||
return SEC_E_INCOMPLETE_MESSAGE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pInput->pBuffers[0].pvBuffer)
|
if (!pInput->pBuffers[0].pvBuffer)
|
||||||
{
|
{
|
||||||
HeapFree(GetProcessHeap(), 0, buffer);
|
ret = SEC_E_INTERNAL_ERROR;
|
||||||
HeapFree(GetProcessHeap(), 0, bin);
|
goto end;
|
||||||
return SEC_E_INTERNAL_ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pInput->pBuffers[0].cbBuffer > max_len)
|
if(pInput->pBuffers[0].cbBuffer > max_len)
|
||||||
{
|
{
|
||||||
TRACE("pInput->pBuffers[0].cbBuffer is: %ld\n",
|
TRACE("pInput->pBuffers[0].cbBuffer is: %ld\n",
|
||||||
pInput->pBuffers[0].cbBuffer);
|
pInput->pBuffers[0].cbBuffer);
|
||||||
HeapFree(GetProcessHeap(), 0, buffer);
|
ret = SEC_E_INVALID_TOKEN;
|
||||||
HeapFree(GetProcessHeap(), 0, bin);
|
goto end;
|
||||||
return SEC_E_INVALID_TOKEN;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
bin_len = pInput->pBuffers[0].cbBuffer;
|
bin_len = pInput->pBuffers[0].cbBuffer;
|
||||||
|
@ -607,22 +549,13 @@ static SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextW(
|
||||||
|
|
||||||
if((ret = encodeBase64(bin, bin_len, buffer+3,
|
if((ret = encodeBase64(bin, bin_len, buffer+3,
|
||||||
max_len-3, &buffer_len)) != SEC_E_OK)
|
max_len-3, &buffer_len)) != SEC_E_OK)
|
||||||
{
|
goto end;
|
||||||
HeapFree(GetProcessHeap(), 0, buffer);
|
|
||||||
HeapFree(GetProcessHeap(), 0, bin);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
TRACE("Server sent: %s\n", debugstr_a(buffer));
|
TRACE("Server sent: %s\n", debugstr_a(buffer));
|
||||||
|
|
||||||
/* send TT base64 blob to ntlm_auth */
|
/* send TT base64 blob to ntlm_auth */
|
||||||
if((ret = run_helper(helper, buffer, max_len, &buffer_len)) !=
|
if((ret = run_helper(helper, buffer, max_len, &buffer_len)) != SEC_E_OK)
|
||||||
SEC_E_OK)
|
goto end;
|
||||||
{
|
|
||||||
HeapFree(GetProcessHeap(), 0, buffer);
|
|
||||||
HeapFree(GetProcessHeap(), 0, bin);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
TRACE("Helper replied: %s\n", debugstr_a(buffer));
|
TRACE("Helper replied: %s\n", debugstr_a(buffer));
|
||||||
|
|
||||||
|
@ -644,6 +577,12 @@ static SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextW(
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
phNewContext->dwUpper = ctxt_attr;
|
||||||
|
phNewContext->dwLower = ret;
|
||||||
|
|
||||||
|
ret = SEC_E_OK;
|
||||||
|
}
|
||||||
|
|
||||||
/* put the decoded client blob into the out buffer */
|
/* put the decoded client blob into the out buffer */
|
||||||
|
|
||||||
if (fContextReq & ISC_REQ_ALLOCATE_MEMORY)
|
if (fContextReq & ISC_REQ_ALLOCATE_MEMORY)
|
||||||
|
@ -659,29 +598,21 @@ static SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextW(
|
||||||
if (!pOutput || !pOutput->cBuffers || pOutput->pBuffers[0].cbBuffer < bin_len)
|
if (!pOutput || !pOutput->cBuffers || pOutput->pBuffers[0].cbBuffer < bin_len)
|
||||||
{
|
{
|
||||||
TRACE("out buffer is NULL or has not enough space\n");
|
TRACE("out buffer is NULL or has not enough space\n");
|
||||||
HeapFree(GetProcessHeap(), 0, buffer);
|
ret = SEC_E_BUFFER_TOO_SMALL;
|
||||||
HeapFree(GetProcessHeap(), 0, bin);
|
goto end;
|
||||||
return SEC_E_BUFFER_TOO_SMALL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pOutput->pBuffers[0].pvBuffer)
|
if (!pOutput->pBuffers[0].pvBuffer)
|
||||||
{
|
{
|
||||||
TRACE("out buffer is NULL\n");
|
TRACE("out buffer is NULL\n");
|
||||||
HeapFree(GetProcessHeap(), 0, buffer);
|
ret = SEC_E_INTERNAL_ERROR;
|
||||||
HeapFree(GetProcessHeap(), 0, bin);
|
goto end;
|
||||||
return SEC_E_INTERNAL_ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pOutput->pBuffers[0].cbBuffer = bin_len;
|
pOutput->pBuffers[0].cbBuffer = bin_len;
|
||||||
pOutput->pBuffers[0].BufferType = SECBUFFER_DATA;
|
pOutput->pBuffers[0].BufferType = SECBUFFER_DATA;
|
||||||
memcpy(pOutput->pBuffers[0].pvBuffer, bin, bin_len);
|
memcpy(pOutput->pBuffers[0].pvBuffer, bin, bin_len);
|
||||||
|
|
||||||
ret = SEC_E_OK;
|
|
||||||
phNewContext->dwUpper = ctxt_attr;
|
|
||||||
phNewContext->dwLower = ret;
|
|
||||||
}
|
|
||||||
HeapFree(GetProcessHeap(), 0, buffer);
|
|
||||||
HeapFree(GetProcessHeap(), 0, bin);
|
|
||||||
if(ret != SEC_I_CONTINUE_NEEDED)
|
if(ret != SEC_I_CONTINUE_NEEDED)
|
||||||
{
|
{
|
||||||
TRACE("Deleting password!\n");
|
TRACE("Deleting password!\n");
|
||||||
|
@ -689,18 +620,9 @@ static SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextW(
|
||||||
memset(helper->password, 0, helper->pwlen-2);
|
memset(helper->password, 0, helper->pwlen-2);
|
||||||
HeapFree(GetProcessHeap(), 0, helper->password);
|
HeapFree(GetProcessHeap(), 0, helper->password);
|
||||||
}
|
}
|
||||||
|
end:
|
||||||
}
|
HeapFree(GetProcessHeap(), 0, buffer);
|
||||||
else
|
HeapFree(GetProcessHeap(), 0, bin);
|
||||||
{
|
|
||||||
ret = SEC_E_INVALID_HANDLE;
|
|
||||||
TRACE("Helper mode = %d\n", helper->mode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ret = SEC_E_INVALID_HANDLE;
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue