FreeRDP
Loading...
Searching...
No Matches
TestSspiTSSSP.c
1#include <stdio.h>
2#include <winpr/sspi.h>
3#include <winpr/winpr.h>
4#include <winpr/tchar.h>
5#include <winpr/credssp.h>
6#include <winpr/schannel.h>
7
8/* The TSSSP package must register in the WinPR SSPI table on every platform so
9 * that core/tsssp.c resolves it the same way everywhere. On Windows the package
10 * forwards to the native secur32 provider, so acquiring an outbound credential
11 * handle is exercised too (best effort: a host without the provider is not a
12 * test failure). */
13
14static int test_query_package(void)
15{
16 SecPkgInfoW* info = nullptr;
17 SecurityFunctionTableW* table = InitSecurityInterfaceExW(0);
18 if (!table || !table->QuerySecurityPackageInfoW)
19 {
20 (void)fprintf(stderr, "no WinPR security function table\n");
21 return -1;
22 }
23
24 WCHAR name[] = { 'T', 'S', 'S', 'S', 'P', '\0' };
25 const SECURITY_STATUS status = table->QuerySecurityPackageInfoW(name, &info);
26 if (status != SEC_E_OK)
27 {
28 (void)fprintf(stderr, "QuerySecurityPackageInfoW(TSSSP) failed: 0x%08" PRIx32 "\n",
29 (UINT32)status);
30 return -1;
31 }
32
33 int rc = 0;
34 if (!info || !info->Name || (_wcscmp(info->Name, name) != 0))
35 {
36 (void)fprintf(stderr, "QuerySecurityPackageInfoW(TSSSP) returned an unexpected name\n");
37 rc = -1;
38 }
39
40 if (table->FreeContextBuffer)
41 (void)table->FreeContextBuffer(info);
42 return rc;
43}
44
45#if defined(_WIN32) && !defined(_UWP)
46static void test_acquire_credentials(void)
47{
48 SecurityFunctionTableW* table = InitSecurityInterfaceExW(0);
49 if (!table || !table->AcquireCredentialsHandleW || !table->FreeCredentialsHandle)
50 return;
51
52 SCH_CREDENTIALS sc = WINPR_C_ARRAY_INIT;
53 sc.dwVersion = SCH_CREDENTIALS_VERSION;
54
55 CREDSSP_CRED cred = WINPR_C_ARRAY_INIT;
56 cred.Type = CredsspSubmitBufferBothOld;
57 cred.pSchannelCred = &sc;
58 cred.pSpnegoCred = nullptr;
59
60 CREDSSP_CRED_EX credEx = WINPR_C_ARRAY_INIT;
61 credEx.Type = (CREDSPP_SUBMIT_TYPE)CredsspCredEx;
62 credEx.Version = CREDSSP_CRED_EX_VERSION;
63 credEx.Flags = CREDSSP_FLAG_REDIRECT;
64 credEx.Cred = cred;
65
66 WCHAR pkg[] = { 'T', 'S', 'S', 'S', 'P', '\0' };
67 CredHandle handle = WINPR_C_ARRAY_INIT;
68 TimeStamp expiry = WINPR_C_ARRAY_INIT;
69 const SECURITY_STATUS status = table->AcquireCredentialsHandleW(
70 nullptr, pkg, SECPKG_CRED_OUTBOUND, nullptr, &credEx, nullptr, nullptr, &handle, &expiry);
71
72 (void)fprintf(stderr, "AcquireCredentialsHandleW(TSSSP) returned 0x%08" PRIx32 "\n",
73 (UINT32)status);
74 if (status == SEC_E_OK)
75 (void)table->FreeCredentialsHandle(&handle);
76}
77#endif
78
79int TestSspiTSSSP(int argc, char* argv[])
80{
81 WINPR_UNUSED(argc);
82 WINPR_UNUSED(argv);
83
84 sspi_GlobalInit();
85
86 int rc = test_query_package();
87
88#if defined(_WIN32) && !defined(_UWP)
89 if (rc == 0)
90 test_acquire_credentials();
91#endif
92
93 sspi_GlobalFinish();
94 return rc;
95}