| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
import os |
| 18 |
import subprocess |
| 19 |
|
| 20 |
from rsyncfns import ( |
| 21 |
SCRATCHDIR, rmtree, rsync_argv, start_test_daemon, test_fail, write_daemon_conf, |
| 22 |
) |
| 23 |
|
| 24 |
DAEMON_PORT = 12978 |
| 25 |
SECRET = "PROTECTED-IN-EXCLUDED-SUBTREE\n" |
| 26 |
|
| 27 |
base = SCRATCHDIR / 'symlink-exclude-component' |
| 28 |
rmtree(base) |
| 29 |
base.mkdir() |
| 30 |
|
| 31 |
mod = base / 'mod' |
| 32 |
mod.mkdir() |
| 33 |
secret = mod / 'secret' |
| 34 |
secret.mkdir() |
| 35 |
victim = secret / 'x' |
| 36 |
victim.write_text(SECRET) |
| 37 |
|
| 38 |
blink = mod / 'blink' |
| 39 |
os.symlink('secret/', blink) |
| 40 |
|
| 41 |
src = base / 'src' |
| 42 |
(src / 'blink').mkdir(parents=True) |
| 43 |
(src / 'blink' / 'x').write_text("NEW\n") |
| 44 |
|
| 45 |
conf = write_daemon_conf( |
| 46 |
[('mod', {'path': str(mod), 'read only': 'no', 'exclude': '/secret/'})]) |
| 47 |
url = start_test_daemon(conf, DAEMON_PORT) |
| 48 |
|
| 49 |
|
| 50 |
subprocess.run( |
| 51 |
rsync_argv('-a', '--keep-dirlinks', f'{src}/', f'{url}mod/'), |
| 52 |
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
| 53 |
|
| 54 |
after = victim.read_text() if victim.exists() else None |
| 55 |
if after == SECRET: |
| 56 |
test_fail( |
| 57 |
"the daemon refused a transferred path through an in-dest symlink that " |
| 58 |
f"stock rsync (3.2.7) follows: {victim} is still {after!r}. The daemon " |
| 59 |
"filter is name-based (it sees the logical 'blink/x', not 'secret/x'); it " |
| 60 |
"must not block this -- `munge symlinks` defends a writable module.") |
| 61 |
print("daemon exclude is name-based: a transferred path through an in-dest symlink " |
| 62 |
"lands in the excluded subtree (3.2.7-equivalent)") |