On 3/29/25 04:30, Corinna Vinschen wrote:
What it should do if only the POSIX.1e draft 17 functions are available
is something along these lines:

Yes, that sounds like a better approach. However, shouldn't it use O_PATH not O_RDONLY? We might lack read access.

Does the attached Gnulib patch work for you? I haven't tested or installed it (I don't use Cygwin).
From e245ab6ac865c7ff723837645886eb717c53a754 Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Sat, 29 Mar 2025 10:27:01 -0600
Subject: [PATCH] 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.
(HAVE_ACL_GET_LINK_NP): Define this if defining acl_get_link_np.
---
 ChangeLog          |  9 +++++++++
 lib/file-has-acl.c | 21 ++++++++++++++++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 58195260cf..a7fa40dc33 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2025-03-29  Paul Eggert  <egg...@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.
+	(HAVE_ACL_GET_LINK_NP): Define this if defining acl_get_link_np.
+
 2025-03-29  Bruno Haible  <br...@clisp.org>
 
 	acl-permissions: Update comments regarding NetBSD.
diff --git a/lib/file-has-acl.c b/lib/file-has-acl.c
index 179e805bd4..2538b61944 100644
--- a/lib/file-has-acl.c
+++ b/lib/file-has-acl.c
@@ -362,6 +362,25 @@ 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 && defined 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
+
 /* 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
@@ -467,7 +486,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
-- 
2.34.1

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

Reply via email to