Browse Source

Minor logging improvement

Tal Aloni 7 years ago
parent
commit
7a6469f3c2

+ 12 - 0
SMBLibrary/Server/SMB1/FileStoreResponseHelper.cs

@@ -31,9 +31,11 @@ namespace SMBLibrary.Server.SMB1
             header.Status = SMB1FileStoreHelper.CreateDirectory(share.FileStore, request.DirectoryName, session.SecurityContext);
             if (header.Status != NTStatus.STATUS_SUCCESS)
             {
+                state.LogToServer(Severity.Verbose, "Create Directory '{0}{1}' failed. NTStatus: {2}.", share.Name, request.DirectoryName, header.Status);
                 return new ErrorResponse(request.CommandName);
             }
 
+            state.LogToServer(Severity.Verbose, "Create Directory: User '{0}' created '{1}{2}'.", session.UserName, share.Name, request.DirectoryName);
             return new CreateDirectoryResponse();
         }
 
@@ -53,8 +55,10 @@ namespace SMBLibrary.Server.SMB1
             header.Status = SMB1FileStoreHelper.DeleteDirectory(share.FileStore, request.DirectoryName, session.SecurityContext);
             if (header.Status != NTStatus.STATUS_SUCCESS)
             {
+                state.LogToServer(Severity.Verbose, "Delete Directory '{0}{1}' failed. NTStatus: {2}.", share.Name, request.DirectoryName, header.Status);
                 return new ErrorResponse(request.CommandName);
             }
+            state.LogToServer(Severity.Verbose, "Delete Directory: User '{0}' deleted '{1}{2}'.", session.UserName, share.Name, request.DirectoryName);
             return new DeleteDirectoryResponse();
         }
 
@@ -75,8 +79,10 @@ namespace SMBLibrary.Server.SMB1
             header.Status = SMB1FileStoreHelper.DeleteFile(share.FileStore, request.FileName, session.SecurityContext);
             if (header.Status != NTStatus.STATUS_SUCCESS)
             {
+                state.LogToServer(Severity.Verbose, "Delete '{0}{1}' failed. NTStatus: {2}.", share.Name, request.FileName, header.Status);
                 return new ErrorResponse(request.CommandName);
             }
+            state.LogToServer(Severity.Verbose, "Delete: User '{0}' deleted '{1}{2}'.", session.UserName, share.Name, request.FileName);
             return new DeleteResponse();
         }
 
@@ -102,8 +108,10 @@ namespace SMBLibrary.Server.SMB1
             header.Status = SMB1FileStoreHelper.Rename(share.FileStore, request.OldFileName, request.NewFileName, request.SearchAttributes, session.SecurityContext);
             if (header.Status != NTStatus.STATUS_SUCCESS)
             {
+                state.LogToServer(Severity.Verbose, "Rename '{0}{1}' to '{0}{2}' failed. NTStatus: {3}.", share.Name, request.OldFileName, request.NewFileName, header.Status);
                 return new ErrorResponse(request.CommandName);
             }
+            state.LogToServer(Severity.Verbose, "Rename: User '{0}' renamed '{1}{2}' to '{1}{3}'.", session.UserName, share.Name, request.OldFileName, request.NewFileName);
             return new RenameResponse();
         }
 
@@ -184,9 +192,11 @@ namespace SMBLibrary.Server.SMB1
             header.Status = SMB1FileStoreHelper.SetInformation(share.FileStore, request.FileName, request.FileAttributes, request.LastWriteTime, session.SecurityContext);
             if (header.Status != NTStatus.STATUS_SUCCESS)
             {
+                state.LogToServer(Severity.Verbose, "Set Information on '{0}{1}' failed. NTStatus: {2}", share.Name, request.FileName, header.Status);
                 return new ErrorResponse(request.CommandName);
             }
 
+            state.LogToServer(Severity.Verbose, "Set Information on '{0}{1}' succeeded.", share.Name, request.FileName);
             return new SetInformationResponse();
         }
 
@@ -213,9 +223,11 @@ namespace SMBLibrary.Server.SMB1
             header.Status = SMB1FileStoreHelper.SetInformation2(share.FileStore, openFile.Handle, request.CreationDateTime, request.LastAccessDateTime, request.LastWriteDateTime);
             if (header.Status != NTStatus.STATUS_SUCCESS)
             {
+                state.LogToServer(Severity.Verbose, "Set Information 2 on '{0}{1}' failed. NTStatus: {2}", share.Name, openFile.Path, header.Status);
                 return new ErrorResponse(request.CommandName);
             }
 
+            state.LogToServer(Severity.Verbose, "Set Information 2 on '{0}{1}' succeeded.", share.Name, openFile.Path);
             return new SetInformation2Response();
         }
     }

+ 1 - 0
SMBLibrary/Server/SMB1/ServerResponseHelper.cs

@@ -21,6 +21,7 @@ namespace SMBLibrary.Server.SMB1
             OpenFileObject openFile = session.GetOpenFileObject(request.FID);
             if (openFile == null)
             {
+                state.LogToServer(Severity.Verbose, "Close failed. Invalid FID.");
                 header.Status = NTStatus.STATUS_SMB_BAD_FID;
                 return new ErrorResponse(request.CommandName);
             }

+ 1 - 0
SMBLibrary/Server/SMB2/CloseHelper.cs

@@ -20,6 +20,7 @@ namespace SMBLibrary.Server.SMB2
             OpenFileObject openFile = session.GetOpenFileObject(request.FileId);
             if (openFile == null)
             {
+                state.LogToServer(Severity.Verbose, "Close failed. Invalid FileId.");
                 return new ErrorResponse(request.CommandName, NTStatus.STATUS_FILE_CLOSED);
             }
 

+ 3 - 0
SMBLibrary/Server/SMB2/IOCtlHelper.cs

@@ -38,6 +38,7 @@ namespace SMBLibrary.Server.SMB2
                 }
                 else
                 {
+                    state.LogToServer(Severity.Verbose, "IOCTL failed. Invalid FileId.");
                     return new ErrorResponse(request.CommandName, NTStatus.STATUS_FILE_CLOSED);
                 }
             }
@@ -51,9 +52,11 @@ namespace SMBLibrary.Server.SMB2
             NTStatus status = share.FileStore.DeviceIOControl(handle, request.CtlCode, request.Input, out output, maxOutputLength);
             if (status != NTStatus.STATUS_SUCCESS && status != NTStatus.STATUS_BUFFER_OVERFLOW)
             {
+                state.LogToServer(Severity.Verbose, "IOCTL failed. CTL Code: 0x{0}. NTStatus: {1}.", request.CtlCode.ToString("x"), status);
                 return new ErrorResponse(request.CommandName, status);
             }
 
+            state.LogToServer(Severity.Verbose, "IOCTL succeeded. CTL Code: 0x{0}.", request.CtlCode.ToString("x"));
             IOCtlResponse response = new IOCtlResponse();
             response.Header.Status = status;
             response.CtlCode = request.CtlCode;

+ 1 - 0
SMBLibrary/Server/SMB2/QueryDirectoryHelper.cs

@@ -20,6 +20,7 @@ namespace SMBLibrary.Server.SMB2
             OpenFileObject openFile = session.GetOpenFileObject(request.FileId);
             if (openFile == null)
             {
+                state.LogToServer(Severity.Verbose, "Query Directory failed. Invalid FileId.");
                 return new ErrorResponse(request.CommandName, NTStatus.STATUS_FILE_CLOSED);
             }
 

+ 1 - 0
SMBLibrary/Server/SMB2/QueryInfoHelper.cs

@@ -22,6 +22,7 @@ namespace SMBLibrary.Server.SMB2
                 OpenFileObject openFile = session.GetOpenFileObject(request.FileId);
                 if (openFile == null)
                 {
+                    state.LogToServer(Severity.Verbose, "GetFileInformation failed. Invalid FileId.");
                     return new ErrorResponse(request.CommandName, NTStatus.STATUS_FILE_CLOSED);
                 }
 

+ 3 - 0
SMBLibrary/Server/SMB2/ReadWriteResponseHelper.cs

@@ -20,6 +20,7 @@ namespace SMBLibrary.Server.SMB2
             OpenFileObject openFile = session.GetOpenFileObject(request.FileId);
             if (openFile == null)
             {
+                state.LogToServer(Severity.Verbose, "Read failed. Invalid FileId.");
                 return new ErrorResponse(request.CommandName, NTStatus.STATUS_FILE_CLOSED);
             }
 
@@ -49,6 +50,7 @@ namespace SMBLibrary.Server.SMB2
             OpenFileObject openFile = session.GetOpenFileObject(request.FileId);
             if (openFile == null)
             {
+                state.LogToServer(Severity.Verbose, "Write failed. Invalid FileId.");
                 return new ErrorResponse(request.CommandName, NTStatus.STATUS_FILE_CLOSED);
             }
 
@@ -78,6 +80,7 @@ namespace SMBLibrary.Server.SMB2
             OpenFileObject openFile = session.GetOpenFileObject(request.FileId);
             if (openFile == null)
             {
+                state.LogToServer(Severity.Verbose, "Flush failed. Invalid FileId.");
                 return new ErrorResponse(request.CommandName, NTStatus.STATUS_FILE_CLOSED);
             }
             NTStatus status = share.FileStore.FlushFileBuffers(openFile.Handle);

+ 1 - 0
SMBLibrary/Server/SMB2/SetInfoHelper.cs

@@ -22,6 +22,7 @@ namespace SMBLibrary.Server.SMB2
                 OpenFileObject openFile = session.GetOpenFileObject(request.FileId);
                 if (openFile == null)
                 {
+                    state.LogToServer(Severity.Verbose, "SetFileInformation failed. Invalid FileId.");
                     return new ErrorResponse(request.CommandName, NTStatus.STATUS_FILE_CLOSED);
                 }