bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

acl: small fix for Cygwin


From: Bruno Haible
Subject: acl: small fix for Cygwin
Date: Tue, 18 Sep 2018 22:59:04 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-134-generic; KDE/5.18.0; x86_64; ; )

On Cygwin 2.9, the test-file-has-acl*.sh tests fail.

The reason is that Cygwin 2.5 has added ACL functions similar to
the ones in Linux libacl, that behave mostly like the Linux ones,
but not exactly. See https://cygwin.com/cygwin-ug-net/ov-new.html

The gnulib code has appropriate #ifs that work fine nearly everywhere.
I needed to change only two pieces of logic (and comments, of course).


2018-09-18  Bruno Haible  <address@hidden>

        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.

diff --git a/lib/acl-internal.c b/lib/acl-internal.c
index c62adb0..92e7b9b 100644
--- a/lib/acl-internal.c
+++ b/lib/acl-internal.c
@@ -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 @@ acl_extended_nontrivial (acl_t acl)
   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 @@ acl_access_nontrivial (acl_t acl)
      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 @@ acl_default_nontrivial (acl_t acl)
 
 # 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 @@ void
 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 @@ free_permission_context (struct permission_context *ctx)
     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);
diff --git a/lib/acl-internal.h b/lib/acl-internal.h
index 0669d83..2da7c5a 100644
--- a/lib/acl-internal.h
+++ b/lib/acl-internal.h
@@ -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 @@ _GL_INLINE_HEADER_BEGIN
 
 # 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 @@ rpl_acl_set_fd (int fd, acl_t acl)
 #  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_access_nontrivial (acl_t);
 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 @@ extern int acl_nontrivial (int count, struct acl 
*entries);
 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
diff --git a/lib/acl_entries.c b/lib/acl_entries.c
index 59dd420..ce730d4 100644
--- a/lib/acl_entries.c
+++ b/lib/acl_entries.c
@@ -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 @@ acl_entries (acl_t acl)
 
   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 @@ acl_entries (acl_t acl)
            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;
diff --git a/lib/file-has-acl.c b/lib/file-has-acl.c
index 2434986..97fb08a 100644
--- a/lib/file-has-acl.c
+++ b/lib/file-has-acl.c
@@ -74,7 +74,7 @@ file_has_acl (char const *name, struct stat const *sb)
 # 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 @@ file_has_acl (char const *name, struct stat const *sb)
              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 @@ file_has_acl (char const *name, struct stat const *sb)
             }
           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 @@ file_has_acl (char const *name, struct stat const *sb)
               /* 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 @@ file_has_acl (char const *name, struct stat const *sb)
                   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 @@ file_has_acl (char const *name, struct stat const *sb)
         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
 
diff --git a/lib/get-permissions.c b/lib/get-permissions.c
index 83ba263..3b98451 100644
--- a/lib/get-permissions.c
+++ b/lib/get-permissions.c
@@ -38,9 +38,9 @@ get_permissions (const char *name, int desc, mode_t mode,
 
 #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 @@ get_permissions (const char *name, int desc, mode_t mode,
         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)
diff --git a/lib/set-permissions.c b/lib/set-permissions.c
index d42335a..a415e13 100644
--- a/lib/set-permissions.c
+++ b/lib/set-permissions.c
@@ -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 @@ acl_from_mode (mode_t mode)
 {
 #  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 @@ acl_from_mode (mode_t mode)
 #  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 @@ set_acls (struct permission_context *ctx, const char *name, 
int desc,
 
 # 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 @@ set_acls (struct permission_context *ctx, const char 
*name, int desc,
         }
     }
 
-# 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 */
diff --git a/m4/acl.m4 b/m4/acl.m4
index 485cf9a..b64aa84 100644
--- a/m4/acl.m4
+++ b/m4/acl.m4
@@ -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_DEFUN([gl_FUNC_ACL],
       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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]