Debian Codegraph @

testsuite/operator-path-link-dest_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # --link-dest symlink policy matrix. A followed --link-dest symlink lets the
3 # basis lookup read an out-of-tree directory and HARDLINK dest files to it. The
4 # operator-path ownership walk must follow only uid0/euid-owned symlinks (abs and
5 # rel, leaf and parent); --insecure-links is the local opt-out.
6
7 import os
8 import subprocess
9
10 from rsyncfns import rsync_argv, run_symlink_matrix, plant_operator_symlink
11
12 T = 1234567890 # shared mtime so the quick check treats the basis as a match
13
14
15 def case(ctx):
16 src = ctx.base / 'src'
17 dest = ctx.base / 'dest'
18 src.mkdir()
19 dest.mkdir()
20 (src / 'f0').write_text("BASIS-MATCH\n")
21 opt, escape = plant_operator_symlink(ctx, dest) # rel --link-dest anchors at dest
22 escape.mkdir(parents=True, exist_ok=True)
23 (escape / 'f0').write_text("BASIS-MATCH\n") # identical out-of-tree basis
24 os.utime(src / 'f0', (T, T))
25 os.utime(escape / 'f0', (T, T))
26 extra = ['--insecure-links'] if ctx.insecure else []
27 subprocess.run(
28 rsync_argv('-a', f'--link-dest={opt}', *extra, 'src/', 'dest/'),
29 cwd=str(ctx.base), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
30 df = dest / 'f0'
31 if not df.exists():
32 return False
33 try:
34 # Followed == dest/f0 is a hardlink to the out-of-tree basis.
35 return os.stat(df).st_ino == os.stat(escape / 'f0').st_ino
36 except OSError:
37 return False
38
39
40 run_symlink_matrix('--link-dest', case)
41 print("--link-dest symlink policy matrix: enforced")