| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
import os |
| 24 |
import subprocess |
| 25 |
|
| 26 |
from rsyncfns import ( |
| 27 |
SCRATCHDIR, makepath, rmtree, rsync_argv, start_test_daemon, |
| 28 |
test_fail, test_skipped, write_daemon_conf, |
| 29 |
) |
| 30 |
|
| 31 |
DAEMON_PORT = 12923 |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
if os.geteuid() == 0: |
| 38 |
import grp |
| 39 |
usable = [] |
| 40 |
for gr in grp.getgrall(): |
| 41 |
if gr.gr_gid not in usable: |
| 42 |
usable.append(gr.gr_gid) |
| 43 |
if len(usable) < 2: |
| 44 |
test_skipped("need >=2 groups defined on the system") |
| 45 |
else: |
| 46 |
usable = [] |
| 47 |
for g in [os.getgid()] + list(os.getgroups()): |
| 48 |
if g not in usable: |
| 49 |
usable.append(g) |
| 50 |
if len(usable) < 2: |
| 51 |
test_skipped("need >=2 groups the test user belongs to") |
| 52 |
src_gid, dst_gid = usable[0], usable[1] |
| 53 |
|
| 54 |
moddir = SCRATCHDIR / 'gmod' |
| 55 |
srcdir = SCRATCHDIR / 'gsrc' |
| 56 |
makepath(moddir) |
| 57 |
|
| 58 |
conf = write_daemon_conf([('gmod', {'path': str(moddir), 'read only': 'no'})]) |
| 59 |
url = start_test_daemon(conf, DAEMON_PORT) + 'gmod/' |
| 60 |
|
| 61 |
|
| 62 |
def check(label, *extra_opts): |
| 63 |
rmtree(moddir) |
| 64 |
rmtree(srcdir) |
| 65 |
makepath(moddir) |
| 66 |
makepath(srcdir) |
| 67 |
f = srcdir / 'f.dat' |
| 68 |
f.write_text("hi\n") |
| 69 |
os.chown(f, -1, src_gid) |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
proc = subprocess.run( |
| 74 |
rsync_argv('-rg', *extra_opts, f'--groupmap=*:{dst_gid}', str(f), url), |
| 75 |
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) |
| 76 |
if proc.returncode != 0: |
| 77 |
print(proc.stdout) |
| 78 |
test_fail(f"[{label}] groupmap upload failed (rc={proc.returncode})") |
| 79 |
|
| 80 |
got = os.stat(moddir / 'f.dat').st_gid |
| 81 |
if got != dst_gid: |
| 82 |
test_fail(f"[{label}] --groupmap='*:{dst_gid}' wildcard ignored over " |
| 83 |
f"daemon: got gid {got}, expected {dst_gid} (regression of #829)") |
| 84 |
|
| 85 |
|
| 86 |
check('default-args') |
| 87 |
check('secluded-args', '--secluded-args') |