| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 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 |
|
| 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') |