コード例 #1
0
        public static NTStatus SetInformation(INTFileStore fileStore, string path, SMBFileAttributes fileAttributes, DateTime?lastWriteTime, SecurityContext securityContext)
        {
            object     handle;
            FileStatus fileStatus;
            NTStatus   status = fileStore.CreateFile(out handle, out fileStatus, path, (AccessMask)FileAccessMask.FILE_WRITE_ATTRIBUTES, (FileAttributes)0, ShareAccess.Read | ShareAccess.Write, CreateDisposition.FILE_OPEN, 0, securityContext);

            if (status != NTStatus.STATUS_SUCCESS)
            {
                return(status);
            }

            FileBasicInformation basicInfo = new FileBasicInformation();

            basicInfo.LastWriteTime = lastWriteTime;

            if ((fileAttributes & SMBFileAttributes.Hidden) > 0)
            {
                basicInfo.FileAttributes |= FileAttributes.Hidden;
            }

            if ((fileAttributes & SMBFileAttributes.ReadOnly) > 0)
            {
                basicInfo.FileAttributes |= FileAttributes.ReadOnly;
            }

            if ((fileAttributes & SMBFileAttributes.Archive) > 0)
            {
                basicInfo.FileAttributes |= FileAttributes.Archive;
            }

            status = fileStore.SetFileInformation(handle, basicInfo);
            fileStore.CloseFile(handle);
            return(status);
        }
コード例 #2
0
 public QueryInformationResponse(byte[] buffer, int offset) : base(buffer, offset, false)
 {
     FileAttributes = (SMBFileAttributes)LittleEndianConverter.ToUInt16(this.SMBParameters, 0);
     LastWriteTime  = UTimeHelper.ReadNullableUTime(this.SMBParameters, 2);
     FileSize       = LittleEndianConverter.ToUInt32(this.SMBParameters, 6);
     Reserved       = ByteReader.ReadBytes(this.SMBParameters, 10, 10);
 }
コード例 #3
0
        public DeleteRequest(byte[] buffer, int offset, bool isUnicode) : base(buffer, offset, isUnicode)
        {
            SearchAttributes = (SMBFileAttributes)LittleEndianConverter.ToUInt16(this.SMBParameters, 0);

            BufferFormat = ByteReader.ReadByte(this.SMBData, 0);
            if (BufferFormat != SupportedBufferFormat)
            {
                throw new InvalidDataException("Unsupported Buffer Format");
            }
            FileName = SMB1Helper.ReadSMBString(this.SMBData, 1, isUnicode);
        }
コード例 #4
0
        public SetInformationRequest(byte[] buffer, int offset, bool isUnicode) : base(buffer, offset, isUnicode)
        {
            FileAttributes = (SMBFileAttributes)LittleEndianConverter.ToUInt16(this.SMBParameters, 0);
            LastWriteTime  = UTimeHelper.ReadNullableUTime(this.SMBParameters, 2);
            Reserved       = ByteReader.ReadBytes(this.SMBParameters, 6, 10);

            BufferFormat = ByteReader.ReadByte(this.SMBData, 0);
            if (BufferFormat != SupportedBufferFormat)
            {
                throw new InvalidDataException("Unsupported Buffer Format");
            }
            FileName = SMB1Helper.ReadSMBString(this.SMBData, 1, isUnicode);
        }
コード例 #5
0
        public Transaction2Open2Request(byte[] parameters, byte[] data, bool isUnicode) : base()
        {
            Flags          = (Open2Flags)LittleEndianConverter.ToUInt16(parameters, 0);
            AccessMode     = new AccessModeOptions(parameters, 2);
            Reserved1      = LittleEndianConverter.ToUInt16(parameters, 4);
            FileAttributes = (SMBFileAttributes)LittleEndianConverter.ToUInt16(parameters, 6);
            CreationTime   = UTimeHelper.ReadNullableUTime(parameters, 8);
            OpenMode       = new OpenMode(parameters, 12);
            AllocationSize = LittleEndianConverter.ToUInt32(parameters, 14);
            Reserved       = ByteReader.ReadBytes(parameters, 18, 10);
            FileName       = SMB1Helper.ReadSMBString(parameters, 28, isUnicode);

            ExtendedAttributeList = new FullExtendedAttributeList(data, 0);
        }
コード例 #6
0
 public Transaction2Open2Response(byte[] parameters, byte[] data, bool isUnicode) : base()
 {
     FID            = LittleEndianConverter.ToUInt16(parameters, 0);
     FileAttributes = (SMBFileAttributes)LittleEndianConverter.ToUInt16(parameters, 2);
     CreationTime   = UTimeHelper.ReadNullableUTime(parameters, 4);
     FileDataSize   = LittleEndianConverter.ToUInt32(parameters, 8);
     AccessMode     = new AccessModeOptions(parameters, 12);
     ResourceType   = (ResourceType)LittleEndianConverter.ToUInt16(parameters, 14);
     NMPipeStatus   = new NamedPipeStatus(parameters, 16);
     ActionTaken    = new ActionTaken(parameters, 18);
     Reserved       = LittleEndianConverter.ToUInt32(parameters, 20);
     ExtendedAttributeErrorOffset = LittleEndianConverter.ToUInt16(parameters, 24);
     ExtendedAttributeLength      = LittleEndianConverter.ToUInt32(parameters, 26);
 }
コード例 #7
0
        public Transaction2FindFirst2Request(byte[] parameters, byte[] data, bool isUnicode) : base()
        {
            SearchAttributes  = (SMBFileAttributes)LittleEndianConverter.ToUInt16(parameters, 0);
            SearchCount       = LittleEndianConverter.ToUInt16(parameters, 2);
            Flags             = (FindFlags)LittleEndianConverter.ToUInt16(parameters, 4);
            InformationLevel  = (FindInformationLevel)LittleEndianConverter.ToUInt16(parameters, 6);
            SearchStorageType = (SearchStorageType)LittleEndianConverter.ToUInt32(parameters, 8);
            FileName          = SMB1Helper.ReadSMBString(parameters, 12, isUnicode);

            if (InformationLevel == FindInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST)
            {
                GetExtendedAttributeList = new ExtendedAttributeNameList(data, 0);
            }
        }
コード例 #8
0
ファイル: OpenAndXResponse.cs プロジェクト: SonnyX/SMB-Client
        public OpenAndXResponse(byte[] buffer, int offset) : base(buffer, offset)
        {
            int parametersOffset = 4;

            FID           = LittleEndianReader.ReadUInt16(SMBParameters, ref parametersOffset);
            FileAttrs     = (SMBFileAttributes)LittleEndianReader.ReadUInt16(SMBParameters, ref parametersOffset);
            LastWriteTime = UTimeHelper.ReadNullableUTime(SMBParameters, ref parametersOffset);
            FileDataSize  = LittleEndianReader.ReadUInt32(SMBParameters, ref parametersOffset);
            AccessRights  = (AccessRights)LittleEndianReader.ReadUInt16(SMBParameters, ref parametersOffset);
            ResourceType  = (ResourceType)LittleEndianReader.ReadUInt16(SMBParameters, ref parametersOffset);
            NMPipeStatus  = NamedPipeStatus.Read(SMBParameters, ref parametersOffset);
            OpenResults   = OpenResults.Read(SMBParameters, ref parametersOffset);
            Reserved      = ByteReader.ReadBytes(SMBParameters, ref parametersOffset, 6);
        }
コード例 #9
0
ファイル: OpenAndXRequest.cs プロジェクト: gonsovsky/dnSvc
        public OpenAndXRequest(byte[] buffer, int offset, bool isUnicode) : base(buffer, offset, isUnicode)
        {
            int parametersOffset = 4;

            Flags          = (OpenFlags)LittleEndianReader.ReadUInt16(this.SMBParameters, ref parametersOffset);
            AccessMode     = AccessModeOptions.Read(this.SMBParameters, ref parametersOffset);
            SearchAttrs    = (SMBFileAttributes)LittleEndianReader.ReadUInt16(this.SMBParameters, ref parametersOffset);
            FileAttrs      = (SMBFileAttributes)LittleEndianReader.ReadUInt16(this.SMBParameters, ref parametersOffset);
            CreationTime   = UTimeHelper.ReadNullableUTime(this.SMBParameters, ref parametersOffset);
            OpenMode       = OpenMode.Read(this.SMBParameters, ref parametersOffset);
            AllocationSize = LittleEndianReader.ReadUInt32(this.SMBParameters, ref parametersOffset);
            Timeout        = LittleEndianReader.ReadUInt32(this.SMBParameters, ref parametersOffset);
            Reserved       = LittleEndianReader.ReadUInt32(this.SMBParameters, ref parametersOffset);

            int dataOffset = 0;

            if (isUnicode)
            {
                dataOffset = 1; // 1 byte padding for 2 byte alignment
            }
            FileName = SMB1Helper.ReadSMBString(this.SMBData, dataOffset, isUnicode);
        }
コード例 #10
0
        public RenameRequest(byte[] buffer, int offset, bool isUnicode) : base(buffer, offset, isUnicode)
        {
            SearchAttributes = (SMBFileAttributes)LittleEndianConverter.ToUInt16(this.SMBParameters, 0);

            int dataOffset = 0;

            BufferFormat1 = ByteReader.ReadByte(this.SMBData, ref dataOffset);
            if (BufferFormat1 != SupportedBufferFormat)
            {
                throw new InvalidDataException("Unsupported Buffer Format");
            }
            OldFileName   = SMB1Helper.ReadSMBString(this.SMBData, ref dataOffset, isUnicode);
            BufferFormat2 = ByteReader.ReadByte(this.SMBData, ref dataOffset);
            if (BufferFormat2 != SupportedBufferFormat)
            {
                throw new InvalidDataException("Unsupported Buffer Format");
            }
            if (isUnicode)
            {
                dataOffset++;
            }
            NewFileName = SMB1Helper.ReadSMBString(this.SMBData, ref dataOffset, isUnicode);
        }
コード例 #11
0
        public static SMBFileAttributes GetFileAttributes(FileAttributes attributes)
        {
            SMBFileAttributes result = SMBFileAttributes.Normal;

            if ((attributes & FileAttributes.Hidden) > 0)
            {
                result |= SMBFileAttributes.Hidden;
            }
            if ((attributes & FileAttributes.ReadOnly) > 0)
            {
                result |= SMBFileAttributes.ReadOnly;
            }
            if ((attributes & FileAttributes.Archive) > 0)
            {
                result |= SMBFileAttributes.Archive;
            }
            if ((attributes & FileAttributes.Directory) > 0)
            {
                result |= SMBFileAttributes.Directory;
            }

            return(result);
        }
コード例 #12
0
        public static NTStatus Rename(INTFileStore fileStore, string oldName, string newName, SMBFileAttributes searchAttributes, SecurityContext securityContext)
        {
            object        handle;
            FileStatus    fileStatus;
            CreateOptions createOptions = 0;

            // Windows 2000 SP4 clients will use this command to rename directories.
            // Hidden, System and Directory attributes are inclusive.
            if ((searchAttributes & SMBFileAttributes.Directory) == 0)
            {
                createOptions = CreateOptions.FILE_NON_DIRECTORY_FILE;
            }
            ShareAccess shareAccess = ShareAccess.Read | ShareAccess.Write | ShareAccess.Delete;
            NTStatus    status      = fileStore.CreateFile(out handle, out fileStatus, oldName, AccessMask.DELETE, 0, shareAccess, CreateDisposition.FILE_OPEN, createOptions, securityContext);

            if (status != NTStatus.STATUS_SUCCESS)
            {
                return(status);
            }
            FileRenameInformationType2 renameInfo = new FileRenameInformationType2();

            renameInfo.ReplaceIfExists = false;
            renameInfo.FileName        = newName;
            status = fileStore.SetFileInformation(handle, renameInfo);
            fileStore.CloseFile(handle);
            return(status);
        }