internal static SMB1Command GetReadResponse(SMB1Header header, ReadAndXRequest request, ISMBShare share, SMB1ConnectionState state)
        {
            SMB1Session    session  = state.GetSession(header.UID);
            OpenFileObject openFile = session.GetOpenFileObject(request.FID);

            if (openFile == null)
            {
                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));
            }

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

            uint maxCount = request.MaxCount;

            if ((share is FileSystemShare) && state.LargeRead)
            {
                maxCount = request.MaxCountLarge;
            }
            byte[] data;
            header.Status = share.FileStore.ReadFile(out data, openFile.Handle, (long)request.Offset, (int)maxCount);
            if (header.Status == NTStatus.STATUS_END_OF_FILE)
            {
                // [MS-CIFS] Windows servers set the DataLength field to 0x0000 and return STATUS_SUCCESS.
                // JCIFS expects the same response.
                data          = new byte[0];
                header.Status = NTStatus.STATUS_SUCCESS;
            }
            else if (header.Status != NTStatus.STATUS_SUCCESS)
            {
                state.LogToServer(Severity.Verbose, "Read from '{0}{1}' failed. NTStatus: {2}. (FID: {3})", share.Name, openFile.Path, header.Status, request.FID);
                return(new ErrorResponse(request.CommandName));
            }

            ReadAndXResponse response = new ReadAndXResponse();

            if (share is FileSystemShare)
            {
                // If the client reads from a disk file, this field MUST be set to -1 (0xFFFF)
                response.Available = 0xFFFF;
            }
            response.Data = data;
            return(response);
        }
示例#2
0
        internal static SMB1Command GetReadResponse(SMB1Header header, ReadAndXRequest request, ISMBShare share, SMB1ConnectionState state)
        {
            SMB1Session    session  = state.GetSession(header.UID);
            OpenFileObject openFile = session.GetOpenFileObject(request.FID);

            if (openFile == null)
            {
                header.Status = NTStatus.STATUS_INVALID_HANDLE;
                return(null);
            }

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

            uint maxCount = request.MaxCount;

            if ((share is FileSystemShare) && state.LargeRead)
            {
                maxCount = request.MaxCountLarge;
            }
            byte[] data;
            header.Status = share.FileStore.ReadFile(out data, openFile.Handle, (long)request.Offset, (int)maxCount);
            if (header.Status != NTStatus.STATUS_SUCCESS)
            {
                return(new ErrorResponse(request.CommandName));
            }

            ReadAndXResponse response = new ReadAndXResponse();

            if (share is FileSystemShare)
            {
                // If the client reads from a disk file, this field MUST be set to -1 (0xFFFF)
                response.Available = 0xFFFF;
            }
            response.Data = data;
            return(response);
        }
示例#3
0
        internal static SMBCommand GetReadResponse(SMBHeader header, ReadAndXRequest request, object share, StateObject state)
        {
            uint maxCount = request.MaxCount;

            if ((share is FileSystemShare) && state.LargeRead)
            {
                maxCount = request.MaxCountLarge;
            }
            byte[] data = PerformRead(header, share, request.FID, request.Offset, maxCount, state);
            if (header.Status != NTStatus.STATUS_SUCCESS)
            {
                return(new ErrorResponse(CommandName.SMB_COM_READ_ANDX));
            }

            ReadAndXResponse response = new ReadAndXResponse();

            if (share is FileSystemShare)
            {
                // If the client reads from a disk file, this field MUST be set to -1 (0xFFFF)
                response.Available = 0xFFFF;
            }
            response.Data = data;
            return(response);
        }
示例#4
0
        public override IEnumerable <AbstractPacket> GetSubPackets(bool includeSelfReference)
        {
            if (includeSelfReference)
            {
                yield return(this);
            }

            AbstractPacket packet = null;

            try {
                CommandTypes commandType = (CommandTypes)command;
                if (commandType == CommandTypes.SMB_COM_NT_CREATE_ANDX)
                {
                    if (!this.FlagsResponse)
                    {
                        packet = new NTCreateAndXRequest(this);
                    }
                    else
                    {
                        packet = new NTCreateAndXResponse(this);
                    }
                }
                else if (commandType == CommandTypes.SMB_COM_READ_ANDX)
                {
                    if (this.FlagsResponse)
                    {
                        packet = new ReadAndXResponse(this);
                    }
                    else
                    {
                        packet = new ReadAndXRequest(this);
                    }
                }
                else if (commandType == CommandTypes.SMB_COM_CLOSE)
                {
                    if (!this.FlagsResponse)
                    {
                        packet = new CloseRequest(this);
                    }
                }
                else if (commandType == CommandTypes.SMB_COM_NEGOTIATE)
                {
                    if (!this.FlagsResponse)
                    {
                        packet = new NegotiateProtocolRequest(this);
                    }
                    else
                    {
                        packet = new NegotiateProtocolResponse(this);
                    }
                }
                else if (commandType == CommandTypes.SMB_COM_SESSION_SETUP_ANDX)
                {
                    if (!this.FlagsResponse)
                    {
                        packet = new SetupAndXRequest(this);
                    }
                    else
                    {
                        packet = new SetupAndXResponse(this);
                    }
                }
            }
            catch (Exception e) {
                yield break;//no sub packets
            }

            if (packet != null)
            {
                yield return(packet);

                foreach (AbstractPacket subPacket in packet.GetSubPackets(false))
                {
                    yield return(subPacket);
                }
            }
            else
            {
                yield break;
            }
        }