6#include <winpr/credssp.h>
13int TestSspiCredSSP(
int argc,
char* argv[])
19 if (!table || !table->QuerySecurityPackageInfoW || !table->AcquireCredentialsHandleW ||
20 !table->FreeCredentialsHandle)
22 (void)fprintf(stderr,
"no WinPR security function table\n");
26 WCHAR pkg[] = {
'C',
'R',
'E',
'D',
'S',
'S',
'P',
'\0' };
29 PSecPkgInfoW info =
nullptr;
30 if (table->QuerySecurityPackageInfoW(pkg, &info) != SEC_E_OK)
32 (void)fprintf(stderr,
"QuerySecurityPackageInfoW(CREDSSP) failed\n");
35 if (table->FreeContextBuffer)
36 (void)table->FreeContextBuffer(info);
38 WCHAR user[] = {
't',
'e',
's',
't',
'u',
's',
'e',
'r',
'\0' };
39 WCHAR domain[] = {
'T',
'E',
'S',
'T',
'\0' };
40 WCHAR pass[] = {
'S',
'e',
'c',
'r',
'e',
't',
'1',
'!',
'\0' };
42 identity.User = (UINT16*)user;
43 identity.UserLength = 8;
44 identity.Domain = (UINT16*)domain;
45 identity.DomainLength = 4;
46 identity.Password = (UINT16*)pass;
47 identity.PasswordLength = 8;
48 identity.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
50 CREDSSP_CRED cred = { .Type = CredsspSubmitBufferBothOld };
51 cred.pSpnegoCred = &identity;
52 CREDSSP_CRED_EX credEx = { .Type = (CREDSPP_SUBMIT_TYPE)CredsspCredEx };
53 credEx.Version = CREDSSP_CRED_EX_VERSION;
56 CredHandle creds = WINPR_C_ARRAY_INIT;
57 TimeStamp expiry = WINPR_C_ARRAY_INIT;
58 const SECURITY_STATUS status = table->AcquireCredentialsHandleW(
59 nullptr, pkg, SECPKG_CRED_OUTBOUND,
nullptr, &credEx,
nullptr,
nullptr, &creds, &expiry);
60 if (status != SEC_E_OK)
62 (void)fprintf(stderr,
"AcquireCredentialsHandle(CREDSSP) failed: 0x%08" PRIx32
"\n",
67 const SECURITY_STATUS freed = table->FreeCredentialsHandle(&creds);
68 if (freed != SEC_E_OK)
70 (void)fprintf(stderr,
"FreeCredentialsHandle(CREDSSP) failed: 0x%08" PRIx32
"\n",