| 1 |
|
| 2 |
#include <stdio.h> |
| 3 |
#include <winpr/crt.h> |
| 4 |
#include <winpr/sspi.h> |
| 5 |
#include <winpr/winpr.h> |
| 6 |
|
| 7 |
static const char* test_User = "User"; |
| 8 |
static const char* test_Domain = "Domain"; |
| 9 |
static const char* test_Password = "Password"; |
| 10 |
|
| 11 |
int TestAcquireCredentialsHandle(int argc, char* argv[]) |
| 12 |
{ |
| 13 |
int rc = -1; |
| 14 |
SECURITY_STATUS status = 0; |
| 15 |
CredHandle credentials = WINPR_C_ARRAY_INIT; |
| 16 |
TimeStamp expiration; |
| 17 |
SEC_WINNT_AUTH_IDENTITY identity; |
| 18 |
SecurityFunctionTable* table = nullptr; |
| 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 = |
| 38 |
table->AcquireCredentialsHandle(nullptr, NTLM_SSP_NAME, SECPKG_CRED_OUTBOUND, nullptr, |
| 39 |
&identity, nullptr, nullptr, &credentials, &expiration); |
| 40 |
|
| 41 |
if (status != SEC_E_OK) |
| 42 |
goto fail; |
| 43 |
|
| 44 |
status = |
| 45 |
table->QueryCredentialsAttributes(&credentials, SECPKG_CRED_ATTR_NAMES, &credential_names); |
| 46 |
|
| 47 |
if (status != SEC_E_OK) |
| 48 |
goto fail; |
| 49 |
|
| 50 |
rc = 0; |
| 51 |
fail: |
| 52 |
|
| 53 |
if (SecIsValidHandle(&credentials)) |
| 54 |
table->FreeCredentialsHandle(&credentials); |
| 55 |
|
| 56 |
free(identity.User); |
| 57 |
free(identity.Domain); |
| 58 |
free(identity.Password); |
| 59 |
sspi_GlobalFinish(); |
| 60 |
return rc; |
| 61 |
} |