]> Savannah Git Hosting - gnulib.git/commitdiff
file-has-acl: port symlink code to Cygwin
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 7 Apr 2025 08:45:17 +0000 (01:45 -0700)
committerBruno Haible <bruno@clisp.org>
Mon, 14 Apr 2025 22:37:15 +0000 (00:37 +0200)
Problem reported by Corinna Vinschen in:
https://lists.gnu.org/r/bug-gnulib/2025-03/msg00112.html
* lib/file-has-acl.c (acl_get_link_np): New static function,
defined only if needed; include <fcntl.h> if needed for this.
(HAVE_ACL_GET_LINK_NP): Define this if defining acl_get_link_np.

ChangeLog
lib/file-has-acl.c

index 96caf549e32e63854ae3866d4262750938ee7cfb..dab6369e1d67889e6519a8520538d2582093b53e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2025-04-07  Paul Eggert  <eggert@cs.ucla.edu>
+
+       file-has-acl: port symlink code to Cygwin
+       Problem reported by Corinna Vinschen in:
+       https://lists.gnu.org/r/bug-gnulib/2025-03/msg00112.html
+       * lib/file-has-acl.c (acl_get_link_np): New static function,
+       defined only if needed; include <fcntl.h> if needed for this.
+       (HAVE_ACL_GET_LINK_NP): Define this if defining acl_get_link_np.
+
 2025-04-07  Simon Josefsson  <simon@josefsson.org>
 
        maintainer-makefile: Avoid submodule-checks fail without submodules.
index c02cfee842bf5f7f847d641d28a4081b4e0f1aa3..59ad9b94fc136b9763ac333f8623f6a2bf99a8a6 100644 (file)
@@ -363,6 +363,29 @@ acl_nfs4_nontrivial (uint32_t *xattr, ssize_t nbytes)
 }
 #endif
 
+#if (!USE_LINUX_XATTR && USE_ACL && HAVE_ACL_GET_FD \
+     && !HAVE_ACL_EXTENDED_FILE && !HAVE_ACL_TYPE_EXTENDED \
+     && !HAVE_ACL_GET_LINK_NP)
+# include <fcntl.h>
+# ifdef O_PATH
+
+/* Like acl_get_file, but do not follow symbolic links.  */
+static acl_t
+acl_get_link_np (char const *name, acl_type_t type)
+{
+  int fd = open (name, O_PATH | O_NOFOLLOW);
+  if (fd < 0)
+    return NULL;
+  acl_t r = acl_get_fd (fd);
+  int err = errno;
+  close (fd);
+  errno = err;
+  return r;
+}
+#  define HAVE_ACL_GET_LINK_NP 1
+# endif
+#endif
+
 /* Return 1 if NAME has a nontrivial access control list,
    0 if ACLs are not supported, or if NAME has no or only a base ACL,
    and -1 (setting errno) on error.  Note callers can determine
@@ -468,7 +491,7 @@ file_has_aclinfo (MAYBE_UNUSED char const *restrict name,
       ret = -1;
 #   else /* FreeBSD, NetBSD >= 10, IRIX, Tru64, Cygwin >= 2.5 */
     acl_t (*acl_get_file_or_link) (char const *, acl_type_t) = acl_get_file;
-#    if HAVE_ACL_GET_LINK_NP /* FreeBSD, NetBSD >= 10 */
+#    if HAVE_ACL_GET_LINK_NP /* FreeBSD, NetBSD >= 10, Cygwin >= 2.5 */
     if (! (flags & ACL_SYMLINK_FOLLOW))
       acl_get_file_or_link = acl_get_link_np;
 #    endif