How to check wheter POSIX ACL is enabled for a given path
Asked Answered
M

1

11

After reading the man page of getfacl / setfacl I could not find an obvious/robust/elegant method to check whether acl is enabled for a given path in (ba)sh.

Any suggestions?

Mirianmirielle answered 7/6, 2011 at 16:26 Comment(6)
getfacl path;if [ $? -ne 0 ]; then echo "NO ACL"; fi doesn't work?Guilty
@Let_Me_Be: no, that's successful even with a kernel with no ACL support. (It translates the file mode bits to ACLs I guess)Mailer
@Mat: Exactly. getfacl indicates whether an acl is set or not. But not if the underlying filesystem has acl enabled.Mirianmirielle
do you have w access? can you create a temporary and setfacl it with something complex?Linis
@vladr: i also thought about that, but I would say this is more a hackMirianmirielle
In AIX there is a handy aclgettypes /my/path/to/test, but I haven't seen anything similar in other flavors.Stumper
T
5
{
  # Determine what the mount point for the path is:
  MOUNT_POINT=$(df -P $FILENAME | tail -n 1 | awk '{print $6}')
  # Get the mount options for the path:
  MOUNT_OPTS=$(awk '$2=="'$MOUNT_POINT'" { print $4 }' /proc/mounts)
  # Check to see if acl is one of the mount points:
  echo $MOUNT_OPTS | tr , \\\n | grep '^acl$' -q
  if [ $? -eq 0 ]; then
    echo "ACLs enabled"
  else
    echo "ACLs disabled"
  fi
}
Tobacco answered 12/6, 2011 at 18:27 Comment(3)
What part doesn't work? Is the implication that NFS acls aren't denoted by the 'acl' mount option or does his script break on NFS mounts somehow?Gittern
@Mr. Mr.: AFAIK the NFS never supported ACLs... just normal UNIX rights. Maybe it changed but I don't think so.Sickroom
@Sickroom : NFS has had ACL since v4Dorkus

© 2022 - 2024 — McMap. All rights reserved.