mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-05-06 13:37:49 +02:00
TreeConnectHelper: Code refactoring and logging improvements
This commit is contained in:
parent
e639361c9c
commit
9cd6180e57
4 changed files with 16 additions and 10 deletions
|
@ -41,6 +41,7 @@ namespace SMBLibrary.Server.SMB1
|
||||||
|
|
||||||
if (!((FileSystemShare)share).HasReadAccess(session.SecurityContext, @"\"))
|
if (!((FileSystemShare)share).HasReadAccess(session.SecurityContext, @"\"))
|
||||||
{
|
{
|
||||||
|
state.LogToServer(Severity.Verbose, "Tree Connect to '{0}' failed. User '{1}' was denied access.", share.Name, session.UserName);
|
||||||
header.Status = NTStatus.STATUS_ACCESS_DENIED;
|
header.Status = NTStatus.STATUS_ACCESS_DENIED;
|
||||||
return new ErrorResponse(request.CommandName);
|
return new ErrorResponse(request.CommandName);
|
||||||
}
|
}
|
||||||
|
@ -51,6 +52,7 @@ namespace SMBLibrary.Server.SMB1
|
||||||
header.Status = NTStatus.STATUS_INSUFF_SERVER_RESOURCES;
|
header.Status = NTStatus.STATUS_INSUFF_SERVER_RESOURCES;
|
||||||
return new ErrorResponse(request.CommandName);
|
return new ErrorResponse(request.CommandName);
|
||||||
}
|
}
|
||||||
|
state.LogToServer(Severity.Information, "Tree Connect: User '{0}' connected to '{1}'", session.UserName, share.Name);
|
||||||
header.TID = treeID.Value;
|
header.TID = treeID.Value;
|
||||||
if (isExtended)
|
if (isExtended)
|
||||||
{
|
{
|
||||||
|
@ -89,16 +91,11 @@ namespace SMBLibrary.Server.SMB1
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static SMB1Command GetTreeDisconnectResponse(SMB1Header header, TreeDisconnectRequest request, SMB1ConnectionState state)
|
internal static SMB1Command GetTreeDisconnectResponse(SMB1Header header, TreeDisconnectRequest request, ISMBShare share, SMB1ConnectionState state)
|
||||||
{
|
{
|
||||||
SMB1Session session = state.GetSession(header.UID);
|
SMB1Session session = state.GetSession(header.UID);
|
||||||
if (!session.IsTreeConnected(header.TID))
|
|
||||||
{
|
|
||||||
header.Status = NTStatus.STATUS_SMB_BAD_TID;
|
|
||||||
return new ErrorResponse(request.CommandName);
|
|
||||||
}
|
|
||||||
|
|
||||||
session.DisconnectTree(header.TID);
|
session.DisconnectTree(header.TID);
|
||||||
|
state.LogToServer(Severity.Information, "Tree Disconnect: User '{0}' disconnected from '{1}'", session.UserName, share.Name);
|
||||||
return new TreeDisconnectResponse();
|
return new TreeDisconnectResponse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ namespace SMBLibrary.Server.SMB2
|
||||||
|
|
||||||
if (!((FileSystemShare)share).HasReadAccess(session.SecurityContext, @"\"))
|
if (!((FileSystemShare)share).HasReadAccess(session.SecurityContext, @"\"))
|
||||||
{
|
{
|
||||||
|
state.LogToServer(Severity.Verbose, "Tree Connect to '{0}' failed. User '{1}' was denied access.", share.Name, session.UserName);
|
||||||
return new ErrorResponse(request.CommandName, NTStatus.STATUS_ACCESS_DENIED);
|
return new ErrorResponse(request.CommandName, NTStatus.STATUS_ACCESS_DENIED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,6 +50,7 @@ namespace SMBLibrary.Server.SMB2
|
||||||
{
|
{
|
||||||
return new ErrorResponse(request.CommandName, NTStatus.STATUS_INSUFF_SERVER_RESOURCES);
|
return new ErrorResponse(request.CommandName, NTStatus.STATUS_INSUFF_SERVER_RESOURCES);
|
||||||
}
|
}
|
||||||
|
state.LogToServer(Severity.Information, "Tree Connect: User '{0}' connected to '{1}'", session.UserName, share.Name);
|
||||||
response.Header.TreeID = treeID.Value;
|
response.Header.TreeID = treeID.Value;
|
||||||
response.ShareType = shareType;
|
response.ShareType = shareType;
|
||||||
response.ShareFlags = shareFlags;
|
response.ShareFlags = shareFlags;
|
||||||
|
@ -59,5 +61,13 @@ namespace SMBLibrary.Server.SMB2
|
||||||
FileAccessMask.DELETE | FileAccessMask.READ_CONTROL | FileAccessMask.WRITE_DAC | FileAccessMask.WRITE_OWNER | FileAccessMask.SYNCHRONIZE;
|
FileAccessMask.DELETE | FileAccessMask.READ_CONTROL | FileAccessMask.WRITE_DAC | FileAccessMask.WRITE_OWNER | FileAccessMask.SYNCHRONIZE;
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static SMB2Command GetTreeDisconnectResponse(TreeDisconnectRequest request, ISMBShare share, SMB2ConnectionState state)
|
||||||
|
{
|
||||||
|
SMB2Session session = state.GetSession(request.Header.SessionID);
|
||||||
|
session.DisconnectTree(request.Header.TreeID);
|
||||||
|
state.LogToServer(Severity.Information, "Tree Disconnect: User '{0}' disconnected from '{1}'", session.UserName, share.Name);
|
||||||
|
return new TreeDisconnectResponse();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -252,7 +252,7 @@ namespace SMBLibrary.Server
|
||||||
else if (command is TreeDisconnectRequest)
|
else if (command is TreeDisconnectRequest)
|
||||||
{
|
{
|
||||||
TreeDisconnectRequest request = (TreeDisconnectRequest)command;
|
TreeDisconnectRequest request = (TreeDisconnectRequest)command;
|
||||||
return TreeConnectHelper.GetTreeDisconnectResponse(header, request, state);
|
return TreeConnectHelper.GetTreeDisconnectResponse(header, request, share, state);
|
||||||
}
|
}
|
||||||
else if (command is TransactionRequest) // Both TransactionRequest and Transaction2Request
|
else if (command is TransactionRequest) // Both TransactionRequest and Transaction2Request
|
||||||
{
|
{
|
||||||
|
|
|
@ -136,8 +136,7 @@ namespace SMBLibrary.Server
|
||||||
|
|
||||||
if (command is TreeDisconnectRequest)
|
if (command is TreeDisconnectRequest)
|
||||||
{
|
{
|
||||||
session.DisconnectTree(command.Header.TreeID);
|
return TreeConnectHelper.GetTreeDisconnectResponse((TreeDisconnectRequest)command, share, state);
|
||||||
return new TreeDisconnectResponse();
|
|
||||||
}
|
}
|
||||||
else if (command is CreateRequest)
|
else if (command is CreateRequest)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue