From 9d6fe1a6f0233c7567dfb114835751aff85a578b Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Mon, 3 Jan 2011 11:07:47 -0800 Subject: [PATCH] Avoid reading ACL/xattr info on filetypes not being copied. Make Linux avoid xattr access on symlinks. Make OS X avoid xattr access on device/special files. Fixes bug 5458. --- acls.c | 19 +++++++++++++++++++ configure.ac | 3 +++ flist.c | 1 + xattrs.c | 23 +++++++++++++++++++++++ 4 files changed, 46 insertions(+) diff --git a/acls.c b/acls.c index e2bdc4c9..27a93c0b 100644 --- a/acls.c +++ b/acls.c @@ -31,6 +31,8 @@ extern int list_only; extern int orig_umask; extern int numeric_ids; extern int inc_recurse; +extern int preserve_devices; +extern int preserve_specials; /* Flags used to indicate what items are being transmitted for an entry. */ #define XMIT_USER_OBJ (1<<0) @@ -540,6 +542,23 @@ static int get_rsync_acl(const char *fname, rsync_acl *racl, int get_acl(const char *fname, stat_x *sxp) { sxp->acc_acl = create_racl(); + + if (S_ISREG(sxp->st.st_mode) || S_ISDIR(sxp->st.st_mode)) { + /* Everyone supports this. */ + } else if (S_ISLNK(sxp->st.st_mode)) { + return 0; + } else if (IS_SPECIAL(sxp->st.st_mode)) { +#ifndef NO_SPECIAL_ACLS + if (!preserve_specials) +#endif + return 0; + } else if (IS_DEVICE(sxp->st.st_mode)) { +#ifndef NO_DEVICE_ACLS + if (!preserve_devices) +#endif + return 0; + } + if (get_rsync_acl(fname, sxp->acc_acl, SMB_ACL_TYPE_ACCESS, sxp->st.st_mode) < 0) { free_acl(sxp); diff --git a/configure.ac b/configure.ac index d447b897..845ce0fc 100644 --- a/configure.ac +++ b/configure.ac @@ -963,11 +963,14 @@ else AC_MSG_RESULT(Using Linux xattrs) AC_DEFINE(HAVE_LINUX_XATTRS, 1, [True if you have Linux xattrs]) AC_DEFINE(SUPPORT_XATTRS, 1) + AC_DEFINE(NO_SYMLINK_XATTRS, 1, [True if symlinks do not support xattrs]) ;; darwin*) AC_MSG_RESULT(Using OS X xattrs) AC_DEFINE(HAVE_OSX_XATTRS, 1, [True if you have Mac OS X xattrs]) AC_DEFINE(SUPPORT_XATTRS, 1) + AC_DEFINE(NO_DEVICE_XATTRS, 1, [True if device files do not support xattrs]) + AC_DEFINE(NO_SPECIAL_XATTRS, 1, [True if special files do not support xattrs]) ;; freebsd*) AC_MSG_RESULT(Using FreeBSD extattrs) diff --git a/flist.c b/flist.c index 253dbe0a..86e45412 100644 --- a/flist.c +++ b/flist.c @@ -1429,6 +1429,7 @@ static struct file_struct *send_file_name(int f, struct file_list *flist, #endif #ifdef SUPPORT_XATTRS if (preserve_xattrs) { + sx.st.st_mode = file->mode; sx.xattr = NULL; if (get_xattr(fname, &sx) < 0) { io_error |= IOERR_GENERAL; diff --git a/xattrs.c b/xattrs.c index cc8f8d79..6f9afc94 100644 --- a/xattrs.c +++ b/xattrs.c @@ -32,6 +32,9 @@ extern int am_generator; extern int read_only; extern int list_only; extern int preserve_xattrs; +extern int preserve_links; +extern int preserve_devices; +extern int preserve_specials; extern int checksum_seed; #define RSYNC_XAL_INITIAL 5 @@ -283,6 +286,26 @@ int get_xattr(const char *fname, stat_x *sxp) { sxp->xattr = new(item_list); *sxp->xattr = empty_xattr; + + if (S_ISREG(sxp->st.st_mode) || S_ISDIR(sxp->st.st_mode)) { + /* Everyone supports this. */ + } else if (S_ISLNK(sxp->st.st_mode)) { +#ifndef NO_SYMLINK_XATTRS + if (!preserve_links) +#endif + return 0; + } else if (IS_SPECIAL(sxp->st.st_mode)) { +#ifndef NO_SPECIAL_XATTRS + if (!preserve_specials) +#endif + return 0; + } else if (IS_DEVICE(sxp->st.st_mode)) { +#ifndef NO_DEVICE_XATTRS + if (!preserve_devices) +#endif + return 0; + } + if (rsync_xal_get(fname, sxp->xattr) < 0) { free_xattr(sxp); return -1; -- 2.47.3