FreeRDP
Loading...
Searching...
No Matches
TestAcquireCredentialsHandle.c
1
2#include <stdio.h>
3#include <winpr/crt.h>
4#include <winpr/sspi.h>
5#include <winpr/winpr.h>
6
7static const char* test_User = "User";
8static const char* test_Domain = "Domain";
9static const char* test_Password = "Password";
10
11int TestAcquireCredentialsHandle(int argc, char* argv[])
12{
13 int rc = -1;
14 SECURITY_STATUS status = 0;
15 CredHandle credentials = { 0 };
16 TimeStamp expiration;
17 SEC_WINNT_AUTH_IDENTITY identity;
18 SecurityFunctionTable* table = NULL;
19 SecPkgCredentials_Names credential_names;
20
21 WINPR_UNUSED(argc);
22 WINPR_UNUSED(argv);
23
24 sspi_GlobalInit();
25 table = InitSecurityInterfaceEx(0);
26 identity.User = (UINT16*)_strdup(test_User);
27 identity.Domain = (UINT16*)_strdup(test_Domain);
28 identity.Password = (UINT16*)_strdup(test_Password);
29
30 if (!identity.User || !identity.Domain || !identity.Password)
31 goto fail;
32
33 identity.UserLength = strlen(test_User);
34 identity.DomainLength = strlen(test_Domain);
35 identity.PasswordLength = strlen(test_Password);
36 identity.Flags = SEC_WINNT_AUTH_IDENTITY_ANSI;
37 status = table->AcquireCredentialsHandle(NULL, NTLM_SSP_NAME, SECPKG_CRED_OUTBOUND, NULL,
38 &identity, NULL, NULL, &credentials, &expiration);
39
40 if (status != SEC_E_OK)
41 goto fail;
42
43 status =
44 table->QueryCredentialsAttributes(&credentials, SECPKG_CRED_ATTR_NAMES, &credential_names);
45
46 if (status != SEC_E_OK)
47 goto fail;
48
49 rc = 0;
50fail:
51
52 if (SecIsValidHandle(&credentials))
53 table->FreeCredentialsHandle(&credentials);
54
55 free(identity.User);
56 free(identity.Domain);
57 free(identity.Password);
58 sspi_GlobalFinish();
59 return rc;
60}