Skip to content

fix: apply daemon incoming/outgoing chmod specs at transfer time - #5530

Merged
oferchen merged 3 commits into
masterfrom
fix/uts-7-daemon-filter-chmod
Jun 10, 2026
Merged

oferchen merged 3 commits into
masterfrom
fix/uts-7-daemon-filter-chmod

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

The daemon parser stored incoming chmod = SPEC and outgoing chmod = SPEC as raw strings on ModuleDefinition but never converted them into mode-bit rewrites at transfer time. Push transfers silently ignored incoming chmod, and pull transfers silently ignored outgoing chmod, so the upstream daemon-filter_test.py regression for these directives was a no-op.

This change parses both directives into metadata::ChmodModifiers via the existing client-side --chmod parser at module-use time, then plumbs the parsed clauses through ServerConfig to the canonical mode-finalize sites in each direction:

  • Receiver (push direction). setup_transfer now installs daemon_incoming_chmod on the per-file MetadataOptions via with_chmod, so the existing apply_permissions_with_chmod site rewrites the destination mode at file-finalize time. Mirrors upstream rsync.c:set_file_attrs() consulting daemon_chmod_modes.
  • Sender (pull direction). GeneratorContext::create_entry rewrites the entry's mode via ChmodModifiers::apply after every other flist field is populated but before the caller serializes the entry. Mirrors upstream flist.c:make_file() applying daemon_chmod_modes to the wire-emitted file_struct.

Invalid specs surface as @ERROR: invalid 'incoming chmod' directive ... during module setup, matching the upstream semantics of aborting a session on a malformed chmod argument.

The chmod-spec parser (metadata::ChmodModifiers::parse) was already vetted for the client-side --chmod flag and accepts every form upstream's parse_chmod() accepts: bare octal (644), prefix-letter (F600), class-action-perms (u+x), and combined (Du+x,Fg-r,Fo-r).

Audit findings

  • Parser at crates/daemon/src/daemon/sections/config_parsing/module_directives.rs:195-220 stored incoming chmod / outgoing chmod as Option<String> on ModuleDefinition and never converted them to mode bits.
  • Existing client-side chmod-spec parser at crates/metadata/src/chmod/{mod,parse,apply,spec}.rs was the natural reuse target; no new grammar code needed.
  • Receiver mode-finalize site: crates/transfer/src/receiver/transfer/setup.rs:135-154 (the MetadataOptions builder) routes into crates/metadata/src/apply/permissions.rs:142-192 (apply_permissions_with_chmod).
  • Sender mode-emission site: crates/transfer/src/generator/file_list/entry.rs:53-110 (the FileEntry construction switch); a single set_mode rewrite after every other field is populated covers all file types uniformly.

Wire-up

  • ServerConfig (crates/transfer/src/config/mod.rs:421-451): two new optional ChmodModifiers fields.
  • ServerConfigBuilder (crates/transfer/src/config/builder.rs:468-505): matching daemon_incoming_chmod / daemon_outgoing_chmod setters.
  • Daemon module setup (crates/daemon/src/daemon/sections/module_access/client_args.rs:292-314): parse strings on session entry, abort with @ERROR on invalid spec.
  • Receiver wire-up (crates/transfer/src/receiver/transfer/setup.rs:148-154): MetadataOptions::with_chmod.
  • Sender wire-up (crates/transfer/src/generator/file_list/entry.rs:247-258): set_mode rewrite at the end of create_entry.

Regression coverage

  • crates/transfer/src/receiver/transfer/setup.rs daemon_incoming_chmod_tests: end-to-end filesystem test - incoming chmod = F600 rewrites a 0o644 source into a 0o600 destination on disk; absence of the directive preserves the source mode verbatim.
  • crates/transfer/src/generator/file_list/entry.rs daemon_outgoing_chmod_tests: end-to-end wire-emission test - outgoing chmod = Fg-r clears the group-read bit on the FileEntry mode (0o664 -> 0o624); absence of the directive emits the on-disk mode untouched.
  • crates/transfer/src/config/builder_tests.rs: builder round-trip tests for both new fields.
  • crates/daemon/src/daemon/sections/module_access/client_args.rs daemon_chmod_spec_tests: parser tests for None passthrough, all four upstream spec forms, and error-message provenance.

Cross-platform

ChmodModifiers::apply and apply_permissions_with_chmod already short-circuit to no-op on non-Unix. No additional #[cfg] gates needed; the incoming chmod path naturally becomes a no-op on Windows, matching upstream's behavior where daemon_chmod_modes is filtered through POSIX-only mode bits.

Test plan

  • cargo nextest run -p transfer --all-features -E 'test(daemon_incoming_chmod)' passes
  • cargo nextest run -p transfer --all-features -E 'test(daemon_outgoing_chmod)' passes
  • cargo nextest run -p transfer --all-features -E 'test(builder)' passes (new builder round-trip tests)
  • cargo nextest run -p daemon --all-features -E 'test(daemon_chmod_spec)' passes
  • Full CI matrix (fmt+clippy, nextest stable Linux, Windows, macOS, Linux musl) green
  • Upstream daemon-filter_test.py incoming chmod / outgoing chmod cases pass against the new daemon binary

Upstream references

  • options.c::parse_chmod() - canonical chmod-spec parser
  • clientserver.c::rsync_module() - daemon-side arming of daemon_chmod_modes via parse_chmod(lp_xxx_chmod(i), ...)
  • flist.c::make_file() - sender applies daemon_chmod_modes while building wire file_struct
  • rsync.c::set_file_attrs() - receiver consults daemon_chmod_modes at file finalize time

@github-actions github-actions Bot added the bug Something isn't working label Jun 10, 2026
oferchen added 3 commits June 10, 2026 13:46
The daemon parser stored `incoming chmod = SPEC` and `outgoing chmod = SPEC`
as raw strings on `ModuleDefinition` but never converted them to mode-bit
rewrites at transfer time. Push transfers ignored `incoming chmod`; pull
transfers ignored `outgoing chmod`.

Parse the strings into `metadata::ChmodModifiers` via the existing
client-side chmod parser when building the per-session `ServerConfig`,
and plumb the parsed clauses to:

- the receiver, via `MetadataOptions::with_chmod` in `setup_transfer`,
  so the existing `apply_permissions_with_chmod` site rewrites the
  destination mode at file-finalize time (push direction); and
- the sender, via the new `daemon_outgoing_chmod` field consumed in
  `GeneratorContext::create_entry`, so each `FileEntry` ships with the
  rewritten mode on the wire (pull direction).

Mirrors upstream `clientserver.c:rsync_module()` arming `daemon_chmod_modes`
through `parse_chmod(lp_*_chmod(i), ...)` and applying it via
`flist.c:make_file()` (sender) and `rsync.c:set_file_attrs()` (receiver).

Invalid specs surface as `@ERROR: invalid 'incoming chmod' directive ...`
during module setup, matching the upstream behavior of aborting the
session on a bad `--chmod` style argument.

Non-Unix platforms inherit the existing no-op semantics of
`ChmodModifiers::apply` and `apply_permissions_with_chmod`, so the wire-up
adds no Windows path that would diverge from upstream.

Regression coverage: filesystem-level tests confirm `incoming chmod = F600`
rewrites the destination to `0o600` and `outgoing chmod = Fg-r` clears the
group-read bit on the wire mode, plus negative cases proving the absence
of a directive leaves modes untouched. Builder round-trip and daemon-side
chmod-spec parser tests cover the wire-up.
ModuleDefinition exposes incoming_chmod/outgoing_chmod as both Option<String>
fields and Option<&str> accessor methods. Through Deref on ModuleRuntime,
the field shadows the method in resolution, so module.incoming_chmod() was
parsed as "call the field as a function" and rejected on MSRV 1.88. Use the
field directly with .as_deref() to match the surrounding pattern (e.g.
module.dont_compress.as_deref() above) and feed the existing Option<&str>
signature of parse_one_chmod_spec.
@oferchen
oferchen force-pushed the fix/uts-7-daemon-filter-chmod branch from 63b0933 to 0096c86 Compare June 10, 2026 10:46
@oferchen
oferchen merged commit 46c765a into master Jun 10, 2026
2 of 11 checks passed
@oferchen
oferchen deleted the fix/uts-7-daemon-filter-chmod branch June 10, 2026 10:48
oferchen added a commit that referenced this pull request Aug 24, 2026
* fix: apply daemon incoming/outgoing chmod specs at transfer time

The daemon parser stored `incoming chmod = SPEC` and `outgoing chmod = SPEC`
as raw strings on `ModuleDefinition` but never converted them to mode-bit
rewrites at transfer time. Push transfers ignored `incoming chmod`; pull
transfers ignored `outgoing chmod`.

Parse the strings into `metadata::ChmodModifiers` via the existing
client-side chmod parser when building the per-session `ServerConfig`,
and plumb the parsed clauses to:

- the receiver, via `MetadataOptions::with_chmod` in `setup_transfer`,
  so the existing `apply_permissions_with_chmod` site rewrites the
  destination mode at file-finalize time (push direction); and
- the sender, via the new `daemon_outgoing_chmod` field consumed in
  `GeneratorContext::create_entry`, so each `FileEntry` ships with the
  rewritten mode on the wire (pull direction).

Mirrors upstream `clientserver.c:rsync_module()` arming `daemon_chmod_modes`
through `parse_chmod(lp_*_chmod(i), ...)` and applying it via
`flist.c:make_file()` (sender) and `rsync.c:set_file_attrs()` (receiver).

Invalid specs surface as `@ERROR: invalid 'incoming chmod' directive ...`
during module setup, matching the upstream behavior of aborting the
session on a bad `--chmod` style argument.

Non-Unix platforms inherit the existing no-op semantics of
`ChmodModifiers::apply` and `apply_permissions_with_chmod`, so the wire-up
adds no Windows path that would diverge from upstream.

Regression coverage: filesystem-level tests confirm `incoming chmod = F600`
rewrites the destination to `0o600` and `outgoing chmod = Fg-r` clears the
group-read bit on the wire mode, plus negative cases proving the absence
of a directive leaves modes untouched. Builder round-trip and daemon-side
chmod-spec parser tests cover the wire-up.

* fix: correct ModuleRuntime field access for incoming/outgoing chmod

ModuleDefinition exposes incoming_chmod/outgoing_chmod as both Option<String>
fields and Option<&str> accessor methods. Through Deref on ModuleRuntime,
the field shadows the method in resolution, so module.incoming_chmod() was
parsed as "call the field as a function" and rejected on MSRV 1.88. Use the
field directly with .as_deref() to match the surrounding pattern (e.g.
module.dont_compress.as_deref() above) and feed the existing Option<&str>
signature of parse_one_chmod_spec.

* style: apply rustfmt to daemon chmod receiver tests
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