Skip to content

fix(daemon): merge phase-1 cmdline + phase-2 stdin args under secluded-args - #5736

Merged
oferchen merged 2 commits into
masterfrom
fix/uts-8-daemon-groupmap-wild-wildcard
Jun 12, 2026
Merged

oferchen merged 2 commits into
masterfrom
fix/uts-8-daemon-groupmap-wild-wildcard

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Under secluded-args mode upstream rsync emits a two-phase argv: phase 1 (cmdline) carries --server, --sender, the compact flag string (-slogDtprIzxe.iLsfxCIvu) and --iconv=...; phase 2 (stdin via send_protected_args) carries every long-form option (--list-only, --log-format, --usermap, --groupmap, ...), the . separator and the positional paths.
  • The daemon was discarding phase 1 entirely and parsing only phase 2, so the compact flag string, --sender, and --iconv never reached ServerConfig. Compression / recursion / role negotiation diverged before the transfer started, explaining the early connection drop on the daemon-groupmap-wild secluded-args case (upstream issue Add daemon hosts allow/deny enforcement for module access #829): the wildcard groupmap was actually parsed correctly by fix(daemon): parse --usermap/--groupmap from daemon client args #5717, but the missing -z from phase 1 broke the protocol handshake.
  • The fix concatenates the two phases (dropping the synthetic "rsync" arg0 upstream rewrites into the NULL slot) and feeds the merged list through the same single-pass option parser.

Why this fixes daemon-groupmap-wild [secluded-args]

Upstream sender connects with -s (secluded-args). Wire trace at the cutoff:

  1. Daemon → client: @RSYNCD: 32.0 sha512 sha256 sha1 md5 md4\n (greeting).
  2. Client → daemon: @RSYNCD: 32.0\n, module name, then phase 1 args (--server\0--sender\0-slogDtprIze.LsfxCIvu\0\0).
  3. Daemon → client: @RSYNCD: OK\n.
  4. Client → daemon: phase 2 args (rsync\0--log-format=%i\0--groupmap=*:1000\0.\0upload/\0\0).
  5. Daemon parses phase 2 ONLY. -z from phase 1 is gone; ServerConfig.flags.compress = false.
  6. Both sides start setup_protocol(). Sender uses zlib; receiver expects raw. After @RSYNCD: OK\n is read the sender's stats.total_read is around 23 bytes (legacy greeting + OK frame), then the receiver mis-decodes the post-OK compat-flags varint and EOFs the socket. Sender surfaces connection unexpectedly closed (23 bytes received so far) [sender] and error in rsync protocol data stream (code 12).

Merging the two phases restores the compact flag string into ServerConfig so -z, -l, -r, ..., --sender all reach parse_arguments-equivalent state. The wildcard --groupmap=*:GID already round-trips through #5717's typed mapping parser.

What this preserves

  • URV-2.a unbackslash_arg on the non-protect_args path - the else branch is untouched.
  • PR fix(daemon): finish setup_protocol before multiplexing refuse-options error #5734 daemon-refuse-options multiplex error path - only touches client_args.rs, not the refused-option handler.
  • validate_client_paths_in_module path traversal checks - the merged argv still flows through the same path-component splitter; the fix only widens the options that reach the parser, never widens what counts as a positional path.

Upstream references

  • clientserver.c:1059-1086 - two-phase read_args() + parse_arguments()
  • options.c:2614-2745 - server_options() placement of --server, --sender, argstr and the secluded-args NULL split point
  • options.c:2551 - safe_arg() if (!protect_args ...) guard that emits * verbatim under secluded-args
  • rsync.c:283-320 - send_protected_args() NULL/arg0 rewrite

Test plan

  • merge_secluded_args_prepends_phase1_and_skips_rsync_arg0 - locks the canonical phase 1 + phase 2 layout.
  • merge_secluded_args_passes_phase2_through_when_no_synthetic_arg0 - guards the no-rsync-arg0 fallback.
  • merge_secluded_args_preserves_groupmap_wildcard_through_apply_long_form - end-to-end: parse --groupmap=*:1234 through the merged argv, assert ServerConfig.group_mapping.spec() == "*:1234".
  • CI: daemon-groupmap-wild upstream-testsuite must transition from [secluded-args] groupmap upload failed (rc=12) to PASS.
  • CI: existing unescape_phase1_option_args_* and read_client_arguments_with_secluded_flag tests must keep passing (no regression on the non-secluded path).

oferchen added 2 commits June 12, 2026 09:50
…d-args

Under secluded-args mode upstream rsync splits the daemon argv at the
NULL it injects at options.c:2745: phase 1 (cmdline) carries `--server`,
`--sender`, the compact flag string (`-slogDtprIzxe.iLsfxCIvu`) and
`--iconv=...`; phase 2 (stdin via `send_protected_args`) carries every
long-form option (`--list-only`, `--log-format`, `--usermap`,
`--groupmap`, ...), the `.` separator and the positional paths.

Upstream re-runs `parse_arguments()` against each phase so the popt
globals carry the union forward (clientserver.c:1073,1083). The daemon
was discarding phase 1 entirely and parsing only phase 2, so the
compact flag string, `--sender`, and `--iconv` never reached
`ServerConfig`. Compression / recursion / role negotiation diverged
before the transfer started, explaining the early connection drop on
the `daemon-groupmap-wild` secluded-args case (upstream issue #829):
the wildcard groupmap was parsed correctly but the missing `-z` from
phase 1 broke the protocol handshake.

The fix concatenates the two phases (dropping the synthetic `"rsync"`
arg0 upstream rewrites into the NULL slot) and feeds the merged list
through the same single-pass option parser. No unbackslash pass is
needed on either phase: `safe_arg()` skips the WILD_CHARS escape when
`protect_args` is set (options.c:2551), so phase 2 args - including
`--groupmap=*:GID` - arrive verbatim.

upstream: clientserver.c:1059-1086 two-phase read_args() + parse_arguments()
upstream: options.c:2614-2745 server_options() placement of `--server`,
  `--sender`, argstr and the secluded-args NULL split point
upstream: rsync.c:283-320 send_protected_args() NULL/arg0 rewrite
Replace the shadow `let mut phase2 = phase2` with `mut phase2: Vec<String>`
in the parameter list to drop a redundant statement.
@github-actions github-actions Bot added the bug Something isn't working label Jun 12, 2026
@oferchen
oferchen merged commit 3bedbc2 into master Jun 12, 2026
17 of 18 checks passed
@oferchen
oferchen deleted the fix/uts-8-daemon-groupmap-wild-wildcard branch June 12, 2026 14:39
oferchen added a commit that referenced this pull request Aug 24, 2026
…d-args (#5736)

* fix(daemon): merge phase-1 cmdline + phase-2 stdin args under secluded-args

Under secluded-args mode upstream rsync splits the daemon argv at the
NULL it injects at options.c:2745: phase 1 (cmdline) carries `--server`,
`--sender`, the compact flag string (`-slogDtprIzxe.iLsfxCIvu`) and
`--iconv=...`; phase 2 (stdin via `send_protected_args`) carries every
long-form option (`--list-only`, `--log-format`, `--usermap`,
`--groupmap`, ...), the `.` separator and the positional paths.

Upstream re-runs `parse_arguments()` against each phase so the popt
globals carry the union forward (clientserver.c:1073,1083). The daemon
was discarding phase 1 entirely and parsing only phase 2, so the
compact flag string, `--sender`, and `--iconv` never reached
`ServerConfig`. Compression / recursion / role negotiation diverged
before the transfer started, explaining the early connection drop on
the `daemon-groupmap-wild` secluded-args case (upstream issue #829):
the wildcard groupmap was parsed correctly but the missing `-z` from
phase 1 broke the protocol handshake.

The fix concatenates the two phases (dropping the synthetic `"rsync"`
arg0 upstream rewrites into the NULL slot) and feeds the merged list
through the same single-pass option parser. No unbackslash pass is
needed on either phase: `safe_arg()` skips the WILD_CHARS escape when
`protect_args` is set (options.c:2551), so phase 2 args - including
`--groupmap=*:GID` - arrive verbatim.

upstream: clientserver.c:1059-1086 two-phase read_args() + parse_arguments()
upstream: options.c:2614-2745 server_options() placement of `--server`,
  `--sender`, argstr and the secluded-args NULL split point
upstream: rsync.c:283-320 send_protected_args() NULL/arg0 rewrite

* style(daemon): take phase2 by mut value in merge_secluded_args

Replace the shadow `let mut phase2 = phase2` with `mut phase2: Vec<String>`
in the parameter list to drop a redundant statement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant