Skip to content

Client: Add ResetSecurityContext to IAuthenticationClient#348

Open
jahales wants to merge 1 commit into
TalAloni:masterfrom
jahales:3-smb2-dfs-auth-infrastructure
Open

Client: Add ResetSecurityContext to IAuthenticationClient#348
jahales wants to merge 1 commit into
TalAloni:masterfrom
jahales:3-smb2-dfs-auth-infrastructure

Conversation

@jahales
Copy link
Copy Markdown
Contributor

@jahales jahales commented Apr 18, 2026

Adds ResetSecurityContext(string host) to IAuthenticationClient and implements it in NTLMAuthenticationClient, enabling authentication clients to be reused when following DFS referrals to a different host.

Changes:

  • IAuthenticationClient: new ResetSecurityContext(string host) method
  • NTLMAuthenticationClient: implementation that rebinds SPN and clears handshake state
  • SMB2Client: retains the IAuthenticationClient instance after login, exposes Transport property — both needed by the upcoming DFS file store

Context: This is the first of two PRs for DFS support (related to #326). The second PR will add SMB2DfsFileStore which uses these interfaces to transparently follow DFS referrals.

…S target auth

Add ResetSecurityContext(string host) to IAuthenticationClient interface,
enabling auth-client reuse when connecting to DFS target servers.

- IAuthenticationClient: add ResetSecurityContext(string host) method
- NTLMAuthenticationClient: implement reset (update SPN, clear handshake state)
- SMB2Client: retain IAuthenticationClient after Login, clear on Logoff/Disconnect
- SMB2Client: expose Transport property for target client construction

BREAKING CHANGE: IAuthenticationClient now requires a ResetSecurityContext(string host) method.
Existing implementations must add this method.
@TalAloni
Copy link
Copy Markdown
Owner

Thanks,
I had to do some realignment of existing code (moving existing CIFS SPN creation to NTLMAuthenticationClient for symmetry)
And I also wanted SMB1Client to have the Transport property - for consistency.
So I went ahead and pushed those changes.

In addition I decided "serverAddress" would be easier to understand than "host" as an argument name for ResetSecurityContext. I also wanted a summary there to clarify what it is used for.

To save some back-and-forth I already pushed those changes.
The only thing remaining is the addition of m_authenticationClient which I'm now looking into.

if (response != null)
{
m_isLoggedIn = (response.Header.Status != NTStatus.STATUS_SUCCESS);
if (!m_isLoggedIn)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the client is disposed the GC will handle this for us, and if Login is called again the GC will handle this for us, so it's not really needed to set the m_authenticationClient to null IMO

m_sessionID = 0;
m_availableCredits = 1;
m_connectionSupportsMultiCredit = false;
m_authenticationClient = null;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either the client will be handled by the GC or the user will Connect and Login again - in both cases we don't need to make an effort to set m_authenticationClient to null IMO

@TalAloni TalAloni force-pushed the master branch 2 times, most recently from 57cfb6a to 336c47f Compare April 20, 2026 20:46
@TalAloni
Copy link
Copy Markdown
Owner

TalAloni commented Apr 20, 2026

I changed ResetSecurityContext to accept spn instead of serverAddress, as I realized NTLMAuthenticationClient is not the place for CIFS specific logic. I did create a new method in SMB2Client called CreateSPN - it can be moved to a more convenient location if necessary.

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.

2 participants