Skip to content

feat: implement Close, Read, and QueryInfo handlers for E2E file read#5

Open
tmthecoder wants to merge 4 commits intomainfrom
feat/file-read-handlers
Open

feat: implement Close, Read, and QueryInfo handlers for E2E file read#5
tmthecoder wants to merge 4 commits intomainfrom
feat/file-read-handlers

Conversation

@tmthecoder
Copy link
Owner

Summary

Implements the server-side handlers needed for a complete file read flow: Create → QueryInfo → Read → Close.

Changes

Protocol Types

  • Add accessor methods to SMBCloseRequest, SMBReadRequest, SMBQueryInfoRequest
  • Add constructors for SMBCloseResponse, SMBReadResponse, SMBQueryInfoResponse
  • Make close::flags and query_info::info_type modules public

Trait Extensions

  • Add read_data() to ResourceHandle trait with implementations for SMBFileSystemHandle (seeks + reads) and SMBIPCHandle (stub returning InvalidDeviceRequest)
  • Add read_data() to Open trait, delegating to the underlying handle
  • Add open_table_mut() to Session trait for close cleanup
  • Add remove_open() to Server trait for global open table cleanup
  • Fix SMBOpen::inner() todo!() → returns None (terminal handler)

Handlers (tree_connect.rs)

Handler Behavior
handle_close Returns file metadata if POSTQUERY_ATTRIB flag set; removes open from server then session tables
handle_read Reads data from the open's underlying handle; enforces minimum_count; returns SMBReadResponse
handle_query_info Supports FileBasicInformation (class 4), FileStandardInformation (class 5), FileNetworkOpenInformation (class 34) per MS-FSCC

Lock Ordering

All handlers acquire locks outer → inner (server → connection → session → open), readers before writers. Also fixes lock ordering in the existing handle_create.

NTStatus

Added: FileClosed, EndOfFile, InvalidInfoClass, InvalidDeviceRequest

Tests

  • 13 unit tests — request accessor validation + response constructor serialization round-trips for Close, Read, and QueryInfo types
  • 3 integration tests (#[ignore]d) — smbclient E2E: file read, directory listing, nonexistent file error handling

How to Test

# Unit tests
cargo test --lib --features "server,anyhow" -- close::tests read::tests query_info::tests

# Integration tests (requires smbclient)
cargo test --test smbclient --features "server,anyhow" -- --ignored

Add the server-side handlers needed for a complete file read flow:
Create → QueryInfo → Read → Close.

Protocol types:
- Add accessor methods to SMBCloseRequest, SMBReadRequest, SMBQueryInfoRequest
- Add constructors for SMBCloseResponse, SMBReadResponse, SMBQueryInfoResponse
- Make close::flags and query_info::info_type modules public

Trait extensions:
- Add read_data() to ResourceHandle trait with implementations for
  SMBFileSystemHandle (seeks + reads) and SMBIPCHandle (stub)
- Add read_data() to Open trait, delegating to the underlying handle
- Add open_table_mut() to Session trait for close cleanup
- Add remove_open() to Server trait for global open table cleanup
- Fix SMBOpen::inner() todo!() → return None (terminal handler)

Handlers (tree_connect.rs):
- handle_close: returns file metadata if POSTQUERY_ATTRIB flag set,
  removes open from server (outer) then session (inner) tables
- handle_read: reads data from the open's underlying handle, enforces
  minimum_count, returns SMBReadResponse
- handle_query_info: supports FileBasicInformation (class 4),
  FileStandardInformation (class 5), FileNetworkOpenInformation (class 34)
  per MS-FSCC; returns InvalidInfoClass for unsupported types
- Fix lock ordering in handle_create: server write before session write

Lock ordering: all handlers acquire locks outer→inner
(server → connection → session → open), readers before writers.

NTStatus: add FileClosed, EndOfFile, InvalidInfoClass, InvalidDeviceRequest

Tests:
- 13 unit tests for request accessor and response constructor round-trips
- 3 integration tests (smbclient E2E: file read, dir listing, missing file)
@tmthecoder tmthecoder force-pushed the feat/file-read-handlers branch from d4bad02 to 8e2e795 Compare February 8, 2026 23:12
- Fix SMBCreateRequest NameOffset subtract (68→64): offset is relative to
  SMB2 header start (64 bytes), not 68. This caused 4-byte misalignment
  producing leading NUL chars and filename truncation.

- Fix SMBInfoType enum values to match MS-SMB2 spec: File=1, Filesystem=2,
  Security=3, Quota=4 (was incorrectly starting at 0).

- Fix SMBQueryInfoResponse StructureSize: 9 per MS-SMB2 2.2.38, not 17.

- Add FileAllInformation (class 18) handler in QueryInfo dispatch per
  MS-FSCC 2.4.2 (composite of Basic+Standard+Internal+EA+Access+Position+
  Mode+Alignment+Name).

- Fix tree_id in TreeConnect response header (use dynamic ID, not hardcoded 1).

- Add SMB_SHARE_PATH env var support in main.rs for configurable share root.

- Sanitize file paths in SMBFileSystemShare::handle_create: strip trailing
  NUL terminators and convert backslashes to forward slashes.

- Improve integration test diagnostics: capture smbclient stdout/stderr,
  verify file contents in file_read test.

All 66 unit tests and 10 integration tests pass.
Introduce protocol::body::file_info module with proper typed structs for
MS-FSCC file information classes:
- FileBasicInformation (2.4.7)
- FileStandardInformation (2.4.41)
- FileInternalInformation (2.4.20)
- FileEaInformation (2.4.12)
- FileAccessInformation (2.4.1)
- FilePositionInformation (2.4.35)
- FileModeInformation (2.4.26)
- FileAlignmentInformation (2.4.3)
- FileNameInformation (2.4.28)
- FileNetworkOpenInformation (2.4.29)
- FileAllInformation (2.4.2)

All types use SMBFromBytes/SMBToBytes/SMBByteSize derive macros for
automatic serialization, replacing manual Vec<u8> byte-pushing in
tree_connect.rs build_file_* methods.

Includes 14 unit tests (round-trip serialization + size assertions).
All 80 unit tests and 10 integration tests pass.
…vention

Move each MS-FSCC file information struct out of mod.rs into its own
file (access.rs, alignment.rs, basic.rs, ea.rs, internal.rs, mode.rs,
name.rs, network_open.rs, position.rs, standard.rs). mod.rs now only
contains module declarations, re-exports, and the composite
FileAllInformation type.

All 80 unit tests and 10 integration tests pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant