| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
import os |
| 22 |
import platform |
| 23 |
import shutil |
| 24 |
import subprocess |
| 25 |
|
| 26 |
from rsyncfns import ( |
| 27 |
SCRATCHDIR, forced_protocol, rmtree, run_rsync, test_fail, test_skipped, |
| 28 |
) |
| 29 |
|
| 30 |
NEW_UID = 60002 |
| 31 |
STALE_UID = 60009 |
| 32 |
|
| 33 |
if platform.system() != 'Linux': |
| 34 |
test_skipped("POSIX ACL test is Linux-only (setfacl/getfacl semantics)") |
| 35 |
if not shutil.which('setfacl') or not shutil.which('getfacl'): |
| 36 |
test_skipped("setfacl/getfacl not available") |
| 37 |
if '"ACLs": true' not in run_rsync('-VV', check=True, capture_output=True).stdout: |
| 38 |
test_skipped("rsync built without ACL support") |
| 39 |
proto = forced_protocol() |
| 40 |
if proto is not None and proto < 30: |
| 41 |
test_skipped(f"ACL transfer requires protocol 30+ (negotiated {proto})") |
| 42 |
|
| 43 |
|
| 44 |
def setfacl(spec, path): |
| 45 |
if subprocess.run(['setfacl', '-m', spec, str(path)]).returncode != 0: |
| 46 |
test_skipped("filesystem has ACLs disabled (setfacl failed)") |
| 47 |
|
| 48 |
|
| 49 |
def getfacl(path) -> str: |
| 50 |
|
| 51 |
return subprocess.run(['getfacl', str(path)], |
| 52 |
capture_output=True, text=True).stdout |
| 53 |
|
| 54 |
|
| 55 |
base = SCRATCHDIR / 'acls-unpinnable' |
| 56 |
src = base / 'src' |
| 57 |
dest = base / 'dest' |
| 58 |
rmtree(base) |
| 59 |
(src / 'dropbox').mkdir(parents=True) |
| 60 |
(src / 'top.txt').write_text('top\n') |
| 61 |
(dest / 'dropbox').mkdir(parents=True) |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
setfacl(f'user:{NEW_UID}:rwx', src / 'dropbox') |
| 67 |
os.chmod(src / 'dropbox', 0o300) |
| 68 |
setfacl(f'user:{STALE_UID}:rwx', dest / 'dropbox') |
| 69 |
os.chmod(dest / 'dropbox', 0o300) |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
proc = run_rsync('-aA', f'{src}/', f'{dest}/', check=False, capture_output=True) |
| 74 |
if proc.returncode not in (0, 23): |
| 75 |
test_fail(f"rsync exited {proc.returncode}:\n{proc.stderr}") |
| 76 |
|
| 77 |
acl = getfacl(dest / 'dropbox') |
| 78 |
if f'user:{NEW_UID}:' not in acl: |
| 79 |
test_fail("--acls did not apply the source ACL to the un-pinnable (0300) " |
| 80 |
f"destination directory (stale/missing ACL); getfacl:\n{acl}") |
| 81 |
if f'user:{STALE_UID}:' in acl: |
| 82 |
test_fail("--acls left the stale destination ACL entry in place on the " |
| 83 |
f"un-pinnable (0300) directory -- a revocation did not propagate; " |
| 84 |
f"getfacl:\n{acl}") |
| 85 |
|
| 86 |
print("acls-unpinnable: --acls updates the ACL of a no-owner-read (0300) dir") |