[PATCH 0/1] Fix facl on files opened with O_PATH

Corinna Vinschen corinna-cygwin@cygwin.com
Wed Feb 24 09:42:42 GMT 2021

On Feb 23 17:49, Ken Brown via Cygwin-patches wrote:
> I'm not sure if this patch is right.  Should facl fail on all commands
> or just on SETACL?  If the command is GETACL, for example, should this
> fail like fgetxattr(2) or should it succeed like fstat(2)?
> Cygwin may be the only platform that supports both facl(2) and O_PATH,
> so I guess we're on our own here.

Not entirely.  facl is also the underlying function for the POSIX ACL
calls, deprecated but still supported by Linux.  I. e., on a file system
supporting ACLs (xfs, ext4, etc), this needs testing:

  int fd = open (..., O_PATH);
  if (fd < 0)
    perror ("open");
  else if (acl_get_fd (fd) != NULL)
    printf ("acl_get_fd works with O_PATH\n");
    perror ("acl_get_fd");

I just did that and it turns out that the above code returns with

  acl_get_fd: Bad file descriptor

At first I was actually a bit surprised.  I thought fetching ACLs is
along the lines of fstat, but on second though it's not.  ACLs are
stored as extended attributes and given that fgetxattr is supposed to
fail with EBADF, it's logical that acl_get_fd fails with EBADF as well.

So your patch looks good.


More information about the Cygwin-patches mailing list