2007-10-30 13:37:41 +01:00
|
|
|
/*
|
|
|
|
* Credential Function Tests
|
|
|
|
*
|
|
|
|
* Copyright 2007 Robert Shearman
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wincred.h"
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
|
|
|
static BOOL (WINAPI *pCredDeleteA)(LPCSTR,DWORD,DWORD);
|
|
|
|
static BOOL (WINAPI *pCredEnumerateA)(LPCSTR,DWORD,DWORD *,PCREDENTIALA **);
|
|
|
|
static VOID (WINAPI *pCredFree)(PVOID);
|
2008-02-13 22:10:55 +01:00
|
|
|
static BOOL (WINAPI *pCredGetSessionTypes)(DWORD,LPDWORD);
|
2007-10-30 13:37:41 +01:00
|
|
|
static BOOL (WINAPI *pCredReadA)(LPCSTR,DWORD,DWORD,PCREDENTIALA *);
|
|
|
|
static BOOL (WINAPI *pCredRenameA)(LPCSTR,LPCSTR,DWORD,DWORD);
|
|
|
|
static BOOL (WINAPI *pCredWriteA)(PCREDENTIALA,DWORD);
|
|
|
|
|
|
|
|
#define TEST_TARGET_NAME "credtest.winehq.org"
|
|
|
|
#define TEST_TARGET_NAME2 "credtest2.winehq.org"
|
2008-02-13 22:07:08 +01:00
|
|
|
static const WCHAR TEST_PASSWORD[] = {'p','4','$','$','w','0','r','d','!',0};
|
2007-10-30 13:37:41 +01:00
|
|
|
|
|
|
|
static void test_CredReadA(void)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
PCREDENTIALA cred;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pCredReadA(TEST_TARGET_NAME, -1, 0, &cred);
|
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
|
|
|
|
"CredReadA should have failed with ERROR_INVALID_PARAMETER instead of %d\n",
|
|
|
|
GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pCredReadA(TEST_TARGET_NAME, CRED_TYPE_GENERIC, 0xdeadbeef, &cred);
|
2008-01-25 01:23:00 +01:00
|
|
|
ok(!ret && ( GetLastError() == ERROR_INVALID_FLAGS || GetLastError() == ERROR_INVALID_PARAMETER ),
|
|
|
|
"CredReadA should have failed with ERROR_INVALID_FLAGS or ERROR_INVALID_PARAMETER instead of %d\n",
|
2007-10-30 13:37:41 +01:00
|
|
|
GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pCredReadA(NULL, CRED_TYPE_GENERIC, 0, &cred);
|
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
|
|
|
|
"CredReadA should have failed with ERROR_INVALID_PARAMETER instead of %d\n",
|
|
|
|
GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_CredWriteA(void)
|
|
|
|
{
|
|
|
|
CREDENTIALA new_cred;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pCredWriteA(NULL, 0);
|
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
|
|
|
|
"CredWriteA should have failed with ERROR_INVALID_PARAMETER instead of %d\n",
|
|
|
|
GetLastError());
|
|
|
|
|
|
|
|
new_cred.Flags = 0;
|
|
|
|
new_cred.Type = CRED_TYPE_GENERIC;
|
|
|
|
new_cred.TargetName = NULL;
|
|
|
|
new_cred.Comment = (char *)"Comment";
|
|
|
|
new_cred.CredentialBlobSize = 0;
|
|
|
|
new_cred.CredentialBlob = NULL;
|
|
|
|
new_cred.Persist = CRED_PERSIST_ENTERPRISE;
|
|
|
|
new_cred.AttributeCount = 0;
|
|
|
|
new_cred.Attributes = NULL;
|
|
|
|
new_cred.TargetAlias = NULL;
|
|
|
|
new_cred.UserName = (char *)"winetest";
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pCredWriteA(&new_cred, 0);
|
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
|
|
|
|
"CredWriteA should have failed with ERROR_INVALID_PARAMETER instead of %d\n",
|
|
|
|
GetLastError());
|
|
|
|
|
|
|
|
new_cred.TargetName = (char *)TEST_TARGET_NAME;
|
|
|
|
new_cred.Type = CRED_TYPE_DOMAIN_PASSWORD;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pCredWriteA(&new_cred, 0);
|
2008-01-25 01:23:00 +01:00
|
|
|
ok(!ret && ( GetLastError() == ERROR_BAD_USERNAME || GetLastError() == ERROR_NO_SUCH_LOGON_SESSION /* Vista */ ),
|
|
|
|
"CredWrite with username without domain should return ERROR_BAD_USERNAME or ERROR_NO_SUCH_LOGON_SESSION not %d\n", GetLastError());
|
2007-10-30 13:37:41 +01:00
|
|
|
|
|
|
|
new_cred.UserName = NULL;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pCredWriteA(&new_cred, 0);
|
|
|
|
ok(!ret && GetLastError() == ERROR_BAD_USERNAME,
|
|
|
|
"CredWriteA with NULL username should have failed with ERROR_BAD_USERNAME instead of %d\n",
|
|
|
|
GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_CredDeleteA(void)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pCredDeleteA(TEST_TARGET_NAME, -1, 0);
|
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
|
|
|
|
"CredDeleteA should have failed with ERROR_INVALID_PARAMETER instead of %d\n",
|
|
|
|
GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pCredDeleteA(TEST_TARGET_NAME, CRED_TYPE_GENERIC, 0xdeadbeef);
|
2008-01-25 01:23:00 +01:00
|
|
|
ok(!ret && ( GetLastError() == ERROR_INVALID_FLAGS || GetLastError() == ERROR_INVALID_PARAMETER /* Vista */ ),
|
|
|
|
"CredDeleteA should have failed with ERROR_INVALID_FLAGS or ERROR_INVALID_PARAMETER instead of %d\n",
|
2007-10-30 13:37:41 +01:00
|
|
|
GetLastError());
|
|
|
|
}
|
|
|
|
|
2008-02-13 22:10:55 +01:00
|
|
|
static void check_blob(int line, DWORD cred_type, PCREDENTIALA cred)
|
|
|
|
{
|
|
|
|
if (cred_type == CRED_TYPE_DOMAIN_PASSWORD)
|
|
|
|
{
|
|
|
|
todo_wine
|
|
|
|
ok_(__FILE__, line)(cred->CredentialBlobSize == 0, "expected CredentialBlobSize of 0 but got %d\n", cred->CredentialBlobSize);
|
|
|
|
todo_wine
|
|
|
|
ok_(__FILE__, line)(!cred->CredentialBlob, "expected NULL credentials but got %p\n", cred->CredentialBlob);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD size=sizeof(TEST_PASSWORD);
|
|
|
|
ok_(__FILE__, line)(cred->CredentialBlobSize == size, "expected CredentialBlobSize of %u but got %u\n", size, cred->CredentialBlobSize);
|
|
|
|
ok_(__FILE__, line)(cred->CredentialBlob != NULL, "CredentialBlob should be present\n");
|
|
|
|
if (cred->CredentialBlob)
|
|
|
|
ok_(__FILE__, line)(!memcmp(cred->CredentialBlob, TEST_PASSWORD, size), "wrong CredentialBlob\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-30 13:37:41 +01:00
|
|
|
static void test_generic(void)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
DWORD count, i;
|
|
|
|
PCREDENTIALA *creds;
|
|
|
|
CREDENTIALA new_cred;
|
|
|
|
PCREDENTIALA cred;
|
|
|
|
BOOL found = FALSE;
|
|
|
|
|
|
|
|
new_cred.Flags = 0;
|
|
|
|
new_cred.Type = CRED_TYPE_GENERIC;
|
|
|
|
new_cred.TargetName = (char *)TEST_TARGET_NAME;
|
|
|
|
new_cred.Comment = (char *)"Comment";
|
2008-02-13 22:07:08 +01:00
|
|
|
new_cred.CredentialBlobSize = sizeof(TEST_PASSWORD);
|
|
|
|
new_cred.CredentialBlob = (LPBYTE)TEST_PASSWORD;
|
2007-10-30 13:37:41 +01:00
|
|
|
new_cred.Persist = CRED_PERSIST_ENTERPRISE;
|
|
|
|
new_cred.AttributeCount = 0;
|
|
|
|
new_cred.Attributes = NULL;
|
|
|
|
new_cred.TargetAlias = NULL;
|
|
|
|
new_cred.UserName = (char *)"winetest";
|
|
|
|
|
|
|
|
ret = pCredWriteA(&new_cred, 0);
|
|
|
|
ok(ret, "CredWriteA failed with error %d\n", GetLastError());
|
|
|
|
|
|
|
|
ret = pCredEnumerateA(NULL, 0, &count, &creds);
|
|
|
|
ok(ret, "CredEnumerateA failed with error %d\n", GetLastError());
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (!strcmp(creds[i]->TargetName, TEST_TARGET_NAME))
|
|
|
|
{
|
|
|
|
ok(creds[i]->Type == CRED_TYPE_GENERIC, "expected creds[%d]->Type CRED_TYPE_GENERIC but got %d\n", i, creds[i]->Type);
|
|
|
|
ok(!creds[i]->Flags, "expected creds[%d]->Flags 0 but got 0x%x\n", i, creds[i]->Flags);
|
|
|
|
ok(!strcmp(creds[i]->Comment, "Comment"), "expected creds[%d]->Comment \"Comment\" but got \"%s\"\n", i, creds[i]->Comment);
|
2008-02-13 22:10:55 +01:00
|
|
|
check_blob(__LINE__, CRED_TYPE_GENERIC, creds[i]);
|
2007-10-30 13:37:41 +01:00
|
|
|
ok(creds[i]->Persist, "expected creds[%d]->Persist CRED_PERSIST_ENTERPRISE but got %d\n", i, creds[i]->Persist);
|
|
|
|
ok(!strcmp(creds[i]->UserName, "winetest"), "expected creds[%d]->UserName \"winetest\" but got \"%s\"\n", i, creds[i]->UserName);
|
|
|
|
found = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pCredFree(creds);
|
|
|
|
ok(found, "credentials not found\n");
|
|
|
|
|
|
|
|
ret = pCredReadA(TEST_TARGET_NAME, CRED_TYPE_GENERIC, 0, &cred);
|
|
|
|
ok(ret, "CredReadA failed with error %d\n", GetLastError());
|
|
|
|
pCredFree(cred);
|
|
|
|
|
|
|
|
ret = pCredDeleteA(TEST_TARGET_NAME, CRED_TYPE_GENERIC, 0);
|
|
|
|
ok(ret, "CredDeleteA failed with error %d\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
2008-02-13 22:10:55 +01:00
|
|
|
static void test_domain_password(DWORD cred_type)
|
2007-10-30 13:37:41 +01:00
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
DWORD count, i;
|
|
|
|
PCREDENTIALA *creds;
|
|
|
|
CREDENTIALA new_cred;
|
|
|
|
PCREDENTIALA cred;
|
|
|
|
BOOL found = FALSE;
|
|
|
|
|
|
|
|
new_cred.Flags = 0;
|
2008-02-13 22:10:55 +01:00
|
|
|
new_cred.Type = cred_type;
|
2007-10-30 13:37:41 +01:00
|
|
|
new_cred.TargetName = (char *)TEST_TARGET_NAME;
|
|
|
|
new_cred.Comment = (char *)"Comment";
|
2008-02-13 22:07:08 +01:00
|
|
|
new_cred.CredentialBlobSize = sizeof(TEST_PASSWORD);
|
|
|
|
new_cred.CredentialBlob = (LPBYTE)TEST_PASSWORD;
|
2007-10-30 13:37:41 +01:00
|
|
|
new_cred.Persist = CRED_PERSIST_ENTERPRISE;
|
|
|
|
new_cred.AttributeCount = 0;
|
|
|
|
new_cred.Attributes = NULL;
|
|
|
|
new_cred.TargetAlias = NULL;
|
|
|
|
new_cred.UserName = (char *)"test\\winetest";
|
|
|
|
ret = pCredWriteA(&new_cred, 0);
|
|
|
|
ok(ret, "CredWriteA failed with error %d\n", GetLastError());
|
|
|
|
|
|
|
|
ret = pCredEnumerateA(NULL, 0, &count, &creds);
|
|
|
|
ok(ret, "CredEnumerateA failed with error %d\n", GetLastError());
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (!strcmp(creds[i]->TargetName, TEST_TARGET_NAME))
|
|
|
|
{
|
2008-02-13 22:10:55 +01:00
|
|
|
ok(creds[i]->Type == cred_type, "expected creds[%d]->Type CRED_TYPE_DOMAIN_PASSWORD but got %d\n", i, creds[i]->Type);
|
2007-10-30 13:37:41 +01:00
|
|
|
ok(!creds[i]->Flags, "expected creds[%d]->Flags 0 but got 0x%x\n", i, creds[i]->Flags);
|
|
|
|
ok(!strcmp(creds[i]->Comment, "Comment"), "expected creds[%d]->Comment \"Comment\" but got \"%s\"\n", i, creds[i]->Comment);
|
2008-02-13 22:10:55 +01:00
|
|
|
check_blob(__LINE__, cred_type, creds[i]);
|
2007-10-30 13:37:41 +01:00
|
|
|
ok(creds[i]->Persist, "expected creds[%d]->Persist CRED_PERSIST_ENTERPRISE but got %d\n", i, creds[i]->Persist);
|
|
|
|
ok(!strcmp(creds[i]->UserName, "test\\winetest"), "expected creds[%d]->UserName \"winetest\" but got \"%s\"\n", i, creds[i]->UserName);
|
|
|
|
found = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pCredFree(creds);
|
|
|
|
ok(found, "credentials not found\n");
|
|
|
|
|
2008-02-13 22:10:55 +01:00
|
|
|
ret = pCredReadA(TEST_TARGET_NAME, cred_type, 0, &cred);
|
2007-10-30 13:37:41 +01:00
|
|
|
ok(ret, "CredReadA failed with error %d\n", GetLastError());
|
2008-01-25 01:23:00 +01:00
|
|
|
if (ret) /* don't check the values of cred, if CredReadA failed. */
|
|
|
|
{
|
2008-02-13 22:10:55 +01:00
|
|
|
check_blob(__LINE__, cred_type, cred);
|
2008-01-25 01:23:00 +01:00
|
|
|
pCredFree(cred);
|
|
|
|
}
|
2007-10-30 13:37:41 +01:00
|
|
|
|
2008-02-13 22:10:55 +01:00
|
|
|
ret = pCredDeleteA(TEST_TARGET_NAME, cred_type, 0);
|
2007-10-30 13:37:41 +01:00
|
|
|
ok(ret, "CredDeleteA failed with error %d\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(cred)
|
|
|
|
{
|
2008-02-13 22:10:55 +01:00
|
|
|
DWORD persists[CRED_TYPE_MAXIMUM];
|
|
|
|
|
2007-10-30 13:37:41 +01:00
|
|
|
pCredEnumerateA = (void *)GetProcAddress(GetModuleHandle("advapi32.dll"), "CredEnumerateA");
|
|
|
|
pCredFree = (void *)GetProcAddress(GetModuleHandle("advapi32.dll"), "CredFree");
|
2008-02-13 22:10:55 +01:00
|
|
|
pCredGetSessionTypes = (void *)GetProcAddress(GetModuleHandle("advapi32.dll"), "CredGetSessionTypes");
|
2007-10-30 13:37:41 +01:00
|
|
|
pCredWriteA = (void *)GetProcAddress(GetModuleHandle("advapi32.dll"), "CredWriteA");
|
|
|
|
pCredDeleteA = (void *)GetProcAddress(GetModuleHandle("advapi32.dll"), "CredDeleteA");
|
|
|
|
pCredReadA = (void *)GetProcAddress(GetModuleHandle("advapi32.dll"), "CredReadA");
|
|
|
|
pCredRenameA = (void *)GetProcAddress(GetModuleHandle("advapi32.dll"), "CredRenameA");
|
|
|
|
|
|
|
|
if (!pCredEnumerateA || !pCredFree || !pCredWriteA || !pCredDeleteA ||
|
|
|
|
!pCredReadA)
|
|
|
|
{
|
|
|
|
skip("credentials functions not present in advapi32.dll\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-13 22:10:55 +01:00
|
|
|
if (pCredGetSessionTypes)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
DWORD i;
|
|
|
|
ret = pCredGetSessionTypes(CRED_TYPE_MAXIMUM, persists);
|
|
|
|
ok(ret, "CredGetSessionTypes failed with error %d\n", GetLastError());
|
|
|
|
ok(persists[0] == CRED_PERSIST_NONE, "persists[0] = %u instead of CRED_PERSIST_NONE\n", persists[0]);
|
|
|
|
for (i=0; i < CRED_TYPE_MAXIMUM; i++)
|
|
|
|
ok(persists[i] <= CRED_PERSIST_ENTERPRISE, "bad value for persists[%u]: %u\n", i, persists[i]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
memset(persists, CRED_PERSIST_ENTERPRISE, sizeof(persists));
|
|
|
|
|
2007-10-30 13:37:41 +01:00
|
|
|
test_CredReadA();
|
|
|
|
test_CredWriteA();
|
|
|
|
test_CredDeleteA();
|
|
|
|
|
|
|
|
trace("generic:\n");
|
2008-02-13 22:10:55 +01:00
|
|
|
if (persists[CRED_TYPE_GENERIC] == CRED_PERSIST_NONE)
|
|
|
|
skip("CRED_TYPE_GENERIC credentials are not supported or are disabled. Skipping\n");
|
|
|
|
else
|
|
|
|
test_generic();
|
|
|
|
|
|
|
|
trace("domain password:\n");
|
|
|
|
if (persists[CRED_TYPE_DOMAIN_PASSWORD] == CRED_PERSIST_NONE)
|
|
|
|
skip("CRED_TYPE_DOMAIN_PASSWORD credentials are not supported or are disabled. Skipping\n");
|
|
|
|
else
|
|
|
|
test_domain_password(CRED_TYPE_DOMAIN_PASSWORD);
|
|
|
|
|
|
|
|
trace("domain visible password:\n");
|
|
|
|
if (persists[CRED_TYPE_DOMAIN_VISIBLE_PASSWORD] == CRED_PERSIST_NONE)
|
|
|
|
skip("CRED_TYPE_DOMAIN_VISIBLE_PASSWORD credentials are not supported or are disabled. Skipping\n");
|
|
|
|
else
|
|
|
|
test_domain_password(CRED_TYPE_DOMAIN_VISIBLE_PASSWORD);
|
2007-10-30 13:37:41 +01:00
|
|
|
}
|