private List <SMB1Command> ProcessSMB1Command(SMB1Header header, SMB1Command command, SMB1ConnectionState state) { if (command is SessionSetupAndXRequest) { SessionSetupAndXRequest request = (SessionSetupAndXRequest)command; state.MaxBufferSize = request.MaxBufferSize; return(SessionSetupHelper.GetSessionSetupResponse(header, request, m_securityProvider, state)); } else if (command is SessionSetupAndXRequestExtended) { SessionSetupAndXRequestExtended request = (SessionSetupAndXRequestExtended)command; state.MaxBufferSize = request.MaxBufferSize; return(SessionSetupHelper.GetSessionSetupResponseExtended(header, request, m_securityProvider, state)); } else if (command is EchoRequest) { return(EchoHelper.GetEchoResponse((EchoRequest)command)); } else { SMB1Session session = state.GetSession(header.UID); if (session == null) { header.Status = NTStatus.STATUS_USER_SESSION_DELETED; return(new ErrorResponse(command.CommandName)); } if (command is TreeConnectAndXRequest) { return(TreeConnectHelper.GetTreeConnectResponse(header, (TreeConnectAndXRequest)command, state, m_services, m_shares)); } else if (command is LogoffAndXRequest) { state.LogToServer(Severity.Information, "Logoff: User '{0}' logged off. (UID: {1})", session.UserName, header.UID); m_securityProvider.DeleteSecurityContext(ref session.SecurityContext.AuthenticationContext); state.RemoveSession(header.UID); return(new LogoffAndXResponse()); } else { ISMBShare share = session.GetConnectedTree(header.TID); if (share == null) { state.LogToServer(Severity.Verbose, "{0} failed. Invalid TID (UID: {1}, TID: {2}).", command.CommandName, header.UID, header.TID); header.Status = NTStatus.STATUS_SMB_BAD_TID; return(new ErrorResponse(command.CommandName)); } if (command is CreateDirectoryRequest) { return(FileStoreResponseHelper.GetCreateDirectoryResponse(header, (CreateDirectoryRequest)command, share, state)); } else if (command is DeleteDirectoryRequest) { return(FileStoreResponseHelper.GetDeleteDirectoryResponse(header, (DeleteDirectoryRequest)command, share, state)); } else if (command is CloseRequest) { return(CloseHelper.GetCloseResponse(header, (CloseRequest)command, share, state)); } else if (command is FlushRequest) { return(ReadWriteResponseHelper.GetFlushResponse(header, (FlushRequest)command, share, state)); } else if (command is DeleteRequest) { return(FileStoreResponseHelper.GetDeleteResponse(header, (DeleteRequest)command, share, state)); } else if (command is RenameRequest) { return(FileStoreResponseHelper.GetRenameResponse(header, (RenameRequest)command, share, state)); } else if (command is QueryInformationRequest) { return(FileStoreResponseHelper.GetQueryInformationResponse(header, (QueryInformationRequest)command, share, state)); } else if (command is SetInformationRequest) { return(FileStoreResponseHelper.GetSetInformationResponse(header, (SetInformationRequest)command, share, state)); } else if (command is ReadRequest) { return(ReadWriteResponseHelper.GetReadResponse(header, (ReadRequest)command, share, state)); } else if (command is WriteRequest) { return(ReadWriteResponseHelper.GetWriteResponse(header, (WriteRequest)command, share, state)); } else if (command is CheckDirectoryRequest) { return(FileStoreResponseHelper.GetCheckDirectoryResponse(header, (CheckDirectoryRequest)command, share, state)); } else if (command is WriteRawRequest) { // [MS-CIFS] 3.3.5.26 - Receiving an SMB_COM_WRITE_RAW Request: // the server MUST verify that the Server.Capabilities include CAP_RAW_MODE, // If an error is detected [..] the Write Raw operation MUST fail and // the server MUST return a Final Server Response [..] with the Count field set to zero. return(new WriteRawFinalResponse()); } else if (command is SetInformation2Request) { return(FileStoreResponseHelper.GetSetInformation2Response(header, (SetInformation2Request)command, share, state)); } else if (command is LockingAndXRequest) { return(LockingHelper.GetLockingAndXResponse(header, (LockingAndXRequest)command, share, state)); } else if (command is OpenAndXRequest) { return(OpenAndXHelper.GetOpenAndXResponse(header, (OpenAndXRequest)command, share, state)); } else if (command is ReadAndXRequest) { return(ReadWriteResponseHelper.GetReadResponse(header, (ReadAndXRequest)command, share, state)); } else if (command is WriteAndXRequest) { return(ReadWriteResponseHelper.GetWriteResponse(header, (WriteAndXRequest)command, share, state)); } else if (command is FindClose2Request) { return(CloseHelper.GetFindClose2Response(header, (FindClose2Request)command, state)); } else if (command is TreeDisconnectRequest) { return(TreeConnectHelper.GetTreeDisconnectResponse(header, (TreeDisconnectRequest)command, share, state)); } else if (command is TransactionRequest) // Both TransactionRequest and Transaction2Request { return(TransactionHelper.GetTransactionResponse(header, (TransactionRequest)command, share, state)); } else if (command is TransactionSecondaryRequest) // Both TransactionSecondaryRequest and Transaction2SecondaryRequest { return(TransactionHelper.GetTransactionResponse(header, (TransactionSecondaryRequest)command, share, state)); } else if (command is NTTransactRequest) { return(NTTransactHelper.GetNTTransactResponse(header, (NTTransactRequest)command, share, state)); } else if (command is NTTransactSecondaryRequest) { return(NTTransactHelper.GetNTTransactResponse(header, (NTTransactSecondaryRequest)command, share, state)); } else if (command is NTCreateAndXRequest) { return(NTCreateHelper.GetNTCreateResponse(header, (NTCreateAndXRequest)command, share, state)); } else if (command is NTCancelRequest) { CancelHelper.ProcessNTCancelRequest(header, (NTCancelRequest)command, share, state); // [MS-CIFS] The SMB_COM_NT_CANCEL command MUST NOT send a response. return(new List <SMB1Command>()); } } } header.Status = NTStatus.STATUS_SMB_BAD_COMMAND; return(new ErrorResponse(command.CommandName)); }