]> Savannah Git Hosting - gnulib.git/commitdiff
acl-permissions: Fix test-file-has-acl-2.sh failure on Cygwin.
authorBruno Haible <bruno@clisp.org>
Mon, 3 Jun 2024 15:20:20 +0000 (17:20 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 6 Jun 2024 23:22:31 +0000 (01:22 +0200)
* lib/acl-internal.c: Include <sys/types.h>, <grp.h>, <string.h>.
(acl_access_nontrivial): On Cygwin, ignore group:SYSTEM:*,
group:Administrators:*, group:Users:*, mask::* entries.
* doc/acl-resources.txt: Add one more reference.

ChangeLog
doc/acl-resources.txt
lib/acl-internal.c

index f85987ccb69dbe793f5f86b26b6622b2c0bf2157..6b27f2f15647f7aa6fea98df06c2206d4993a6e0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-06-03  Bruno Haible  <bruno@clisp.org>
+
+       acl-permissions: Fix test-file-has-acl-2.sh failure on Cygwin.
+       * lib/acl-internal.c: Include <sys/types.h>, <grp.h>, <string.h>.
+       (acl_access_nontrivial): On Cygwin, ignore group:SYSTEM:*,
+       group:Administrators:*, group:Users:*, mask::* entries.
+       * doc/acl-resources.txt: Add one more reference.
+
 2024-06-03  Bruno Haible  <bruno@clisp.org>
 
        dprintf-posix tests: Skip the memory leak test on macOS.
index a46e1a6403ad7f458f1f00d70171f1f9532a311e..5236d4722421ff66a097bbf95c9d3925818e7911 100644 (file)
@@ -7,6 +7,9 @@ POSIX ACLs
 Documents from POSIX.1e (headers & functions) and POSIX.2c (utilities):
   http://wt.tuxomania.net/publications/posix.1e/download.html
 
+Explanation of mask:
+  https://unix.stackexchange.com/questions/475698/
+
 
 Linux ACLs
 
index fbe9b2c9a06f045a1bfedd8404916e4386d9741e..ae5398306af2fd306b262753b76e6f22560c5b31 100644 (file)
@@ -1,6 +1,6 @@
 /* Test whether a file has a nontrivial ACL.  -*- coding: utf-8 -*-
 
-   Copyright (C) 2002-2003, 2005-2023 Free Software Foundation, Inc.
+   Copyright (C) 2002-2003, 2005-2024 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 
 #include "acl-internal.h"
 
+#if defined __CYGWIN__
+# include <sys/types.h>
+# include <grp.h>
+# include <string.h>
+#endif
+
 #if USE_ACL && HAVE_ACL_GET_FILE /* Linux, FreeBSD, Mac OS X, IRIX, Tru64, Cygwin >= 2.5 */
 
 # if HAVE_ACL_TYPE_EXTENDED /* Mac OS X */
@@ -63,8 +69,69 @@ acl_access_nontrivial (acl_t acl)
       acl_tag_t tag;
       if (acl_get_tag_type (ace, &tag) < 0)
         return -1;
-      if (!(tag == ACL_USER_OBJ || tag == ACL_GROUP_OBJ || tag == ACL_OTHER))
-        return 1;
+      switch (tag)
+        {
+        case ACL_USER_OBJ:
+        case ACL_GROUP_OBJ:
+        case ACL_OTHER:
+          break;
+#   ifdef __CYGWIN__
+        /* On Cygwin, a trivial ACL inside the Cygwin file system consists of
+           e.g.
+             user::rwx
+             group::r-x
+             other::r-x
+           but a trivial ACL outside the Cygwin file system has more entries:
+           e.g.
+             user::rwx
+             group::r-x
+             group:SYSTEM:rwx
+             group:Administrators:rwx
+             mask::r-x
+             other::r-x
+           or
+             user::rwx
+             group::r-x
+             group:SYSTEM:rwx
+             group:Administrators:rwx
+             group:Users:rwx
+             mask::rwx
+             other::r-x
+         */
+        case ACL_GROUP:
+          {
+            int ignorable = 0;
+            void *qualifier = acl_get_qualifier (ace);
+            if (qualifier != NULL)
+              {
+                gid_t group_id = *(gid_t const *) qualifier;
+                acl_free (qualifier);
+                struct group *group_details = getgrgid (group_id);
+                if (group_details != NULL)
+                  {
+                    const char *group_sid = group_details->gr_passwd;
+                    /* Ignore the ace if the group_sid is one of
+                       - S-1-5-18 (group "SYSTEM")
+                       - S-1-5-32-544 (group "Administrators")
+                       - S-1-5-32-545 (group "Users")
+                       Cf. <https://learn.microsoft.com/en-us/windows/win32/secauthz/well-known-sids>
+                       and look at the output of the 'mkgroup' command.  */
+                    ignorable = (strcmp (group_sid, "S-1-5-18") == 0
+                                 || strcmp (group_sid, "S-1-5-32-544") == 0
+                                 || strcmp (group_sid, "S-1-5-32-545") == 0);
+                  }
+              }
+            if (!ignorable)
+              return 1;
+          }
+          break;
+        case ACL_MASK:
+          /* XXX Is it OK to ignore acl_get_permset (ace, ...) ?  */
+          break;
+#   endif
+        default:
+          return 1;
+        }
     }
   return got_one;