| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
import os |
| 15 |
import subprocess |
| 16 |
|
| 17 |
from rsyncfns import ( |
| 18 |
SCRATCHDIR, rmtree, rsync_argv, start_test_daemon, test_fail, write_daemon_conf, |
| 19 |
) |
| 20 |
|
| 21 |
SECRET = "LEAF-EXCLUDED-IN-A-SERVED-DIR\n" |
| 22 |
|
| 23 |
|
| 24 |
def run_case(label, opt, extra, port): |
| 25 |
base = SCRATCHDIR / f'leaf-{label}' |
| 26 |
rmtree(base) |
| 27 |
base.mkdir() |
| 28 |
mod = base / 'mod' |
| 29 |
pub = mod / 'public' |
| 30 |
pub.mkdir(parents=True) |
| 31 |
(pub / 'f0').write_text(SECRET) |
| 32 |
(pub / 'served.txt').write_text("served\n") |
| 33 |
(mod / 'f0').write_text("OLD-DEST-CONTENT\n") |
| 34 |
os.symlink('public', mod / 'blink') |
| 35 |
src = base / 'src' |
| 36 |
src.mkdir() |
| 37 |
(src / 'f0').write_text("NEW\n") |
| 38 |
|
| 39 |
conf = write_daemon_conf( |
| 40 |
[('mod', {'path': str(mod), 'read only': 'no', 'exclude': '/public/f0'})], |
| 41 |
{'pid file': str(SCRATCHDIR / f'rsyncd-leaf-{label}.pid')}, |
| 42 |
name=f'leaf-{label}.conf') |
| 43 |
url = start_test_daemon(conf, port) |
| 44 |
subprocess.run( |
| 45 |
rsync_argv('-a', *extra, f'{opt}=/blink', f'{src}/', f'{url}mod/'), |
| 46 |
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
| 47 |
after = (pub / 'f0').read_text() if (pub / 'f0').exists() else None |
| 48 |
if after == SECRET: |
| 49 |
test_fail( |
| 50 |
f"{label}: the daemon refused a {opt} symlink to a leaf-excluded file " |
| 51 |
f"that stock rsync (3.2.7) reaches: public/f0 is unchanged ({after!r}). " |
| 52 |
"The daemon exclude filter is name-based ('blink' is not excluded), not " |
| 53 |
"a symlink boundary; it must not block this.") |
| 54 |
|
| 55 |
|
| 56 |
run_case('backup', '--backup-dir', ['--backup'], 12906) |
| 57 |
run_case('partial', '--partial-dir', [], 12907) |
| 58 |
print("daemon exclude is name-based: an operator-path symlink reaches a " |
| 59 |
"leaf-excluded file in a served dir (3.2.7-equivalent)") |