예제 #1
0
        public async void CreateDirectory_Correct()
        {
            var optionsMock = GetAppSettingsMock();
            var queueMock   = GetQueueMock();

            var guardMock = new Mock <IGuardApi>();

            guardMock.Setup(api => api.AddDirectory(
                                It.IsAny <string>(),
                                It.IsAny <string>(),
                                It.IsAny <string>()))
            .ReturnsAsync(true);

            var writeObjectsController = new WriteObjectsController(optionsMock.Object, guardMock.Object, null, queueMock.Object);

            var request = new CreateDirectoryRequest()
            {
                SubDirectoryName = "MySubDir"
            };

            var response = await writeObjectsController.CreateDirectory(IdGenerator.NewId(IdType.Directory), request);

            var metadataResponseObject = Assert.IsType <OkObjectResult>(response);
            var newDirectoryId         = Assert.IsType <string>(metadataResponseObject.Value);

            Assert.True(IdGenerator.TypeFromId(newDirectoryId, out var typeOfId));
            Assert.Equal(IdType.Directory, typeOfId);
        }
예제 #2
0
    public IObjects Get(IObjects request)
    {
        CreateDirectoryRequest t = (CreateDirectoryRequest)request;

        CreateNewDirectory(t.directory);
        return(t);
    }
        internal CreateDirectoryResponse CreateDirectory(CreateDirectoryRequest request)
        {
            var marshaller   = new CreateDirectoryRequestMarshaller();
            var unmarshaller = CreateDirectoryResponseUnmarshaller.Instance;

            return(Invoke <CreateDirectoryRequest, CreateDirectoryResponse>(request, marshaller, unmarshaller));
        }
예제 #4
0
        internal static SMBCommand GetCreateDirectoryResponse(SMBHeader header, CreateDirectoryRequest request, FileSystemShare share, StateObject state)
        {
            string userName = state.GetConnectedUserName(header.UID);

            if (!share.HasWriteAccess(userName))
            {
                header.Status = NTStatus.STATUS_ACCESS_DENIED;
                return(new ErrorResponse(CommandName.SMB_COM_CREATE_DIRECTORY));
            }
            IFileSystem fileSystem = share.FileSystem;

            try
            {
                fileSystem.CreateDirectory(request.DirectoryName);
            }
            catch (IOException)
            {
                header.Status = NTStatus.STATUS_OBJECT_NAME_INVALID;
                return(new ErrorResponse(CommandName.SMB_COM_CREATE_DIRECTORY));
            }
            catch (UnauthorizedAccessException)
            {
                header.Status = NTStatus.STATUS_ACCESS_DENIED;
                return(new ErrorResponse(CommandName.SMB_COM_CREATE_DIRECTORY));
            }

            return(new CreateDirectoryResponse());
        }
예제 #5
0
        public async Task <FileSystemResult <IDirectory> > CreateDirectoryAsync(string name, Dictionary <string, object> properties)
        {
            if (properties == null)
            {
                properties = new Dictionary <string, object>();
            }
            CreateDirectoryRequest req = new CreateDirectoryRequest();

            req.Name   = name;
            req.Folder = new Folder();
            string requesturl = CreateDir.FormatRest(this is OneDriveRoot ? "root" : Id);
            FileSystemResult <ExpandoObject> ex = await FS.OAuth.CreateMetadataStream <ExpandoObject>(requesturl, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(req)), "application/json");

            if (ex.IsOk)
            {
                string id;
                if (InternalTryGetProperty(ex.Result, "id", out id))
                {
                    FileSystemResult <ExpandoObject> ex2 =
                        await FS.OAuth.CreateMetadataStream <ExpandoObject>(Item.FormatRest(FS.OneDriveUrl, id));

                    OneDriveDirectory dir = new OneDriveDirectory(FullName, FS)
                    {
                        Parent = this
                    };
                    dir.SetData(JsonConvert.SerializeObject(ex.Result));
                    FS.Refs[dir.FullName] = dir;
                    _directories.Add(dir);
                    return(new FileSystemResult <IDirectory>(dir));
                }
                return(new FileSystemResult <IDirectory>("Unable to get id from the created directory"));
            }
            return(new FileSystemResult <IDirectory>(ex.Error));
        }
        /// <summary>
        /// Initiates the asynchronous execution of the CreateDirectory operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the CreateDirectory operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public Task <CreateDirectoryResponse> CreateDirectoryAsync(CreateDirectoryRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = new CreateDirectoryRequestMarshaller();
            var unmarshaller = CreateDirectoryResponseUnmarshaller.Instance;

            return(InvokeAsync <CreateDirectoryRequest, CreateDirectoryResponse>(request, marshaller,
                                                                                 unmarshaller, cancellationToken));
        }
예제 #7
0
        /// <summary>
        ///     Create a new directory in the given library
        /// </summary>
        /// <param name="libraryId">The id of the library to create the directory in</param>
        /// <param name="path">Path of the directory to create</param>
        /// <returns>A value which indicates if the creation was successful</returns>
        public async Task <bool> CreateDirectory(string libraryId, string path)
        {
            libraryId.ThrowOnNull(nameof(libraryId));
            path.ThrowOnNull(nameof(path));

            var request = new CreateDirectoryRequest(AuthToken, libraryId, path);

            return(await _webConnection.SendRequestAsync(ServerUri, request));
        }
예제 #8
0
        public async Task <ServiceResponse <IDirectory> > CreateDirectory(CreateDirectoryRequest request)
        {
            try
            {
                var directory = await _fileSystem.CreateDirectory(request.Path);

                return(new ServiceResponse <IDirectory>(directory));
            }
            catch (Exception exception)
            {
                _logger.LogWarning(exception, $"Could not create Directory: {request.Path}");
                return(new ServiceResponse <IDirectory>(exception));
            }
        }
예제 #9
0
        public void CopyToVM(string localFilePathGlob, string remoteFilePath, bool recursive, bool force)
        {
            CheckProfileCanResolveSlave();

            Log(string.Format("Copying from local path '{0}' to remote path '{1}'{2}{3}.", localFilePathGlob, remoteFilePath,
                              recursive ? " recursively" : "",
                              force ? " force overwrite" : ""));

            var client = GetSlaveClient();

            bool foundFile = FileUtil.TraverseFiles(localFilePathGlob, recursive,
                                                    (file, relativePath) =>
            {
                Log(string.Format("Copying '{0}'.", relativePath));

                byte[] contents = File.ReadAllBytes(file.FullName);

                WriteFileRequest request = new WriteFileRequest()
                {
                    Contents  = contents,
                    Path      = Path.Combine(remoteFilePath, relativePath),
                    Overwrite = force
                };
                client.WriteFile(request);
            },
                                                    (directory, relativePath) =>
            {
                Log(string.Format("Creating directory '{0}'.", relativePath));

                CreateDirectoryRequest request = new CreateDirectoryRequest()
                {
                    Path = Path.Combine(remoteFilePath, relativePath)
                };
                client.CreateDirectory(request);
            });

            if (!foundFile && !FileUtil.HasWildcard(localFilePathGlob))
            {
                throw new OperationFailedException()
                      {
                          Why = string.Format("Local file{0} not found '{1}'.", recursive ? " or directory" : "", localFilePathGlob)
                      }
            }
            ;
        }
예제 #10
0
        public override CreateDirectoryResponse CreateDirectory(CreateDirectoryRequest request)
        {
            log.InfoFormat("CreateDirectory:\n  Path: {0}", request.Path);

            try
            {
                if (!Directory.Exists(request.Path))
                {
                    Directory.CreateDirectory(request.Path);
                }
            }
            catch (Exception ex)
            {
                throw OperationFailed(string.Format("Could not read file '{0}'.", request.Path), ex.Message);
            }

            return(new CreateDirectoryResponse());
        }
        public async Task <IActionResult> CreateDirectory(
            [FromRoute] string directoryId,
            [FromBody] CreateDirectoryRequest createDirectoryRequest
            )
        {
            try
            {
                var createDirectoryMetadata = await writeApi.ObjectApi.CreateDirectory(
                    directoryId,
                    createDirectoryRequest.SubDirectoryName);

                var responseObject = new DirectoryMetadataResponse(createDirectoryMetadata);
                return(Ok(responseObject));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(BadRequest());
            }
        }
        internal static SMB1Command GetCreateDirectoryResponse(SMB1Header header, CreateDirectoryRequest request, ISMBShare share, SMB1ConnectionState state)
        {
            SMB1Session session = state.GetSession(header.UID);

            if (share is FileSystemShare)
            {
                if (!((FileSystemShare)share).HasWriteAccess(session.SecurityContext, request.DirectoryName))
                {
                    state.LogToServer(Severity.Verbose, "Create Directory '{0}{1}' failed. User '{2}' was denied access.", share.Name, request.DirectoryName, session.UserName);
                    header.Status = NTStatus.STATUS_ACCESS_DENIED;
                    return(new ErrorResponse(request.CommandName));
                }
            }

            header.Status = SMB1FileStoreHelper.CreateDirectory(share.FileStore, request.DirectoryName, session.SecurityContext);
            if (header.Status != NTStatus.STATUS_SUCCESS)
            {
                return(new ErrorResponse(request.CommandName));
            }

            return(new CreateDirectoryResponse());
        }
        public async Task <IActionResult> CreateDirectory(
            [FromRoute] string directoryId,
            [FromBody] CreateDirectoryRequest createDirectoryRequest
            )
        {
            #region - Input data validation -

            if (!IdGenerator.TypeFromId(directoryId, out var typOfId) || typOfId != IdType.Directory)
            {
                return(BadRequest());
            }

            if (string.IsNullOrWhiteSpace(createDirectoryRequest.SubDirectoryName))
            {
                return(BadRequest());
            }

            #endregion


            try
            {
                var newDirectoryId = IdGenerator.NewId(IdType.Directory);
                var successful     = await guardApi.AddDirectory(directoryId, createDirectoryRequest.SubDirectoryName, newDirectoryId);

                if (!successful)
                {
                    return(BadRequest());
                }

                return(Ok(newDirectoryId));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(BadRequest());
            }
        }
예제 #14
0
        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(ServerResponseHelper.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)
                {
                    TreeConnectAndXRequest request = (TreeConnectAndXRequest)command;
                    return(TreeConnectHelper.GetTreeConnectResponse(header, request, state, m_services, m_shares));
                }
                else if (command is LogoffAndXRequest)
                {
                    state.LogToServer(Severity.Information, "Logoff: User '{0}' logged off.", session.UserName);
                    m_securityProvider.DeleteSecurityContext(ref session.SecurityContext.AuthenticationContext);
                    state.RemoveSession(header.UID);
                    return(new LogoffAndXResponse());
                }
                else
                {
                    ISMBShare share = session.GetConnectedTree(header.TID);
                    if (share == null)
                    {
                        header.Status = NTStatus.STATUS_SMB_BAD_TID;
                        return(new ErrorResponse(command.CommandName));
                    }

                    if (command is CreateDirectoryRequest)
                    {
                        CreateDirectoryRequest request = (CreateDirectoryRequest)command;
                        return(FileStoreResponseHelper.GetCreateDirectoryResponse(header, request, share, state));
                    }
                    else if (command is DeleteDirectoryRequest)
                    {
                        DeleteDirectoryRequest request = (DeleteDirectoryRequest)command;
                        return(FileStoreResponseHelper.GetDeleteDirectoryResponse(header, request, share, state));
                    }
                    else if (command is CloseRequest)
                    {
                        CloseRequest request = (CloseRequest)command;
                        return(ServerResponseHelper.GetCloseResponse(header, request, share, state));
                    }
                    else if (command is FlushRequest)
                    {
                        return(new FlushResponse());
                    }
                    else if (command is DeleteRequest)
                    {
                        DeleteRequest request = (DeleteRequest)command;
                        return(FileStoreResponseHelper.GetDeleteResponse(header, request, share, state));
                    }
                    else if (command is RenameRequest)
                    {
                        RenameRequest request = (RenameRequest)command;
                        return(FileStoreResponseHelper.GetRenameResponse(header, request, share, state));
                    }
                    else if (command is QueryInformationRequest)
                    {
                        QueryInformationRequest request = (QueryInformationRequest)command;
                        return(FileStoreResponseHelper.GetQueryInformationResponse(header, request, share, state));
                    }
                    else if (command is SetInformationRequest)
                    {
                        SetInformationRequest request = (SetInformationRequest)command;
                        return(FileStoreResponseHelper.GetSetInformationResponse(header, request, share, state));
                    }
                    else if (command is ReadRequest)
                    {
                        ReadRequest request = (ReadRequest)command;
                        return(ReadWriteResponseHelper.GetReadResponse(header, request, share, state));
                    }
                    else if (command is WriteRequest)
                    {
                        WriteRequest request = (WriteRequest)command;
                        return(ReadWriteResponseHelper.GetWriteResponse(header, request, share, state));
                    }
                    else if (command is CheckDirectoryRequest)
                    {
                        CheckDirectoryRequest request = (CheckDirectoryRequest)command;
                        return(FileStoreResponseHelper.GetCheckDirectoryResponse(header, request, 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)
                    {
                        SetInformation2Request request = (SetInformation2Request)command;
                        return(FileStoreResponseHelper.GetSetInformation2Response(header, request, share, state));
                    }
                    else if (command is LockingAndXRequest)
                    {
                        header.Status = NTStatus.STATUS_ACCESS_DENIED;
                        return(new ErrorResponse(command.CommandName));
                    }
                    else if (command is OpenAndXRequest)
                    {
                        OpenAndXRequest request = (OpenAndXRequest)command;
                        return(OpenAndXHelper.GetOpenAndXResponse(header, request, share, state));
                    }
                    else if (command is ReadAndXRequest)
                    {
                        ReadAndXRequest request = (ReadAndXRequest)command;
                        return(ReadWriteResponseHelper.GetReadResponse(header, request, share, state));
                    }
                    else if (command is WriteAndXRequest)
                    {
                        WriteAndXRequest request = (WriteAndXRequest)command;
                        return(ReadWriteResponseHelper.GetWriteResponse(header, request, share, state));
                    }
                    else if (command is FindClose2Request)
                    {
                        return(ServerResponseHelper.GetFindClose2Request(header, (FindClose2Request)command, state));
                    }
                    else if (command is TreeDisconnectRequest)
                    {
                        TreeDisconnectRequest request = (TreeDisconnectRequest)command;
                        return(TreeConnectHelper.GetTreeDisconnectResponse(header, request, share, state));
                    }
                    else if (command is TransactionRequest) // Both TransactionRequest and Transaction2Request
                    {
                        TransactionRequest request = (TransactionRequest)command;
                        return(TransactionHelper.GetTransactionResponse(header, request, share, state));
                    }
                    else if (command is TransactionSecondaryRequest) // Both TransactionSecondaryRequest and Transaction2SecondaryRequest
                    {
                        TransactionSecondaryRequest request = (TransactionSecondaryRequest)command;
                        return(TransactionHelper.GetTransactionResponse(header, request, share, state));
                    }
                    else if (command is NTTransactRequest)
                    {
                        NTTransactRequest request = (NTTransactRequest)command;
                        return(NTTransactHelper.GetNTTransactResponse(header, request, share, state));
                    }
                    else if (command is NTTransactSecondaryRequest)
                    {
                        NTTransactSecondaryRequest request = (NTTransactSecondaryRequest)command;
                        return(NTTransactHelper.GetNTTransactResponse(header, request, share, state));
                    }
                    else if (command is NTCreateAndXRequest)
                    {
                        NTCreateAndXRequest request = (NTCreateAndXRequest)command;
                        return(NTCreateHelper.GetNTCreateResponse(header, request, share, state));
                    }
                }
            }

            header.Status = NTStatus.STATUS_SMB_BAD_COMMAND;
            return(new ErrorResponse(command.CommandName));
        }
예제 #15
0
 public abstract CreateDirectoryResponse CreateDirectory(CreateDirectoryRequest request);
예제 #16
0
        public override CreateDirectoryResponse CreateDirectory(CreateDirectoryRequest request)
        {
            log.InfoFormat("CreateDirectory:\n  Path: {0}", request.Path);

            try
            {
                if (!Directory.Exists(request.Path))
                    Directory.CreateDirectory(request.Path);
            }
            catch (Exception ex)
            {
                throw OperationFailed(string.Format("Could not read file '{0}'.", request.Path), ex.Message);
            }

            return new CreateDirectoryResponse();
        }
예제 #17
0
 public abstract CreateDirectoryResponse CreateDirectory(CreateDirectoryRequest request);
예제 #18
0
        public void CopyToVM(string localFilePathGlob, string remoteFilePath, bool recursive, bool force)
        {
            CheckProfileCanResolveSlave();

            Log(string.Format("Copying from local path '{0}' to remote path '{1}'{2}{3}.", localFilePathGlob, remoteFilePath,
                recursive ? " recursively" : "",
                force ? " force overwrite" : ""));

            var client = GetSlaveClient();

            bool foundFile = FileUtil.TraverseFiles(localFilePathGlob, recursive,
                (file, relativePath) =>
                {
                    Log(string.Format("Copying '{0}'.", relativePath));

                    byte[] contents = File.ReadAllBytes(file.FullName);

                    WriteFileRequest request = new WriteFileRequest()
                    {
                        Contents = contents,
                        Path = Path.Combine(remoteFilePath, relativePath),
                        Overwrite = force
                    };
                    client.WriteFile(request);
                },
                (directory, relativePath) =>
                {
                    Log(string.Format("Creating directory '{0}'.", relativePath));

                    CreateDirectoryRequest request = new CreateDirectoryRequest()
                    {
                        Path = Path.Combine(remoteFilePath, relativePath)                        
                    };
                    client.CreateDirectory(request);
                });

            if (!foundFile && ! FileUtil.HasWildcard(localFilePathGlob))
                throw new OperationFailedException() {
                    Why = string.Format("Local file{0} not found '{1}'.", recursive ? " or directory" : "", localFilePathGlob) };
        }
예제 #19
0
        /// <summary>
        /// May return null
        /// </summary>
        public SMBCommand ProcessCommand(SMBHeader header, SMBCommand command, StateObject state, List <SMBCommand> sendQueue)
        {
            if (command is NegotiateRequest)
            {
                NegotiateRequest request = (NegotiateRequest)command;
                if (request.Dialects.Contains(SMBServer.NTLanManagerDialect))
                {
                    if (EnableExtendedSecurity && header.ExtendedSecurityFlag)
                    {
                        return(NegotiateHelper.GetNegotiateResponseExtended(request, m_serverGuid));
                    }
                    else
                    {
                        return(new NegotiateResponseNotSupported());
                    }
                }
                else
                {
                    return(new NegotiateResponseNotSupported());
                }
            }
            else if (command is SessionSetupAndXRequest)
            {
                SessionSetupAndXRequest request = (SessionSetupAndXRequest)command;
                state.MaxBufferSize = request.MaxBufferSize;
                //this probably won't work
                return(NegotiateHelper.GetSessionSetupResponse(header, request, state));
            }
            else if (command is SessionSetupAndXRequestExtended)
            {
                SessionSetupAndXRequestExtended request = (SessionSetupAndXRequestExtended)command;
                state.MaxBufferSize = request.MaxBufferSize;
                return(NegotiateHelper.GetSessionSetupResponseExtended(header, request, state));
            }
            else if (command is EchoRequest)
            {
                return(ServerResponseHelper.GetEchoResponse((EchoRequest)command, sendQueue));
            }
            else if (state.IsAuthenticated(header.UID))
            {
                if (command is TreeConnectAndXRequest)
                {
                    TreeConnectAndXRequest request = (TreeConnectAndXRequest)command;
                    return(TreeConnectHelper.GetTreeConnectResponse(header, request, state, m_shares));
                }
                else if (command is LogoffAndXRequest)
                {
                    return(new LogoffAndXResponse());
                }
                else if (state.IsTreeConnected(header.TID))
                {
                    string rootPath = state.GetConnectedTreePath(header.TID);
                    object share;
                    if (state.IsIPC(header.TID))
                    {
                        share = m_services;
                    }
                    else
                    {
                        share = m_shares.GetShareFromRelativePath(rootPath);
                    }

                    if (command is CreateDirectoryRequest)
                    {
                        if (!(share is FileSystemShare))
                        {
                            header.Status = NTStatus.STATUS_SMB_BAD_COMMAND;
                            return(new ErrorResponse(command.CommandName));
                        }
                        CreateDirectoryRequest request = (CreateDirectoryRequest)command;
                        return(FileSystemResponseHelper.GetCreateDirectoryResponse(header, request, (FileSystemShare)share, state));
                    }
                    else if (command is DeleteDirectoryRequest)
                    {
                        if (!(share is FileSystemShare))
                        {
                            header.Status = NTStatus.STATUS_SMB_BAD_COMMAND;
                            return(new ErrorResponse(command.CommandName));
                        }
                        DeleteDirectoryRequest request = (DeleteDirectoryRequest)command;
                        return(FileSystemResponseHelper.GetDeleteDirectoryResponse(header, request, (FileSystemShare)share, state));
                    }
                    else if (command is CloseRequest)
                    {
                        CloseRequest request = (CloseRequest)command;
                        return(ServerResponseHelper.GetCloseResponse(header, request, state));
                    }
                    else if (command is FlushRequest)
                    {
                        return(new FlushResponse());
                    }
                    else if (command is DeleteRequest)
                    {
                        if (!(share is FileSystemShare))
                        {
                            header.Status = NTStatus.STATUS_SMB_BAD_COMMAND;
                            return(new ErrorResponse(command.CommandName));
                        }
                        DeleteRequest request = (DeleteRequest)command;
                        return(FileSystemResponseHelper.GetDeleteResponse(header, request, (FileSystemShare)share, state));
                    }
                    else if (command is RenameRequest)
                    {
                        if (!(share is FileSystemShare))
                        {
                            header.Status = NTStatus.STATUS_SMB_BAD_COMMAND;
                            return(new ErrorResponse(command.CommandName));
                        }
                        RenameRequest request = (RenameRequest)command;
                        return(FileSystemResponseHelper.GetRenameResponse(header, request, (FileSystemShare)share, state));
                    }
                    else if (command is QueryInformationRequest)
                    {
                        if (!(share is FileSystemShare))
                        {
                            header.Status = NTStatus.STATUS_SMB_BAD_COMMAND;
                            return(new ErrorResponse(command.CommandName));
                        }
                        QueryInformationRequest request = (QueryInformationRequest)command;
                        return(FileSystemResponseHelper.GetQueryInformationResponse(header, request, (FileSystemShare)share));
                    }
                    else if (command is SetInformationRequest)
                    {
                        if (!(share is FileSystemShare))
                        {
                            header.Status = NTStatus.STATUS_SMB_BAD_COMMAND;
                            return(new ErrorResponse(command.CommandName));
                        }
                        SetInformationRequest request = (SetInformationRequest)command;
                        return(FileSystemResponseHelper.GetSetInformationResponse(header, request, (FileSystemShare)share, state));
                    }
                    else if (command is ReadRequest)
                    {
                        ReadRequest request = (ReadRequest)command;
                        return(ReadWriteResponseHelper.GetReadResponse(header, request, share, state));
                    }
                    else if (command is WriteRequest)
                    {
                        string userName = state.GetConnectedUserName(header.UID);
                        if (share is FileSystemShare && !((FileSystemShare)share).HasWriteAccess(userName))
                        {
                            header.Status = NTStatus.STATUS_ACCESS_DENIED;
                            return(new ErrorResponse(command.CommandName));
                        }
                        WriteRequest request = (WriteRequest)command;
                        return(ReadWriteResponseHelper.GetWriteResponse(header, request, share, state));
                    }
                    else if (command is CheckDirectoryRequest)
                    {
                        if (!(share is FileSystemShare))
                        {
                            header.Status = NTStatus.STATUS_SMB_BAD_COMMAND;
                            return(new ErrorResponse(command.CommandName));
                        }
                        CheckDirectoryRequest request = (CheckDirectoryRequest)command;
                        return(FileSystemResponseHelper.GetCheckDirectoryResponse(header, request, (FileSystemShare)share));
                    }
                    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)
                    {
                        if (!(share is FileSystemShare))
                        {
                            header.Status = NTStatus.STATUS_SMB_BAD_COMMAND;
                            return(new ErrorResponse(command.CommandName));
                        }
                        SetInformation2Request request = (SetInformation2Request)command;
                        return(FileSystemResponseHelper.GetSetInformation2Response(header, request, (FileSystemShare)share, state));
                    }
                    else if (command is LockingAndXRequest)
                    {
                        header.Status = NTStatus.STATUS_ACCESS_DENIED;
                        return(new ErrorResponse(CommandName.SMB_COM_LOCKING_ANDX));
                    }
                    else if (command is OpenAndXRequest)
                    {
                        OpenAndXRequest request = (OpenAndXRequest)command;
                        return(OpenAndXHelper.GetOpenAndXResponse(header, request, share, state));
                    }
                    else if (command is ReadAndXRequest)
                    {
                        ReadAndXRequest request = (ReadAndXRequest)command;
                        return(ReadWriteResponseHelper.GetReadResponse(header, request, share, state));
                    }
                    else if (command is WriteAndXRequest)
                    {
                        string userName = state.GetConnectedUserName(header.UID);
                        if (share is FileSystemShare && !((FileSystemShare)share).HasWriteAccess(userName))
                        {
                            header.Status = NTStatus.STATUS_ACCESS_DENIED;
                            return(new ErrorResponse(command.CommandName));
                        }
                        WriteAndXRequest request = (WriteAndXRequest)command;
                        return(ReadWriteResponseHelper.GetWriteResponse(header, request, share, state));
                    }
                    else if (command is FindClose2Request)
                    {
                        return(ServerResponseHelper.GetFindClose2Request(header, (FindClose2Request)command, state));
                    }
                    else if (command is TreeDisconnectRequest)
                    {
                        TreeDisconnectRequest request = (TreeDisconnectRequest)command;
                        return(TreeConnectHelper.GetTreeDisconnectResponse(header, request, state));
                    }
                    else if (command is TransactionRequest) // Both TransactionRequest and Transaction2Request
                    {
                        TransactionRequest request = (TransactionRequest)command;
                        try
                        {
                            return(TransactionHelper.GetTransactionResponse(header, request, share, state, sendQueue));
                        }
                        catch (UnsupportedInformationLevelException)
                        {
                            header.Status = NTStatus.STATUS_INVALID_PARAMETER;
                            return(new ErrorResponse(command.CommandName));
                        }
                    }
                    else if (command is TransactionSecondaryRequest) // Both TransactionSecondaryRequest and Transaction2SecondaryRequest
                    {
                        TransactionSecondaryRequest request = (TransactionSecondaryRequest)command;
                        try
                        {
                            return(TransactionHelper.GetTransactionResponse(header, request, share, state, sendQueue));
                        }
                        catch (UnsupportedInformationLevelException)
                        {
                            header.Status = NTStatus.STATUS_INVALID_PARAMETER;
                            return(new ErrorResponse(command.CommandName));
                        }
                    }
                    else if (command is NTTransactRequest)
                    {
                        NTTransactRequest request = (NTTransactRequest)command;
                        return(NTTransactHelper.GetNTTransactResponse(header, request, share, state, sendQueue));
                    }
                    else if (command is NTTransactSecondaryRequest)
                    {
                        NTTransactSecondaryRequest request = (NTTransactSecondaryRequest)command;
                        return(NTTransactHelper.GetNTTransactResponse(header, request, share, state, sendQueue));
                    }
                    else if (command is NTCreateAndXRequest)
                    {
                        NTCreateAndXRequest request = (NTCreateAndXRequest)command;
                        return(NTCreateHelper.GetNTCreateResponse(header, request, share, state));
                    }
                }
                else
                {
                    header.Status = NTStatus.STATUS_SMB_BAD_TID;
                    return(new ErrorResponse(command.CommandName));
                }
            }

            header.Status = NTStatus.STATUS_SMB_BAD_COMMAND;
            return(new ErrorResponse(command.CommandName));
        }