Debian Codegraph @

testsuite/symlink-exclude-meta_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # Daemon module-exclude bypass: metadata write on a PRE-EXISTING excluded leaf
3 # reached through an in-tree directory symlink. (Reported by codex.)
4 #
5 # No create is needed: pub/blocked already exists and is excluded (/pub/blocked).
6 # pub/ is not excluded, so resolving the parent through blink2 -> pub/ succeeds;
7 # the generator can then stat the leaf through the held parent fd and push
8 # metadata (chmod/chown/times) onto it via the held-dirfd metadata ops. Those
9 # must refuse an excluded physical leaf, or a peer can alter a file the module
10 # does not serve. Runs unprivileged (mtime is the observable a non-root peer can
11 # drive).
12 import os
13 import subprocess
14 import time
15
16 from rsyncfns import (
17 SCRATCHDIR, rmtree, rsync_argv, start_test_daemon, test_fail, write_daemon_conf,
18 )
19
20 DAEMON_PORT = 12989
21
22 base = SCRATCHDIR / 'symlink-exclude-meta'
23 rmtree(base)
24 base.mkdir()
25
26 mod = base / 'mod'
27 mod.mkdir()
28 pub = mod / 'pub' # NOT excluded
29 pub.mkdir()
30 victim = pub / 'blocked' # excluded leaf, pre-exists
31 victim.write_text("PROTECTED\n")
32 old = 1_000_000_000
33 os.utime(victim, (old, old)) # known baseline mtime
34 os.symlink('pub/', mod / 'blink2') # in-tree dir symlink -> pub/
35
36 src = base / 'src'
37 (src / 'blink2').mkdir(parents=True)
38 (src / 'blink2' / 'blocked').write_text("PROTECTED\n") # same content: only meta differs
39 new = old + 999_999
40 os.utime(src / 'blink2' / 'blocked', (new, new))
41
42 conf = write_daemon_conf(
43 [('mod', {'path': str(mod), 'read only': 'no', 'exclude': '/pub/blocked'})])
44 url = start_test_daemon(conf, DAEMON_PORT)
45
46 subprocess.run(
47 rsync_argv('-a', '--keep-dirlinks', f'{src}/', f'{url}mod/'),
48 stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
49
50 if int(victim.stat().st_mtime) == old:
51 test_fail(
52 "the daemon refused a metadata write onto an excluded leaf that stock "
53 f"rsync (3.2.7) performs: {victim} mtime is still {old} (expected it to "
54 f"advance to {new}). The exclude is name-based ('blink2/blocked', not the "
55 "physical 'pub/blocked'); it must not block this.")
56 print("daemon exclude is name-based: metadata on an excluded leaf via an in-tree "
57 "symlink is written (3.2.7-equivalent)")