Debian Codegraph @

testsuite/daemon-copy-links-symlink_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # A daemon must follow an IN-TREE symlink in its served module when the client
3 # asks to dereference it (-L copy-links / -k copy-dirlinks) -- the symlink is
4 # inside the operator's own served tree, which 3.4.x follows.
5 #
6 # A/B + fuzzer-discovered 3.5 regression (abdiff --fuzz: 16 candidates, one root
7 # cause): an early per-component O_NOFOLLOW resolver made the daemon SENDER refuse
8 # to follow the in-tree dir-symlink that -L/-k must dereference (exit 23, files
9 # lost; the -L pull case could even exit 0 while SILENTLY dropping the symlinked
10 # content). The secure resolver now follows in-tree directory symlinks on every
11 # platform, so -L/-k over the daemon transport works uniformly; 3.4.x is unaffected.
12 #
13 # Same root cause as the local -K (keep-dirlinks-symlinked-dest) and -aR
14 # (relative-symlinked-parent) regressions, but a BROADER surface: it adds -L and
15 # -k, over the DAEMON transport (the local -L/-k paths are unaffected). No root;
16 # uses the standard test-daemon seam (no real TCP in the default mode).
17
18 import os
19
20 from rsyncfns import (SCRATCHDIR, assert_same, get_rootgid, get_rootuid,
21 get_testuid, makepath, rmtree, run_rsync,
22 start_test_daemon, test_fail)
23
24 DAEMON_PORT = 12898
25 base = SCRATCHDIR / 'daemon_copylinks'
26 rmtree(base)
27 mod = base / 'mod'
28 makepath(mod / 'dir' / 'sub', base / 'dest')
29 (mod / 'dir' / 'a.txt').write_text('payload a\n')
30 (mod / 'dir' / 'sub' / 'b.txt').write_text('payload b\n')
31 os.symlink('dir', mod / 'dir_link') # in-tree dir-symlink within the module
32
33 # When the suite runs as root (e.g. the CI fleet's sudo pass) a use-chroot=no
34 # daemon otherwise drops to nobody and can't read the root-owned module, so the
35 # sender fails with EACCES on every file -- nothing to do with the symlink.
36 # Pin uid/gid to root in that case, as build_rsyncd_conf() does. Non-root
37 # cannot set uid/gid (and doesn't need to: it owns the module).
38 root = get_testuid() == get_rootuid()
39 ids = f"uid = {get_rootuid()}\ngid = {get_rootgid()}" if root else ""
40
41 conf = base / 'copylinks.conf'
42 conf.write_text(f"""\
43 pid file = {base}/rsyncd.pid
44 use chroot = no
45 {ids}
46 log file = {base}/rsyncd.log
47
48 [m]
49 path = {mod}
50 read only = yes
51 hosts allow = 127.0.0.1
52 """)
53 url = start_test_daemon(conf, DAEMON_PORT)
54
55 # -L (copy-links): dir_link must arrive as a real directory with its content.
56 # check=False: the fallback regression manifests either as exit 23 or as a
57 # silent exit-0 partial copy -- assert on the resulting tree either way.
58 run_rsync('-aL', f'{url}m/', f'{base}/dest/', check=False)
59
60 for rel in ('dir_link/a.txt', 'dir_link/sub/b.txt'):
61 if not (base / 'dest' / rel).is_file():
62 test_fail(f"daemon pull -aL dropped in-tree symlinked content: dest/{rel} missing")
63 assert_same(mod / 'dir' / 'a.txt', base / 'dest' / 'dir_link' / 'a.txt', label='content')
64
65 print("daemon-copy-links-symlink: daemon -aL follows an in-tree dir-symlink in the module")