Hi,
While running APR's tests on Windows, I encountered a failure in the
group-name round-trip test. On this system, the process token's
primary-group SID resolves successfully through Windows, but its type is
SidTypeUser. Consequently, apr_gid_name_get() correctly returns APR_EINVAL.
The attached patch tests the Windows group-name round trip using
CreateWellKnownSid(WinBuiltinUsersSid) instead. This avoids assuming that
the token's primary-group SID identifies a group, without hard-coding a
localized group name or changing runtime validation. The non-Windows test
is unchanged.
The patch is against trunk at 6ba11501ce7b41f67b913ae213207c836711f182.
A fresh Windows x64 build with MSVC 19.52 and CMake 4.5.1 passed testuser.
Non-Windows testing was not performed.
For reference, the same change is available here:
https://github.com/urbasus/apr/tree/fix-win32-group-test
This patch was prepared with Copilot assistance and tested locally.
Thanks,
Andreas Urbán
diff --git a/test/testuser.c b/test/testuser.c
index 3ecf254..4e2d77a 100644
--- a/test/testuser.c
+++ b/test/testuser.c
@@ -19,6 +19,10 @@
#include "apr_general.h"
#include "apr_user.h"
+#ifdef WIN32
+#include <windows.h>
+#endif
+
#if APR_HAS_USER
static void uid_current(abts_case *tc, void *data)
{
@@ -78,13 +82,27 @@ static void username(abts_case *tc, void *data)
static void groupname(abts_case *tc, void *data)
{
+#ifdef WIN32
+ BYTE sid[SECURITY_MAX_SID_SIZE];
+ DWORD sidlen = sizeof(sid);
+#else
apr_uid_t uid;
+#endif
apr_gid_t gid;
apr_gid_t retreived_gid;
char *gname = NULL;
+#ifdef WIN32
+ /* A token's primary group can be a user SID rather than a group SID. */
+ if (!CreateWellKnownSid(WinBuiltinUsersSid, NULL, sid, &sidlen)) {
+ APR_ASSERT_SUCCESS(tc, "CreateWellKnownSid failed",
apr_get_os_error());
+ return;
+ }
+ gid = sid;
+#else
APR_ASSERT_SUCCESS(tc, "apr_uid_current failed",
apr_uid_current(&uid, &gid, p));
+#endif
APR_ASSERT_SUCCESS(tc, "apr_gid_name_get failed",
apr_gid_name_get(&gname, gid, p));