From 14c38be04dcf5078b08927fd3fa12bea7f5a9891 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 25 Dec 2024 01:34:23 +0100 Subject: [PATCH] access, euidaccess tests: Avoid test failure in Cygwin 3.5.5. * tests/test-access.h [__CYGWIN__]: Include , , . (is_administrator): New function. (is_root): New macro. (test_access): Reenable F_OK test for non-administrators on Cygwin. Disable X_OK test for administrators on Cygwin. --- ChangeLog | 10 +++++++++ tests/test-access.h | 49 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5d86ec951c..b39a4f48b0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2024-12-24 Bruno Haible + + access, euidaccess tests: Avoid test failure in Cygwin 3.5.5. + * tests/test-access.h [__CYGWIN__]: Include , , + . + (is_administrator): New function. + (is_root): New macro. + (test_access): Reenable F_OK test for non-administrators on Cygwin. + Disable X_OK test for administrators on Cygwin. + 2024-12-24 Bruno Haible wchar: Support several gnulib-tool invocations better. diff --git a/tests/test-access.h b/tests/test-access.h index 2bc98146fa..5f537526ef 100644 --- a/tests/test-access.h +++ b/tests/test-access.h @@ -19,6 +19,38 @@ # define geteuid() ROOT_UID #endif +#if defined __CYGWIN__ +/* Cygwin uses the security model from Windows. */ +# include +# include +# include +/* Test whether the current user is in the 'Administrators' group. + We cannot use the group name "Administrators", due to internationalization. + Therefore test for the SID "S-1-5-32-544" (cf. + ). + */ +static int +is_administrator (void) +{ + gid_t list[100]; + int i; + int count = getgroups (sizeof (list) / sizeof (list[0]), list); + if (count < 0) + return 0; + for (i = 0; i < count; i++) + { + gid_t id = list[i]; + struct group *details = getgrgid (id); + if (details != NULL && strcmp (details->gr_passwd, "S-1-5-32-544") == 0) + return 1; + } + return 0; +} +# define is_root() is_administrator () +#else +# define is_root() (geteuid () == ROOT_UID) +#endif + static void test_access (int (*func) (const char * /*file*/, int /*mode*/)) { @@ -79,22 +111,27 @@ test_access (int (*func) (const char * /*file*/, int /*mode*/)) /* On Cygwin, for users that are in the 'Administrators' group, W_OK is allowed. */ -#if !defined __CYGWIN__ - if (geteuid () != ROOT_UID) + if (! is_root ()) { errno = 0; ASSERT (func (BASE "f2", W_OK) == -1); ASSERT (errno == EACCES); } -#endif #if defined _WIN32 && !defined __CYGWIN__ /* X_OK works like R_OK. */ ASSERT (func (BASE "f2", X_OK) == 0); #else - errno = 0; - ASSERT (func (BASE "f2", X_OK) == -1); - ASSERT (errno == EACCES); + /* On Cygwin 3.5.5, for users that are in the 'Administrators' group, + X_OK is allowed. */ +# if defined __CYGWIN__ + if (! is_root ()) +# endif + { + errno = 0; + ASSERT (func (BASE "f2", X_OK) == -1); + ASSERT (errno == EACCES); + } #endif } -- 2.39.5