Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/scripts/guest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
from contextlib import ExitStack
import json
import os
from pathlib import Path
Expand Down Expand Up @@ -39,6 +40,7 @@ def main():
status = 1
active = None
cross_device = None
fileflags_fs = ExitStack()
mounted = False
source = None
env = {**os.environ, 'PYTHONDONTWRITEBYTECODE': '1'}
Expand Down Expand Up @@ -109,7 +111,17 @@ def command(label, argv, *, required=True, destination=None, account=None):
feature_options = []
profiles = f'non-asan,self-peer,{args.platform}'
if args.platform == 'freebsd':
from harness.interop_metadata import metadata_filesystem

env.update(CPPFLAGS='-I/usr/local/include', LDFLAGS='-L/usr/local/lib')
# Neither the shared checkout nor the guest's default scratch is guaranteed
# to support the file flags this test exercises.
fileflags_root = Path(fileflags_fs.enter_context(
tempfile.TemporaryDirectory(prefix='rsync-fileflags-fs.', dir='/var/tmp')))
fileflags_root.chmod(0o711)
fileflags_tmp = fileflags_fs.enter_context(metadata_filesystem(fileflags_root, 'freebsd'))
fileflags_tmp.chmod(0o1777)
env['RSYNC_FILEFLAGS_TEST_TMP'] = str(fileflags_tmp)
flags += ['--disable-md2man', '--enable-iconv', '--enable-acl-support', '--enable-xattr-support',
'--enable-roll-simd', '--enable-roll-asm', '--enable-md5-asm']
features = ['zstd', 'lz4', 'xxh128', 'xxh3', 'xxh64', 'iconv', 'IDN', 'ACLs', 'xattrs']
Expand Down Expand Up @@ -186,6 +198,11 @@ def command(label, argv, *, required=True, destination=None, account=None):
print(f'::error::Guest checks failed: {error}', file=sys.stderr)
status = 1
finally:
try:
fileflags_fs.close()
except (OSError, ValueError) as error:
print(f'::error::Fileflags filesystem cleanup failed: {error}', file=sys.stderr)
status = 1
if cross_device is not None:
try:
if mounted:
Expand Down
28 changes: 27 additions & 1 deletion .github/scripts/test-guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
from pathlib import Path
import runpy
import subprocess
import sys
import tempfile
from types import SimpleNamespace
Expand Down Expand Up @@ -38,13 +39,21 @@ def process(command, **kwargs):
code = 1 if failure and failure(command) else 0
calls.append((command, kwargs))
return SimpleNamespace(wait=lambda: code, poll=lambda: code)
def run(command, **kwargs):
code = 1 if failure and failure(command) else 0
calls.append((command, kwargs))
stdout = b'md7\n' if command[:2] == ['mdconfig', '-a'] else b''
result = subprocess.CompletedProcess(command, code, stdout=stdout, stderr=b'')
if kwargs.get('check'):
result.check_returncode()
return result
argv = ['guest.py', platform, '--release', '11.0', '--output', str(output)]
system = {'freebsd': 'FreeBSD', 'netbsd': 'NetBSD', 'openbsd': 'OpenBSD', 'solaris': 'SunOS'}[platform]
with patch.object(sys, 'argv', argv), patch('platform.system', return_value=system), \
patch('platform.release', return_value='11.0'), patch('platform.machine', return_value='amd64'), \
patch('pwd.getpwnam', return_value=account), patch('os.getgrouplist', return_value=[1000, 1001]), \
patch('os.chown'), patch('subprocess.Popen', side_effect=process), \
patch('subprocess.run', return_value=SimpleNamespace(returncode=0)), \
patch('subprocess.run', side_effect=run), \
redirect_stdout(log), redirect_stderr(StringIO()):
result = guest['main']()
return result, (output / 'status').read_text().strip(), calls, log.getvalue()
Expand All @@ -67,6 +76,16 @@ def test_native_passes(self):
self.assertEqual(options['env']['HOME'], '/home/rsynctest')
else:
self.assertNotIn('user', options)
if platform == 'freebsd':
scratch = {options['env']['RSYNC_FILEFLAGS_TEST_TMP'] for _, options in tests}
self.assertEqual(len(scratch), 1)
path = scratch.pop()
commands = [command for command, _ in calls]
mount = ['mount', '-t', 'ufs', '-o', 'acls,nosuid', '/dev/md7', path]
unmount = ['umount', path]
self.assertLess(commands.index(mount), commands.index(tests[0][0]))
self.assertLess(commands.index(tests[-1][0]), commands.index(unmount))
self.assertLess(commands.index(unmount), commands.index(['mdconfig', '-d', '-u', '7']))
if platform == 'openbsd':
self.assertTrue(all('-j2' in command for command, _ in tests if '--use-tcp' in command))
if platform in ('netbsd', 'solaris'):
Expand Down Expand Up @@ -106,6 +125,13 @@ def test_failed_build_stops_tests(self):
self.assertEqual((result, status), (0, '1'))
self.assertFalse(any('testsuite/tools/check.py' in command for command, _ in calls))

def test_failed_fileflags_mount_stops_tests(self):
result, status, calls, _ = self.run_guest('freebsd', lambda command: command[:3] == ['mount', '-t', 'ufs'])
self.assertEqual((result, status), (0, '1'))
commands = [command for command, _ in calls]
self.assertIn(['mdconfig', '-d', '-u', '7'], commands)
self.assertFalse(any('testsuite/tools/check.py' in command for command in commands))

def test_missing_probe_does_not_stop_tests(self):
def missing(command):
if command[0].endswith('/dirfd-probe'):
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- Add local FIFO transfers on supported Linux builds with `--stream-source`.
Require an exact byte count and EOF before replacing a regular destination.
- Add `--fileflags` to preserve the native `nodump` flag on regular files and
directories in local FreeBSD transfers.
- Accept `TCP_CONGESTION=NAME` in socket options on supported Linux builds.
Distinguish unknown names, unavailable options and malformed values.
- Add `--placement-log` for local receivers to record verified regular files
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ On supported Linux builds, `--stream-source --stream-size=SIZE` copies one
local named pipe into a regular file. The writer must produce exactly `SIZE`
bytes and close the pipe before rsync can publish the file.

FreeBSD builds with descriptor-based file flag support can preserve the
`nodump` flag in local transfers with `--fileflags`.

For local transfers to an existing directory, `--compare-dest-per-dir` and
`--copy-dest-per-dir` can use files in that tree as bases for missing regular
files. The [option reference](rsync.1.md#options) describes their limits.
Expand Down
2 changes: 2 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ Where the operating system supports them, rsync uses held directory descriptors

Holding a directory descriptor does not pin every entry in that directory or provide a consistent snapshot of a tree being modified during a transfer.

The local FreeBSD `--fileflags` option changes only `nodump` through a checked file descriptor. It does not clear protection flags to replace or delete an object. The filesystem API replaces a complete flag word, so changes made by another process between inspection and update are not serialised with rsync.

Daemon authentication proves knowledge of a shared secret but does not encrypt the connection. Legacy clients can negotiate MD4 or MD5. Operators who require a strong digest should set `auth digest = sha256`; sensitive transfers should use SSH or verified TLS.

## Unsupported releases
Expand Down
3 changes: 3 additions & 0 deletions compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ extern struct name_num_item *xfer_sum_nni;

int remote_protocol = 0;
int file_extra_cnt = 0; /* count of file-list extras that everyone gets */
int nodump_ndx = 0;
int inc_recurse = 0;
int compat_flags = 0;
int use_safe_inc_flist = 0;
Expand Down Expand Up @@ -654,6 +655,8 @@ void setup_protocol(int f_out,int f_in)
acls_ndx = ++file_extra_cnt;
if (preserve_xattrs)
xattrs_ndx = ++file_extra_cnt;
if (preserve_fileflags)
nodump_ndx = ++file_extra_cnt;

if (!saw_stderr_opt && protocol_version <= 28 && am_server)
msgs2stderr = 0; /* The client side may not have stderr setup for us. */
Expand Down
19 changes: 19 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,25 @@ AC_CHECK_FUNCS(waitpid wait4 getcwd chown chmod lchmod mknod mkfifo fdopendir \
initgroups utimensat futimens posix_fallocate attropen setvbuf nanosleep usleep \
setenv unsetenv mbrtowc setpriority)

AC_CACHE_CHECK([for FreeBSD descriptor-based file flags], [rsync_cv_fileflags], [
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#ifndef __FreeBSD__
#error FreeBSD file flags required
#endif]], [[
struct stat st;
int fd = openat(AT_FDCWD, ".", O_PATH | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);
(void) &chflagsat;
if (fstat(fd, &st) < 0)
return 1;
return chflagsat(fd, "", st.st_flags | UF_NODUMP, AT_EMPTY_PATH);
]])], [rsync_cv_fileflags=yes], [rsync_cv_fileflags=no])
])
if test x"$rsync_cv_fileflags" = xyes; then
AC_DEFINE([SUPPORT_FILEFLAGS], 1, [Define to 1 for FreeBSD descriptor-based file flags.])
fi

dnl Require the socket header to declare bindat() as well as a linkable symbol.
AC_CACHE_CHECK([for usable bindat()], [rsync_cv_HAVE_BINDAT], [
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
Expand Down
34 changes: 34 additions & 0 deletions delete.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,29 @@ static int del_unlink(const char *fbuf)
return robust_unlink(fbuf); /* fall back (ETXTBSY retry, or not held) */
}

#ifdef SUPPORT_FILEFLAGS
static BOOL fileflags_allow_delete(const char *path)
{
STRUCT_STAT st;
const char *leaf;
int dfd, ret;

if (!preserve_fileflags || dry_run)
return True;
dfd = del_held_dfd(path, &leaf);
ret = dfd >= 0 ? do_lstat_atfd(dfd, leaf, &st) : do_lstat_at(path, &st);
if (ret < 0 && errno == ENOENT)
return True;
if (ret == 0) {
if (!(st.st_flags & PROTECTED_FILEFLAGS))
return True;
errno = EPERM;
}
rsyserr(FERROR_XFER, errno, "refusing to delete %s with --fileflags", full_fname(path));
return False;
}
#endif

static inline int is_backup_file(char *fn)
{
int k = strlen(fn) - backup_suffix_len;
Expand Down Expand Up @@ -191,6 +214,12 @@ static enum delret delete_dir_contents(char *fname, uint16 flags, BOOL back_up_d
}

strlcpy(p, fp->basename, remainder);
#ifdef SUPPORT_FILEFLAGS
if (!fileflags_allow_delete(fname)) {
ret = DR_NOT_EMPTY;
continue;
}
#endif
back_up = back_up_dirs ? directory_backup_stat(fname, fp->mode, flags, &st) : 0;
if (back_up < 0) {
if (errno != ENOENT)
Expand Down Expand Up @@ -254,6 +283,11 @@ static enum delret delete_item_with_stat(char *fbuf, uint16 mode, uint16 flags,
fbuf, (int)mode, (int)flags);
}

#ifdef SUPPORT_FILEFLAGS
if (!(flags & DEL_DIR_IS_EMPTY) && !fileflags_allow_delete(fbuf))
return DR_FAILURE;
#endif

if (flags & DEL_NO_UID_WRITE)
restore_mode = del_chmod(fbuf, mode | S_IWUSR) == 0 && backup_stat;

Expand Down
11 changes: 11 additions & 0 deletions flist.c
Original file line number Diff line number Diff line change
Expand Up @@ -1618,6 +1618,9 @@ static struct file_struct *recv_file_entry(int f, struct file_list *flist, int x
read_buf(f, bp, flist_csum_len);
}

if (nodump_ndx)
F_NODUMP(file) = read_byte(f) != 0;

#ifdef SUPPORT_ACLS
if (preserve_acls && !S_ISLNK(mode))
receive_acl(f, file);
Expand Down Expand Up @@ -1952,6 +1955,10 @@ struct file_struct *make_file(const char *fname, struct file_list *flist,
}
#endif
file->mode = st.st_mode;
#ifdef SUPPORT_FILEFLAGS
if (nodump_ndx && (S_ISREG(file->mode) || S_ISDIR(file->mode)))
F_NODUMP(file) = (st.st_flags & UF_NODUMP) != 0;
#endif
if (preserve_uid)
F_OWNER(file) = st.st_uid;
if (preserve_gid)
Expand Down Expand Up @@ -2135,6 +2142,10 @@ static struct file_struct *send_file_name(int f, struct file_list *flist,
#endif
flist->used, flist->ndx_start);

/* The local child inherits the option. No external peer or batch sees this field. */
if (nodump_ndx)
write_byte(f, F_NODUMP(file));

#ifdef SUPPORT_ACLS
if (preserve_acls && !S_ISLNK(file->mode)) {
send_acl(f, &sx);
Expand Down
25 changes: 23 additions & 2 deletions generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,11 @@ void itemize(const char *fnamecmp, struct file_struct *file, int ndx, int statre

if (S_ISREG(file->mode) && F_LENGTH(file) != sxp->st.st_size)
iflags |= ITEM_REPORT_SIZE;
#ifdef SUPPORT_FILEFLAGS
if (nodump_ndx && (S_ISREG(file->mode) || S_ISDIR(file->mode))
&& F_NODUMP(file) != ((sxp->st.st_flags & UF_NODUMP) != 0))
iflags |= ITEM_REPORT_CHANGE;
#endif
if (file->flags & FLAG_TIME_FAILED) { /* symlinks only */
if (iflags & ITEM_LOCAL_CHANGE)
iflags |= symlink_timeset_failed_flags;
Expand Down Expand Up @@ -2200,6 +2205,13 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
mode_t added_perms;
if (!implied_dirs && file->flags & FLAG_IMPLIED_DIR)
goto cleanup;
if (preserve_fileflags && statret == 0 && stype != FT_DIR) {
if (is_dir < 0)
goto cleanup;
rprintf(FERROR_XFER, "--fileflags refuses to replace a non-directory with %s\n",
full_fname(fname));
goto skipping_dir_contents;
}
if (am_root < 0) {
/* For --fake-super, the dir must be usable by the copying
* user, just like it would be for root. */
Expand Down Expand Up @@ -2284,7 +2296,8 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
if (preserve_xattrs && statret == 1)
gen_entry_copy_xattrs(fnamecmpbuf, fname, file);
#endif
if (set_file_attrs(fname, file, real_ret ? NULL : &real_sx, NULL, 0)
if (set_file_attrs(fname, file, real_ret ? NULL : &real_sx, NULL,
preserve_fileflags ? ATTRS_SET_FILEFLAGS : 0)
&& INFO_GTE(NAME, 1) && code != FNONE && f_out != -1)
rprintf(code, "%s/\n", fname);

Expand Down Expand Up @@ -2548,6 +2561,12 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
full_fname(fname));
exit_cleanup(RERR_FILEIO);
}
/* Do not remove the old entry before the receiver can set the staged flags. */
if (preserve_fileflags) {
rprintf(FERROR_XFER, "--fileflags refuses to replace a non-regular file with %s\n",
full_fname(fname));
goto cleanup;
}
if (delete_item(fname, sx.st.st_mode, del_opts | DEL_FOR_FILE) != 0)
goto cleanup;
statret = -1;
Expand Down Expand Up @@ -2663,7 +2682,9 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
operator_path_resolve = 0;
handle_partial_dir(partialptr, PDIR_DELETE);
}
set_file_attrs(fname, file, &sx, NULL, maybe_ATTRS_REPORT | maybe_ATTRS_ACCURATE_TIME);
if (set_file_attrs(fname, file, &sx, NULL, maybe_ATTRS_REPORT | maybe_ATTRS_ACCURATE_TIME
| (preserve_fileflags ? ATTRS_SET_FILEFLAGS | ATTRS_REQUIRE_SUCCESS : 0)) < 0)
goto cleanup;
if (itemizing)
itemize(fnamecmp, file, ndx, statret, &sx, 0, 0, NULL);
#ifdef SUPPORT_HARD_LINKS
Expand Down
5 changes: 5 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1616,6 +1616,11 @@ static int start_client(int argc, char *argv[])
exit_cleanup(RERR_SYNTAX);
}

if (preserve_fileflags && (!local_server || list_only)) {
rprintf(FERROR, "--fileflags is only supported for local transfers\n");
exit_cleanup(RERR_SYNTAX);
}

if (placement_log && am_sender && !local_server) {
rprintf(FERROR, "--placement-log requires a local receiver\n");
exit_cleanup(RERR_SYNTAX);
Expand Down
32 changes: 32 additions & 0 deletions options.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ int preserve_links = 0;
int preserve_hard_links = 0;
int preserve_acls = 0;
int preserve_xattrs = 0;
int preserve_fileflags = 0;
int preserve_perms = 0;
int preserve_executability = 0;
int preserve_devices = 0;
Expand Down Expand Up @@ -669,6 +670,8 @@ static struct poptOption long_options[] = {
{"xattrs", 'X', POPT_ARG_NONE, 0, 'X', 0, 0 },
{"no-xattrs", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
{"no-X", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
{"fileflags", 0, POPT_ARG_VAL, &preserve_fileflags, 1, 0, 0 },
{"no-fileflags", 0, POPT_ARG_VAL, &preserve_fileflags, 0, 0, 0 },
{"times", 't', POPT_ARG_VAL, &preserve_mtimes, 1, 0, 0 },
{"no-times", 0, POPT_ARG_VAL, &preserve_mtimes, 0, 0, 0 },
{"no-t", 0, POPT_ARG_VAL, &preserve_mtimes, 0, 0, 0 },
Expand Down Expand Up @@ -2414,6 +2417,35 @@ int parse_arguments(int *argc_p, const char ***argv_p)
if (fuzzy_basis > 1)
fuzzy_basis = basis_dir_cnt + 1;

if (preserve_fileflags) {
#ifndef SUPPORT_FILEFLAGS
strlcpy(err_buf, "--fileflags is not supported by this build\n", sizeof err_buf);
goto cleanup;
#else
const char *conflict = read_batch ? "--read-batch"
: write_batch ? "--write-batch or --only-write-batch"
: remote_option_cnt ? "--remote-option"
: am_root < 0 ? "--fake-super"
: make_backups || backup_dir ? "--backup or --backup-dir"
: inplace || append_mode || write_devices ? "--inplace, --append or --write-devices"
: keep_partial || partial_dir || delay_updates ? "--partial, --partial-dir or --delay-updates"
: tmpdir ? "--temp-dir"
: basis_dir_cnt ? alt_dest_opt(0)
: preserve_hard_links ? "--hard-links"
: copy_devices ? "--copy-devices"
: keep_dirlinks ? "--keep-dirlinks"
: insecure_links ? "--insecure-links" : NULL;
if (am_server || am_daemon) {
strlcpy(err_buf, "--fileflags is only supported for local transfers\n", sizeof err_buf);
goto cleanup;
}
if (conflict) {
snprintf(err_buf, sizeof err_buf, "--fileflags cannot be combined with %s\n", conflict);
goto cleanup;
}
#endif
}

/* Don't let the client reset protect_args if it was already processed */
if (orig_protect_args == 2 && am_server)
protect_args = orig_protect_args;
Expand Down
Loading
Loading