Skip to content

Commit d17576d

Browse files
committed
syscall: preserve macOS creation times through dirfds
1 parent 07da8d4 commit d17576d

3 files changed

Lines changed: 22 additions & 21 deletions

File tree

‎configure.ac‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ AC_CHECK_FUNCS(waitpid wait4 getcwd chown chmod lchmod mknod mkfifo fdopendir \
874874
strlcat strlcpy strtol mallinfo mallinfo2 getgroups setgroups geteuid getegid \
875875
setlocale setmode open64 lseek64 mkstemp64 mtrace va_copy __va_copy \
876876
seteuid strerror putenv iconv_open locale_charset nl_langinfo getxattr \
877-
extattr_get_link sigaction sigprocmask setattrlist getgrouplist \
877+
extattr_get_link sigaction sigprocmask setattrlist setattrlistat getgrouplist \
878878
initgroups utimensat futimens posix_fallocate attropen setvbuf nanosleep usleep \
879879
setenv unsetenv mbrtowc)
880880

‎rsync.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
774774
if (!same_time(sxp->crtime, 0L, file_crtime, 0L)) {
775775
if (
776776
#ifdef HAVE_GETATTRLIST
777-
do_setattrlist_crtime(fname, file_crtime) == 0
777+
do_setattrlist_crtime(dfd, leaf, fname, file_crtime) == 0
778778
#elif defined __CYGWIN__
779779
do_SetFileTime(fname, file_crtime) == 0
780780
#else

‎syscall.c‎

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,7 +2467,6 @@ OFF_T do_lseek(int fd, OFF_T offset, int whence)
24672467
#ifdef HAVE_SETATTRLIST
24682468
int do_setattrlist_times(const char *path, STRUCT_STAT *stp)
24692469
{
2470-
extern int am_daemon, am_chrooted;
24712470
struct attrlist attrList;
24722471
struct timespec ts[2];
24732472

@@ -2477,7 +2476,7 @@ int do_setattrlist_times(const char *path, STRUCT_STAT *stp)
24772476

24782477
/* setattrlist() takes a raw path and follows parent symlinks
24792478
* (FSOPT_NOFOLLOW only blocks the final component). On a
2480-
* daemon-no-chroot deployment, return ENOSYS so set_times()'
2479+
* confined receiver, return ENOSYS so set_times()'
24812480
* tier walk falls through to do_utimensat_at(), which routes
24822481
* the timestamp update through a secure parent dirfd. The
24832482
* macOS-specific attribute set this function would have used
@@ -2502,33 +2501,36 @@ int do_setattrlist_times(const char *path, STRUCT_STAT *stp)
25022501
}
25032502

25042503
#ifdef SUPPORT_CRTIMES
2505-
int do_setattrlist_crtime(const char *path, time_t crtime)
2504+
int do_setattrlist_crtime(int dfd, const char *leaf, const char *path, time_t crtime)
25062505
{
2507-
extern int am_daemon, am_chrooted;
25082506
struct attrlist attrList;
25092507
struct timespec ts;
25102508

25112509
if (dry_run) return 0;
25122510
RETURN_ERROR_IF_RO_OR_LO;
25132511

2514-
/* Same path-follows-parent-symlinks concern as
2515-
* do_setattrlist_times. There is no portable at-aware variant
2516-
* of setattrlist that targets ATTR_CMN_CRTIME, so on a
2517-
* daemon-no-chroot deployment we return -1 and accept that
2518-
* crtime preservation is silently dropped for that file (the
2519-
* caller treats this as "crtime not updated"). The transfer
2520-
* itself continues normally. */
2521-
if (secure_relpath_active()) {
2522-
errno = ENOSYS;
2523-
return -1;
2524-
}
2525-
25262512
ts.tv_sec = crtime;
25272513
ts.tv_nsec = 0;
25282514

25292515
memset(&attrList, 0, sizeof attrList);
25302516
attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
25312517
attrList.commonattr = ATTR_CMN_CRTIME;
2518+
2519+
#ifdef HAVE_SETATTRLISTAT
2520+
if (dfd >= 0)
2521+
return setattrlistat(dfd, leaf, &attrList, &ts, sizeof ts, FSOPT_NOFOLLOW);
2522+
#else
2523+
(void)dfd;
2524+
(void)leaf;
2525+
#endif
2526+
2527+
/* The raw path form follows parent symlinks, so confined receivers need
2528+
* the held-parent form above. */
2529+
if (secure_relpath_active()) {
2530+
errno = ENOSYS;
2531+
return -1;
2532+
}
2533+
25322534
return setattrlist(path, &attrList, &ts, sizeof ts, FSOPT_NOFOLLOW);
25332535
}
25342536
#endif
@@ -2538,15 +2540,14 @@ int do_setattrlist_crtime(const char *path, time_t crtime)
25382540
time_t get_create_time(const char *path, STRUCT_STAT *stp)
25392541
{
25402542
#ifdef HAVE_GETATTRLIST
2541-
extern int am_daemon, am_chrooted;
25422543
static struct create_time attrBuf;
25432544
struct attrlist attrList;
25442545

25452546
(void)stp;
25462547
/* getattrlist() is also path-based and follows parent
2547-
* symlinks. In daemon-no-chroot, refuse rather than read the
2548+
* symlinks. In a confined receiver, refuse rather than read the
25482549
* crtime of a file the parent-symlink chain might point at
2549-
* outside the module. The caller's "no crtime available"
2550+
* outside the transfer root. The caller's "no crtime available"
25502551
* path returns 0; the file gets a fresh crtime instead of
25512552
* preserving the source's. */
25522553
if (secure_relpath_active())

0 commit comments

Comments
 (0)