| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
import os |
| 8 |
import subprocess |
| 9 |
|
| 10 |
from rsyncfns import ( |
| 11 |
SCRATCHDIR, forced_protocol, rmtree, rsync_argv, start_test_daemon, test_fail, |
| 12 |
test_skipped, write_daemon_conf, xattrs_supported, |
| 13 |
) |
| 14 |
|
| 15 |
if not xattrs_supported() or not hasattr(os, 'getxattr') or not hasattr(os, 'setxattr'): |
| 16 |
test_skipped("user xattrs not available") |
| 17 |
|
| 18 |
proto = forced_protocol() |
| 19 |
if proto is not None and proto < 30: |
| 20 |
test_skipped(f"xattr (-X) transfer requires protocol 30+ (negotiated {proto})") |
| 21 |
|
| 22 |
DAEMON_PORT = 12992 |
| 23 |
XNAME = 'user.rsync.marker' |
| 24 |
|
| 25 |
|
| 26 |
def getx(p): |
| 27 |
try: |
| 28 |
return os.getxattr(str(p), XNAME).decode() |
| 29 |
except OSError: |
| 30 |
return None |
| 31 |
|
| 32 |
|
| 33 |
base = SCRATCHDIR / 'symlink-exclude-xattr' |
| 34 |
rmtree(base) |
| 35 |
base.mkdir() |
| 36 |
|
| 37 |
mod = base / 'mod' |
| 38 |
mod.mkdir() |
| 39 |
pub = mod / 'pub' |
| 40 |
pub.mkdir() |
| 41 |
victim = pub / 'blocked' |
| 42 |
victim.write_text("DATA\n") |
| 43 |
try: |
| 44 |
os.setxattr(str(victim), XNAME, b'ORIGINAL') |
| 45 |
except OSError: |
| 46 |
test_skipped("cannot set user xattr on this filesystem") |
| 47 |
os.symlink('pub/', mod / 'blink2') |
| 48 |
|
| 49 |
src = base / 'src' |
| 50 |
(src / 'blink2').mkdir(parents=True) |
| 51 |
sf = src / 'blink2' / 'blocked' |
| 52 |
sf.write_text("DATA\n") |
| 53 |
os.setxattr(str(sf), XNAME, b'ATTACKER') |
| 54 |
|
| 55 |
conf = write_daemon_conf( |
| 56 |
[('mod', {'path': str(mod), 'read only': 'no', 'exclude': '/pub/blocked'})]) |
| 57 |
url = start_test_daemon(conf, DAEMON_PORT) |
| 58 |
|
| 59 |
subprocess.run( |
| 60 |
rsync_argv('-aX', '--keep-dirlinks', f'{src}/', f'{url}mod/'), |
| 61 |
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
| 62 |
|
| 63 |
if getx(victim) == 'ORIGINAL': |
| 64 |
test_fail( |
| 65 |
"the daemon refused an xattr write on an excluded leaf that stock rsync " |
| 66 |
f"(3.2.7) performs: {victim} marker is still 'ORIGINAL' (expected " |
| 67 |
"'ATTACKER'). The exclude is name-based ('blink2/blocked', not the " |
| 68 |
"physical 'pub/blocked'); it must not block this.") |
| 69 |
print("daemon exclude is name-based: an xattr write on an excluded leaf via an " |
| 70 |
"in-tree symlink is performed (3.2.7-equivalent)") |