| 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 |
DAEMON_PORT = 12982 |
| 22 |
SECRET = "PROTECTED-IN-EXCLUDED-SUBTREE\n" |
| 23 |
|
| 24 |
base = SCRATCHDIR / 'symlink-exclude-chdir-alias' |
| 25 |
rmtree(base) |
| 26 |
base.mkdir() |
| 27 |
|
| 28 |
mod = base / 'mod' |
| 29 |
mod.mkdir() |
| 30 |
public = mod / 'public' |
| 31 |
public.mkdir() |
| 32 |
secret = public / 'secret' |
| 33 |
secret.mkdir() |
| 34 |
victim = secret / 'x' |
| 35 |
victim.write_text(SECRET) |
| 36 |
|
| 37 |
os.symlink('public/', mod / 'blink2') |
| 38 |
|
| 39 |
src = base / 'src' |
| 40 |
(src / 'secret').mkdir(parents=True) |
| 41 |
(src / 'secret' / 'x').write_text("NEW\n") |
| 42 |
|
| 43 |
conf = write_daemon_conf( |
| 44 |
[('mod', {'path': str(mod), 'read only': 'no', 'exclude': '/public/secret/'})]) |
| 45 |
url = start_test_daemon(conf, DAEMON_PORT) |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
subprocess.run( |
| 50 |
rsync_argv('-a', '--keep-dirlinks', f'{src}/', f'{url}mod/blink2/'), |
| 51 |
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
| 52 |
|
| 53 |
after = victim.read_text() if victim.exists() else None |
| 54 |
if after == SECRET: |
| 55 |
test_fail( |
| 56 |
"the daemon refused a symlinked-chdir push that stock rsync (3.2.7) " |
| 57 |
f"follows: blink2/secret/x did not reach public/secret/ ({victim} is still " |
| 58 |
f"{after!r}). The exclude is name-based (the logical alias path), not the " |
| 59 |
"physical target; it must not block this.") |
| 60 |
print("daemon exclude is name-based: a push via an allowed symlinked chdir reaches " |
| 61 |
"the nested excluded subtree (3.2.7-equivalent)") |