Repository navigation
Add transport session handshake dispatcher - #351
Merged
Merged
Conversation
oferchen
added a commit
that referenced
this pull request
Feb 22, 2026
6 tasks
oferchen
added a commit
that referenced
this pull request
Feb 22, 2026
oferchen
added a commit
that referenced
this pull request
May 1, 2026
oferchen
added a commit
that referenced
this pull request
May 5, 2026
8 of 9 tasks
oferchen
added a commit
that referenced
this pull request
Nov 27, 2026
## What rsync 3.5.2 does A `--files-from` list carried over the connection is converted with `--iconv` only under `--protect-args` / `--secluded-args`: - `compat.c:820-827` - `if (protect_args && files_from)` sets `filesfrom_convert`: `filesfrom_host && ic_send != -1` on the sender, `!filesfrom_host && ic_recv != -1` on the receiver. - `io.c:502` - `forward_filesfrom_data()` converts each forwarded name with `ic_send` only under `filesfrom_convert`. - `flist.c:2766` - `send_file_list()` adds `RL_CONVERT` to its `read_line()` flags only under `filesfrom_convert`. - `io.c:505` and `io.c:1462` - both conversions use `ICB_INCLUDE_BAD`, which converts what it can and copies each unconvertible byte through verbatim (`rsync.c:262`). A server learns `protect_args` from the client's `-s` (`main.c:1960-1962` over a remote shell, `clientserver.c:1165-1167` on a daemon). ## What oc did - A sender reading a forwarded list (`--files-from=-`) converted it whenever `--iconv` was set, with or without `-s`. Against a 3.5.2 client pulling without `-s`, oc copied a file 3.5.2 reports missing. - A server receiver forwarding a list it opened (`--files-from=:list` on a push) never converted it, even under `-s`, so a 3.5.2 client pushing with `-s` missed its file. - Both directions converted strictly: one invalid byte made the whole name fall back to its raw bytes, so the valid characters around it were left unconverted. ## The fix - `ConnectionConfig` gains `protect_args`, set by the remote-shell server from its `-s` detection, by the daemon from the client's option args, and by the client from its resolved `--protect-args`. - `ConnectionConfig::files_from_converter()` returns the `--iconv` converter only under `protect_args`. Both the reading sender and the forwarding server receiver use it. - `forward_files_from` and `read_files_from_stream` use the `ICB_INCLUDE_BAD` converters (`local_to_remote_lossy` / `remote_to_local_lossy`), which already exist for `read_line(RL_CONVERT)` and secluded args. The implied-include code is not touched. ## Measured (host, glibc) Client `--iconv=UTF-8,ISO-8859-1` over a remote shell. `latin1` is `café`: UTF-8 on the client, ISO-8859-1 on the server. `bad` is `bad\xff`. A local list is in the client's charset, a remote (`:list`) list in the server's. Each cell shows the exit code and what reached the destination. | cell | 3.5.2 to 3.5.2 | 3.5.2 client, oc server (before) | 3.5.2 client, oc server (after) | oc to oc (before) | oc to oc (after) | |---|---|---|---|---|---| | pull local, no -s, latin1 | 23, none | **0, café** | 23, none | **0, café** | 23, none | | pull local, no -s, bad | 4, none | 4, none | 4, none | 4, none | 4, none | | pull local, -s, latin1 | 0, café | 0, café | 0, café | 0, café | 0, café | | pull local, -s, bad | 4, none | 4, none | 4, none | 4, none | 4, none | | pull remote, no -s / -s, latin1 | 0, café | 0, café | 0, café | 0, café | 0, café | | pull remote, no -s / -s, bad | 0, badÿ | 0, badÿ | 0, badÿ | 0, badÿ | 0, badÿ | | push local, no -s / -s, latin1 | 0, caf\351 | 0, caf\351 | 0, caf\351 | 0, caf\351 | 0, caf\351 | | push local, no -s / -s, bad | 23, none | 23, none | 23, none | 23, none | 23, none | | push remote, no -s, latin1 | 23, none | 23, none | 23, none | 23, none | 23, none | | push remote, no -s, bad | 23, none | 23, none | 23, none | 23, none | 23, none | | push remote, -s, latin1 | 0, caf\351 | **23, none** | 0, caf\351 | **23, none** | 0, caf\351 | | push remote, -s, bad | 23, none | 23, none | 23, none | 23, none | 23, none | After the fix, all 16 cells of the 3.5.2-client, oc-server pairing match 3.5.2 exactly, and so do the oc-to-oc exit codes and destinations. Both binaries were built from this branch and its base in a target dir used by this branch alone. The exit-4 `bad` pull cells are the receiver rejecting the converted name as unrequested. 3.5.2 does the same, and that path is the implied-include check, which this change leaves alone. ## Tests - `crates/cli/tests/files_from_iconv_protect_args.rs` (new, 8 cells): pull, push from a remote list, daemon pull with `charset = ISO-8859-1`, and a push from an ISO-8859-1 client, each with and without `-s`. The expected values are the 3.5.2 results. With `OC_RSYNC_UPSTREAM_COMPAT=1` each cell also runs 3.5.2 at both ends and with one end each. - `generator::tests::files_from` - a stream name is looked up unconverted without `protect_args` and converted with it. - receiver `files_from_forwarding_framing_tests` - a server receiver forwards unconverted without `protect_args` and converted with it. - `protocol::files_from` - a name holding one invalid byte has its valid characters converted and the bad byte copied, on both the forward and the read side. Mutation results (each fix site reverted on its own; each revert fails at least one new test): | reverted | failing tests | |---|---| | sender gate (`filters.rs`) | generator unit test; cli pull and daemon pull without `-s` | | receiver forward (`context.rs`) | receiver unit test; cli push with `-s` | | `ICB_INCLUDE_BAD` conversion (`files_from.rs`) | both protocol invalid-byte tests | | remote-shell server `-s` wiring (`run.rs`) | cli pull and push with `-s` | | daemon `-s` wiring (`server_config.rs`) | cli daemon pull with `-s` | | client `protect_args` wiring (`flags.rs`) | cli ISO-8859-1 client push with `-s` | ## Remaining differences (not fixed here) - **oc client with `-s` pulling from a 3.5.2 daemon** reads the list unconverted and exits 23, where 3.5.2 at both ends exits 0. The behaviour is the same before this change. The oc client sends `--secluded-args --iconv=ISO-8859-1` in the first pass, while 3.5.2 sends `-s` inside its flag string and `--iconv=UTF-8` (its client truncates `iconv_opt` in `setup_iconv()`, `rsync.c:119-123`, before `server_options()` runs). The test leaves out that one pairing and says so in a comment. - **Diagnostics with a non-UTF-8 name**: the oc sender's `link_stat` line shows `caf\357\277\275` where 3.5.2 prints `caf\#351`. The lookup used the raw bytes, and the exit code and result match. Only the message text is lossy, because sender diagnostics are built as Rust `String`s. - **Push of an invalid UTF-8 local name** (`bad\xff`): exit 23 matches, but oc reports `[receiver] cannot convert filename` plus extra `delete_file`/`could not make way` lines, where 3.5.2 reports `[sender] cannot convert filename`. That is flist iconv, not files-from. Closes #8864
oferchen
added a commit
that referenced
this pull request
Nov 27, 2026
## What rsync 3.5.2 does Under `-s`, `server_options()` builds `--server`, `--sender` (on a pull), the compact flag string with `s` as its first letter (options.c:2858-2859) and `--iconv=...` (options.c:2975-2983), then inserts a `NULL` (options.c:2985-2986). `start_inband_exchange()` sends the args before that `NULL` in the first pass (clientserver.c:443-450). `send_protected_args()` then sends `rsync` and only the args after the `NULL` (rsync.c:284-296). A daemon client runs `setup_iconv()` before `server_options()` (clientserver.c:171-172 for a socket, main.c:678-679 before `start_inband_exchange()` over a remote shell). `rsync.c:119-123` truncates `iconv_opt` at the comma there, so the daemon is sent the local charset. A remote-shell server is different: `main.c:624` runs `server_options()` before `setup_iconv()`, so it gets the post-comma half. oc already sends that correctly. ## Why the 3.5.2 daemon read the list unconverted I captured the daemon's stdin with strace (`--iconv=UTF-8,ISO-8859-1 -s --files-from=list`, module `charset = ISO-8859-1`): ``` 3.5.2 client: --server\0--sender\0-srRe.iLsfxCIvu\0--iconv=UTF-8\0\0 rsync\0--files-from=-\0--from0\0.\0src/\0\0 oc client: --server\0--sender\0--secluded-args\0--iconv=ISO-8859-1\0\0 rsync\0--server\0--sender\0-rRe.iLsfxCIvu\0--files-from=-\0--from0\0.\0src/\0\0 ``` oc's second pass repeated `--server`. The daemon's second `parse_arguments()` handles `OPT_SERVER` and sets `iconv_opt = NULL` (options.c:1535-1547). `rsync_module()` then sees no `iconv_opt` and closes the `ic_send`/`ic_recv` converters that came from the module `charset` (clientserver.c:1279-1289). With no converters, `filesfrom_convert` stays 0 (compat.c:820-826). The daemon sender looked up the raw UTF-8 name and failed with `link_stat "caf\#303\#251" (in src) failed`, which gives exit 23. The `--iconv` value itself does not matter on the daemon, because its converters come only from the module `charset` (clientserver.c:763-768). Only the repeated `--server` breaks the transfer. ## The fix Daemon client argv only (`orchestration/arguments.rs`): - The flag string carries `s` under `-s`, and `--iconv=` follows it directly, as in upstream. - The first pass is the upstream prefix: `--server`, `--sender` on a pull, the flag string and `--iconv`. The protected args are `rsync` plus everything after it. Nothing from the first pass is repeated. - `--iconv=` forwards the local charset (the pre-comma half). - `--checksum-choice` moves from before the flag string to after `--suffix`, its upstream position (options.c:3052-3056). It has to move out of the first-pass prefix. - `build_minimal_daemon_args` (the old `--secluded-args` first pass) is removed. The remote-shell argv already matched 3.5.2 for both pull and push (captured: `--server [--sender] -srRe.iLsfxCIvu --iconv=ISO-8859-1`, then `rsync ... . path`). It is unchanged. ## Measured (oc client, rsync 3.5.2 daemon over a remote shell, module charset ISO-8859-1) | client | `-s` | daemon argv after the fix | exit | copied | |---|---|---|---|---| | rsync 3.5.2 | yes | `-srRe.iLsfxCIvu --iconv=UTF-8` / `rsync --files-from=- --from0 . src/` | 0 | `café` | | oc before | yes | `--secluded-args --iconv=ISO-8859-1` / `rsync --server --sender -rRe... ...` | 23 | nothing | | oc after | yes | byte-identical to 3.5.2 (strace) | 0 | `café` | | rsync 3.5.2 | no | `-rRe.iLsfxCIvu --iconv=UTF-8 --files-from=- --from0 . src/` | 23 | nothing | | oc before | no | `-rRe... --files-from=- --from0 --iconv=ISO-8859-1 . src/` | 23 | nothing | | oc after | no | byte-identical to 3.5.2 (strace) | 23 | nothing | ## Tests - `crates/cli/tests/files_from_iconv_protect_args.rs`: the skip of the oc client to rsync 3.5.2 daemon pairing under `-s` is removed, so `a_daemon_pull_with_protect_args_converts_the_list` now covers it. `a_daemon_pull_without_protect_args_sends_the_list_unconverted` covers the case without `-s`. - `orchestration/tests.rs`: four wire tests check the bytes sent for each pass: a protected pull's first pass (flag string with `s`, local `--iconv`), a protected pull's second pass (`rsync . test/` only), a protected push without iconv, and an unprotected pull with `--iconv` right after the flag string. - Mutation: reverting `arguments.rs` to the base makes all 4 new unit tests fail, and makes `a_daemon_pull_with_protect_args_converts_the_list` fail in the oc client to rsync 3.5.2 daemon pairing (exit 23, nothing copied, where 3.5.2 gives exit 0 and `café`). With the fix all 8 cells pass with `OC_RSYNC_UPSTREAM_COMPAT=1`, and the daemon `module_access` tests pass (342). ## Remaining differences (separate issues) - Sender diagnostics print a non-UTF-8 name lossily (`caf\357\277\275` where 3.5.2 prints `caf\#351`). - An invalid UTF-8 name on a push gives `[receiver] cannot convert filename` plus extra `delete_file` / `could not make way` lines. 3.5.2 prints `[sender] cannot convert filename`. - The oc daemon still accepts the old oc-client first pass (`--secluded-args`), so older oc clients keep working. Closes #8877
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SessionHandshakeenum that encapsulates binary and legacy daemon negotiation resultsnegotiate_sessionhelpers that automatically detect the transport style and reuse the existing handshake implementationsTesting