| 229 | } |
| 230 | |
| 231 | static int rsync_xal_get(const char *fname, item_list *xalp) |
| 232 | { |
| 233 | ssize_t list_len, name_len; |
| 234 | size_t datum_len, name_offset; |
| 235 | char *name, *ptr; |
| 236 | #ifdef HAVE_LINUX_XATTRS |
| 237 | int user_only = am_sender ? 0 : !am_root; |
| 238 | #endif |
| 239 | rsync_xa *rxa; |
| 240 | int count; |
| 241 | |
| 242 | /* This puts the name list into the "namebuf" buffer. */ |
| 243 | if ((list_len = get_xattr_names(fname)) < 0) |
| 244 | return -1; |
| 245 | |
| 246 | for (name = namebuf; list_len > 0; name += name_len) { |
| 247 | name_len = strlen(name) + 1; |
| 248 | list_len -= name_len; |
| 249 | |
| 250 | if (saw_xattr_filter) { |
| 251 | if (name_is_excluded(name, NAME_IS_XATTR, ALL_FILTERS)) |
| 252 | continue; |
| 253 | } |
| 254 | #ifdef HAVE_LINUX_XATTRS |
| 255 | /* Choose between ignoring the system namespace or (non-root) ignoring any non-user namespace. */ |
| 256 | else if (user_only ? !HAS_PREFIX(name, USER_PREFIX) : HAS_PREFIX(name, SYSTEM_PREFIX)) |
| 257 | continue; |
| 258 | #endif |
| 259 | |
| 260 | /* No rsync.%FOO attributes are copied w/o 2 -X options. */ |
| 261 | if (name_len > RPRE_LEN && name[RPRE_LEN] == '%' && HAS_PREFIX(name, RSYNC_PREFIX)) { |
| 262 | if ((am_sender && preserve_xattrs < 2) |
| 263 | || (am_root < 0 |
| 264 | && (strcmp(name+RPRE_LEN+1, XSTAT_SUFFIX) == 0 |
| 265 | || strcmp(name+RPRE_LEN+1, XACC_ACL_SUFFIX) == 0 |
| 266 | || strcmp(name+RPRE_LEN+1, XDEF_ACL_SUFFIX) == 0))) |
| 267 | continue; |
| 268 | } |
| 269 | |
| 270 | datum_len = name_len; /* Pass extra size to get_xattr_data() */ |
| 271 | if (!(ptr = get_xattr_data(fname, name, &datum_len, 0))) |
| 272 | return -1; |
| 273 | |
| 274 | if (datum_len > MAX_FULL_DATUM) { |
| 275 | /* For large datums, we store a flag and a checksum. */ |
| 276 | name_offset = 1 + MAX_XATTR_DIGEST_LEN; |
| 277 | sum_init(xattr_sum_nni, checksum_seed); |
| 278 | sum_update(ptr, datum_len); |
| 279 | free(ptr); |
| 280 | |
| 281 | ptr = new_array(char, name_offset + name_len); |
| 282 | *ptr = XSTATE_ABBREV; |
| 283 | sum_end(ptr + 1); |
| 284 | } else |
| 285 | name_offset = datum_len; |
| 286 | |
| 287 | rxa = EXPAND_ITEM_LIST(xalp, rsync_xa, RSYNC_XAL_INITIAL); |
| 288 | rxa->name = ptr + name_offset; |
no test coverage detected