Ejemplo n.º 1
0
        /// <summary>
        /// Returns DavLocationFolder folder if path corresponds to [DavLocation].
        /// </summary>
        /// <param name="context">Instance of <see cref="DavContext"/></param>
        /// <param name="path">Encoded path relative to WebDAV root.</param>
        /// <returns>DavLocationFolder instance or null if physical folder not found in file system.</returns>
        public static DavLocationFolder GetDavLocationFolder(DavContext context, string path)
        {
            string davPath = DavLocationFolderPath;

            if (!path.Equals(davPath.Trim(new[] { '/' }), StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            string        folderPath = context.MapPath(davPath).TrimEnd(System.IO.Path.DirectorySeparatorChar);
            DirectoryInfo folder     = new DirectoryInfo(folderPath);

            if (!folder.Exists)
            {
                throw new Exception(string.Format("Can not find folder that corresponds to '{0}' ([DavLocation] folder) in file system.", davPath));
            }

            return(new DavLocationFolder(folder, context, davPath));
        }
Ejemplo n.º 2
0
        /// <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);

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

            return(davFile);
        }
Ejemplo n.º 3
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) : base(context)
 {
     this.fileSystemInfo = fileSystemInfo;
     this.context        = context;
     this.Path           = path;
 }
Ejemplo n.º 4
0
 /// <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;
 }
Ejemplo n.º 5
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;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of this class.
 /// </summary>
 /// <param name="directory">Instance of <see cref="DirectoryInfo"/> class with information about the folder in file system.</param>
 /// <param name="context">Instance of <see cref="DavContext"/>.</param>
 /// <param name="path">Relative to WebDAV root folder path.</param>
 private DavLocationFolder(DirectoryInfo directory, DavContext context, string path)
     : base(directory, context, path)
 {
 }
 protected LogicalFolder(DavContext context, string name, string path) : base(context)
 {
     this.Context = context;
     this.Name    = name;
     this.Path    = path;
 }
Ejemplo n.º 8
0
 public Discovery(DavContext context)
 {
     this.context = context;
 }