-
Notifications
You must be signed in to change notification settings - Fork 216
Add opt-in DFS client support with referral resolution #326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Should be fully backwards-compatible / not break existing code. I tested what I could in a local environment, but I no longer have access to an enterprise environment. Note that this code was written with the help of LLMs--if that's a concern, I can just keep this in a fork. I am willing to be the maintainer for the DFS logic. |
|
Hi Jacob, I see that in addition to the code (and unit-tests) you also contributed documentation and PowerShell tests scripts that need to be run manually. Thanks! |
|
Hey Tal, Happy to give a little back to the open source community. I agree to the contribution terms. I removed the scripts and trimmed down the documentation. When I get time I'll try to make a better lab setup and do some cross-platform testing. Thanks, |
|
Thanks Jacob,
|
|
Hey Tal,
I'm honestly open to whatever you prefer. I have no concerns with you modifying the code for style or anything like that and merging it piecemeal. Or if it's easier, I can maintain a separate wrapper package that consumes SMBLibrary as a dependency, and you can keep your focus on the core SMB implementation. |
093b856 to
5c5c764
Compare
|
Hey Jacob,
If you have the time, it would be nice it you could rebase your branch and use the newly added data structures and see if I got everything right. Thanks! |
|
Hey Tal, Good catch. I rebased and made a few minor updates. I disassembled my lab setup but I'll get that going again in a couple weeks. I'll see if I can setup some VMs with more Windows versions and start collecting traces. There's no rush on my end, so take your time and I appreciate you being willing to support this. Thanks, |
|
Thanks, |
I take that back, in "2.2.5 Referral Entry Types", it's clearly stated that "The strings referenced from the fields of a referral entry MUST follow the last referral entry in the RESP_GET_DFS_REFERRAL message". I pushed a fix to the above. |
|
According to the specs there should be a SiteNameLength field in REQ_GET_DFS_REFERRAL_EX but your code assumes RequestFileName will be immediately followed by SiteName. could you please use WireShark to capture such REQ_GET_DFS_REFERRAL_EX request? |
- Add RequestFileNameLength (2 bytes) before RequestFileName - Add SiteNameLength (2 bytes) before SiteName when flag is set - Update parsing to read length fields correctly - Add tests with captured Windows 11 FSCTL_DFS_GET_REFERRALS_EX data Addresses Tal's feedback on PR TalAloni#326 regarding missing length fields.
…ution - Add DFS referral structures (V1-V4) and response codecs - Implement DFS path resolver with caching support - Add DFS-aware client adapter and file store factory - Implement IOCTL request builder for DFS referrals - Add comprehensive unit and integration tests - Include client usage examples and documentation
- docs/codebase-patterns.md: Architecture and code style guide - docs/dfs-usage.md: DFS client configuration and troubleshooting - docs/lab-setup.md: General SMB/DFS lab setup options - docs/lab-setup-hyperv.md: Detailed Hyper-V Windows Server lab walkthrough - scripts/test-smb-client.ps1: Basic SMB2 client test - scripts/test-smb-client-full.ps1: Comprehensive read/write/echo test - scripts/test-smb1.ps1: SMB1 legacy protocol test - ClientExamples.md: Add reference to DFS usage guide
- Updated client code to use SMBLibrary.DFS namespace - Updated DfsReferralSelector to handle V1 ShareName vs V2/V3 NetworkAddress - Updated DfsClientResolver and DfsPathResolver TTL handling for V2/V3 - Fixed tests to use correct V2 buffer format and enum names (ReferalServers) - Removed incompatible V1 buffer tests pending rewrite
Per MS-DFSC 2.2.4, the R bit flag is named 'ReferralServers' (with double 'r')
- Fixed V3 NameListReferral parsing to use relative offsets per MS-DFSC (specialNameOffset and expandedNameOffset must be added to entry offset) - Changed RequestGetDfsReferralEx namespace from SMBLibrary to SMBLibrary.DFS for consistency with other DFS files
Added tests for: - V1 round-trip (ShareName serialization/parsing) - V2 round-trip (all fields) - V3 round-trip (with ServiceSiteGuid) - Multiple V3 referrals - Empty referral list - DfsClientResolver with multiple V2 referrals - DfsClientResolver with empty NetworkAddress (error case) - DfsClientResolver with V1 ShareName
- Added GetBytes round-trip tests to DfsReferralEntryV1Tests, V2Tests, V3Tests, V4Tests - Added Length calculation tests - Added V3 NameListReferral round-trip test - All 303 tests pass (NTFileStoreTests requires C:\Tests directory)
- Add RequestFileNameLength (2 bytes) before RequestFileName - Add SiteNameLength (2 bytes) before SiteName when flag is set - Update parsing to read length fields correctly - Add tests with captured Windows 11 FSCTL_DFS_GET_REFERRALS_EX data Addresses Tal's feedback on PR TalAloni#326 regarding missing length fields.
Sure. I just got my lab setup again so I can start running other tests too. Anything else you'd like me to capture? Pushed a fix. |
|
Thank you for the capture, it has been useful for both RequestGetDfsReferralEx and multiple referral entries in the response. I added RequestGetDfsReferralEx implementation, so I believe you can now use the code in \SMBLibrary\DFS as-is, correct me if I'm wrong or if something is not working correctly. I'll try to start looking into the client code this weekend. |
…DfsReferralEntryV2.WriteBytes bug, add .cascade to gitignore
|
Looking great. I resynced my fork. Just a heads up, I noticed a small issue in DfsReferralEntryV2.WriteBytes - the offset field writes at lines 67-69 are missing the offset + prefix: |
|
Thanks. fixed. |
|
Hi Jacob, |
|
No problem at all. Honestly there's no rush on my end, so take your time. |
PR: Add DFS Client Support
Summary
This PR adds opt-in Distributed File System (DFS) client support to SMBLibrary, enabling automatic resolution of DFS paths to their underlying file server targets. DFS remains disabled by default to maintain full backward compatibility.
Motivation
DFS is widely used in enterprise environments to provide:
Without DFS support, clients must manually resolve DFS paths before connecting.
Changes
Core DFS Client Implementation (
SMBLibrary/Client/DFS/)DfsClientFactoryDfsClientOptionsDfsPathResolverDfsAwareClientAdapterISMBFileStorewith transparent DFS resolutionDfsSessionManagerReferralCache/DomainCacheSmb2DfsReferralTransportFSCTL_DFS_GET_REFERRALSvia SMB2DFS Protocol Types (
SMBLibrary/DFS/)ResponseGetDfsReferral— Extended to fully parse referral responses (v1–v4)RequestGetDfsReferralEx— Support forFSCTL_DFS_GET_REFERRALS_EXwith site hintsDfsReferralEntryV1–V4— Referral entry structures per MS-DFSCDfsReferralHeaderFlags,DfsReferralEntryFlags,DfsServerType— EnumsTests (
SMBLibrary.Tests/)Documentation (
docs/)dfs-usage.mdcodebase-patterns.mdlab-setup.mdlab-setup-hyperv.mdTest Scripts (
scripts/)test-smb-client.ps1— Basic SMB2 client validationtest-smb-client-full.ps1— Comprehensive read/write/echo testtest-smb1.ps1— SMB1 legacy protocol testOther Changes
ClientExamples.md— Added DFS usage exampleSMB2FileStore.cs— Minor adjustment for DFS compatibilityUsage Example
Backward Compatibility
This PR has zero impact on existing code. DFS support is entirely opt-in:
DfsClientOptions.Enableddefaults tofalseSMB2Client,SMB1Client,ISMBFileStore, and all existing interfaces remain unchangedDfsClientFactory, all existing code paths are untouchedWhat happens if you don't use DFS?
Nothing changes. Existing code like this continues to work exactly as before:
DFS is only activated when you explicitly opt in:
Design Principles
DfsClientOptions.Enabled = falsepreserves existing behaviorTesting
References