| 1 | #!/usr/bin/env python3 |
| 2 | # rsync -aR through an in-tree symlinked parent whose target climbs with ".." |
| 3 | # but stays BENEATH the transfer anchor must transfer the file. This is the |
| 4 | # RESOLVE_BENEATH rule: an in-tree ".." that does not rise above the root is |
| 5 | # allowed (kernel paths follow it, and 3.4.x followed it). |
| 6 | # |
| 7 | # Companion to relative-symlinked-parent_test.py (whose symlink target has no |
| 8 | # ".."): the portable per-component fallback (the BSDs / Solaris / Cygwin, or a |
| 9 | # Linux build configured --disable-openat2) originally refused EVERY symlink, |
| 10 | # then -- after the #715 fix -- still refused any symlink target containing |
| 11 | # "..", even a safe internal climb. Both are now followed via a dirfd stack |
| 12 | # that pops ".." back to the pinned parent (never above the anchor), so this |
| 13 | # passes everywhere while genuine escapes (../ above the anchor, absolute |
| 14 | # targets) stay refused -- see secure-relpath-validation / the *-symlink-race |
| 15 | # tests. Plain transfer, no root. |
| 16 | |
| 17 | import os |
| 18 | |
| 19 | from rsyncfns import SCRATCHDIR, assert_same, makepath, rmtree, run_rsync, test_fail |
| 20 | |
| 21 | base = SCRATCHDIR / 'rsymparentdd' |
| 22 | rmtree(base) |
| 23 | # src/real/sub/file is the payload; src/deep/alias is an in-tree symlink whose |
| 24 | # target "../real" climbs out of src/deep back to src/ (still beneath src/). |
| 25 | makepath(base / 'src' / 'real' / 'sub', base / 'src' / 'deep', base / 'dest') |
| 26 | (base / 'src' / 'real' / 'sub' / 'file').write_text('payload data\n') |
| 27 | os.symlink('../real', base / 'src' / 'deep' / 'alias') # in-tree ".." dir-symlink |
| 28 | |
| 29 | os.chdir(base) # -R mirrors the path as given |
| 30 | run_rsync('-aR', 'src/deep/alias/sub/file', 'dest/') # check=True: fallback exits 23 if unfixed |
| 31 | |
| 32 | landed = base / 'dest' / 'src' / 'deep' / 'alias' / 'sub' / 'file' |
| 33 | if not landed.is_file(): |
| 34 | test_fail(f"-aR through an in-tree '..' symlinked parent dropped the file: {landed} missing") |
| 35 | assert_same(base / 'src' / 'real' / 'sub' / 'file', landed, label='content') |
| 36 | |
| 37 | print("relative-symlinked-parent-dotdot: -aR follows an in-tree '..' symlinked parent beneath the anchor") |