Commit ccc26add4e1dca76e7a3ded465c94db4064bc20d

Paul Eggert 2024-09-29T16:13:53

file-has-acl: new function file_has_aclinfo This is for GNU coreutils, whose ‘ls’ can be made faster with the new function because it means (for example) that ‘ls’ needn’t call both listxattr and lgetxattr in the common case where the file has no extended attributes. * lib/acl.h (ACL_SYMLINK_FOLLOW): New constant. (struct aclinfo): New type. * lib/file-has-acl.c (UNKNOWN_SECURITY_CONTEXT): New constant. (USE_LINUX_XATTR): New macro. When set: Include stdint.h (for uint32_t). If also USE_SELINUX_SELINUX_H, include selinux/selinux.h (for getfilecon). If HAVE_SMACK, include <sys/smack.h>, otherwise provide substitutes for smack_smackfs_path and smack_new_label_from_path. (is_smack_enabled): New function. (aclinfo_has_xattr): Rename from have_xattr and make it extern. Use struct aclinfo const * arg instead of char const * and ssize_t. Work even if ai->size < 0. Supply a no-op macro on platforms lacking xattr. (get_aclinfo): New static function, much of it taken from coreutils/src/ls.c. (file_has_aclinfo): New function, which generalizes file_has_acl to provide more info. Its body is taken from the old file_has_acl with new stuff from ls.c. (file_has_acl): Use it. (aclinfo_scontext_free, aclinfo_free): Nwew functions, if not already no-op macros. * m4/acl.m4 (gl_FUNC_ACL_ARG): Add --without-libsmack option. (gl_FILE_HAS_ACL): Check for libsmack, selinux. * m4/selinux-selinux-h.m4 (gl_CHECK_HEADER_SELINUX_SELINUX_H): New macro, for use by file-has-acl. Rename HAVE_SELINUX_SELINUX_H to USE_SELINUX_SELINUX_H to avoid confusion as to whether we have <selinux/selinux.h>; all uses changed. (gl_HEADERS_SELINUX_SELINUX_H): Use the new macro. * modules/file-has-acl (Files): Add m4/selinux-selinux-h.m4. (Depends-on): Add errno, ssize_t. * tests/test-file-has-acl.c (main): Add a little test for file_has_aclinfo.