| 1 |
|
| 2 |
"""Coverage: --fake-super -A stores/loads ACLs via the user.rsync.%aacl / |
| 3 |
%dacl xattrs (xattrs.c get_xattr_acl/set_xattr_acl/del_def_xattr_acl and the |
| 4 |
acls.c am_root<0 IVAL/SIVAL pack/unpack paths). |
| 5 |
|
| 6 |
Three legs, all with -A --fake-super on the *receiving* side: |
| 7 |
|
| 8 |
1. real-ACL src -> fake-super dst (acls.c set_xattr_acl path: SIVAL pack |
| 9 |
+ xattrs.c set_xattr_acl) |
| 10 |
2. fake-super dst -> fake-super dst2 (acls.c get_xattr_acl path: IVAL |
| 11 |
unpack on the SENDER side via -M |
| 12 |
--fake-super, then set_xattr_acl |
| 13 |
again on the receiver) |
| 14 |
3. drop the source dir's default ACL and re-sync dst -> del_def_xattr_acl |
| 15 |
removes the stale %dacl xattr. |
| 16 |
|
| 17 |
Structural assertions only (xattr presence/absence): the per-field ACL |
| 18 |
round-trip is acls_test.py's job; this test exists to cover the xattr- |
| 19 |
encoding branch that the regular -A tests (am_root>=0) never reach. |
| 20 |
""" |
| 21 |
|
| 22 |
import os |
| 23 |
import platform |
| 24 |
import subprocess |
| 25 |
|
| 26 |
from rsyncfns import ( |
| 27 |
SCRATCHDIR, FROMDIR, |
| 28 |
acls_supported, makepath, rmtree, rsync_argv, |
| 29 |
test_fail, test_skipped, xattrs_supported, |
| 30 |
) |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
if platform.system() != 'Linux': |
| 37 |
test_skipped("fake-super ACL xattrs use the Linux user.rsync.* namespace") |
| 38 |
|
| 39 |
if not acls_supported(): |
| 40 |
test_skipped("ACLs not supported on this filesystem") |
| 41 |
if not xattrs_supported(): |
| 42 |
test_skipped("xattrs not supported on this filesystem") |
| 43 |
|
| 44 |
src = FROMDIR |
| 45 |
dst = SCRATCHDIR / 'fakesuper-dst' |
| 46 |
dst2 = SCRATCHDIR / 'fakesuper-dst2' |
| 47 |
for d in (src, dst, dst2): |
| 48 |
rmtree(d) |
| 49 |
makepath(src) |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
(src / 'f').write_text('hello\n') |
| 55 |
sd = src / 'd' |
| 56 |
sd.mkdir() |
| 57 |
(sd / 'g').write_text('world\n') |
| 58 |
|
| 59 |
r = subprocess.run(['setfacl', '-m', f'u:{os.getuid()}:rwx', str(src / 'f')], |
| 60 |
capture_output=True, text=True) |
| 61 |
if r.returncode != 0: |
| 62 |
test_skipped(f"setfacl on file failed: {r.stderr!r}") |
| 63 |
r = subprocess.run(['setfacl', '-d', '-m', f'u:{os.getuid()}:rwx', str(sd)], |
| 64 |
capture_output=True, text=True) |
| 65 |
if r.returncode != 0: |
| 66 |
test_skipped(f"setfacl -d on dir failed: {r.stderr!r}") |
| 67 |
|
| 68 |
|
| 69 |
def has_xattr(path, name): |
| 70 |
try: |
| 71 |
os.getxattr(str(path), name, follow_symlinks=False) |
| 72 |
return True |
| 73 |
except OSError: |
| 74 |
return False |
| 75 |
|
| 76 |
|
| 77 |
def sync(args, frm, to): |
| 78 |
r = subprocess.run(rsync_argv(*args, f'{frm}/', f'{to}/'), |
| 79 |
capture_output=True, text=True) |
| 80 |
if r.returncode != 0: |
| 81 |
test_fail(f"rsync {' '.join(args)} {frm} -> {to} " |
| 82 |
f"(rc={r.returncode}):\n{r.stderr}") |
| 83 |
return r |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
sync(['-rA', '-M--fake-super'], src, dst) |
| 90 |
if not has_xattr(dst / 'f', 'user.rsync.%aacl'): |
| 91 |
test_fail("--fake-super -A should have stored user.rsync.%aacl on dst/f") |
| 92 |
if not has_xattr(dst / 'd', 'user.rsync.%dacl'): |
| 93 |
test_fail("--fake-super -A should have stored user.rsync.%dacl on dst/d") |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
sync(['-rA', '--fake-super', '-M--fake-super'], dst, dst2) |
| 100 |
if not has_xattr(dst2 / 'f', 'user.rsync.%aacl'): |
| 101 |
test_fail("fake-super -> fake-super -A round-trip lost %aacl on dst2/f") |
| 102 |
if not has_xattr(dst2 / 'd', 'user.rsync.%dacl'): |
| 103 |
test_fail("fake-super -> fake-super -A round-trip lost %dacl on dst2/d") |
| 104 |
|
| 105 |
|
| 106 |
subprocess.run(['setfacl', '-k', str(sd)], check=True) |
| 107 |
sync(['-rA', '-M--fake-super'], src, dst) |
| 108 |
if has_xattr(dst / 'd', 'user.rsync.%dacl'): |
| 109 |
test_fail("re-sync after `setfacl -k` should have removed %dacl from dst/d " |
| 110 |
"(del_def_xattr_acl)") |
| 111 |
|
| 112 |
print("fake-super-acl-xattr: %aacl/%dacl set+get round-trip + del_def ok") |