| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
import os |
| 16 |
import subprocess |
| 17 |
|
| 18 |
from rsyncfns import ( |
| 19 |
SCRATCHDIR, rmtree, rsync_argv, start_test_daemon, test_fail, write_daemon_conf, |
| 20 |
) |
| 21 |
|
| 22 |
def run_case(label, opt, extra, port): |
| 23 |
base = SCRATCHDIR / f'outside-{label}' |
| 24 |
rmtree(base) |
| 25 |
base.mkdir() |
| 26 |
mod = base / 'mod' |
| 27 |
mod.mkdir() |
| 28 |
outside = base / 'outside' |
| 29 |
outside.mkdir() |
| 30 |
(mod / 'f0').write_text("OLD-DEST-CONTENT\n") |
| 31 |
src = base / 'src' |
| 32 |
src.mkdir() |
| 33 |
(src / 'f0').write_text("NEW\n") |
| 34 |
|
| 35 |
os.symlink(str(outside), mod / 'elink') |
| 36 |
|
| 37 |
conf = write_daemon_conf( |
| 38 |
[('mod', {'path': str(mod), 'read only': 'no'})], |
| 39 |
{'pid file': str(SCRATCHDIR / f'rsyncd-outside-{label}.pid')}, |
| 40 |
name=f'outside-{label}.conf') |
| 41 |
url = start_test_daemon(conf, port) |
| 42 |
subprocess.run( |
| 43 |
rsync_argv('-a', *extra, f'{opt}=/elink', f'{src}/', f'{url}mod/'), |
| 44 |
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
| 45 |
leaked = [os.path.join(r, f) for r, _d, fs in os.walk(outside) for f in fs] |
| 46 |
if leaked: |
| 47 |
test_fail( |
| 48 |
f"{label}: the daemon followed an in-module symlink whose target is " |
| 49 |
f"OUTSIDE the module root and wrote there: {leaked} (a peer modified " |
| 50 |
"files the module does not serve). The resolver must confine an " |
| 51 |
"operator/peer path to the module root.") |
| 52 |
|
| 53 |
|
| 54 |
run_case('backup', '--backup-dir', ['--backup'], 12905) |
| 55 |
run_case('partial', '--partial-dir', [], 12909) |
| 56 |
print("daemon confines peer --partial-dir/--backup-dir symlinks to the module root") |