| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
import os |
| 9 |
import platform |
| 10 |
import subprocess |
| 11 |
|
| 12 |
from rsyncfns import FROMDIR, SCRATCHDIR, TODIR, makepath, run_rsync, test_fail, test_skipped |
| 13 |
|
| 14 |
|
| 15 |
vv = run_rsync('-VV', check=True, capture_output=True) |
| 16 |
if '"ACLs": true' not in vv.stdout: |
| 17 |
test_skipped("Rsync is configured without ACL support") |
| 18 |
|
| 19 |
makepath(FROMDIR / 'foo') |
| 20 |
(FROMDIR / 'file1').write_text("something\n") |
| 21 |
(FROMDIR / 'file2').write_text("else\n") |
| 22 |
|
| 23 |
files = ['foo', 'file1', 'file2'] |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
setfacl_nodef = os.environ.get('setfacl_nodef', 'true') |
| 28 |
|
| 29 |
|
| 30 |
def _chmod_plus_a_supported() -> bool: |
| 31 |
"""macOS-style: chmod +a 'user allow ...'.""" |
| 32 |
out = subprocess.run(['chmod', '--help'], capture_output=True, text=True) |
| 33 |
return '+a' in (out.stdout + out.stderr) |
| 34 |
|
| 35 |
|
| 36 |
use_chmod_plus_a = setfacl_nodef == 'true' and _chmod_plus_a_supported() |
| 37 |
|
| 38 |
if setfacl_nodef == 'true' and not use_chmod_plus_a: |
| 39 |
test_skipped("I don't know how to use setfacl or chmod for ACLs") |
| 40 |
|
| 41 |
|
| 42 |
def _setfacl(*args) -> int: |
| 43 |
return subprocess.run(['setfacl', *args]).returncode |
| 44 |
|
| 45 |
|
| 46 |
def _chmod_acl(*args) -> int: |
| 47 |
return subprocess.run(['chmod', *args]).returncode |
| 48 |
|
| 49 |
|
| 50 |
if use_chmod_plus_a: |
| 51 |
if _chmod_acl('+a', 'root allow read,write,execute', |
| 52 |
str(FROMDIR / 'foo')) != 0: |
| 53 |
test_skipped("Your filesystem has ACLs disabled") |
| 54 |
_chmod_acl('+a', 'root allow read,execute', str(FROMDIR / 'file1')) |
| 55 |
_chmod_acl('+a', 'admin allow read', str(FROMDIR / 'file1')) |
| 56 |
_chmod_acl('+a', 'daemon allow read,write', str(FROMDIR / 'file1')) |
| 57 |
_chmod_acl('+a', 'root allow read,execute', str(FROMDIR / 'file2')) |
| 58 |
|
| 59 |
def see_acls(paths): |
| 60 |
return subprocess.check_output(['ls', '-le', *paths], text=True) |
| 61 |
else: |
| 62 |
if _setfacl('-m', 'u:0:7', str(FROMDIR / 'foo')) != 0: |
| 63 |
test_skipped("Your filesystem has ACLs disabled") |
| 64 |
_setfacl('-m', 'g:1:5', str(FROMDIR / 'foo')) |
| 65 |
_setfacl('-m', 'g:2:1', str(FROMDIR / 'foo')) |
| 66 |
_setfacl('-m', 'g:0:7', str(FROMDIR / 'foo')) |
| 67 |
_setfacl('-m', 'u:2:1', str(FROMDIR / 'foo')) |
| 68 |
_setfacl('-m', 'u:1:5', str(FROMDIR / 'foo')) |
| 69 |
|
| 70 |
_setfacl('-m', 'u:0:5', str(FROMDIR / 'file1')) |
| 71 |
_setfacl('-m', 'g:0:4', str(FROMDIR / 'file1')) |
| 72 |
_setfacl('-m', 'u:1:6', str(FROMDIR / 'file1')) |
| 73 |
|
| 74 |
_setfacl('-m', 'u:0:5', str(FROMDIR / 'file2')) |
| 75 |
|
| 76 |
def see_acls(paths): |
| 77 |
return subprocess.check_output(['getfacl', *paths], text=True) |
| 78 |
|
| 79 |
|
| 80 |
os.chdir(FROMDIR) |
| 81 |
run_rsync('-avvA', *files, f'{TODIR}/') |
| 82 |
|
| 83 |
before = see_acls(files) |
| 84 |
(SCRATCHDIR / 'acls.txt').write_text(before) |
| 85 |
|
| 86 |
os.chdir(TODIR) |
| 87 |
after = see_acls(files) |
| 88 |
if before != after: |
| 89 |
print("--- expected (from) ---") |
| 90 |
print(before) |
| 91 |
print("--- got (to) ---") |
| 92 |
print(after) |
| 93 |
test_fail("ACL listing differs between source and destination") |