Exemplo 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));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates initial address books for user.
        /// </summary>
        internal static async Task CreateAddressbookFoldersAsync(DavContext context)
        {
            string physicalRepositoryPath = context.RepositoryPath;

            // Get path to user folder /addrsessbooks/[user_name]/ and check if it exists.
            string addressbooksUserFolder     = string.Format("{0}{1}", AddressbooksRootFolder.AddressbooksRootFolderPath.Replace('/', Path.DirectorySeparatorChar), context.UserName);
            string pathAddressbooksUserFolder = Path.Combine(physicalRepositoryPath, addressbooksUserFolder.TrimStart(Path.DirectorySeparatorChar));

            if (!Directory.Exists(pathAddressbooksUserFolder))
            {
                Directory.CreateDirectory(pathAddressbooksUserFolder);

                // Create user address books, such as /addressbooks/[user_name]/Addressbook/.
                string pathAddressbook = Path.Combine(pathAddressbooksUserFolder, "Addressbook1");
                Directory.CreateDirectory(pathAddressbook);
                pathAddressbook = Path.Combine(pathAddressbooksUserFolder, "Business1");
                Directory.CreateDirectory(pathAddressbook);
            }
        }
Exemplo n.º 3
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);
        }
Exemplo 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;
 }
Exemplo 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;
 }
Exemplo n.º 6
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;
 }
Exemplo n.º 7
0
 protected LogicalFolder(DavContext context, string name, string path) : base(context)
 {
     this.Context = context;
     this.Name    = name;
     this.Path    = path;
 }
Exemplo n.º 8
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)
 {
 }
Exemplo n.º 9
0
 public Discovery(DavContext context)
 {
     this.context = context;
 }