[CRYPT32] Initial implementation of CertEnumSystemStoreLocation() (#7746)
authorRatin Gao <ratin@knsoft.org>
Tue, 11 Mar 2025 13:17:38 +0000 (21:17 +0800)
committerGitHub <noreply@github.com>
Tue, 11 Mar 2025 13:17:38 +0000 (14:17 +0100)
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.

dll/win32/crypt32/crypt32.spec
dll/win32/crypt32/store.c
modules/rostests/apitests/CMakeLists.txt
modules/rostests/apitests/crypt32/CMakeLists.txt [new file with mode: 0644]
modules/rostests/apitests/crypt32/CertEnumSystemStoreLocation.c [new file with mode: 0644]
modules/rostests/apitests/crypt32/testlist.c [new file with mode: 0644]

index fc32570..9754b02 100644 (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)
index 2b8ea1d..c89d414 100644 (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)
 {
index 92ea113..5b29c63 100644 (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)
diff --git a/modules/rostests/apitests/crypt32/CMakeLists.txt b/modules/rostests/apitests/crypt32/CMakeLists.txt
new file mode 100644 (file)
index 0000000..a34bee9
--- /dev/null
@@ -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)
diff --git a/modules/rostests/apitests/crypt32/CertEnumSystemStoreLocation.c b/modules/rostests/apitests/crypt32/CertEnumSystemStoreLocation.c
new file mode 100644 (file)
index 0000000..9dbd781
--- /dev/null
@@ -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");
+}
diff --git a/modules/rostests/apitests/crypt32/testlist.c b/modules/rostests/apitests/crypt32/testlist.c
new file mode 100644 (file)
index 0000000..45a8a29
--- /dev/null
@@ -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 }
+};