Client: Add SMB2DfsFileStore to follow DFS referrals - #352
Merged
Conversation
…r to support DFS The authentication client is kept so it can be reused via ResetSecurityContext when following a DFS referral to another server.
TreeConnect() now returns an SMB2DfsFileStore when the share reply has the SMB2_SHAREFLAG_DFS_ROOT flag set. When a CreateFile is not covered by the DFS root (STATUS_PATH_NOT_COVERED), a DFS referral is requested and the operation is retried against the referral target, connecting to another server when necessary by reusing the authentication client via IAuthenticationClient.ResetSecurityContext.
Owner
|
Thank you Jacob!, |
TalAloni
approved these changes
Jul 10, 2026
Owner
|
Thank you! Merged. |
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.
Adds
SMB2DfsFileStore, which follows DFS referrals transparently, building on the DFS data structures/helpers from #346 andResetSecurityContextfrom #348. This is the client-side counterpart that ties those pieces together into working DFS support.Integration (as you suggested in #326)
SMB2Client.TreeConnect()returns anSMB2DfsFileStoreif and only if the tree connect reply has theSMB2_SHAREFLAG_DFS_ROOTflag set; otherwise it returns the plainSMB2FileStoreas before. Non-DFS shares are completely unaffected.Behavior
When a
CreateFileis not covered by the DFS root (STATUS_PATH_NOT_COVERED), the store requests a DFS referral (viaDfsReferralHelper), rewrites the path to the referral target (viaDfsPath.ReplacePrefix), and retries the open against that target — connecting to another server when the target lives elsewhere, reusing the authentication client viaIAuthenticationClient.ResetSecurityContext. Handles are routed back to the connection they were opened against, so reads/writes/closes go to the right target.On breaking changes
You asked in #326 whether
ResetSecurityContextwould be the end of it. It is — that remains the only public/breaking API change.SMB2DfsFileStoreis declaredinternal, and the cross-server connect/login reuse is done throughinternalhelpers onSMB2Client(ConnectAndLoginToDfsTarget), so there's no further public surface. (I also updated theKerberosNetAuthenticationClientexample inClientExamples.mdto implement the new interface method.)The first commit (retaining the
IAuthenticationClientafter login) is the small piece from #348 folded in here, since it's only actually used by this file store — happy to close #348 in favor of this.Scope / deliberate limitations
Kept intentionally minimal:
STATUS_PATH_NOT_COVERED.ReferralCache; I left it out to keep this PR focused, so each open under a link currently re-requests a referral. Easy follow-up if you'd like it.Tests
SMB2DfsFileStoreTestscovers the referral-following loop, handle routing, cross-server target selection, and multi-target failover using the real captured V4 referral format, without needing a live server.A note on size
This is a bit larger than the earlier pieces. For what it's worth,
SMB2DfsFileStore.csis ~400 lines but ~150 of those are the mechanicalISMBFileStoreforwarding methods and ~130 are the actual DFS logic. If you'd prefer, I'm happy to split the cross-server support (auth reuse + failover) out into a separate follow-up PR and keep this one to the wrapper + same-server referral following — just let me know.