/// <summary>
        /// Returns file that corresponds to path.
        /// </summary>
        /// <param name="context">WebDAV Context.</param>
        /// <param name="path">Encoded path relative to WebDAV root folder.</param>
        /// <returns>File instance or null if physical file is not found in file system.</returns>
        public static async Task <DavFile> GetFileAsync(DavContext context, string path)
        {
            string   filePath = context.MapPath(path);
            FileInfo file     = new FileInfo(filePath);

            // This code blocks vulnerability when "%20" folder can be injected into path and file.Exists returns 'true'.
            if (!file.Exists || string.Compare(file.FullName.TrimEnd(System.IO.Path.DirectorySeparatorChar), filePath, StringComparison.OrdinalIgnoreCase) != 0)
            {
                return(null);
            }

            DavFile davFile = new DavFile(file, context, path);

            davFile.serialNumber = await file.GetExtendedAttributeAsync <int?>("SerialNumber") ?? 0;

            davFile.TotalContentLength = await file.GetExtendedAttributeAsync <long?>("TotalContentLength") ?? 0;

            return(davFile);
        }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of this class.
 /// </summary>
 /// <param name="fileSystemInfo">Corresponding file or folder in the file system.</param>
 /// <param name="context">WebDAV Context.</param>
 /// <param name="path">Encoded path relative to WebDAV root folder.</param>
 protected DavHierarchyItem(FileSystemInfo fileSystemInfo, DavContext context, string path)
 {
     this.fileSystemInfo = fileSystemInfo;
     this.context        = context;
     this.Path           = path;
 }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of this class.
 /// </summary>
 /// <param name="file">Corresponding file in the file system.</param>
 /// <param name="context">WebDAV Context.</param>
 /// <param name="path">Encoded path relative to WebDAV root folder.</param>
 protected DavFile(FileInfo file, DavContext context, string path)
     : base(file, context, path)
 {
     this.fileInfo = file;
 }
 /// <summary>
 /// Initializes a new instance of this class.
 /// </summary>
 /// <param name="directory">Corresponding folder in the file system.</param>
 /// <param name="context">WebDAV Context.</param>
 /// <param name="path">Encoded path relative to WebDAV root folder.</param>
 protected DavFolder(DirectoryInfo directory, DavContext context, string path)
     : base(directory, context, path.TrimEnd('/') + "/")
 {
     dirInfo = directory;
 }