Debian Codegraph @

testsuite/daemon-subdir-climb-symlink_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # Regression: a daemon subdir pull in a symlink-following mode must still follow
3 # an IN-MODULE symlink whose relative target climbs with ".." to a sibling that
4 # stays inside the module.
5 #
6 # The directory-enumeration confinement must use the same module-root anchor as
7 # the content open (sender_open_copylinks_confined anchors at module_dir). A
8 # daemon chdir's into the requested subdir (do_server_sender, main.c), so
9 # anchoring the scan at the cwd instead of module_dir would wrongly refuse
10 # "sub/climb -> ../sibling" -- which resolves to module/sibling, still inside the
11 # module -- a regression vs the legacy opendir that followed it (while a target
12 # escaping the module is still refused). This pulls module subdir "sub/" with
13 # --copy-dirlinks over an in-module ..-climbing dir symlink and asserts its
14 # content arrives.
15
16 import os
17
18 from rsyncfns import (
19 SCRATCHDIR, get_rootgid, get_rootuid, get_testuid, makepath, rmtree,
20 run_rsync, start_test_daemon, test_fail,
21 )
22
23 DAEMON_PORT = 12948
24 CONTENT = "in-module sibling\n"
25
26 base = SCRATCHDIR / 'daemon-subdir-climb'
27 rmtree(base)
28 mod = base / 'mod'
29 dest = base / 'dest'
30 makepath(mod / 'sub', mod / 'sibling', dest)
31 (mod / 'sibling' / 's.txt').write_text(CONTENT)
32 # In-module dir symlink in the subdir, climbing ".." to a sibling still inside
33 # the module. --copy-dirlinks descends it; it must be followed.
34 os.symlink('../sibling', mod / 'sub' / 'climb')
35
36 root = get_testuid() == get_rootuid()
37 ids = f"uid = {get_rootuid()}\ngid = {get_rootgid()}" if root else ""
38
39 conf = base / 'd.conf'
40 conf.write_text(f"""\
41 pid file = {base}/rsyncd.pid
42 use chroot = no
43 {ids}
44 log file = {base}/rsyncd.log
45
46 [m]
47 path = {mod}
48 read only = yes
49 hosts allow = 127.0.0.1
50 """)
51 url = start_test_daemon(conf, DAEMON_PORT)
52
53 # Pull the SUBDIR (so the daemon chdir's into mod/sub) with --copy-dirlinks.
54 run_rsync('-a', '--copy-dirlinks', f'{url}m/sub/', f'{dest}/', check=False)
55
56 got = dest / 'climb' / 's.txt'
57 if not got.is_file() or got.read_text() != CONTENT:
58 test_fail(
59 "daemon subdir pull with --copy-dirlinks failed to follow an in-module "
60 "symlink that climbs '..' to a sibling inside the module "
61 "(dest/climb/s.txt missing/wrong): the enumeration must anchor at "
62 "module_dir, not the scan cwd.")
63 print("daemon-subdir-climb-symlink: in-module ..-climbing symlink followed under --copy-dirlinks")