2012-10-01 04:15:42 +04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/sspi.h>
|
|
|
|
#include <winpr/winpr.h>
|
|
|
|
|
|
|
|
static const char* test_User = "User";
|
|
|
|
static const char* test_Domain = "Domain";
|
|
|
|
static const char* test_Password = "Password";
|
|
|
|
|
|
|
|
int TestAcquireCredentialsHandle(int argc, char* argv[])
|
|
|
|
{
|
2017-11-15 11:11:12 +03:00
|
|
|
int rc = -1;
|
2012-10-01 04:15:42 +04:00
|
|
|
SECURITY_STATUS status;
|
|
|
|
CredHandle credentials;
|
|
|
|
TimeStamp expiration;
|
|
|
|
SEC_WINNT_AUTH_IDENTITY identity;
|
|
|
|
SecurityFunctionTable* table;
|
|
|
|
SecPkgCredentials_Names credential_names;
|
|
|
|
sspi_GlobalInit();
|
|
|
|
table = InitSecurityInterface();
|
|
|
|
identity.User = (UINT16*) _strdup(test_User);
|
|
|
|
identity.Domain = (UINT16*) _strdup(test_Domain);
|
|
|
|
identity.Password = (UINT16*) _strdup(test_Password);
|
2017-07-03 13:47:56 +03:00
|
|
|
|
2015-06-17 23:08:02 +03:00
|
|
|
if (!identity.User || !identity.Domain || !identity.Password)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2017-07-03 13:47:56 +03:00
|
|
|
|
2015-06-22 19:52:13 +03:00
|
|
|
identity.UserLength = strlen(test_User);
|
|
|
|
identity.DomainLength = strlen(test_Domain);
|
|
|
|
identity.PasswordLength = strlen(test_Password);
|
2012-10-01 04:15:42 +04:00
|
|
|
identity.Flags = SEC_WINNT_AUTH_IDENTITY_ANSI;
|
2017-07-03 13:47:56 +03:00
|
|
|
status = table->AcquireCredentialsHandle(NULL, NTLM_SSP_NAME,
|
|
|
|
SECPKG_CRED_OUTBOUND, NULL, &identity, NULL, NULL, &credentials, &expiration);
|
2012-10-01 04:15:42 +04:00
|
|
|
|
|
|
|
if (status != SEC_E_OK)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2012-10-01 04:15:42 +04:00
|
|
|
|
|
|
|
status = table->QueryCredentialsAttributes(&credentials, SECPKG_CRED_ATTR_NAMES, &credential_names);
|
|
|
|
|
|
|
|
if (status != SEC_E_OK)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2012-10-01 04:15:42 +04:00
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
rc = 0;
|
|
|
|
fail:
|
|
|
|
|
|
|
|
if (SecIsValidHandle(&credentials))
|
|
|
|
table->FreeCredentialsHandle(&credentials);
|
|
|
|
|
|
|
|
free(identity.User);
|
|
|
|
free(identity.Domain);
|
|
|
|
free(identity.Password);
|
2012-10-01 04:15:42 +04:00
|
|
|
sspi_GlobalFinish();
|
2017-11-15 11:11:12 +03:00
|
|
|
return rc;
|
2012-10-01 04:15:42 +04:00
|
|
|
}
|
|
|
|
|