2012-10-01 04:15:42 +04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/sspi.h>
|
|
|
|
#include <winpr/winpr.h>
|
|
|
|
|
|
|
|
static const char* test_User = "User";
|
|
|
|
static const char* test_Domain = "Domain";
|
|
|
|
static const char* test_Password = "Password";
|
|
|
|
|
|
|
|
int TestInitializeSecurityContext(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
UINT32 cbMaxLen;
|
|
|
|
UINT32 fContextReq;
|
|
|
|
void* output_buffer;
|
|
|
|
CtxtHandle context;
|
|
|
|
ULONG pfContextAttr;
|
|
|
|
SECURITY_STATUS status;
|
|
|
|
CredHandle credentials;
|
|
|
|
TimeStamp expiration;
|
|
|
|
PSecPkgInfo pPackageInfo;
|
|
|
|
SEC_WINNT_AUTH_IDENTITY identity;
|
|
|
|
SecurityFunctionTable* table;
|
|
|
|
PSecBuffer p_SecBuffer;
|
|
|
|
SecBuffer output_SecBuffer;
|
|
|
|
SecBufferDesc output_SecBuffer_desc;
|
|
|
|
|
|
|
|
sspi_GlobalInit();
|
|
|
|
|
|
|
|
table = InitSecurityInterface();
|
|
|
|
|
2017-05-11 19:51:45 +03:00
|
|
|
status = QuerySecurityPackageInfo(NTLMSSP_NAME, &pPackageInfo);
|
2012-10-01 04:15:42 +04:00
|
|
|
|
|
|
|
if (status != SEC_E_OK)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("QuerySecurityPackageInfo status: 0x%08"PRIX32"\n", status);
|
2012-10-01 04:15:42 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cbMaxLen = pPackageInfo->cbMaxToken;
|
|
|
|
|
|
|
|
identity.User = (UINT16*) _strdup(test_User);
|
|
|
|
identity.Domain = (UINT16*) _strdup(test_Domain);
|
|
|
|
identity.Password = (UINT16*) _strdup(test_Password);
|
2015-06-17 23:08:02 +03:00
|
|
|
if (!identity.User || !identity.Domain || !identity.Password)
|
|
|
|
{
|
|
|
|
free(identity.User);
|
|
|
|
free(identity.Domain);
|
|
|
|
free(identity.Password);
|
|
|
|
fprintf(stderr, "Memory allocation failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-06-22 19:52:13 +03:00
|
|
|
identity.UserLength = strlen(test_User);
|
|
|
|
identity.DomainLength = strlen(test_Domain);
|
|
|
|
identity.PasswordLength = strlen(test_Password);
|
2012-10-01 04:15:42 +04:00
|
|
|
identity.Flags = SEC_WINNT_AUTH_IDENTITY_ANSI;
|
|
|
|
|
2017-05-11 19:51:45 +03:00
|
|
|
status = table->AcquireCredentialsHandle(NULL, NTLMSSP_NAME,
|
2012-10-01 04:15:42 +04:00
|
|
|
SECPKG_CRED_OUTBOUND, NULL, &identity, NULL, NULL, &credentials, &expiration);
|
|
|
|
|
|
|
|
if (status != SEC_E_OK)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("AcquireCredentialsHandle status: 0x%08"PRIX32"\n", status);
|
2012-10-01 04:15:42 +04:00
|
|
|
sspi_GlobalFinish();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fContextReq = ISC_REQ_REPLAY_DETECT | ISC_REQ_SEQUENCE_DETECT | ISC_REQ_CONFIDENTIALITY | ISC_REQ_DELEGATE;
|
|
|
|
|
|
|
|
output_buffer = malloc(cbMaxLen);
|
2015-04-03 17:21:01 +03:00
|
|
|
if (!output_buffer)
|
|
|
|
{
|
|
|
|
printf("Memory allocation failed\n");
|
|
|
|
sspi_GlobalFinish();
|
|
|
|
return -1;
|
|
|
|
}
|
2012-10-01 04:15:42 +04:00
|
|
|
|
|
|
|
output_SecBuffer_desc.ulVersion = 0;
|
|
|
|
output_SecBuffer_desc.cBuffers = 1;
|
|
|
|
output_SecBuffer_desc.pBuffers = &output_SecBuffer;
|
|
|
|
|
|
|
|
output_SecBuffer.cbBuffer = cbMaxLen;
|
|
|
|
output_SecBuffer.BufferType = SECBUFFER_TOKEN;
|
|
|
|
output_SecBuffer.pvBuffer = output_buffer;
|
|
|
|
|
|
|
|
status = table->InitializeSecurityContext(&credentials, NULL, NULL, fContextReq, 0, 0, NULL, 0,
|
|
|
|
&context, &output_SecBuffer_desc, &pfContextAttr, &expiration);
|
|
|
|
|
|
|
|
if (status != SEC_I_CONTINUE_NEEDED)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("InitializeSecurityContext status: 0x%08"PRIX32"\n", status);
|
2012-10-01 04:15:42 +04:00
|
|
|
sspi_GlobalFinish();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("cBuffers: %"PRIu32" ulVersion: %"PRIu32"\n", output_SecBuffer_desc.cBuffers, output_SecBuffer_desc.ulVersion);
|
2012-10-01 04:15:42 +04:00
|
|
|
|
|
|
|
p_SecBuffer = &output_SecBuffer_desc.pBuffers[0];
|
|
|
|
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("BufferType: 0x%08"PRIX32" cbBuffer: %"PRIu32"\n", p_SecBuffer->BufferType, p_SecBuffer->cbBuffer);
|
2012-10-01 04:15:42 +04:00
|
|
|
|
|
|
|
table->FreeCredentialsHandle(&credentials);
|
|
|
|
|
|
|
|
FreeContextBuffer(pPackageInfo);
|
|
|
|
|
|
|
|
sspi_GlobalFinish();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|