https://git.reactos.org/?p=reactos.git;a=commitdiff;h=275c40d26dfb6a8c123ba377ef29f8a05a447163

commit 275c40d26dfb6a8c123ba377ef29f8a05a447163
Author:     Ratin Gao <ra...@knsoft.org>
AuthorDate: Tue Mar 11 21:17:38 2025 +0800
Commit:     GitHub <nore...@github.com>
CommitDate: Tue Mar 11 14:17:38 2025 +0100

    [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.
---
 dll/win32/crypt32/crypt32.spec                     |  1 +
 dll/win32/crypt32/store.c                          | 55 ++++++++++++++++
 modules/rostests/apitests/CMakeLists.txt           |  1 +
 modules/rostests/apitests/crypt32/CMakeLists.txt   | 10 +++
 .../apitests/crypt32/CertEnumSystemStoreLocation.c | 74 ++++++++++++++++++++++
 modules/rostests/apitests/crypt32/testlist.c       | 13 ++++
 6 files changed, 154 insertions(+)

diff --git a/dll/win32/crypt32/crypt32.spec b/dll/win32/crypt32/crypt32.spec
index fc32570b52e..9754b0296cd 100644
--- a/dll/win32/crypt32/crypt32.spec
+++ b/dll/win32/crypt32/crypt32.spec
@@ -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)
diff --git a/dll/win32/crypt32/store.c b/dll/win32/crypt32/store.c
index 2b8ea1d5d82..c89d414a2c0 100644
--- a/dll/win32/crypt32/store.c
+++ b/dll/win32/crypt32/store.c
@@ -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)
 {
diff --git a/modules/rostests/apitests/CMakeLists.txt 
b/modules/rostests/apitests/CMakeLists.txt
index 92ea11342a9..5b29c633dce 100644
--- a/modules/rostests/apitests/CMakeLists.txt
+++ b/modules/rostests/apitests/CMakeLists.txt
@@ -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
index 00000000000..a34bee9de0c
--- /dev/null
+++ b/modules/rostests/apitests/crypt32/CMakeLists.txt
@@ -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
index 00000000000..9dbd781b9df
--- /dev/null
+++ b/modules/rostests/apitests/crypt32/CertEnumSystemStoreLocation.c
@@ -0,0 +1,74 @@
+/*
+ * PROJECT:     ReactOS API Tests
+ * LICENSE:     MIT (https://spdx.org/licenses/MIT)
+ * PURPOSE:     Test for CertEnumSystemStoreLocation
+ * COPYRIGHT:   Copyright 2025 Ratin Gao <ra...@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
index 00000000000..45a8a29d118
--- /dev/null
+++ b/modules/rostests/apitests/crypt32/testlist.c
@@ -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 }
+};

Reply via email to