changeset 39854:02e3e9bb4409

file-has-acl: Fix test failure on Cygwin 2.9. * m4/acl.m4 (gl_FUNC_ACL): Update comments regarding Cygwin. * lib/acl-internal.h: Likewise. (HAVE_ACL_EXTENDED_FILE): Undefine on Cygwin. * lib/acl-internal.c: Update comments regarding Cygwin. * lib/acl_entries.c: Likewise. * lib/file-has-acl.c: Likewise. (file_has_acl): For Cygwin, use a different way to determine whether the "default" ACL of a directory is nontrivial. * lib/get-permissions.c: Update comments regarding Cygwin. * lib/set-permissions.c: Likewise.
author Bruno Haible <bruno@clisp.org>
date Tue, 18 Sep 2018 22:58:23 +0200
parents 508633341b55
children a29036ff511d
files ChangeLog lib/acl-internal.c lib/acl-internal.h lib/acl_entries.c lib/file-has-acl.c lib/get-permissions.c lib/set-permissions.c m4/acl.m4
diffstat 8 files changed, 60 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Sep 18 21:27:15 2018 +0200
+++ b/ChangeLog	Tue Sep 18 22:58:23 2018 +0200
@@ -1,3 +1,17 @@
+2018-09-18  Bruno Haible  <bruno@clisp.org>
+
+	file-has-acl: Fix test failure on Cygwin 2.9.
+	* m4/acl.m4 (gl_FUNC_ACL): Update comments regarding Cygwin.
+	* lib/acl-internal.h: Likewise.
+	(HAVE_ACL_EXTENDED_FILE): Undefine on Cygwin.
+	* lib/acl-internal.c: Update comments regarding Cygwin.
+	* lib/acl_entries.c: Likewise.
+	* lib/file-has-acl.c: Likewise.
+	(file_has_acl): For Cygwin, use a different way to determine whether
+	the "default" ACL of a directory is nontrivial.
+	* lib/get-permissions.c: Update comments regarding Cygwin.
+	* lib/set-permissions.c: Likewise.
+
 2018-09-18  Bruno Haible  <bruno@clisp.org>
 
 	stat-time tests: Fix test failure on Cygwin.
--- a/lib/acl-internal.c	Tue Sep 18 21:27:15 2018 +0200
+++ b/lib/acl-internal.c	Tue Sep 18 22:58:23 2018 +0200
@@ -23,7 +23,7 @@
 
 #include "acl-internal.h"
 
-#if USE_ACL && HAVE_ACL_GET_FILE
+#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 */
 
@@ -37,7 +37,7 @@
   return (acl_entries (acl) > 0);
 }
 
-# else /* Linux, FreeBSD, IRIX, Tru64 */
+# else /* Linux, FreeBSD, IRIX, Tru64, Cygwin >= 2.5 */
 
 /* ACL is an ACL, from a file, stored as type ACL_TYPE_ACCESS.
    Return 1 if the given ACL is non-trivial.
@@ -51,7 +51,7 @@
      at least, allowing us to write
         return (3 < acl_entries (acl));
      but the following code is more robust.  */
-#  if HAVE_ACL_FIRST_ENTRY /* Linux, FreeBSD */
+#  if HAVE_ACL_FIRST_ENTRY /* Linux, FreeBSD, Cygwin >= 2.5 */
 
   acl_entry_t ace;
   int got_one;
@@ -124,7 +124,7 @@
 
 # endif
 
-#elif USE_ACL && HAVE_FACL && defined GETACL /* Solaris, Cygwin, not HP-UX */
+#elif USE_ACL && HAVE_FACL && defined GETACL /* Solaris, Cygwin < 2.5, not HP-UX */
 
 /* Test an ACL retrieved with GETACL.
    Return 1 if the given ACL, consisting of COUNT entries, is non-trivial.
@@ -479,7 +479,7 @@
 free_permission_context (struct permission_context *ctx)
 {
 #if USE_ACL
-# if HAVE_ACL_GET_FILE /* Linux, FreeBSD, Mac OS X, IRIX, Tru64 */
+# if HAVE_ACL_GET_FILE /* Linux, FreeBSD, Mac OS X, IRIX, Tru64, Cygwin >= 2.5 */
   if (ctx->acl)
     acl_free (ctx->acl);
 #  if !HAVE_ACL_TYPE_EXTENDED
@@ -487,7 +487,7 @@
     acl_free (ctx->default_acl);
 #  endif
 
-# elif defined GETACL /* Solaris, Cygwin */
+# elif defined GETACL /* Solaris, Cygwin < 2.5 */
   free (ctx->entries);
 #  ifdef ACE_GETACL
   free (ctx->ace_entries);
--- a/lib/acl-internal.h	Tue Sep 18 21:27:15 2018 +0200
+++ b/lib/acl-internal.h	Tue Sep 18 22:58:23 2018 +0200
@@ -30,7 +30,8 @@
 # define GETACLCNT ACL_CNT
 #endif
 
-/* On Linux, additional ACL related API is available in <acl/libacl.h>.  */
+/* On Linux and Cygwin >= 2.5, additional ACL related API is available in
+   <acl/libacl.h>.  */
 #ifdef HAVE_ACL_LIBACL_H
 # include <acl/libacl.h>
 #endif
@@ -72,7 +73,7 @@
 
 # if HAVE_ACL_GET_FILE
 /* POSIX 1003.1e (draft 17 -- abandoned) specific version.  */
-/* Linux, FreeBSD, Mac OS X, IRIX, Tru64 */
+/* Linux, FreeBSD, Mac OS X, IRIX, Tru64, Cygwin >= 2.5 */
 
 #  ifndef MIN_ACL_ENTRIES
 #   define MIN_ACL_ENTRIES 4
@@ -122,7 +123,10 @@
 #  endif
 
 /* Linux-specific */
-#  ifndef HAVE_ACL_EXTENDED_FILE
+/* Cygwin >= 2.5 implements this function, but it returns 1 for all
+   directories, thus is unusable.  */
+#  if !defined HAVE_ACL_EXTENDED_FILE || defined __CYGWIN__
+#   undef HAVE_ACL_EXTENDED_FILE
 #   define HAVE_ACL_EXTENDED_FILE false
 #   define acl_extended_file(name) (-1)
 #  endif
@@ -163,7 +167,7 @@
 extern int acl_default_nontrivial (acl_t);
 #  endif
 
-# elif HAVE_FACL && defined GETACL /* Solaris, Cygwin, not HP-UX */
+# elif HAVE_FACL && defined GETACL /* Solaris, Cygwin < 2.5, not HP-UX */
 
 /* Set to 0 if a file's mode is stored independently from the ACL.  */
 #  if defined __CYGWIN__ /* Cygwin */
@@ -256,14 +260,14 @@
 struct permission_context {
   mode_t mode;
 #if USE_ACL
-# if HAVE_ACL_GET_FILE /* Linux, FreeBSD, Mac OS X, IRIX, Tru64 */
+# if HAVE_ACL_GET_FILE /* Linux, FreeBSD, Mac OS X, IRIX, Tru64, Cygwin >= 2.5 */
   acl_t acl;
 #  if !HAVE_ACL_TYPE_EXTENDED
   acl_t default_acl;
 #  endif
   bool acls_not_supported;
 
-# elif defined GETACL /* Solaris, Cygwin */
+# elif defined GETACL /* Solaris, Cygwin < 2.5 */
   int count;
   aclent_t *entries;
 #  ifdef ACE_GETACL
--- a/lib/acl_entries.c	Tue Sep 18 21:27:15 2018 +0200
+++ b/lib/acl_entries.c	Tue Sep 18 22:58:23 2018 +0200
@@ -22,7 +22,7 @@
 #include "acl-internal.h"
 
 /* This file assumes POSIX-draft like ACLs
-   (Linux, FreeBSD, Mac OS X, IRIX, Tru64).  */
+   (Linux, FreeBSD, Mac OS X, IRIX, Tru64, Cygwin >= 2.5).  */
 
 /* Return the number of entries in ACL.
    Return -1 and set errno upon failure to determine it.  */
@@ -34,7 +34,7 @@
 
   if (acl != NULL)
     {
-#if HAVE_ACL_FIRST_ENTRY /* Linux, FreeBSD, Mac OS X */
+#if HAVE_ACL_FIRST_ENTRY /* Linux, FreeBSD, Mac OS X, Cygwin >= 2.5 */
 # if HAVE_ACL_TYPE_EXTENDED /* Mac OS X */
       /* acl_get_entry returns 0 when it successfully fetches an entry,
          and -1/EINVAL at the end.  */
@@ -45,7 +45,7 @@
            got_one >= 0;
            got_one = acl_get_entry (acl, ACL_NEXT_ENTRY, &ace))
         count++;
-# else /* Linux, FreeBSD */
+# else /* Linux, FreeBSD, Cygwin >= 2.5 */
       /* acl_get_entry returns 1 when it successfully fetches an entry,
          and 0 at the end.  */
       acl_entry_t ace;
--- a/lib/file-has-acl.c	Tue Sep 18 21:27:15 2018 +0200
+++ b/lib/file-has-acl.c	Tue Sep 18 22:58:23 2018 +0200
@@ -74,7 +74,7 @@
 # elif HAVE_ACL_GET_FILE
 
       /* POSIX 1003.1e (draft 17 -- abandoned) specific version.  */
-      /* Linux, FreeBSD, Mac OS X, IRIX, Tru64 */
+      /* Linux, FreeBSD, Mac OS X, IRIX, Tru64, Cygwin >= 2.5 */
       int ret;
 
       if (HAVE_ACL_EXTENDED_FILE) /* Linux */
@@ -84,7 +84,7 @@
              ACL_TYPE_DEFAULT.  */
           ret = acl_extended_file (name);
         }
-      else /* FreeBSD, Mac OS X, IRIX, Tru64 */
+      else /* FreeBSD, Mac OS X, IRIX, Tru64, Cygwin >= 2.5 */
         {
 #  if HAVE_ACL_TYPE_EXTENDED /* Mac OS X */
           /* On Mac OS X, acl_get_file (name, ACL_TYPE_ACCESS)
@@ -100,7 +100,7 @@
             }
           else
             ret = -1;
-#  else /* FreeBSD, IRIX, Tru64 */
+#  else /* FreeBSD, IRIX, Tru64, Cygwin >= 2.5 */
           acl_t acl = acl_get_file (name, ACL_TYPE_ACCESS);
           if (acl)
             {
@@ -114,7 +114,7 @@
               /* On OSF/1, acl_get_file (name, ACL_TYPE_DEFAULT) always
                  returns NULL with errno not set.  There is no point in
                  making this call.  */
-#   else /* FreeBSD, IRIX */
+#   else /* FreeBSD, IRIX, Cygwin >= 2.5 */
               /* On Linux, FreeBSD, IRIX, acl_get_file (name, ACL_TYPE_ACCESS)
                  and acl_get_file (name, ACL_TYPE_DEFAULT) on a directory
                  either both succeed or both fail; it depends on the
@@ -125,8 +125,15 @@
                   acl = acl_get_file (name, ACL_TYPE_DEFAULT);
                   if (acl)
                     {
+#    ifdef __CYGWIN__ /* Cygwin >= 2.5 */
+                      ret = acl_access_nontrivial (acl);
+                      saved_errno = errno;
+                      acl_free (acl);
+                      errno = saved_errno;
+#    else
                       ret = (0 < acl_entries (acl));
                       acl_free (acl);
+#    endif
                     }
                   else
                     ret = -1;
@@ -141,7 +148,7 @@
         return - acl_errno_valid (errno);
       return ret;
 
-# elif HAVE_FACL && defined GETACL /* Solaris, Cygwin, not HP-UX */
+# elif HAVE_FACL && defined GETACL /* Solaris, Cygwin < 2.5, not HP-UX */
 
 #  if defined ACL_NO_TRIVIAL
 
--- a/lib/get-permissions.c	Tue Sep 18 21:27:15 2018 +0200
+++ b/lib/get-permissions.c	Tue Sep 18 22:58:23 2018 +0200
@@ -38,9 +38,9 @@
 
 #if USE_ACL && HAVE_ACL_GET_FILE
   /* POSIX 1003.1e (draft 17 -- abandoned) specific version.  */
-  /* Linux, FreeBSD, Mac OS X, IRIX, Tru64 */
+  /* Linux, FreeBSD, Mac OS X, IRIX, Tru64, Cygwin >= 2.5 */
 # if !HAVE_ACL_TYPE_EXTENDED
-  /* Linux, FreeBSD, IRIX, Tru64 */
+  /* Linux, FreeBSD, IRIX, Tru64, Cygwin >= 2.5 */
 
   if (HAVE_ACL_GET_FD && desc != -1)
     ctx->acl = acl_get_fd (desc);
@@ -60,13 +60,13 @@
         return -1;
     }
 
-# if HAVE_ACL_TYPE_NFS4  /* FreeBSD */
+#  if HAVE_ACL_TYPE_NFS4  /* FreeBSD */
 
   /* TODO (see set_permissions). */
 
-# endif
+#  endif
 
-#  else /* HAVE_ACL_TYPE_EXTENDED */
+# else /* HAVE_ACL_TYPE_EXTENDED */
   /* Mac OS X */
 
   /* On Mac OS X,  acl_get_file (name, ACL_TYPE_ACCESS)
--- a/lib/set-permissions.c	Tue Sep 18 21:27:15 2018 +0200
+++ b/lib/set-permissions.c	Tue Sep 18 22:58:23 2018 +0200
@@ -24,7 +24,7 @@
 #include "acl-internal.h"
 
 #if USE_ACL
-# if ! defined HAVE_ACL_FROM_MODE && defined HAVE_ACL_FROM_TEXT /* FreeBSD, IRIX, Tru64 */
+# if ! defined HAVE_ACL_FROM_MODE && defined HAVE_ACL_FROM_TEXT /* FreeBSD, IRIX, Tru64, Cygwin >= 2.5 */
 #  if HAVE_ACL_GET_FILE && !HAVE_ACL_TYPE_EXTENDED
 
 static acl_t
@@ -32,7 +32,7 @@
 {
 #  if HAVE_ACL_FREE_TEXT /* Tru64 */
   char acl_text[] = "u::---,g::---,o::---,";
-#  else /* FreeBSD, IRIX */
+#  else /* FreeBSD, IRIX, Cygwin >= 2.5 */
   char acl_text[] = "u::---,g::---,o::---";
 #  endif
 
@@ -51,7 +51,7 @@
 #  endif
 # endif
 
-# if HAVE_FACL && defined GETACL /* Solaris, Cygwin, not HP-UX */
+# if HAVE_FACL && defined GETACL /* Solaris, Cygwin < 2.5, not HP-UX */
 static int
 set_acls_from_mode (const char *name, int desc, mode_t mode, bool *must_chmod)
 {
@@ -489,9 +489,9 @@
 
 # if HAVE_ACL_GET_FILE
   /* POSIX 1003.1e (draft 17 -- abandoned) specific version.  */
-  /* Linux, FreeBSD, Mac OS X, IRIX, Tru64 */
+  /* Linux, FreeBSD, Mac OS X, IRIX, Tru64, Cygwin >= 2.5 */
 #  if !HAVE_ACL_TYPE_EXTENDED
-  /* Linux, FreeBSD, IRIX, Tru64 */
+  /* Linux, FreeBSD, IRIX, Tru64, Cygwin >= 2.5 */
 
 #   ifndef HAVE_ACL_FROM_TEXT
 #    error Must have acl_from_text (see POSIX 1003.1e draft 17).
@@ -542,14 +542,14 @@
         }
     }
 
-# if HAVE_ACL_TYPE_NFS4  /* FreeBSD */
+#   if HAVE_ACL_TYPE_NFS4  /* FreeBSD */
 
   /* File systems either support POSIX ACLs (for example, ufs) or NFS4 ACLs
      (for example, zfs). */
 
   /* TODO: Implement setting ACLs once get_permissions() reads them. */
 
-# endif
+#   endif
 
 #  else /* HAVE_ACL_TYPE_EXTENDED */
   /* Mac OS X */
--- a/m4/acl.m4	Tue Sep 18 21:27:15 2018 +0200
+++ b/m4/acl.m4	Tue Sep 18 22:58:23 2018 +0200
@@ -1,5 +1,5 @@
 # acl.m4 - check for access control list (ACL) primitives
-# serial 22
+# serial 23
 
 # Copyright (C) 2002, 2004-2018 Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
@@ -30,7 +30,8 @@
       ac_save_LIBS=$LIBS
 
       dnl Test for POSIX-draft-like API (GNU/Linux, FreeBSD, Mac OS X,
-      dnl IRIX, Tru64).  -lacl is needed on GNU/Linux, -lpacl on OSF/1.
+      dnl IRIX, Tru64, Cygwin >= 2.5).
+      dnl -lacl is needed on GNU/Linux, -lpacl on OSF/1.
       if test $use_acl = 0; then
         AC_SEARCH_LIBS([acl_get_file], [acl pacl],
           [if test "$ac_cv_search_acl_get_file" != "none required"; then