Skip to content

Commit 4794785

Browse files
committed
qcopy-acl: Fix copying of ACLs on CentOS 7 (regression 2023-01-12).
* lib/qcopy-acl.c: Include <string.h>, <linux/xattr.h>. (XATTR_NAME_NFSV4_ACL, XATTR_NAME_POSIX_ACL_ACCESS, XATTR_NAME_POSIX_ACL_DEFAULT): New macros, from file-has-acl.c. (is_attr_permissions): Test for these names explicitly. * m4/acl.m4 (gl_QCOPY_ACL): New macro. * modules/qcopy-acl (Files): Add m4/acl.m4. (configure.ac): Invoke gl_QCOPY_ACL.
1 parent 4d69ca3 commit 4794785

File tree

4 files changed

+53
-14
lines changed

4 files changed

+53
-14
lines changed

ChangeLog

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
2024-07-15 Bruno Haible <bruno@clisp.org>
2+
3+
qcopy-acl: Fix copying of ACLs on CentOS 7 (regression 2023-01-12).
4+
* lib/qcopy-acl.c: Include <string.h>, <linux/xattr.h>.
5+
(XATTR_NAME_NFSV4_ACL, XATTR_NAME_POSIX_ACL_ACCESS,
6+
XATTR_NAME_POSIX_ACL_DEFAULT): New macros, from file-has-acl.c.
7+
(is_attr_permissions): Test for these names explicitly.
8+
* m4/acl.m4 (gl_QCOPY_ACL): New macro.
9+
* modules/qcopy-acl (Files): Add m4/acl.m4.
10+
(configure.ac): Invoke gl_QCOPY_ACL.
11+
112
2024-07-14 Bruno Haible <bruno@clisp.org>
213

314
stdlib: Fix last commit on macOS, OpenBSD, mingw.

lib/qcopy-acl.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,33 @@
2626
#if USE_XATTR
2727

2828
# include <attr/libattr.h>
29+
# include <string.h>
30+
31+
# if HAVE_LINUX_XATTR_H
32+
# include <linux/xattr.h>
33+
# endif
34+
# ifndef XATTR_NAME_NFSV4_ACL
35+
# define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
36+
# endif
37+
# ifndef XATTR_NAME_POSIX_ACL_ACCESS
38+
# define XATTR_NAME_POSIX_ACL_ACCESS "system.posix_acl_access"
39+
# endif
40+
# ifndef XATTR_NAME_POSIX_ACL_DEFAULT
41+
# define XATTR_NAME_POSIX_ACL_DEFAULT "system.posix_acl_default"
42+
# endif
2943

3044
/* Returns 1 if NAME is the name of an extended attribute that is related
3145
to permissions, i.e. ACLs. Returns 0 otherwise. */
3246

3347
static int
3448
is_attr_permissions (const char *name, struct error_context *ctx)
3549
{
36-
return attr_copy_action (name, ctx) == ATTR_ACTION_PERMISSIONS;
50+
/* We need to explicitly test for the known extended attribute names,
51+
because at least on CentOS 7, attr_copy_action does not do it. */
52+
return strcmp (name, XATTR_NAME_POSIX_ACL_ACCESS) == 0
53+
|| strcmp (name, XATTR_NAME_POSIX_ACL_DEFAULT) == 0
54+
|| strcmp (name, XATTR_NAME_NFSV4_ACL) == 0
55+
|| attr_copy_action (name, ctx) == ATTR_ACTION_PERMISSIONS;
3756
}
3857

3958
#endif /* USE_XATTR */

m4/acl.m4

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# acl.m4
2-
# serial 30
2+
# serial 31
33
dnl Copyright (C) 2002, 2004-2024 Free Software Foundation, Inc.
44
dnl This file is free software; the Free Software Foundation
55
dnl gives unlimited permission to copy and/or distribute it,
@@ -178,13 +178,14 @@ AC_DEFUN([gl_ACL_GET_FILE],
178178
AS_IF([test "$gl_cv_func_working_acl_get_file" != no], [$1], [$2])
179179
])
180180

181-
# On GNU/Linux, testing if a file has an acl can be done with the
182-
# listxattr and getxattr syscalls, which don't require linking
183-
# against additional libraries. Assume this works if linux/attr.h
184-
# and listxattr are present.
181+
# Prerequisites of module file-has-acl.
185182
AC_DEFUN([gl_FILE_HAS_ACL],
186183
[
187184
AC_REQUIRE([gl_FUNC_ACL_ARG])
185+
# On GNU/Linux, testing if a file has an acl can be done with the
186+
# listxattr and getxattr syscalls, which don't require linking
187+
# against additional libraries. Assume this works if linux/attr.h
188+
# and listxattr are present.
188189
AC_CHECK_HEADERS_ONCE([linux/xattr.h])
189190
AC_CHECK_FUNCS_ONCE([listxattr])
190191
FILE_HAS_ACL_LIB=
@@ -198,3 +199,17 @@ AC_DEFUN([gl_FILE_HAS_ACL],
198199
FILE_HAS_ACL_LIB=$LIB_ACL])
199200
AC_SUBST([FILE_HAS_ACL_LIB])
200201
])
202+
203+
# Prerequisites of module qcopy-acl.
204+
AC_DEFUN([gl_QCOPY_ACL],
205+
[
206+
AC_REQUIRE([gl_FUNC_ACL])
207+
AC_CHECK_HEADERS_ONCE([linux/xattr.h])
208+
gl_FUNC_XATTR
209+
if test "$use_xattr" = yes; then
210+
QCOPY_ACL_LIB="$LIB_XATTR"
211+
else
212+
QCOPY_ACL_LIB="$LIB_ACL"
213+
fi
214+
AC_SUBST([QCOPY_ACL_LIB])
215+
])

modules/qcopy-acl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,14 @@ Copy access control list from one file to another. (Unportable.)
33

44
Files:
55
lib/qcopy-acl.c
6+
m4/acl.m4
67
m4/xattr.m4
78

89
Depends-on:
910
acl-permissions [test "$use_xattr" != yes]
1011

1112
configure.ac:
12-
gl_FUNC_XATTR
13-
AC_REQUIRE([gl_FUNC_ACL])
14-
if test "$use_xattr" = yes; then
15-
QCOPY_ACL_LIB="$LIB_XATTR"
16-
else
17-
QCOPY_ACL_LIB="$LIB_ACL"
18-
fi
19-
AC_SUBST([QCOPY_ACL_LIB])
13+
gl_QCOPY_ACL
2014

2115
Makefile.am:
2216
lib_SOURCES += qcopy-acl.c

0 commit comments

Comments
 (0)