Debian Codegraph @

testsuite/chmod-setid_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # Regression for KI-55: --chmod=a+s must set BOTH setuid and setgid (like
3 # chmod(1)). parse_chmod()'s 'a' clause used to leave the set-id bits unset, so
4 # "a+s" fell through to setuid only.
5
6 import os
7
8 from rsyncfns import SCRATCHDIR, run_rsync, test_fail
9
10 base = SCRATCHDIR / 'chmod_setid'
11 src = base / 'src'
12 dst = base / 'dst'
13 src.mkdir(parents=True, exist_ok=True)
14 dst.mkdir(parents=True, exist_ok=True)
15 (src / 'f').write_text('hi\n')
16 os.chmod(src / 'f', 0o644)
17
18 run_rsync('-rp', '--chmod=a+s', f'{src}/', f'{dst}/')
19
20 mode = (dst / 'f').stat().st_mode & 0o7777
21 if not (mode & 0o4000) or not (mode & 0o2000):
22 test_fail(f'--chmod=a+s did not set both setuid+setgid (mode {mode:04o})')
23
24 # Sanity: u+s is setuid only, g+s is setgid only.
25 for spec, want, unwant in (('u+s', 0o4000, 0o2000), ('g+s', 0o2000, 0o4000)):
26 d = base / spec.replace('+', '_')
27 d.mkdir(exist_ok=True)
28 run_rsync('-rp', f'--chmod={spec}', f'{src}/', f'{d}/')
29 m = (d / 'f').stat().st_mode & 0o7777
30 if not (m & want) or (m & unwant):
31 test_fail(f'--chmod={spec} gave mode {m:04o} (want {want:04o}, not {unwant:04o})')
32
33 print('chmod-setid: a+s sets setuid+setgid; u+s/g+s stay single-bit')