1 --- coreutils-6.11/configure.ac
2 +++ coreutils-6.11/configure.ac
4 AC_SUBST([CONFIG_STATUS_DEPENDENCIES])
5 ############################################################################
7 +# Extended attribute copying.
10 AM_GNU_GETTEXT([external], [need-formatstring-macros])
11 AM_GNU_GETTEXT_VERSION([0.15])
13 --- coreutils-6.11/m4/xattr.m4
14 +++ coreutils-6.11/m4/xattr.m4
16 +# xattr.m4 - check for Extended Attributes (Linux)
18 +# Copyright (C) 2003 Free Software Foundation, Inc.
20 +# This program is free software; you can redistribute it and/or modify
21 +# it under the terms of the GNU General Public License as published by
22 +# the Free Software Foundation; either version 2, or (at your option)
25 +# This program is distributed in the hope that it will be useful,
26 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
27 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 +# GNU General Public License for more details.
30 +# You should have received a copy of the GNU General Public License
31 +# along with this program; if not, write to the Free Software Foundation,
32 +# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
34 +# Written by Andreas Gruenbacher.
36 +AC_DEFUN([AC_FUNC_XATTR],
38 + AC_ARG_ENABLE(xattr,
39 + [ --disable-xattr turn off support for extended attributes],
40 + use_xattr=$enableval, use_xattr=yes)
42 + if test "$use_xattr" = "yes"; then
43 + AC_CHECK_HEADERS(attr/error_context.h attr/libattr.h)
44 + if test "$ac_cv_header_attr_libattr_h" = yes \
45 + && test "$ac_cv_header_attr_error_context_h" = yes; then
50 + AC_DEFINE_UNQUOTED(USE_XATTR, $use_xattr,
51 + [Define if you want extended attribute support.])
52 + xattr_saved_LIBS=$LIBS
53 + AC_SEARCH_LIBS(attr_copy_file, attr,
54 + [test "$ac_cv_search_attr_copy_file" = "none required" || LIB_XATTR=$ac_cv_search_attr_copy_file])
56 + AC_CHECK_FUNCS(attr_copy_file)
57 + LIBS=$xattr_saved_LIBS
60 --- coreutils-6.11/src/copy.c
61 +++ coreutils-6.11/src/copy.c
63 #include "areadlink.h"
68 +# include <attr/error_context.h>
69 +# include <attr/libattr.h>
73 # define HAVE_FCHOWN false
74 # define fchown(fd, uid, gid) (-1)
75 @@ -118,6 +124,98 @@ is_ancestor (const struct stat *sb, cons
81 +copy_xattr_error (struct error_context *ctx, const char *fmt, ...)
88 + /* There is no error function that takes a va_list argument,
89 + so we print the message in a buffer first. */
92 + len = vsnprintf (NULL, 0, fmt, ap);
96 + buffer = xmalloc (len + 1);
98 + vsnprintf (buffer, len + 1, fmt, ap);
100 + error (0, err, "%s", buffer);
106 +copy_xattr_quote (struct error_context *ctx, const char *str)
108 + return xstrdup (quote (str));
112 +copy_xattr_free (struct error_context *ctx, const char *str)
114 + free ((void *) str);
117 +struct copy_xattr_context {
118 + struct error_context ctx;
119 + struct cp_options *x;
123 +copy_xattr_filter (const char *name, struct error_context *ctx)
125 + struct copy_xattr_context *copy_ctx = (struct copy_xattr_context *) ctx;
128 + /* We handle POSIX ACLs separately. */
129 + if (!strcmp(name, "system.posix_acl_access")
130 + || !strcmp(name, "system.posix_acl_default"))
133 + action = attr_copy_action(name, ctx);
134 + return (action != ATTR_ACTION_SKIP &&
135 + (!copy_ctx->x->preserve_mode
136 + || action != ATTR_ACTION_PERMISSIONS));
138 +#endif /* USE_XATTR */
141 +copy_xattrs (const char *src_path, int source_desc, const char *dst_path,
142 + int dest_desc, const struct cp_options *x)
144 + struct copy_xattr_context copy_xattr_ctx = {
145 + { copy_xattr_error,
152 + if (x->preserve_xattrs)
156 + if (source_desc != -1 && dest_desc != -1)
157 + ret = attr_copy_fd(src_path, source_desc, dst_path, dest_desc,
158 + copy_xattr_filter, ©_xattr_ctx.ctx);
160 + ret = attr_copy_file (src_path, dst_path,
161 + copy_xattr_filter, ©_xattr_ctx.ctx);
162 + return ret == 0 || !x->require_preserve;
166 +#else /* USE_XATTR */
168 +#endif /* USE_XATTR */
171 /* Read the contents of the directory SRC_NAME_IN, and recursively
172 copy the contents to DST_NAME_IN. NEW_DST is true if
173 DST_NAME_IN is a directory that was created previously in the
174 @@ -509,6 +607,9 @@ copy_reg (char const *src_name, char con
178 + if (!copy_xattrs (src_name, source_desc, dst_name, dest_desc, x))
179 + return_val = false;
181 set_author (dst_name, dest_desc, src_sb);
183 if (x->preserve_mode || x->move_mode)
184 @@ -1755,6 +1856,9 @@ copy_internal (char const *src_name, cha
188 + if (!copy_xattrs (src_name, -1, dst_name, -1, x))
189 + delayed_ok = false;
191 set_author (dst_name, -1, &src_sb);
193 if (x->preserve_mode || x->move_mode)
194 --- coreutils-6.11/src/copy.h
195 +++ coreutils-6.11/src/copy.h
196 @@ -128,6 +128,9 @@ struct cp_options
198 bool preserve_timestamps;
200 + /* If true, attempt to copy extended attributes. */
201 + bool preserve_xattrs;
203 /* Enabled for mv, and for cp by the --preserve=links option.
204 If true, attempt to preserve in the destination files any
205 logical hard links between the source files. If used with cp's
206 --- coreutils-6.11/src/cp.c
207 +++ coreutils-6.11/src/cp.c
208 @@ -191,7 +191,7 @@ Mandatory arguments to long options are
209 -p same as --preserve=mode,ownership,timestamps\n\
210 --preserve[=ATTR_LIST] preserve the specified attributes (default:\n\
211 mode,ownership,timestamps), if possible\n\
212 - additional attributes: context, links, all\n\
213 + additional attributes: context, links, xattrs, all\n\
216 --no-preserve=ATTR_LIST don't preserve the specified attributes\n\
217 @@ -724,6 +724,7 @@ cp_option_init (struct cp_options *x)
218 x->preserve_timestamps = false;
219 x->preserve_security_context = false;
220 x->require_preserve_context = false;
221 + x->preserve_xattrs = false;
223 x->require_preserve = false;
224 x->recursive = false;
225 @@ -752,18 +753,21 @@ decode_preserve_arg (char const *arg, st
232 static enum File_attribute const preserve_vals[] =
234 PRESERVE_MODE, PRESERVE_TIMESTAMPS,
235 - PRESERVE_OWNERSHIP, PRESERVE_LINK, PRESERVE_CONTEXT, PRESERVE_ALL
236 + PRESERVE_OWNERSHIP, PRESERVE_LINK, PRESERVE_CONTEXT,
237 + PRESERVE_XATTRS, PRESERVE_ALL
239 /* Valid arguments to the `--preserve' option. */
240 static char const* const preserve_args[] =
242 "mode", "timestamps",
243 - "ownership", "links", "context", "all", NULL
244 + "ownership", "links", "context",
245 + "xattrs", "all", NULL
247 ARGMATCH_VERIFY (preserve_args, preserve_vals);
249 @@ -799,13 +803,18 @@ decode_preserve_arg (char const *arg, st
250 x->require_preserve_context = on_off;
253 + case PRESERVE_XATTRS:
254 + x->preserve_xattrs = on_off;
258 x->preserve_mode = on_off;
259 x->preserve_timestamps = on_off;
260 x->preserve_ownership = on_off;
261 x->preserve_links = on_off;
263 x->preserve_security_context = on_off;
264 + x->preserve_xattrs = on_off;
268 --- coreutils-6.11/src/install.c
269 +++ coreutils-6.11/src/install.c
270 @@ -154,6 +154,7 @@ cp_option_init (struct cp_options *x)
271 x->preserve_links = false;
272 x->preserve_mode = false;
273 x->preserve_timestamps = false;
274 + x->preserve_xattrs = false;
275 x->require_preserve = false;
276 x->require_preserve_context = false;
277 x->recursive = false;
278 --- coreutils-6.11/src/mv.c
279 +++ coreutils-6.11/src/mv.c
280 @@ -125,6 +125,7 @@ cp_option_init (struct cp_options *x)
281 x->preserve_mode = true;
282 x->preserve_timestamps = true;
283 x->preserve_security_context = selinux_enabled;
284 + x->preserve_xattrs = true;
285 x->require_preserve = false; /* FIXME: maybe make this an option */
286 x->require_preserve_context = false;
288 --- coreutils-6.11/doc/coreutils.texi
289 +++ coreutils-6.11/doc/coreutils.texi
290 @@ -6948,6 +6948,8 @@ Preserve in the destination files
291 any links between corresponding source files.
292 @c Give examples illustrating how hard links are preserved.
293 @c Also, show how soft links map to hard links with -L and -H.
295 +Preserve extended attributes. (See /etc/xattr.conf.)
297 Preserve all file attributes.
298 Equivalent to specifying all of the above.
299 --- coreutils-6.11/src/Makefile.am
300 +++ coreutils-6.11/src/Makefile.am
302 dir_LDADD += $(LIB_ACL)
303 ls_LDADD += $(LIB_ACL)
304 vdir_LDADD += $(LIB_ACL)
305 -cp_LDADD += $(LIB_ACL)
306 -mv_LDADD += $(LIB_ACL)
307 -ginstall_LDADD += $(LIB_ACL)
308 +cp_LDADD += $(LIB_ACL) $(LIB_XATTR)
309 +mv_LDADD += $(LIB_ACL) $(LIB_XATTR)
310 +ginstall_LDADD += $(LIB_ACL) $(LIB_XATTR)
312 stat_LDADD = $(LDADD) $(LIB_SELINUX)