mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-07-06 17:43:17 +02:00
Client: Added support for single-stage and triple-stage session setup
Applicable when working with custom IAuthenticationClient
This commit is contained in:
parent
8b795d5233
commit
ab876da50f
2 changed files with 72 additions and 75 deletions
|
@ -316,9 +316,7 @@ namespace SMBLibrary.Client
|
|||
TrySendMessage(request);
|
||||
|
||||
SMB1Message reply = WaitForMessage(CommandName.SMB_COM_SESSION_SETUP_ANDX);
|
||||
if (reply != null)
|
||||
{
|
||||
if (reply.Header.Status == NTStatus.STATUS_MORE_PROCESSING_REQUIRED && reply.Commands[0] is SessionSetupAndXResponseExtended)
|
||||
while (reply != null && reply.Header.Status == NTStatus.STATUS_MORE_PROCESSING_REQUIRED && reply.Commands[0] is SessionSetupAndXResponseExtended)
|
||||
{
|
||||
SessionSetupAndXResponseExtended response = (SessionSetupAndXResponseExtended)reply.Commands[0];
|
||||
byte[] authenticateMessage = authenticationClient.InitializeSecurityContext(response.SecurityBlob);
|
||||
|
@ -326,7 +324,6 @@ namespace SMBLibrary.Client
|
|||
{
|
||||
return NTStatus.SEC_E_INVALID_TOKEN;
|
||||
}
|
||||
m_sessionKey = authenticationClient.GetSessionKey();
|
||||
|
||||
m_userID = reply.Header.UID;
|
||||
request = new SessionSetupAndXRequestExtended();
|
||||
|
@ -337,20 +334,23 @@ namespace SMBLibrary.Client
|
|||
TrySendMessage(request);
|
||||
|
||||
reply = WaitForMessage(CommandName.SMB_COM_SESSION_SETUP_ANDX);
|
||||
if (reply != null)
|
||||
}
|
||||
|
||||
if (reply != null && reply.Commands[0] is SessionSetupAndXResponseExtended)
|
||||
{
|
||||
m_isLoggedIn = (reply.Header.Status == NTStatus.STATUS_SUCCESS);
|
||||
return reply.Header.Status;
|
||||
if (m_isLoggedIn)
|
||||
{
|
||||
m_sessionKey = authenticationClient.GetSessionKey();
|
||||
}
|
||||
return reply.Header.Status;
|
||||
}
|
||||
else
|
||||
{
|
||||
return reply.Header.Status;
|
||||
}
|
||||
}
|
||||
return NTStatus.STATUS_INVALID_SMB;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public NTStatus Logoff()
|
||||
{
|
||||
|
|
|
@ -257,16 +257,13 @@ namespace SMBLibrary.Client
|
|||
request.SecurityBuffer = negotiateMessage;
|
||||
TrySendCommand(request);
|
||||
SMB2Command response = WaitForCommand(request.MessageID);
|
||||
if (response != null)
|
||||
{
|
||||
if (response.Header.Status == NTStatus.STATUS_MORE_PROCESSING_REQUIRED && response is SessionSetupResponse)
|
||||
while (response is SessionSetupResponse && response.Header.Status == NTStatus.STATUS_MORE_PROCESSING_REQUIRED)
|
||||
{
|
||||
byte[] authenticateMessage = authenticationClient.InitializeSecurityContext(((SessionSetupResponse)response).SecurityBuffer);
|
||||
if (authenticateMessage == null)
|
||||
{
|
||||
return NTStatus.SEC_E_INVALID_TOKEN;
|
||||
}
|
||||
m_sessionKey = authenticationClient.GetSessionKey();
|
||||
|
||||
m_sessionID = response.Header.SessionID;
|
||||
request = new SessionSetupRequest();
|
||||
|
@ -274,11 +271,14 @@ namespace SMBLibrary.Client
|
|||
request.SecurityBuffer = authenticateMessage;
|
||||
TrySendCommand(request);
|
||||
response = WaitForCommand(request.MessageID);
|
||||
if (response != null)
|
||||
}
|
||||
|
||||
if (response is SessionSetupResponse)
|
||||
{
|
||||
m_isLoggedIn = (response.Header.Status == NTStatus.STATUS_SUCCESS);
|
||||
if (m_isLoggedIn)
|
||||
{
|
||||
m_sessionKey = authenticationClient.GetSessionKey();
|
||||
SessionFlags sessionFlags = ((SessionSetupResponse)response).SessionFlags;
|
||||
if ((sessionFlags & SessionFlags.IsGuest) > 0)
|
||||
{
|
||||
|
@ -300,14 +300,11 @@ namespace SMBLibrary.Client
|
|||
}
|
||||
return response.Header.Status;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return response.Header.Status;
|
||||
}
|
||||
}
|
||||
return NTStatus.STATUS_INVALID_SMB;
|
||||
}
|
||||
}
|
||||
|
||||
public NTStatus Logoff()
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue