Przeglądaj źródła

Logging improvement

Tal Aloni 7 lat temu
rodzic
commit
73b27366c5

+ 3 - 3
SMBLibrary/Server/SMB1/CloseHelper.cs

@@ -19,7 +19,7 @@ namespace SMBLibrary.Server.SMB1
             OpenFileObject openFile = session.GetOpenFileObject(request.FID);
             if (openFile == null)
             {
-                state.LogToServer(Severity.Verbose, "Close failed. Invalid FID.");
+                state.LogToServer(Severity.Verbose, "Close failed. Invalid FID. (UID: {0}, TID: {1}, FID: {2})", header.UID, header.TID, request.FID);
                 header.Status = NTStatus.STATUS_SMB_BAD_FID;
                 return new ErrorResponse(request.CommandName);
             }
@@ -27,11 +27,11 @@ namespace SMBLibrary.Server.SMB1
             header.Status = share.FileStore.CloseFile(openFile.Handle);
             if (header.Status != NTStatus.STATUS_SUCCESS)
             {
-                state.LogToServer(Severity.Information, "Close: Closing '{0}{1}' failed. NTStatus: {2}.", share.Name, openFile.Path, header.Status);
+                state.LogToServer(Severity.Information, "Close: Closing '{0}{1}' failed. NTStatus: {2}. (UID: {3}, TID: {4}, FID: {5})", share.Name, openFile.Path, header.Status, header.UID, header.TID, request.FID);
                 return new ErrorResponse(request.CommandName);
             }
 
-            state.LogToServer(Severity.Information, "Close: Closed '{0}{1}'.", share.Name, openFile.Path);
+            state.LogToServer(Severity.Information, "Close: Closed '{0}{1}'. (UID: {2}, TID: {3}, FID: {4})", share.Name, openFile.Path, header.UID, header.TID, request.FID);
             session.RemoveOpenFile(request.FID);
             return new CloseResponse();
         }

+ 1 - 1
SMBLibrary/Server/SMB1/FileStoreResponseHelper.cs

@@ -206,7 +206,7 @@ namespace SMBLibrary.Server.SMB1
             OpenFileObject openFile = session.GetOpenFileObject(request.FID);
             if (openFile == null)
             {
-                state.LogToServer(Severity.Verbose, "Set Information 2 failed. Invalid FID.");
+                state.LogToServer(Severity.Verbose, "Set Information 2 failed. Invalid FID. (UID: {0}, TID: {1}, FID: {2})", header.UID, header.TID, request.FID);
                 header.Status = NTStatus.STATUS_SMB_BAD_FID;
                 return new ErrorResponse(request.CommandName);
             }

+ 1 - 1
SMBLibrary/Server/SMB1/LockingHelper.cs

@@ -19,7 +19,7 @@ namespace SMBLibrary.Server.SMB1
             OpenFileObject openFile = session.GetOpenFileObject(request.FID);
             if (openFile == null)
             {
-                state.LogToServer(Severity.Verbose, "Locking failed. Invalid FID.");
+                state.LogToServer(Severity.Verbose, "Locking failed. Invalid FID. (UID: {0}, TID: {1}, FID: {2})", header.UID, header.TID, request.FID);
                 header.Status = NTStatus.STATUS_INVALID_HANDLE;
                 return new ErrorResponse(request.CommandName);
             }

+ 2 - 1
SMBLibrary/Server/SMB1/NTCreateHelper.cs

@@ -50,15 +50,16 @@ namespace SMBLibrary.Server.SMB1
                 return new ErrorResponse(request.CommandName);
             }
 
-            state.LogToServer(Severity.Verbose, "Create: Opened '{0}{1}'.", share.Name, path);
             ushort? fileID = session.AddOpenFile(header.TID, share.Name, path, handle);
             if (!fileID.HasValue)
             {
                 share.FileStore.CloseFile(handle);
+                state.LogToServer(Severity.Verbose, "Create: Opening '{0}{1}' failed. Too many open files.", share.Name, path);
                 header.Status = NTStatus.STATUS_TOO_MANY_OPENED_FILES;
                 return new ErrorResponse(request.CommandName);
             }
 
+            state.LogToServer(Severity.Verbose, "Create: Opened '{0}{1}'. (UID: {2}, TID: {3}, FID: {4})", share.Name, path, header.UID, header.TID, fileID.Value);
             if (share is NamedPipeShare)
             {
                 if (isExtended)

+ 1 - 1
SMBLibrary/Server/SMB1/NTTransactHelper.cs

@@ -144,7 +144,7 @@ namespace SMBLibrary.Server.SMB1
             OpenFileObject openFile = session.GetOpenFileObject(subcommand.FID);
             if (openFile == null)
             {
-                state.LogToServer(Severity.Verbose, "IOCTL failed. CTL Code: {0}. Invalid FID.", ctlCode);
+                state.LogToServer(Severity.Verbose, "IOCTL failed. CTL Code: {0}. Invalid FID. (UID: {1}, TID: {2}, FID: {3})", ctlCode, header.UID, header.TID, subcommand.FID);
                 header.Status = NTStatus.STATUS_INVALID_HANDLE;
                 return null;
             }

+ 2 - 1
SMBLibrary/Server/SMB1/OpenAndXHelper.cs

@@ -63,15 +63,16 @@ namespace SMBLibrary.Server.SMB1
                 return new ErrorResponse(request.CommandName);
             }
 
-            state.LogToServer(Severity.Verbose, "OpenAndX: Opened '{0}{1}'.", share.Name, path);
             ushort? fileID = session.AddOpenFile(header.TID, share.Name, path, handle);
             if (!fileID.HasValue)
             {
                 share.FileStore.CloseFile(handle);
+                state.LogToServer(Severity.Verbose, "Create: Opening '{0}{1}' failed. Too many open files.", share.Name, path);
                 header.Status = NTStatus.STATUS_TOO_MANY_OPENED_FILES;
                 return new ErrorResponse(request.CommandName);
             }
 
+            state.LogToServer(Severity.Verbose, "OpenAndX: Opened '{0}{1}'. (UID: {2}, TID: {3}, FID: {4})", share.Name, path, header.UID, header.TID, fileID.Value);
             OpenResult openResult = ToOpenResult(fileStatus);
             if (share is NamedPipeShare)
             {

+ 5 - 5
SMBLibrary/Server/SMB1/ReadWriteResponseHelper.cs

@@ -23,7 +23,7 @@ namespace SMBLibrary.Server.SMB1
             OpenFileObject openFile = session.GetOpenFileObject(request.FID);
             if (openFile == null)
             {
-                state.LogToServer(Severity.Verbose, "Read failed. Invalid FID.");
+                state.LogToServer(Severity.Verbose, "Read failed. Invalid FID. (UID: {0}, TID: {1}, FID: {2})", header.UID, header.TID, request.FID);
                 header.Status = NTStatus.STATUS_INVALID_HANDLE;
                 return new ErrorResponse(request.CommandName);
             }
@@ -58,7 +58,7 @@ namespace SMBLibrary.Server.SMB1
             OpenFileObject openFile = session.GetOpenFileObject(request.FID);
             if (openFile == null)
             {
-                state.LogToServer(Severity.Verbose, "Read failed. Invalid FID.");
+                state.LogToServer(Severity.Verbose, "Read failed. Invalid FID. (UID: {0}, TID: {1}, FID: {2})", header.UID, header.TID, request.FID);
                 header.Status = NTStatus.STATUS_INVALID_HANDLE;
                 return new ErrorResponse(request.CommandName);
             }
@@ -109,7 +109,7 @@ namespace SMBLibrary.Server.SMB1
             OpenFileObject openFile = session.GetOpenFileObject(request.FID);
             if (openFile == null)
             {
-                state.LogToServer(Severity.Verbose, "Write failed. Invalid FID.");
+                state.LogToServer(Severity.Verbose, "Write failed. Invalid FID. (UID: {0}, TID: {1}, FID: {2})", header.UID, header.TID, request.FID);
                 header.Status = NTStatus.STATUS_INVALID_HANDLE;
                 return new ErrorResponse(request.CommandName);
             }
@@ -142,7 +142,7 @@ namespace SMBLibrary.Server.SMB1
             OpenFileObject openFile = session.GetOpenFileObject(request.FID);
             if (openFile == null)
             {
-                state.LogToServer(Severity.Verbose, "Write failed. Invalid FID.");
+                state.LogToServer(Severity.Verbose, "Write failed. Invalid FID. (UID: {0}, TID: {1}, FID: {2})", header.UID, header.TID, request.FID);
                 header.Status = NTStatus.STATUS_INVALID_HANDLE;
                 return new ErrorResponse(request.CommandName);
             }
@@ -188,7 +188,7 @@ namespace SMBLibrary.Server.SMB1
             OpenFileObject openFile = session.GetOpenFileObject(request.FID);
             if (openFile == null)
             {
-                state.LogToServer(Severity.Verbose, "Flush failed. Invalid FID.");
+                state.LogToServer(Severity.Verbose, "Flush failed. Invalid FID. (UID: {0}, TID: {1}, FID: {2})", header.UID, header.TID, request.FID);
                 header.Status = NTStatus.STATUS_INVALID_HANDLE;
                 return new ErrorResponse(request.CommandName);
             }

+ 2 - 2
SMBLibrary/Server/SMB1/Transaction2SubcommandHelper.cs

@@ -198,7 +198,7 @@ namespace SMBLibrary.Server.SMB1
             OpenFileObject openFile = session.GetOpenFileObject(subcommand.FID);
             if (openFile == null)
             {
-                state.LogToServer(Severity.Verbose, "QueryFileInformation failed. Invalid FID.");
+                state.LogToServer(Severity.Verbose, "QueryFileInformation failed. Invalid FID. (UID: {0}, TID: {1}, FID: {2})", header.UID, header.TID, subcommand.FID);
                 header.Status = NTStatus.STATUS_INVALID_HANDLE;
                 return null;
             }
@@ -233,7 +233,7 @@ namespace SMBLibrary.Server.SMB1
             OpenFileObject openFile = session.GetOpenFileObject(subcommand.FID);
             if (openFile == null)
             {
-                state.LogToServer(Severity.Verbose, "SetFileInformation failed. Invalid FID.");
+                state.LogToServer(Severity.Verbose, "SetFileInformation failed. Invalid FID. (UID: {0}, TID: {1}, FID: {2})", header.UID, header.TID, subcommand.FID);
                 header.Status = NTStatus.STATUS_INVALID_HANDLE;
                 return null;
             }

+ 1 - 1
SMBLibrary/Server/SMB1/TransactionSubcommandHelper.cs

@@ -22,7 +22,7 @@ namespace SMBLibrary.Server.SMB1
             OpenFileObject openFile = session.GetOpenFileObject(subcommand.FID);
             if (openFile == null)
             {
-                state.LogToServer(Severity.Verbose, "TransactNamedPipe failed. Invalid FID.");
+                state.LogToServer(Severity.Verbose, "TransactNamedPipe failed. Invalid FID. (UID: {0}, TID: {1}, FID: {2})", header.UID, header.TID, subcommand.FID);
                 header.Status = NTStatus.STATUS_INVALID_HANDLE;
                 return null;
             }

+ 3 - 3
SMBLibrary/Server/SMB2/CloseHelper.cs

@@ -20,18 +20,18 @@ namespace SMBLibrary.Server.SMB2
             OpenFileObject openFile = session.GetOpenFileObject(request.FileId);
             if (openFile == null)
             {
-                state.LogToServer(Severity.Verbose, "Close failed. Invalid FileId.");
+                state.LogToServer(Severity.Verbose, "Close failed. Invalid FileId. (SessionID: {0}, TreeID: {1}, FileId: {2})", request.Header.SessionID, request.Header.TreeID, request.FileId.Volatile);
                 return new ErrorResponse(request.CommandName, NTStatus.STATUS_FILE_CLOSED);
             }
 
             NTStatus closeStatus = share.FileStore.CloseFile(openFile.Handle);
             if (closeStatus != NTStatus.STATUS_SUCCESS)
             {
-                state.LogToServer(Severity.Information, "Close: Closing '{0}{1}' failed. NTStatus: {2}.", share.Name, openFile.Path, closeStatus);
+                state.LogToServer(Severity.Information, "Close: Closing '{0}{1}' failed. NTStatus: {2}. (SessionID: {3}, TreeID: {4}, FileId: {5})", share.Name, openFile.Path, closeStatus, request.Header.SessionID, request.Header.TreeID, request.FileId.Volatile);
                 return new ErrorResponse(request.CommandName, closeStatus);
             }
 
-            state.LogToServer(Severity.Information, "Close: Closed '{0}{1}'.", share.Name, openFile.Path);
+            state.LogToServer(Severity.Information, "Close: Closed '{0}{1}'. (SessionID: {2}, TreeID: {3}, FileId: {4})", share.Name, openFile.Path, request.Header.SessionID, request.Header.TreeID, request.FileId.Volatile);
             session.RemoveOpenFile(request.FileId);
             CloseResponse response = new CloseResponse();
             if (request.PostQueryAttributes)

+ 2 - 1
SMBLibrary/Server/SMB2/CreateHelper.cs

@@ -44,14 +44,15 @@ namespace SMBLibrary.Server.SMB2
                 return new ErrorResponse(request.CommandName, createStatus);
             }
 
-            state.LogToServer(Severity.Verbose, "Create: Opened '{0}{1}'.", share.Name, path);
             FileID? fileID = session.AddOpenFile(request.Header.TreeID, share.Name, path, handle);
             if (fileID == null)
             {
                 share.FileStore.CloseFile(handle);
+                state.LogToServer(Severity.Verbose, "Create: Opening '{0}{1}' failed. Too many open files.", share.Name, path);
                 return new ErrorResponse(request.CommandName, NTStatus.STATUS_TOO_MANY_OPENED_FILES);
             }
 
+            state.LogToServer(Severity.Verbose, "Create: Opened '{0}{1}'. (SessionID: {2}, TreeID: {3}, FileId: {4})", share.Name, path, request.Header.SessionID, request.Header.TreeID, fileID.Value.Volatile);
             if (share is NamedPipeShare)
             {
                 return CreateResponseForNamedPipe(fileID.Value, FileStatus.FILE_OPENED);

+ 2 - 2
SMBLibrary/Server/SMB2/IOCtlHelper.cs

@@ -42,7 +42,7 @@ namespace SMBLibrary.Server.SMB2
                 // FSCTL_VALIDATE_NEGOTIATE_INFO requests MUST have FileId set to 0xFFFFFFFFFFFFFFFF.
                 if (request.FileId.Persistent != 0xFFFFFFFFFFFFFFFF || request.FileId.Volatile != 0xFFFFFFFFFFFFFFFF)
                 {
-                    state.LogToServer(Severity.Verbose, "IOCTL failed. CTL Code: {0}. Invalid FileId.", ctlCode);
+                    state.LogToServer(Severity.Verbose, "IOCTL failed. CTL Code: {0}. FileId MUST be 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", ctlCode);
                     return new ErrorResponse(request.CommandName, NTStatus.STATUS_INVALID_PARAMETER);
                 }
                 handle = null;
@@ -52,7 +52,7 @@ namespace SMBLibrary.Server.SMB2
                 OpenFileObject openFile = session.GetOpenFileObject(request.FileId);
                 if (openFile == null)
                 {
-                    state.LogToServer(Severity.Verbose, "IOCTL failed. CTL Code: {0}. Invalid FileId.", ctlCode);
+                    state.LogToServer(Severity.Verbose, "IOCTL failed. CTL Code: {0}. Invalid FileId. (SessionID: {1}, TreeID: {2}, FileId: {3})", ctlCode, request.Header.SessionID, request.Header.TreeID, request.FileId.Volatile);
                     return new ErrorResponse(request.CommandName, NTStatus.STATUS_FILE_CLOSED);
                 }
                 handle = openFile.Handle;

+ 1 - 1
SMBLibrary/Server/SMB2/LockHelper.cs

@@ -20,7 +20,7 @@ namespace SMBLibrary.Server.SMB2
             OpenFileObject openFile = session.GetOpenFileObject(request.FileId);
             if (openFile == null)
             {
-                state.LogToServer(Severity.Verbose, "Lock failed. Invalid FileId.");
+                state.LogToServer(Severity.Verbose, "Lock failed. Invalid FileId. (SessionID: {0}, TreeID: {1}, FileId: {2})", request.Header.SessionID, request.Header.TreeID, request.FileId.Volatile);
                 return new ErrorResponse(request.CommandName, NTStatus.STATUS_FILE_CLOSED);
             }
 

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

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

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

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

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

@@ -20,7 +20,7 @@ namespace SMBLibrary.Server.SMB2
             OpenFileObject openFile = session.GetOpenFileObject(request.FileId);
             if (openFile == null)
             {
-                state.LogToServer(Severity.Verbose, "Read failed. Invalid FileId.");
+                state.LogToServer(Severity.Verbose, "Read failed. Invalid FileId. (SessionID: {0}, TreeID: {1}, FileId: {2})", request.Header.SessionID, request.Header.TreeID, request.FileId.Volatile);
                 return new ErrorResponse(request.CommandName, NTStatus.STATUS_FILE_CLOSED);
             }
 
@@ -51,7 +51,7 @@ namespace SMBLibrary.Server.SMB2
             OpenFileObject openFile = session.GetOpenFileObject(request.FileId);
             if (openFile == null)
             {
-                state.LogToServer(Severity.Verbose, "Write failed. Invalid FileId.");
+                state.LogToServer(Severity.Verbose, "Write failed. Invalid FileId. (SessionID: {0}, TreeID: {1}, FileId: {2})", request.Header.SessionID, request.Header.TreeID, request.FileId.Volatile);
                 return new ErrorResponse(request.CommandName, NTStatus.STATUS_FILE_CLOSED);
             }
 
@@ -82,7 +82,7 @@ namespace SMBLibrary.Server.SMB2
             OpenFileObject openFile = session.GetOpenFileObject(request.FileId);
             if (openFile == null)
             {
-                state.LogToServer(Severity.Verbose, "Flush failed. Invalid FileId.");
+                state.LogToServer(Severity.Verbose, "Flush failed. Invalid FileId. (SessionID: {0}, TreeID: {1}, FileId: {2})", request.Header.SessionID, request.Header.TreeID, request.FileId.Volatile);
                 return new ErrorResponse(request.CommandName, NTStatus.STATUS_FILE_CLOSED);
             }
             NTStatus status = share.FileStore.FlushFileBuffers(openFile.Handle);

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

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