Esempio n. 1
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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public static NTStatus SetInformation2(INTFileStore fileStore, object handle, DateTime?creationTime, DateTime?lastAccessTime, DateTime?lastWriteTime)
        {
            FileNetworkOpenInformation fileInfo  = NTFileStoreHelper.GetNetworkOpenInformation(fileStore, handle);
            FileBasicInformation       basicInfo = new FileBasicInformation();

            basicInfo.FileAttributes = fileInfo.FileAttributes;
            basicInfo.CreationTime   = creationTime;
            basicInfo.LastAccessTime = lastAccessTime;
            basicInfo.LastWriteTime  = lastWriteTime;
            return(fileStore.SetFileInformation(handle, basicInfo));
        }
 public static NTStatus SetFileInformation(INTFileStore fileStore, object handle, SetInformation information)
 {
     if (information is SetFileBasicInfo)
     {
         SetFileBasicInfo     basicInfo     = (SetFileBasicInfo)information;
         FileBasicInformation fileBasicInfo = new FileBasicInformation();
         fileBasicInfo.CreationTime   = basicInfo.CreationTime;
         fileBasicInfo.LastAccessTime = basicInfo.LastAccessTime;
         fileBasicInfo.LastWriteTime  = basicInfo.LastWriteTime;
         fileBasicInfo.ChangeTime     = basicInfo.LastChangeTime;
         fileBasicInfo.FileAttributes = (FileAttributes)basicInfo.ExtFileAttributes;
         fileBasicInfo.Reserved       = basicInfo.Reserved;
         return(fileStore.SetFileInformation(handle, fileBasicInfo));
     }
     else if (information is SetFileDispositionInfo)
     {
         FileDispositionInformation fileDispositionInfo = new FileDispositionInformation();
         fileDispositionInfo.DeletePending = ((SetFileDispositionInfo)information).DeletePending;
         return(fileStore.SetFileInformation(handle, fileDispositionInfo));
     }
     else if (information is SetFileAllocationInfo)
     {
         // This information level is used to set the file length in bytes.
         // Note: the input will NOT be a multiple of the cluster size / bytes per sector.
         FileAllocationInformation fileAllocationInfo = new FileAllocationInformation();
         fileAllocationInfo.AllocationSize = ((SetFileAllocationInfo)information).AllocationSize;
         return(fileStore.SetFileInformation(handle, fileAllocationInfo));
     }
     else if (information is SetFileEndOfFileInfo)
     {
         FileEndOfFileInformation fileEndOfFileInfo = new FileEndOfFileInformation();
         fileEndOfFileInfo.EndOfFile = ((SetFileEndOfFileInfo)information).EndOfFile;
         return(fileStore.SetFileInformation(handle, fileEndOfFileInfo));
     }
     else
     {
         return(NTStatus.STATUS_NOT_IMPLEMENTED);
     }
 }
Esempio n. 5
0
        public static NTStatus Delete(INTFileStore fileStore, string path, CreateOptions createOptions, SecurityContext securityContext)
        {
            object      handle;
            FileStatus  fileStatus;
            ShareAccess shareAccess = ShareAccess.Read | ShareAccess.Write | ShareAccess.Delete;
            NTStatus    status      = fileStore.CreateFile(out handle, out fileStatus, path, AccessMask.DELETE, 0, shareAccess, CreateDisposition.FILE_OPEN, createOptions, securityContext);

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

            fileDispositionInfo.DeletePending = true;
            status = fileStore.SetFileInformation(handle, fileDispositionInfo);
            fileStore.CloseFile(handle);
            return(status);
        }
Esempio n. 6
0
        public static NTStatus Delete(INTFileStore fileStore, string path, CreateOptions createOptions, SecurityContext securityContext)
        {
            object     handle;
            FileStatus fileStatus;
            NTStatus   openStatus = fileStore.CreateFile(out handle, out fileStatus, path, DirectoryAccessMask.DELETE, 0, CreateDisposition.FILE_OPEN, createOptions, securityContext);

            if (openStatus != NTStatus.STATUS_SUCCESS)
            {
                return(openStatus);
            }
            FileDispositionInformation fileDispositionInfo = new FileDispositionInformation();

            fileDispositionInfo.DeletePending = true;
            NTStatus setStatus = fileStore.SetFileInformation(handle, fileDispositionInfo);

            if (setStatus != NTStatus.STATUS_SUCCESS)
            {
                return(setStatus);
            }
            NTStatus closeStatus = fileStore.CloseFile(handle);

            return(closeStatus);
        }
        public static NTStatus SetFileInformation(INTFileStore fileStore, object handle, SetInformation information)
        {
            FileInformation fileInformation = SetInformationHelper.ToFileInformation(information);

            return(fileStore.SetFileInformation(handle, fileInformation));
        }