From: Ondrej Valousek <ondrej.valousek.xm@renesas.com>
To: bug-gnulib@gnu.org, kdudka@redhat.com
Cc: Ondrej Valousek <ondrej.valousek.xm@renesas.com>
Subject: [PATCH] Use xattr (Linux) in copy-acl.c
Date: Wed, 4 Jan 2023 11:03:29 +0100 [thread overview]
Message-ID: <20230104100328.1215830-1-ondrej.valousek.xm@renesas.com> (raw)
Hi Paul/Bruno,
Thanks for valuable input. I have included your suggestions in the
following patch.
Hope it looks fine now.
Ondrej
---
lib/qcopy-acl.c | 33 +++++++++++++++++++++++++++++++++
m4/xattr.m4 | 45 +++++++++++++++++++++++++++++++++++++++++++++
modules/qcopy-acl | 2 ++
3 files changed, 80 insertions(+)
create mode 100644 m4/xattr.m4
diff --git a/lib/qcopy-acl.c b/lib/qcopy-acl.c
index 883bcf7d58..5968189733 100644
--- a/lib/qcopy-acl.c
+++ b/lib/qcopy-acl.c
@@ -23,6 +23,20 @@
#include "acl-internal.h"
+#if USE_XATTR
+
+# include <attr/libattr.h>
+
+/* Returns 1 if NAME is the name of an extended attribute that is related
+ to permissions, i.e. ACLs. Returns 0 otherwise. */
+
+static int
+is_attr_permissions (const char *name, struct error_context *ctx)
+{
+ return attr_copy_action (name, ctx) == ATTR_ACTION_PERMISSIONS;
+}
+
+#endif /* USE_XATTR */
/* Copy access control lists from one file to another. If SOURCE_DESC is
a valid file descriptor, use file descriptor operations, else use
@@ -42,10 +56,29 @@ qcopy_acl (const char *src_name, int source_desc, const char *dst_name,
struct permission_context ctx;
int ret;
+#ifdef USE_XATTR
+ /* in case no ACLs present and also to set higher mode bits
+ we chmod before setting ACLs as doing it after could overwrite them
+ (especially true for NFSv4, posix ACL has that ugly "mask" hack that
+ nobody understands) */
+ ret = chmod_or_fchmod (dst_name, dest_desc, mode);
+ /* Rather than fiddling with acls one by one, we just copy the whole ACL xattrs
+ (Posix or NFSv4). Of course, that won't address ACLs conversion
+ (i.e. posix <-> nfs4) but we can't do it anyway, so for now, we don't care
+ Functions attr_copy_* return 0 in case we copied something OR nothing
+ to copy */
+ if (ret == 0)
+ ret = source_desc <= 0 || dest_desc <= 0
+ ? attr_copy_file (src_name, dst_name, is_attr_permissions, NULL)
+ : attr_copy_fd (src_name, source_desc, dst_name, dest_desc,
+ is_attr_permissions, NULL);
+#else
+ /* no XATTR, so we proceed the old dusty way */
ret = get_permissions (src_name, source_desc, mode, &ctx);
if (ret != 0)
return -2;
ret = set_permissions (&ctx, dst_name, dest_desc);
free_permission_context (&ctx);
+#endif
return ret;
}
diff --git a/m4/xattr.m4 b/m4/xattr.m4
new file mode 100644
index 0000000000..4e8cbb0c4d
--- /dev/null
+++ b/m4/xattr.m4
@@ -0,0 +1,45 @@
+# xattr.m4 - check for Extended Attributes (Linux)
+# serial 4
+
+# Copyright (C) 2003-2021 Free Software Foundation, Inc.
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_XATTR],
+[
+ AC_ARG_ENABLE([xattr],
+ AS_HELP_STRING([--disable-xattr],
+ [do not support extended attributes]),
+ [use_xattr=$enableval], [use_xattr=yes])
+
+ LIB_XATTR=
+ AC_SUBST([LIB_XATTR])
+
+ if test "$use_xattr" = "yes"; then
+ AC_CHECK_HEADERS([attr/error_context.h attr/libattr.h])
+ use_xattr=no
+ if test "$ac_cv_header_attr_libattr_h" = yes \
+ && test "$ac_cv_header_attr_error_context_h" = yes; then
+ xattr_saved_LIBS=$LIBS
+ AC_SEARCH_LIBS([attr_copy_file], [attr],
+ [test "$ac_cv_search_attr_copy_file" = "none required" ||
+ LIB_XATTR="$ac_cv_search_attr_copy_file"])
+ AC_CHECK_FUNCS([attr_copy_file])
+ LIBS=$xattr_saved_LIBS
+ if test "$ac_cv_func_attr_copy_file" = yes; then
+ use_xattr=yes
+ fi
+ fi
+ if test $use_xattr = no; then
+ AC_MSG_WARN([libattr development library was not found or not usable.])
+ AC_MSG_WARN([AC_PACKAGE_NAME will be built without xattr support.])
+ fi
+ fi
+ if test $use_xattr = yes; then
+ use_xattr_value=1
+ else
+ use_xattr_value=0
+ fi
+ AC_DEFINE_UNQUOTED([USE_XATTR], [$use_xattr_value])
+])
diff --git a/modules/qcopy-acl b/modules/qcopy-acl
index c0e5b6a8f8..e0cd914953 100644
--- a/modules/qcopy-acl
+++ b/modules/qcopy-acl
@@ -3,11 +3,13 @@ Copy access control list from one file to another. (Unportable.)
Files:
lib/qcopy-acl.c
+m4/xattr.m4
Depends-on:
acl-permissions
configure.ac:
+gl_FUNC_XATTR
Makefile.am:
lib_SOURCES += qcopy-acl.c
--
2.38.1
next reply other threads:[~2023-01-04 10:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-04 10:03 Ondrej Valousek [this message]
2023-01-04 11:27 ` [PATCH] Use xattr (Linux) in copy-acl.c Bruno Haible
-- strict thread matches above, loose matches on Subject: below --
2023-01-03 14:08 Ondrej Valousek
2023-01-03 16:44 ` Bruno Haible
2023-01-03 20:40 ` Paul Eggert
2023-01-03 20:53 ` Bruno Haible
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230104100328.1215830-1-ondrej.valousek.xm@renesas.com \
--to=ondrej.valousek.xm@renesas.com \
--cc=bug-gnulib@gnu.org \
--cc=kdudka@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).