4 #include <winpr/sspi.h>
5 #include <winpr/winpr.h>
7 static const char* test_User =
"User";
8 static const char* test_Domain =
"Domain";
9 static const char* test_Password =
"Password";
11 int TestInitializeSecurityContext(
int argc,
char* argv[])
15 UINT32 fContextReq = 0;
16 void* output_buffer = NULL;
18 ULONG pfContextAttr = 0;
19 SECURITY_STATUS status = 0;
22 PSecPkgInfo pPackageInfo = NULL;
23 SEC_WINNT_AUTH_IDENTITY identity = { 0 };
24 SecurityFunctionTable* table = NULL;
33 table = InitSecurityInterfaceEx(0);
34 status = table->QuerySecurityPackageInfo(NTLM_SSP_NAME, &pPackageInfo);
36 if (status != SEC_E_OK)
38 printf(
"QuerySecurityPackageInfo status: 0x%08" PRIX32
"\n", status);
42 cbMaxLen = pPackageInfo->cbMaxToken;
43 identity.User = (UINT16*)_strdup(test_User);
44 identity.Domain = (UINT16*)_strdup(test_Domain);
45 identity.Password = (UINT16*)_strdup(test_Password);
47 if (!identity.User || !identity.Domain || !identity.Password)
50 identity.UserLength = strlen(test_User);
51 identity.DomainLength = strlen(test_Domain);
52 identity.PasswordLength = strlen(test_Password);
53 identity.Flags = SEC_WINNT_AUTH_IDENTITY_ANSI;
54 status = table->AcquireCredentialsHandle(NULL, NTLM_SSP_NAME, SECPKG_CRED_OUTBOUND, NULL,
55 &identity, NULL, NULL, &credentials, &expiration);
57 if (status != SEC_E_OK)
59 printf(
"AcquireCredentialsHandle status: 0x%08" PRIX32
"\n", status);
63 fContextReq = ISC_REQ_REPLAY_DETECT | ISC_REQ_SEQUENCE_DETECT | ISC_REQ_CONFIDENTIALITY |
65 output_buffer = malloc(cbMaxLen);
69 printf(
"Memory allocation failed\n");
73 output_SecBuffer_desc.ulVersion = 0;
74 output_SecBuffer_desc.cBuffers = 1;
75 output_SecBuffer_desc.pBuffers = &output_SecBuffer;
76 output_SecBuffer.cbBuffer = cbMaxLen;
77 output_SecBuffer.BufferType = SECBUFFER_TOKEN;
78 output_SecBuffer.pvBuffer = output_buffer;
79 status = table->InitializeSecurityContext(&credentials, NULL, NULL, fContextReq, 0, 0, NULL, 0,
80 &context, &output_SecBuffer_desc, &pfContextAttr,
83 if (status != SEC_I_CONTINUE_NEEDED)
85 printf(
"InitializeSecurityContext status: 0x%08" PRIX32
"\n", status);
89 printf(
"cBuffers: %" PRIu32
" ulVersion: %" PRIu32
"\n", output_SecBuffer_desc.cBuffers,
90 output_SecBuffer_desc.ulVersion);
91 p_SecBuffer = &output_SecBuffer_desc.pBuffers[0];
92 printf(
"BufferType: 0x%08" PRIX32
" cbBuffer: %" PRIu32
"\n", p_SecBuffer->BufferType,
93 p_SecBuffer->cbBuffer);
94 status = table->DeleteSecurityContext(&context);
96 if (status != SEC_E_OK)
98 printf(
"DeleteSecurityContext status: 0x%08" PRIX32
"\n", status);
105 free(identity.Domain);
106 free(identity.Password);
109 if (SecIsValidHandle(&credentials))
110 table->FreeCredentialsHandle(&credentials);
112 table->FreeContextBuffer(pPackageInfo);