[CRYPT32] Initial implementation of CertEnumSystemStoreLocation() (#7746)

Initial implementation of `CertEnumSystemStoreLocation`, which is required by the latest "VirtualBox Guest Additions".

This function returns 8 fixed hard-coded system stores and registered OID system stores, this PR didn't implement the latter because `CryptEnumOIDFunction` is unimplemented, marked as FIXME.
This commit is contained in:
Ratin Gao 2025-03-11 21:17:38 +08:00 committed by GitHub
parent b45debb93a
commit 275c40d26d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 154 additions and 0 deletions

View file

@ -39,6 +39,7 @@
@ stdcall CertEnumCertificatesInStore(ptr ptr)
@ stdcall CertEnumPhysicalStore(ptr long ptr ptr)
@ stdcall CertEnumSystemStore(long ptr ptr ptr)
@ stdcall CertEnumSystemStoreLocation(long ptr ptr)
@ stdcall CertFindAttribute(str long ptr)
@ stdcall CertFindCRLInStore(ptr long long long ptr ptr)
@ stdcall CertFindCTLInStore(ptr long long long ptr ptr)

View file

@ -1358,6 +1358,61 @@ BOOL WINAPI CertEnumSystemStore(DWORD dwFlags, void *pvSystemStoreLocationPara,
return ret;
}
#ifdef __REACTOS__
typedef struct _CERT_SYSTEM_STORE_LOCATION
{
DWORD dwFlags;
PCWSTR pwszStoreLocation;
} CERT_SYSTEM_STORE_LOCATION, *PCERT_SYSTEM_STORE_LOCATION;
static const CERT_SYSTEM_STORE_LOCATION gSystemStoreLocations[] = {
{ CERT_SYSTEM_STORE_CURRENT_USER, L"CurrentUser" },
{ CERT_SYSTEM_STORE_LOCAL_MACHINE, L"LocalMachine" },
{ CERT_SYSTEM_STORE_CURRENT_SERVICE, L"CurrentService" },
{ CERT_SYSTEM_STORE_SERVICES, L"Services" },
{ CERT_SYSTEM_STORE_USERS, L"Users" },
{ CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY, L"CurrentUserGroupPolicy" },
{ CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY, L"LocalMachineGroupPolicy" },
{ CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE, L"LocalMachineEnterprise" },
};
BOOL
WINAPI
CertEnumSystemStoreLocation(
_In_ DWORD dwFlags,
_Inout_opt_ void *pvArg,
__callback PFN_CERT_ENUM_SYSTEM_STORE_LOCATION pfnEnum)
{
DWORD i;
/* Check input flags */
if (dwFlags != 0)
{
SetLastError(E_INVALIDARG);
return FALSE;
}
/* Return fixed system stores */
for (i = 0; i < ARRAYSIZE(gSystemStoreLocations); i++)
{
if (!pfnEnum(gSystemStoreLocations[i].pwszStoreLocation,
gSystemStoreLocations[i].dwFlags,
NULL,
pvArg))
{
return FALSE;
}
}
/* FIXME: Return registered OID system stores by calling CryptEnumOIDFunction */
FIXME("Registered OID system stores is not enumerated\n");
return TRUE;
}
#endif /* __REACTOS__ */
BOOL WINAPI CertEnumPhysicalStore(const void *pvSystemStore, DWORD dwFlags,
void *pvArg, PFN_CERT_ENUM_PHYSICAL_STORE pfnEnum)
{

View file

@ -19,6 +19,7 @@ if (NOT USE_DUMMY_PSEH)
add_subdirectory(compiler)
endif()
add_subdirectory(crt)
add_subdirectory(crypt32)
add_subdirectory(dbghelp)
add_subdirectory(dciman32)
add_subdirectory(dnsapi)

View file

@ -0,0 +1,10 @@
list(APPEND SOURCE
CertEnumSystemStoreLocation.c
testlist.c)
add_executable(crypt32_apitest ${SOURCE})
target_link_libraries(crypt32_apitest wine ${PSEH_LIB})
set_module_type(crypt32_apitest win32cui)
add_importlibs(crypt32_apitest crypt32 msvcrt kernel32 ntdll)
add_rostests_file(TARGET crypt32_apitest)

View file

@ -0,0 +1,74 @@
/*
* PROJECT: ReactOS API Tests
* LICENSE: MIT (https://spdx.org/licenses/MIT)
* PURPOSE: Test for CertEnumSystemStoreLocation
* COPYRIGHT: Copyright 2025 Ratin Gao <ratin@knsoft.org>
*/
#define WIN32_NO_STATUS
#define _INC_WINDOWS
#define COM_NO_WINDOWS_H
#include <apitest.h>
#include <windef.h>
#include <wincrypt.h>
#define ARG_CONTEXT ((PVOID)(ULONG_PTR)0x12345678)
typedef struct _CERT_SYSTEM_STORE_LOCATION
{
DWORD dwFlags;
PCWSTR pwszStoreLocation;
} CERT_SYSTEM_STORE_LOCATION, * PCERT_SYSTEM_STORE_LOCATION;
static const CERT_SYSTEM_STORE_LOCATION g_SystemStoreLocations[] = {
{ CERT_SYSTEM_STORE_CURRENT_USER, L"CurrentUser" },
{ CERT_SYSTEM_STORE_LOCAL_MACHINE, L"LocalMachine" },
{ CERT_SYSTEM_STORE_CURRENT_SERVICE, L"CurrentService" },
{ CERT_SYSTEM_STORE_SERVICES, L"Services" },
{ CERT_SYSTEM_STORE_USERS, L"Users" },
{ CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY, L"CurrentUserGroupPolicy" },
{ CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY, L"LocalMachineGroupPolicy" },
{ CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE, L"LocalMachineEnterprise" },
};
static ULONG g_Index = 0;
static
BOOL
WINAPI
CertEnumSystemStoreLocationCallback(
_In_ LPCWSTR pwszStoreLocation,
_In_ DWORD dwFlags,
_Reserved_ void* pvReserved,
_Inout_opt_ void* pvArg)
{
ok(pvReserved == NULL, "pvReserved is not NULL\n");
ok(pvArg == ARG_CONTEXT, "pvArg incorrect\n");
if (g_Index < ARRAYSIZE(g_SystemStoreLocations))
{
ok(dwFlags == g_SystemStoreLocations[g_Index].dwFlags, "#%lu dwFlags incorrect\n", g_Index);
ok(wcscmp(pwszStoreLocation, g_SystemStoreLocations[g_Index].pwszStoreLocation) == 0,
"#%lu pwszStoreLocation incorrect\n",
g_Index);
}
g_Index++;
return TRUE;
}
START_TEST(CertEnumSystemStoreLocation)
{
BOOL bRet;
/* dwFlags should be 0, otherwise fail with E_INVALIDARG */
bRet = CertEnumSystemStoreLocation(1, ARG_CONTEXT, CertEnumSystemStoreLocationCallback);
ok(bRet == FALSE && GetLastError() == E_INVALIDARG,
"CertEnumSystemStoreLocation should failed with E_INVALIDARG when dwFlags is not 0\n");
/* Start enumeration */
bRet = CertEnumSystemStoreLocation(0, ARG_CONTEXT, CertEnumSystemStoreLocationCallback);
ok(bRet != FALSE, "CertEnumSystemStoreLocation failed with 0x%08lX\n", GetLastError());
ok(g_Index >= ARRAYSIZE(g_SystemStoreLocations), "Count of enumerated item incorrect\n");
}

View file

@ -0,0 +1,13 @@
#define __ROS_LONG64__
#define STANDALONE
#include <apitest.h>
extern void func_CertEnumSystemStoreLocation(void);
const struct test winetest_testlist[] =
{
{ "CertEnumSystemStoreLocation", func_CertEnumSystemStoreLocation },
{ 0, 0 }
};