From cbe34b4e7353df4c1051f377dff4e036c5f8085a Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 2 Dec 2025 14:13:15 +0900 Subject: [PATCH] tar-util: allow to build without libacl support Fixes #39928. Follow-up for 4ded7f7a434c59534f65a0f9d391c55961eb110d. --- src/shared/tar-util.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/shared/tar-util.c b/src/shared/tar-util.c index 40c496bda06..9674599dd3e 100644 --- a/src/shared/tar-util.c +++ b/src/shared/tar-util.c @@ -88,10 +88,12 @@ static void open_inode_done(OpenInode *of) { of->path = mfree(of->path); } xattr_done_many(of->xattr, of->n_xattr); +#if HAVE_ACL if (of->acl_access) sym_acl_free(of->acl_access); if (of->acl_default) sym_acl_free(of->acl_default); +#endif } static void open_inode_done_many(OpenInode *array, size_t n) { @@ -113,14 +115,22 @@ static int open_inode_apply_acl(OpenInode *of) { return 0; if (of->acl_access) { +#if HAVE_ACL if (sym_acl_set_fd(of->fd, of->acl_access) < 0) RET_GATHER(r, log_error_errno(errno, "Failed to adjust ACLs of '%s': %m", of->path)); +#else + log_debug("The archive entry '%s' has ACLs, but ACL support is disabled.", of->path); +#endif } if (of->filetype == S_IFDIR && of->acl_default) { +#if HAVE_ACL /* There's no API to set default ACLs by fd, hence go by /proc/self/fd/ path */ if (sym_acl_set_file(FORMAT_PROC_FD_PATH(of->fd), ACL_TYPE_DEFAULT, of->acl_default) < 0) RET_GATHER(r, log_error_errno(errno, "Failed to adjust default ACLs of '%s': %m", of->path)); +#else + log_debug("The archive entry '%s' has default ACLs, but ACL support is disabled.", of->path); +#endif } return r; @@ -444,6 +454,7 @@ static int archive_entry_read_acl( return 0; assert(c > 0); +#if HAVE_ACL r = dlopen_libacl(); if (r < 0) { log_debug_errno(r, "Not restoring ACL data on inode as libacl is not available: %m"); @@ -454,6 +465,7 @@ static int archive_entry_read_acl( a = sym_acl_init(c); if (!a) return log_oom(); +#endif for (;;) { int rtype, permset, tag, qual; @@ -494,6 +506,7 @@ static int archive_entry_read_acl( if (ntag == ACL_UNDEFINED_TAG) continue; +#if HAVE_ACL acl_entry_t e; if (IN_SET(ntag, ACL_USER, ACL_GROUP)) { id_t id = qual; @@ -539,11 +552,19 @@ static int archive_entry_read_acl( if (sym_acl_set_permset(e, p) < 0) return log_error_errno(errno, "Failed to set ACL entry permission set: %m"); +#else + *acl = POINTER_MAX; /* Indicate the entry has valid ACLs. */ + return 0; +#endif } +#if HAVE_ACL if (*acl) sym_acl_free(*acl); *acl = TAKE_PTR(a); +#else + *acl = NULL; /* Indicate the entry has no ACL. */ +#endif return 0; } @@ -809,7 +830,10 @@ int tar_x(int input_fd, int tree_fd, TarFlags flags) { gid_t gid = GID_INVALID; struct timespec mtime = { .tv_nsec = UTIME_OMIT }; unsigned fflags = 0; - _cleanup_(acl_freep) acl_t acl_access = NULL, acl_default = NULL; +#if HAVE_ACL + _cleanup_(acl_freep) +#endif + acl_t acl_access = NULL, acl_default = NULL; XAttr *xa = NULL; size_t n_xa = 0; CLEANUP_ARRAY(xa, n_xa, xattr_done_many); @@ -1125,6 +1149,7 @@ static int archive_generate_sparse(struct archive_entry *entry, int fd) { return 0; } +#if HAVE_ACL static int archive_write_acl( struct archive_entry *entry, acl_type_t ntype, @@ -1214,6 +1239,7 @@ static int archive_write_acl( return 0; } +#endif static int archive_item( RecurseDirEvent event, @@ -1299,6 +1325,7 @@ static int archive_item( sym_archive_entry_set_symlink(entry, s); } +#if HAVE_ACL if (inode_type_can_acl(sx->stx_mode)) { r = dlopen_libacl(); @@ -1328,6 +1355,7 @@ static int archive_item( } } } +#endif _cleanup_free_ char *xattrs = NULL; r = flistxattr_malloc(inode_fd, &xattrs); -- 2.47.3