Skip to content

Commit 275c40d

Browse files
authored
[CRYPT32] Initial implementation of CertEnumSystemStoreLocation() (reactos#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.
1 parent b45debb commit 275c40d

File tree

6 files changed

+154
-0
lines changed

6 files changed

+154
-0
lines changed

dll/win32/crypt32/crypt32.spec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
@ stdcall CertEnumCertificatesInStore(ptr ptr)
4040
@ stdcall CertEnumPhysicalStore(ptr long ptr ptr)
4141
@ stdcall CertEnumSystemStore(long ptr ptr ptr)
42+
@ stdcall CertEnumSystemStoreLocation(long ptr ptr)
4243
@ stdcall CertFindAttribute(str long ptr)
4344
@ stdcall CertFindCRLInStore(ptr long long long ptr ptr)
4445
@ stdcall CertFindCTLInStore(ptr long long long ptr ptr)

dll/win32/crypt32/store.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,61 @@ BOOL WINAPI CertEnumSystemStore(DWORD dwFlags, void *pvSystemStoreLocationPara,
13581358
return ret;
13591359
}
13601360

1361+
#ifdef __REACTOS__
1362+
1363+
typedef struct _CERT_SYSTEM_STORE_LOCATION
1364+
{
1365+
DWORD dwFlags;
1366+
PCWSTR pwszStoreLocation;
1367+
} CERT_SYSTEM_STORE_LOCATION, *PCERT_SYSTEM_STORE_LOCATION;
1368+
1369+
static const CERT_SYSTEM_STORE_LOCATION gSystemStoreLocations[] = {
1370+
{ CERT_SYSTEM_STORE_CURRENT_USER, L"CurrentUser" },
1371+
{ CERT_SYSTEM_STORE_LOCAL_MACHINE, L"LocalMachine" },
1372+
{ CERT_SYSTEM_STORE_CURRENT_SERVICE, L"CurrentService" },
1373+
{ CERT_SYSTEM_STORE_SERVICES, L"Services" },
1374+
{ CERT_SYSTEM_STORE_USERS, L"Users" },
1375+
{ CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY, L"CurrentUserGroupPolicy" },
1376+
{ CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY, L"LocalMachineGroupPolicy" },
1377+
{ CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE, L"LocalMachineEnterprise" },
1378+
};
1379+
1380+
BOOL
1381+
WINAPI
1382+
CertEnumSystemStoreLocation(
1383+
_In_ DWORD dwFlags,
1384+
_Inout_opt_ void *pvArg,
1385+
__callback PFN_CERT_ENUM_SYSTEM_STORE_LOCATION pfnEnum)
1386+
{
1387+
DWORD i;
1388+
1389+
/* Check input flags */
1390+
if (dwFlags != 0)
1391+
{
1392+
SetLastError(E_INVALIDARG);
1393+
return FALSE;
1394+
}
1395+
1396+
/* Return fixed system stores */
1397+
for (i = 0; i < ARRAYSIZE(gSystemStoreLocations); i++)
1398+
{
1399+
if (!pfnEnum(gSystemStoreLocations[i].pwszStoreLocation,
1400+
gSystemStoreLocations[i].dwFlags,
1401+
NULL,
1402+
pvArg))
1403+
{
1404+
return FALSE;
1405+
}
1406+
}
1407+
1408+
/* FIXME: Return registered OID system stores by calling CryptEnumOIDFunction */
1409+
FIXME("Registered OID system stores is not enumerated\n");
1410+
1411+
return TRUE;
1412+
}
1413+
1414+
#endif /* __REACTOS__ */
1415+
13611416
BOOL WINAPI CertEnumPhysicalStore(const void *pvSystemStore, DWORD dwFlags,
13621417
void *pvArg, PFN_CERT_ENUM_PHYSICAL_STORE pfnEnum)
13631418
{

modules/rostests/apitests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ if (NOT USE_DUMMY_PSEH)
1919
add_subdirectory(compiler)
2020
endif()
2121
add_subdirectory(crt)
22+
add_subdirectory(crypt32)
2223
add_subdirectory(dbghelp)
2324
add_subdirectory(dciman32)
2425
add_subdirectory(dnsapi)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
list(APPEND SOURCE
3+
CertEnumSystemStoreLocation.c
4+
testlist.c)
5+
6+
add_executable(crypt32_apitest ${SOURCE})
7+
target_link_libraries(crypt32_apitest wine ${PSEH_LIB})
8+
set_module_type(crypt32_apitest win32cui)
9+
add_importlibs(crypt32_apitest crypt32 msvcrt kernel32 ntdll)
10+
add_rostests_file(TARGET crypt32_apitest)
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* PROJECT: ReactOS API Tests
3+
* LICENSE: MIT (https://spdx.org/licenses/MIT)
4+
* PURPOSE: Test for CertEnumSystemStoreLocation
5+
* COPYRIGHT: Copyright 2025 Ratin Gao <[email protected]>
6+
*/
7+
8+
#define WIN32_NO_STATUS
9+
#define _INC_WINDOWS
10+
#define COM_NO_WINDOWS_H
11+
12+
#include <apitest.h>
13+
#include <windef.h>
14+
#include <wincrypt.h>
15+
16+
#define ARG_CONTEXT ((PVOID)(ULONG_PTR)0x12345678)
17+
18+
typedef struct _CERT_SYSTEM_STORE_LOCATION
19+
{
20+
DWORD dwFlags;
21+
PCWSTR pwszStoreLocation;
22+
} CERT_SYSTEM_STORE_LOCATION, * PCERT_SYSTEM_STORE_LOCATION;
23+
24+
static const CERT_SYSTEM_STORE_LOCATION g_SystemStoreLocations[] = {
25+
{ CERT_SYSTEM_STORE_CURRENT_USER, L"CurrentUser" },
26+
{ CERT_SYSTEM_STORE_LOCAL_MACHINE, L"LocalMachine" },
27+
{ CERT_SYSTEM_STORE_CURRENT_SERVICE, L"CurrentService" },
28+
{ CERT_SYSTEM_STORE_SERVICES, L"Services" },
29+
{ CERT_SYSTEM_STORE_USERS, L"Users" },
30+
{ CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY, L"CurrentUserGroupPolicy" },
31+
{ CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY, L"LocalMachineGroupPolicy" },
32+
{ CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE, L"LocalMachineEnterprise" },
33+
};
34+
35+
static ULONG g_Index = 0;
36+
37+
static
38+
BOOL
39+
WINAPI
40+
CertEnumSystemStoreLocationCallback(
41+
_In_ LPCWSTR pwszStoreLocation,
42+
_In_ DWORD dwFlags,
43+
_Reserved_ void* pvReserved,
44+
_Inout_opt_ void* pvArg)
45+
{
46+
ok(pvReserved == NULL, "pvReserved is not NULL\n");
47+
ok(pvArg == ARG_CONTEXT, "pvArg incorrect\n");
48+
49+
if (g_Index < ARRAYSIZE(g_SystemStoreLocations))
50+
{
51+
ok(dwFlags == g_SystemStoreLocations[g_Index].dwFlags, "#%lu dwFlags incorrect\n", g_Index);
52+
ok(wcscmp(pwszStoreLocation, g_SystemStoreLocations[g_Index].pwszStoreLocation) == 0,
53+
"#%lu pwszStoreLocation incorrect\n",
54+
g_Index);
55+
}
56+
57+
g_Index++;
58+
return TRUE;
59+
}
60+
61+
START_TEST(CertEnumSystemStoreLocation)
62+
{
63+
BOOL bRet;
64+
65+
/* dwFlags should be 0, otherwise fail with E_INVALIDARG */
66+
bRet = CertEnumSystemStoreLocation(1, ARG_CONTEXT, CertEnumSystemStoreLocationCallback);
67+
ok(bRet == FALSE && GetLastError() == E_INVALIDARG,
68+
"CertEnumSystemStoreLocation should failed with E_INVALIDARG when dwFlags is not 0\n");
69+
70+
/* Start enumeration */
71+
bRet = CertEnumSystemStoreLocation(0, ARG_CONTEXT, CertEnumSystemStoreLocationCallback);
72+
ok(bRet != FALSE, "CertEnumSystemStoreLocation failed with 0x%08lX\n", GetLastError());
73+
ok(g_Index >= ARRAYSIZE(g_SystemStoreLocations), "Count of enumerated item incorrect\n");
74+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#define __ROS_LONG64__
2+
3+
#define STANDALONE
4+
#include <apitest.h>
5+
6+
extern void func_CertEnumSystemStoreLocation(void);
7+
8+
const struct test winetest_testlist[] =
9+
{
10+
{ "CertEnumSystemStoreLocation", func_CertEnumSystemStoreLocation },
11+
12+
{ 0, 0 }
13+
};

0 commit comments

Comments
 (0)