| 1 |
|
| 2 |
"""Daemon coverage: rsyncd.conf `&include`/`&merge` directives + `max connections`. |
| 3 |
|
| 4 |
Covers: |
| 5 |
- params.c include_config(): both the file form (`&merge = file.inc`) and |
| 6 |
the directory form (`&include = dir/` -> readdir + glob *.conf + qsort |
| 7 |
via name_cmp() when count>1) -> the ]push/]reset/]pop section-stack path |
| 8 |
in loadparm.c. |
| 9 |
- connection.c claim_connection() / util1.c lock_range(): a module with |
| 10 |
`max connections = N` + `lock file = path` opens the lock file via |
| 11 |
open_no_attacker_symlinks() and lock_range()s a 4-byte slot. |
| 12 |
""" |
| 13 |
|
| 14 |
import subprocess |
| 15 |
|
| 16 |
from rsyncfns import ( |
| 17 |
SCRATCHDIR, FROMDIR, |
| 18 |
claim_ports, get_rootgid, get_rootuid, get_testuid, |
| 19 |
make_tree, makepath, rmtree, rsync_argv, |
| 20 |
start_test_daemon, test_fail, write_daemon_conf, |
| 21 |
) |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
if get_testuid() == get_rootuid(): |
| 28 |
UIDGID = f'\tuid = {get_rootuid()}\n\tgid = {get_rootgid()}\n' |
| 29 |
else: |
| 30 |
UIDGID = '' |
| 31 |
|
| 32 |
PORT = 12895 |
| 33 |
claim_ports(PORT) |
| 34 |
|
| 35 |
src = FROMDIR |
| 36 |
rmtree(src) |
| 37 |
make_tree(src, depth=1) |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
conf_d = SCRATCHDIR / 'rsyncd.conf.d' |
| 43 |
makepath(conf_d) |
| 44 |
|
| 45 |
dest_a = SCRATCHDIR / 'dest-incA' |
| 46 |
dest_b = SCRATCHDIR / 'dest-incB' |
| 47 |
dest_m = SCRATCHDIR / 'dest-merge' |
| 48 |
makepath(dest_a, dest_b, dest_m) |
| 49 |
|
| 50 |
lockfile = SCRATCHDIR / 'rsyncd.lock' |
| 51 |
|
| 52 |
(conf_d / '20-b.conf').write_text( |
| 53 |
f'[incB]\n\tpath = {dest_b}\n\tread only = no\n{UIDGID}' |
| 54 |
) |
| 55 |
(conf_d / '10-a.conf').write_text( |
| 56 |
'# fragment loaded via &include directory glob\n' |
| 57 |
f'[incA]\n' |
| 58 |
f'\tpath = {dest_a}\n' |
| 59 |
f'\tread only = no\n' |
| 60 |
f'\tmax connections = 2\n' |
| 61 |
f'\tlock file = {lockfile}\n' |
| 62 |
f'{UIDGID}' |
| 63 |
) |
| 64 |
(conf_d / 'README').write_text('not matched by *.conf glob\n') |
| 65 |
|
| 66 |
|
| 67 |
merge_inc = SCRATCHDIR / 'extra.inc' |
| 68 |
merge_inc.write_text( |
| 69 |
f'[merged]\n\tpath = {dest_m}\n\tread only = no\n' |
| 70 |
) |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
conf = write_daemon_conf( |
| 75 |
[], |
| 76 |
globals={ |
| 77 |
'&include': str(conf_d), |
| 78 |
'&merge': str(merge_inc), |
| 79 |
}, |
| 80 |
name='include-maxconn.conf', |
| 81 |
) |
| 82 |
url = start_test_daemon(conf, PORT) |
| 83 |
|
| 84 |
|
| 85 |
def push(module): |
| 86 |
return subprocess.run( |
| 87 |
rsync_argv('-r', f'{src}/', f'{url}{module}/'), |
| 88 |
capture_output=True, text=True, |
| 89 |
) |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
for mod, dest in (('incA', dest_a), ('incB', dest_b)): |
| 94 |
r = push(mod) |
| 95 |
if r.returncode != 0: |
| 96 |
test_fail(f"&include dir: module [{mod}] should exist " |
| 97 |
f"(rc={r.returncode}):\n{r.stderr}") |
| 98 |
if not any(dest.iterdir()): |
| 99 |
test_fail(f"&include dir: push to [{mod}] wrote nothing into {dest}") |
| 100 |
|
| 101 |
|
| 102 |
r = push('merged') |
| 103 |
if r.returncode != 0: |
| 104 |
test_fail(f"&merge file: module [merged] should exist " |
| 105 |
f"(rc={r.returncode}):\n{r.stderr}") |
| 106 |
|
| 107 |
|
| 108 |
if not lockfile.exists(): |
| 109 |
test_fail(f"max connections=2 should have created lock file {lockfile}") |
| 110 |
|
| 111 |
|
| 112 |
r = push('incA') |
| 113 |
if r.returncode != 0: |
| 114 |
test_fail(f"second push to [incA] (max connections=2) failed " |
| 115 |
f"(rc={r.returncode}):\n{r.stderr}") |
| 116 |
|
| 117 |
print(f"daemon-include-maxconn: &include={conf_d.name}/ (2 *.conf, qsort), " |
| 118 |
f"&merge={merge_inc.name}, max connections=2 lock file ok") |