secur32/tests: Add AcquireCredentialsHandleW tests.

Signed-off-by: Alistair Leslie-Hughes <leslie_alistair@hotmail.com>
Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alistair Leslie-Hughes 2016-05-26 10:45:35 +00:00 committed by Alexandre Julliard
parent 5cc400ed60
commit ee7bc087fd
1 changed files with 100 additions and 19 deletions

View File

@ -42,6 +42,8 @@ static SECURITY_STATUS (SEC_ENTRY * pFreeContextBuffer)(PVOID pv);
static SECURITY_STATUS (SEC_ENTRY * pQuerySecurityPackageInfoA)(SEC_CHAR*, PSecPkgInfoA*);
static SECURITY_STATUS (SEC_ENTRY * pAcquireCredentialsHandleA)(SEC_CHAR*, SEC_CHAR*,
ULONG, PLUID, PVOID, SEC_GET_KEY_FN, PVOID, PCredHandle, PTimeStamp);
static SECURITY_STATUS (SEC_ENTRY * pAcquireCredentialsHandleW)(SEC_CHAR*, SEC_WCHAR*,
ULONG, PLUID, void*, SEC_GET_KEY_FN, void*, CredHandle*, TimeStamp*);
static SECURITY_STATUS (SEC_ENTRY * pInitializeSecurityContextA)(PCredHandle, PCtxtHandle,
SEC_CHAR*, ULONG, ULONG, ULONG, PSecBufferDesc, ULONG,
PCtxtHandle, PSecBufferDesc, PULONG, PTimeStamp);
@ -149,6 +151,11 @@ static BYTE crypt_message_server2[] =
{0xc8, 0xf2, 0x39, 0x7f, 0x0c, 0xaf, 0xf5, 0x5d, 0xef, 0x0c,
0x8b, 0x5f, 0x82};
static char test_user[] = "testuser",
workgroup[] = "WORKGROUP",
test_pass[] = "testpass",
sec_pkg_name[] = "NTLM";
static void InitFunctionPtrs(void)
{
secdll = LoadLibraryA("secur32.dll");
@ -160,6 +167,7 @@ static void InitFunctionPtrs(void)
pFreeContextBuffer = (PVOID)GetProcAddress(secdll, "FreeContextBuffer");
pQuerySecurityPackageInfoA = (PVOID)GetProcAddress(secdll, "QuerySecurityPackageInfoA");
pAcquireCredentialsHandleA = (PVOID)GetProcAddress(secdll, "AcquireCredentialsHandleA");
pAcquireCredentialsHandleW = (void*)GetProcAddress(secdll, "AcquireCredentialsHandleW");
pInitializeSecurityContextA = (PVOID)GetProcAddress(secdll, "InitializeSecurityContextA");
pCompleteAuthToken = (PVOID)GetProcAddress(secdll, "CompleteAuthToken");
pAcceptSecurityContext = (PVOID)GetProcAddress(secdll, "AcceptSecurityContext");
@ -568,10 +576,6 @@ static void testInitializeSecurityContextFlags(void)
PSecPkgInfoA pkg_info = NULL;
SspiData client;
SEC_WINNT_AUTH_IDENTITY_A id;
static char sec_pkg_name[] = "NTLM",
test_user[] = "testuser",
workgroup[] = "WORKGROUP",
test_pass[] = "testpass";
ULONG req_attr, ctxt_attr;
TimeStamp ttl;
PBYTE packet;
@ -793,10 +797,6 @@ static void testAuth(ULONG data_rep, BOOL fake)
SspiData client, server;
SEC_WINNT_AUTH_IDENTITY_A id;
SecPkgContext_Sizes ctxt_sizes;
static char sec_pkg_name[] = "NTLM",
test_user[] = "testuser",
workgroup[] = "WORKGROUP",
test_pass[] = "testpass";
if(pQuerySecurityPackageInfoA( sec_pkg_name, &pkg_info)!= SEC_E_OK)
{
@ -930,9 +930,6 @@ static void testSignSeal(void)
SecBuffer data[2], fake_data[2], complex_data[4];
ULONG qop = 0xdeadbeef;
SecPkgContext_Sizes ctxt_sizes;
static char test_user[] = "testuser",
workgroup[] = "WORKGROUP",
test_pass[] = "testpass";
complex_data[1].pvBuffer = complex_data[3].pvBuffer = NULL;
@ -1186,10 +1183,6 @@ static BOOL testAcquireCredentialsHandle(void)
{
CredHandle cred;
TimeStamp ttl;
static char test_user[] = "testuser",
workgroup[] = "WORKGROUP",
test_pass[] = "testpass",
sec_pkg_name[] = "NTLM";
SECURITY_STATUS ret;
SEC_WINNT_AUTH_IDENTITY_A id;
PSecPkgInfoA pkg_info = NULL;
@ -1251,12 +1244,98 @@ static BOOL testAcquireCredentialsHandle(void)
return TRUE;
}
static void testAcquireCredentialsHandleW(void)
{
CredHandle cred;
TimeStamp ttl;
static WCHAR sec_pkg_nameW[] = {'N','T','L','M',0 };
static WCHAR test_userW[] = {'t','e','s','t','u','s','e','r',0 };
static WCHAR workgroupW[] = {'W','O','R','K','G','R','O','U','P',0};
static WCHAR test_passW[] = {'t','e','s','t','p','a','s','s',0};
SECURITY_STATUS ret;
SEC_WINNT_AUTH_IDENTITY_A idA;
SEC_WINNT_AUTH_IDENTITY_W id;
PSecPkgInfoA pkg_info = NULL;
if(!pAcquireCredentialsHandleW)
{
win_skip("AcquireCredentialsHandleW not available\n");
return;
}
if(pQuerySecurityPackageInfoA(sec_pkg_name, &pkg_info) != SEC_E_OK)
{
ok(0, "NTLM package not installed, skipping test\n");
return;
}
pFreeContextBuffer(pkg_info);
id.User = test_userW;
id.UserLength = lstrlenW(test_userW);
id.Domain = workgroupW;
id.DomainLength = lstrlenW(workgroupW);
id.Password = test_passW;
id.PasswordLength = lstrlenW(test_passW);
id.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
ret = pAcquireCredentialsHandleW(NULL, sec_pkg_nameW, SECPKG_CRED_OUTBOUND,
NULL, &id, NULL, NULL, &cred, &ttl);
ok(ret == SEC_E_OK, "AcquireCredentialsHandeW() returned %s\n",
getSecError(ret));
pFreeCredentialsHandle(&cred);
id.DomainLength = 0;
ret = pAcquireCredentialsHandleW(NULL, sec_pkg_nameW, SECPKG_CRED_OUTBOUND,
NULL, &id, NULL, NULL, &cred, &ttl);
ok(ret == SEC_E_OK, "AcquireCredentialsHandeW() returned %s\n",
getSecError(ret));
pFreeCredentialsHandle(&cred);
id.Domain = NULL;
ret = pAcquireCredentialsHandleW(NULL, sec_pkg_nameW, SECPKG_CRED_OUTBOUND,
NULL, &id, NULL, NULL, &cred, &ttl);
ok(ret == SEC_E_OK, "AcquireCredentialsHandeW() returned %s\n",
getSecError(ret));
pFreeCredentialsHandle(&cred);
id.Domain = workgroupW;
id.DomainLength = lstrlenW(workgroupW);
id.UserLength = 0;
id.User = NULL;
ret = pAcquireCredentialsHandleW(NULL, sec_pkg_nameW, SECPKG_CRED_OUTBOUND,
NULL, &id, NULL, NULL, &cred, &ttl);
ok(ret == SEC_E_OK, "AcquireCredentialsHandeW() returned %s\n",
getSecError(ret));
pFreeCredentialsHandle(&cred);
id.User = test_userW;
id.UserLength = lstrlenW(test_userW);
id.Password = test_passW; /* NULL string causes a crash. */
id.PasswordLength = 0;
ret = pAcquireCredentialsHandleW(NULL, sec_pkg_nameW, SECPKG_CRED_OUTBOUND,
NULL, &id, NULL, NULL, &cred, &ttl);
ok(ret == SEC_E_OK, "AcquireCredentialsHandeW() returned %s\n",
getSecError(ret));
pFreeCredentialsHandle(&cred);
/* Test using the ASCII structure. */
idA.User = (unsigned char*) test_user;
idA.UserLength = strlen(test_user);
idA.Domain = (unsigned char *) workgroup;
idA.DomainLength = strlen(workgroup);
idA.Password = (unsigned char*) test_pass;
idA.PasswordLength = strlen(test_pass);
idA.Flags = SEC_WINNT_AUTH_IDENTITY_ANSI;
ret = pAcquireCredentialsHandleW(NULL, sec_pkg_nameW, SECPKG_CRED_OUTBOUND,
NULL, &idA, NULL, NULL, &cred, &ttl);
ok(ret == SEC_E_OK, "AcquireCredentialsHandeW() returned %s\n",
getSecError(ret));
pFreeCredentialsHandle(&cred);
}
static void test_cred_multiple_use(void)
{
static char test_user[] = "testuser",
workgroup[] = "WORKGROUP",
test_pass[] = "testpass",
sec_pkg_name[] = "NTLM";
SECURITY_STATUS ret;
SEC_WINNT_AUTH_IDENTITY_A id;
PSecPkgInfoA pkg_info = NULL;
@ -1373,6 +1452,8 @@ START_TEST(ntlm)
pAcquireCredentialsHandleA && pInitializeSecurityContextA &&
pCompleteAuthToken && pQuerySecurityPackageInfoA)
{
testAcquireCredentialsHandleW();
if(!testAcquireCredentialsHandle())
goto cleanup;
testInitializeSecurityContextFlags();