X Tutup
Skip to content

Commit 23e026d

Browse files
alajovicpoettering
authored andcommitted
shared/copy: add a new flag COPY_ALL_XATTRS
When the flag COPY_ALL_XATTRS is set, it causes the complete set of xattrs to be copied. If the flag is unset, only xattrs from the "user" namespace are copied. Fixes systemd#17178.
1 parent a0c5a3f commit 23e026d

File tree

9 files changed

+18
-16
lines changed

9 files changed

+18
-16
lines changed

src/dissect/dissect.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ static int action_copy(DissectedImage *m, LoopDevice *d) {
679679
if (r < 0)
680680
return log_error_errno(r, "Failed to copy bytes from %s in mage '%s' to '%s': %m", arg_source, arg_image, arg_target);
681681

682-
(void) copy_xattr(source_fd, target_fd);
682+
(void) copy_xattr(source_fd, target_fd, 0);
683683
(void) copy_access(source_fd, target_fd);
684684
(void) copy_times(source_fd, target_fd, 0);
685685

@@ -748,7 +748,7 @@ static int action_copy(DissectedImage *m, LoopDevice *d) {
748748
if (r < 0)
749749
return log_error_errno(r, "Failed to copy bytes from '%s' to '%s' in image '%s': %m", arg_source, arg_target, arg_image);
750750

751-
(void) copy_xattr(source_fd, target_fd);
751+
(void) copy_xattr(source_fd, target_fd, 0);
752752
(void) copy_access(source_fd, target_fd);
753753
(void) copy_times(source_fd, target_fd, 0);
754754

src/import/export-raw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ static int raw_export_process(RawExport *e) {
223223
finish:
224224
if (r >= 0) {
225225
(void) copy_times(e->input_fd, e->output_fd, COPY_CRTIME);
226-
(void) copy_xattr(e->input_fd, e->output_fd);
226+
(void) copy_xattr(e->input_fd, e->output_fd, 0);
227227
}
228228

229229
if (e->on_finished)

src/import/import-raw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ static int raw_import_finish(RawImport *i) {
206206

207207
if (S_ISREG(i->st.st_mode)) {
208208
(void) copy_times(i->input_fd, i->output_fd, COPY_CRTIME);
209-
(void) copy_xattr(i->input_fd, i->output_fd);
209+
(void) copy_xattr(i->input_fd, i->output_fd, 0);
210210
}
211211

212212
if (i->flags & IMPORT_READ_ONLY) {

src/import/pull-raw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ static int raw_pull_make_local_copy(RawPull *i) {
371371
}
372372

373373
(void) copy_times(i->raw_job->disk_fd, dfd, COPY_CRTIME);
374-
(void) copy_xattr(i->raw_job->disk_fd, dfd);
374+
(void) copy_xattr(i->raw_job->disk_fd, dfd, 0);
375375

376376
dfd = safe_close(dfd);
377377

src/locale/keymap-util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ int locale_gen_enable_locale(const char *locale) {
845845
r = copy_access(fileno(fr), fileno(fw));
846846
if (r < 0)
847847
return r;
848-
r = copy_xattr(fileno(fr), fileno(fw));
848+
r = copy_xattr(fileno(fr), fileno(fw), COPY_ALL_XATTRS);
849849
if (r < 0)
850850
return r;
851851
}

src/partition/repart.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2849,13 +2849,13 @@ static int do_copy_files(Partition *p, const char *fs) {
28492849
sfd, ".",
28502850
pfd, fn,
28512851
UID_INVALID, GID_INVALID,
2852-
COPY_REFLINK|COPY_MERGE|COPY_REPLACE|COPY_SIGINT|COPY_HARDLINKS);
2852+
COPY_REFLINK|COPY_MERGE|COPY_REPLACE|COPY_SIGINT|COPY_HARDLINKS|COPY_ALL_XATTRS);
28532853
} else
28542854
r = copy_tree_at(
28552855
sfd, ".",
28562856
tfd, ".",
28572857
UID_INVALID, GID_INVALID,
2858-
COPY_REFLINK|COPY_MERGE|COPY_REPLACE|COPY_SIGINT|COPY_HARDLINKS);
2858+
COPY_REFLINK|COPY_MERGE|COPY_REPLACE|COPY_SIGINT|COPY_HARDLINKS|COPY_ALL_XATTRS);
28592859
if (r < 0)
28602860
return log_error_errno(r, "Failed to copy '%s' to '%s%s': %m", *source, strempty(arg_root), *target);
28612861
} else {
@@ -2890,7 +2890,7 @@ static int do_copy_files(Partition *p, const char *fs) {
28902890
if (r < 0)
28912891
return log_error_errno(r, "Failed to copy '%s' to '%s%s': %m", *source, strempty(arg_root), *target);
28922892

2893-
(void) copy_xattr(sfd, tfd);
2893+
(void) copy_xattr(sfd, tfd, COPY_ALL_XATTRS);
28942894
(void) copy_access(sfd, tfd);
28952895
(void) copy_times(sfd, tfd, 0);
28962896
}

src/shared/btrfs-util.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,6 +1628,7 @@ int btrfs_subvol_snapshot_fd_full(
16281628
COPY_REFLINK|
16291629
COPY_SAME_MOUNT|
16301630
COPY_HARDLINKS|
1631+
COPY_ALL_XATTRS|
16311632
(FLAGS_SET(flags, BTRFS_SNAPSHOT_SIGINT) ? COPY_SIGINT : 0)|
16321633
(FLAGS_SET(flags, BTRFS_SNAPSHOT_SIGTERM) ? COPY_SIGTERM : 0),
16331634
progress_path,

src/shared/copy.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ static int fd_copy_regular(
652652
r = -errno;
653653

654654
(void) futimens(fdt, (struct timespec[]) { st->st_atim, st->st_mtim });
655-
(void) copy_xattr(fdf, fdt);
655+
(void) copy_xattr(fdf, fdt, copy_flags);
656656

657657
if (copy_flags & COPY_FSYNC) {
658658
if (fsync(fdt) < 0) {
@@ -945,7 +945,7 @@ static int fd_copy_directory(
945945
if (fchmod(fdt, st->st_mode & 07777) < 0)
946946
r = -errno;
947947

948-
(void) copy_xattr(dirfd(d), fdt);
948+
(void) copy_xattr(dirfd(d), fdt, copy_flags);
949949
(void) futimens(fdt, (struct timespec[]) { st->st_atim, st->st_mtim });
950950
}
951951

@@ -1139,7 +1139,7 @@ int copy_file_fd_full(
11391139

11401140
if (S_ISREG(fdt)) {
11411141
(void) copy_times(fdf, fdt, copy_flags);
1142-
(void) copy_xattr(fdf, fdt);
1142+
(void) copy_xattr(fdf, fdt, copy_flags);
11431143
}
11441144

11451145
if (copy_flags & COPY_FSYNC_FULL) {
@@ -1211,7 +1211,7 @@ int copy_file_full(
12111211
goto fail;
12121212

12131213
(void) copy_times(fdf, fdt, copy_flags);
1214-
(void) copy_xattr(fdf, fdt);
1214+
(void) copy_xattr(fdf, fdt, copy_flags);
12151215

12161216
if (chattr_mask != 0)
12171217
(void) chattr_fd(fdt, chattr_flags, chattr_mask & ~CHATTR_EARLY_FL, NULL);
@@ -1399,7 +1399,7 @@ int copy_rights_with_fallback(int fdf, int fdt, const char *patht) {
13991399
return fchmod_and_chown_with_fallback(fdt, patht, st.st_mode & 07777, st.st_uid, st.st_gid);
14001400
}
14011401

1402-
int copy_xattr(int fdf, int fdt) {
1402+
int copy_xattr(int fdf, int fdt, CopyFlags copy_flags) {
14031403
_cleanup_free_ char *names = NULL;
14041404
int ret = 0, r;
14051405
const char *p;
@@ -1411,7 +1411,7 @@ int copy_xattr(int fdf, int fdt) {
14111411
NULSTR_FOREACH(p, names) {
14121412
_cleanup_free_ char *value = NULL;
14131413

1414-
if (!startswith(p, "user."))
1414+
if (!(copy_flags & COPY_ALL_XATTRS) && !startswith(p, "user."))
14151415
continue;
14161416

14171417
r = fgetxattr_malloc(fdf, p, &value);

src/shared/copy.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ typedef enum CopyFlags {
2323
COPY_FSYNC = 1 << 10, /* fsync() after we are done */
2424
COPY_FSYNC_FULL = 1 << 11, /* fsync_full() after we are done */
2525
COPY_SYNCFS = 1 << 12, /* syncfs() the *top-level* dir after we are done */
26+
COPY_ALL_XATTRS = 1 << 13, /* Preserve all xattrs when copying, not just those in the user namespace */
2627
} CopyFlags;
2728

2829
typedef int (*copy_progress_bytes_t)(uint64_t n_bytes, void *userdata);
@@ -72,4 +73,4 @@ int copy_rights_with_fallback(int fdf, int fdt, const char *patht);
7273
static inline int copy_rights(int fdf, int fdt) {
7374
return copy_rights_with_fallback(fdf, fdt, NULL); /* no fallback */
7475
}
75-
int copy_xattr(int fdf, int fdt);
76+
int copy_xattr(int fdf, int fdt, CopyFlags copy_flags);

0 commit comments

Comments
 (0)
X Tutup