[packages/rsync] Rel 3. Package rrsync as rsync-rrsync.
arekm
arekm at pld-linux.org
Thu Oct 29 10:59:48 CET 2026
commit cc788cc57df69097cd7db59a3f99c8647560b99e
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Thu Oct 29 10:58:49 2026 +0100
Rel 3. Package rrsync as rsync-rrsync.
Backport upstream 92a2a09e3f: rrsync 3.5.1 refuses uploads onto an
existing file destination with EPERM.
rsync-rrsync-receiver-file-arg.patch | 198 +++++++++++++++++++++++++++++++++++
rsync.spec | 31 +++++-
2 files changed, 228 insertions(+), 1 deletion(-)
---
diff --git a/rsync.spec b/rsync.spec
index c5bdc86..c6fd2ce 100644
--- a/rsync.spec
+++ b/rsync.spec
@@ -17,7 +17,7 @@ Summary(zh_CN.UTF-8): [通讯]传输工具
Summary(zh_TW.UTF-8): [喙啪]$(B6G?i火(c(B
Name: rsync
Version: 3.5.1
-Release: 2
+Release: 3
Epoch: 1
License: GPL v3+
Group: Networking/Utilities
@@ -31,6 +31,7 @@ Source6: %{name}.tmpfiles
Patch0: %{name}-config.patch
Patch1: rsync-norandomfailure.patch
Patch2: %{name}-hash_search-overflow.patch
+Patch3: %{name}-rrsync-receiver-file-arg.patch
URL: https://rsync.samba.org/
BuildRequires: acl-devel
BuildRequires: autoconf >= 2.69
@@ -114,6 +115,26 @@ rsync - це швидша та гнучкіша альтернатива rcp, я
в компресованому виді. При цьому зовсім не обов'язково, щоб одна
машина мала в себе копію того, що є на іншій машині.
+%package rrsync
+Summary: Restricted rsync for ssh forced-command logins
+Summary(pl.UTF-8): Ograniczony rsync dla logowań ssh z wymuszonym poleceniem
+Group: Networking/Utilities
+Requires: %{name} = %{epoch}:%{version}-%{release}
+Requires: python3-modules
+BuildArch: noarch
+
+%description rrsync
+rrsync is a script to be used as a forced command (command=) in
+~/.ssh/authorized_keys. It restricts rsync transfers done with a given
+key to a single directory and can additionally forbid reading, writing
+or deleting files.
+
+%description rrsync -l pl.UTF-8
+rrsync to skrypt do użycia jako wymuszone polecenie (command=) w
+~/.ssh/authorized_keys. Ogranicza transfery rsync wykonywane danym
+kluczem do jednego katalogu i może dodatkowo zabronić odczytu, zapisu
+lub usuwania plików.
+
%package -n rsyncd-inetd
Summary: Files necessary to run rsync in daemon mode
Summary(pl.UTF-8): Pliki niezbędne do uruchomienia rsynca w trybie serwera
@@ -173,8 +194,10 @@ techniczna nowego algorytmu została również dołączona do pakietu.
%patch -P0 -p1
%patch -P1 -p1
%patch -P2 -p1
+%patch -P3 -p1
sed -i -e 's|#!/usr/bin/env bash|#!/bin/bash|' rsync-ssl
+%{__sed} -i -e '1s,/usr/bin/env python3,%{__python3},' support/rrsync
rm -f *.old
@@ -190,6 +213,7 @@ rm -f *.old
--enable-ipv6 \
--enable-xattr-support \
--with-included-zlib=no \
+ --with-rrsync \
%{?with_rsh:--with-rsh=rsh} \
--with-rsyncd-conf=%{_sysconfdir}/rsyncd.conf
%{__make} proto
@@ -272,6 +296,11 @@ fi
%{_mandir}/man1/rsync.1*
%{_mandir}/man1/rsync-ssl.1*
+%files rrsync
+%defattr(644,root,root,755)
+%attr(755,root,root) %{_bindir}/rrsync
+%{_mandir}/man1/rrsync.1*
+
%files -n rsyncd-inetd
%defattr(644,root,root,755)
%dir %{_sysconfdir}
diff --git a/rsync-rrsync-receiver-file-arg.patch b/rsync-rrsync-receiver-file-arg.patch
new file mode 100644
index 0000000..e28f14b
--- /dev/null
+++ b/rsync-rrsync-receiver-file-arg.patch
@@ -0,0 +1,198 @@
+rrsync: pin the parent of existing receiver file arguments; without it an
+upload onto an existing file fails with EPERM on the /proc/self/fd link.
+https://github.com/RsyncProject/rsync/commit/92a2a09e3f (#1107, #1136)
+
+--- a/support/rrsync
++++ b/support/rrsync
+@@ -375,7 +375,7 @@
+ pinned_fds.append(fd)
+ return '/proc/self/fd/%d' % fd
+
+-# sender_pinned_arg() verdicts that are not a rewritten argument.
++# Pinned-argument verdicts that are not a rewritten argument.
+ KEEP_LEAF_PIN = 'keep' # hand rsync the leaf's own /proc/self/fd/N
+ LEAF_PIN_UNUSABLE = 'unusable' # no pin for this shape; keep the plain name
+
+@@ -452,6 +452,22 @@
+ die('post-pin path changed (race?):', orig_arg, check)
+ return pinned
+
++def receiver_pinned_arg(fd, arg, orig_arg):
++ """Keep existing file destinations writable beneath a pinned parent."""
++ leaf_st = os.fstat(fd)
++ if stat.S_ISDIR(leaf_st.st_mode):
++ return KEEP_LEAF_PIN
++
++ parent, leaf = os.path.split(arg)
++ dfd = pin_dir(parent, orig_arg)
++ try:
++ st = os.stat(leaf, dir_fd=dfd, follow_symlinks=False)
++ except OSError as e:
++ die('post-pin stat failed (race?):', orig_arg, e.strerror)
++ if (st.st_dev, st.st_ino) != (leaf_st.st_dev, leaf_st.st_ino):
++ die('post-pin path changed (race?):', orig_arg, leaf)
++ return '/proc/self/fd/%d/%s' % (dfd, leaf)
++
+ def safe_open_logfile():
+ nofollow = getattr(os, 'O_NOFOLLOW', 0)
+ try:
+@@ -923,6 +939,8 @@
+ pinned = sender_pinned_arg(fd, logical, orig_arg,
+ arg_has_trailing_slash,
+ arg_has_trailing_slash_dot)
++ elif opt == 'arg':
++ pinned = receiver_pinned_arg(fd, real_arg, orig_arg)
+ else:
+ pinned = KEEP_LEAF_PIN
+ if pinned == KEEP_LEAF_PIN:
+--- /dev/null
++++ b/testsuite/rrsync-receiver-file-arg_test.py
+@@ -0,0 +1,148 @@
++#!/usr/bin/env python3
++"""Receiver file arguments must remain beneath a pinned parent."""
++
++import os
++import shlex
++import subprocess
++import time
++
++from rsyncfns import (
++ SCRATCHDIR, makepath, patched_rrsync, proc_self_fd_pins, rmtree,
++ rsync_argv, test_fail, test_skipped,
++)
++
++if not proc_self_fd_pins():
++ test_skipped('requires /proc/self/fd directory pins')
++
++base = SCRATCHDIR / 'rrsync-receiver-file'
++rmtree(base)
++restricted = base / 'restricted'
++outside = base / 'outside'
++source = base / 'source'
++downloads = base / 'downloads'
++makepath(restricted, outside, downloads)
++source.write_text('replacement contents\n')
++
++# The optional gate pauses the real server after rrsync validates its argument.
++shim = base / 'rsync-shim'
++shim.write_text('''#!/usr/bin/env python3
++import os, pathlib, sys, time
++ready = os.environ.get('RRSYNC_TEST_READY')
++if ready:
++ pathlib.Path(ready).touch()
++ go = pathlib.Path(os.environ['RRSYNC_TEST_GO'])
++ end = time.monotonic() + 10
++ while not go.exists():
++ if time.monotonic() >= end:
++ sys.exit('timed out waiting for test gate')
++ time.sleep(0.01)
++cmd = %r
++os.execvp(cmd[0], cmd + sys.argv[1:])
++''' % rsync_argv())
++shim.chmod(0o755)
++rrsync = patched_rrsync(base, rsync_path=str(shim))
++rsh = base / 'fake-rsh'
++rsh.write_text('#!/bin/sh\nshift\nSSH_ORIGINAL_COMMAND="$*"\n'
++ 'export SSH_ORIGINAL_COMMAND\nexec %s -no-lock %s\n'
++ % (shlex.quote(str(rrsync)), shlex.quote(str(restricted))))
++rsh.chmod(0o755)
++
++
++def command(src, dest, *options):
++ return rsync_argv('-ac', '-e', str(rsh), *options, str(src), str(dest))
++
++
++def transfer(src, dest, *options, succeeds=True):
++ proc = subprocess.run(command(src, dest, *options), capture_output=True,
++ text=True, timeout=20)
++ if (proc.returncode == 0) != succeeds:
++ test_fail(f'transfer {src} -> {dest}: rc={proc.returncode}, '
++ f'{proc.stdout!r} {proc.stderr!r}')
++ return proc
++
++
++def check_contents(path):
++ if path.is_symlink() or not path.is_file() or path.read_text() != source.read_text():
++ test_fail(f'wrong file contents or type: {path}')
++
++
++for option in ((), ('--inplace',)):
++ destination = restricted / 'existing'
++ destination.write_text('old\n')
++ transfer(source, 'dummy:existing', *option)
++ check_contents(destination)
++ new = restricted / 'new'
++ new.unlink(missing_ok=True)
++ transfer(source, 'dummy:new', *option)
++ check_contents(new)
++
++makepath(restricted / 'directory')
++transfer(source, 'dummy:directory/')
++check_contents(restricted / 'directory' / source.name)
++transfer('dummy:existing', str(downloads) + '/')
++check_contents(downloads / 'existing')
++
++marker = outside / 'untouched'
++marker.write_text('outside fixture\n')
++transfer(source, 'dummy:../outside/untouched', succeeds=False)
++(restricted / 'outside-link').symlink_to(outside, target_is_directory=True)
++transfer(source, 'dummy:outside-link/untouched', succeeds=False)
++if marker.read_text() != 'outside fixture\n':
++ test_fail('a rejected destination changed the outside fixture')
++
++
++def gated_transfer(name, change):
++ ready = base / 'ready'
++ go = base / 'go'
++ ready.unlink(missing_ok=True)
++ go.unlink(missing_ok=True)
++ env = {**os.environ, 'RRSYNC_TEST_READY': str(ready), 'RRSYNC_TEST_GO': str(go)}
++ proc = subprocess.Popen(command(source, f'dummy:{name}', '--inplace'),
++ stdout=subprocess.PIPE, stderr=subprocess.PIPE,
++ text=True, env=env)
++ try:
++ end = time.monotonic() + 10
++ while not ready.exists():
++ if proc.poll() is not None or time.monotonic() >= end:
++ test_fail('receiver did not reach the post-validation gate')
++ time.sleep(0.01)
++ change()
++ go.touch()
++ stdout, stderr = proc.communicate(timeout=20)
++ if marker.read_text() != 'outside fixture\n':
++ test_fail(f'in-place transfer changed the outside fixture: {stdout} {stderr}')
++ return proc.returncode
++ finally:
++ if proc.poll() is None:
++ proc.kill()
++ proc.communicate()
++
++
++leaf = restricted / 'raced-leaf'
++leaf.write_text('old\n')
++
++
++def replace_leaf():
++ leaf.unlink()
++ leaf.symlink_to(marker)
++
++
++rc = gated_transfer('raced-leaf', replace_leaf)
++if rc == 0:
++ check_contents(leaf)
++
++parent = restricted / 'raced-parent'
++makepath(parent)
++(parent / 'untouched').write_text('old\n')
++saved_parent = restricted / 'saved-parent'
++
++
++def replace_parent():
++ parent.rename(saved_parent)
++ parent.symlink_to(outside, target_is_directory=True)
++
++
++if gated_transfer('raced-parent/untouched', replace_parent) == 0:
++ check_contents(saved_parent / 'untouched')
++
++print('rrsync receiver file overwrite, creation, directory, pull and path checks passed')
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/rsync.git/commitdiff/cc788cc57df69097cd7db59a3f99c8647560b99e
More information about the pld-cvs-commit
mailing list