| 1 |
|
| 2 |
import socket |
| 3 |
import stat |
| 4 |
|
| 5 |
from rsyncfns import ( |
| 6 |
SCRATCHDIR, makepath, rmtree, rsync_argv, start_test_daemon, test_skipped, test_fail, |
| 7 |
write_daemon_conf, |
| 8 |
) |
| 9 |
import subprocess |
| 10 |
|
| 11 |
src = SCRATCHDIR / 'sock-src' |
| 12 |
dst = SCRATCHDIR / 'sock-dst' |
| 13 |
rmtree(src) |
| 14 |
rmtree(dst) |
| 15 |
makepath(src, dst) |
| 16 |
sock_path = src / 's' |
| 17 |
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
| 18 |
try: |
| 19 |
s.bind(str(sock_path)) |
| 20 |
except OSError as e: |
| 21 |
test_skipped(f"cannot create unix-domain socket fixture: {e}") |
| 22 |
finally: |
| 23 |
s.close() |
| 24 |
|
| 25 |
conf = write_daemon_conf([ |
| 26 |
('sock', {'path': str(dst), 'read only': 'no', 'use chroot': 'no'}), |
| 27 |
]) |
| 28 |
url = start_test_daemon(conf, 12935) |
| 29 |
proc = subprocess.run( |
| 30 |
rsync_argv('-a', '--specials', f'{src}/', f'{url}sock/'), |
| 31 |
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) |
| 32 |
if proc.returncode != 0: |
| 33 |
test_fail(f"daemon socket-special upload failed:\n{proc.stderr}") |
| 34 |
if not stat.S_ISSOCK((dst / 's').lstat().st_mode): |
| 35 |
test_fail("rsync did not preserve the unix-domain socket fixture") |
| 36 |
print("daemon-unix-socket-atfd: daemon receiver preserves unix sockets without escaping parent confinement") |