public static bool IsInShare(ILogger log, string path, Share share) { try { // non-existent files don't yield results anyway, we might need to have them existent for the checks here later if (!File.Exists(path) && !Directory.Exists(path)) return false; // we should only get rooted paths, but check anyway if (!Path.IsPathRooted(path)) return false; // only check on parent directory path if (File.Exists(path)) path = Path.GetDirectoryName(path); // if share doesn't exist don't allow access if (!Directory.Exists(share.Path)) return false; // check if it's a subdir and log fails bool retval = IsSubdir(share.Path, path); if (!retval) { log.Warn("Tried to access file {0} outside share {1}", path, share.Path); return false; } return true; } catch (Exception ex) { log.Error(String.Format("Exception druing IsInShare with path = {0}", path), ex); } return false; }
private string PathToIdentifier(string path, Share useShare = null) { foreach (Share share in shares) { if (path.StartsWith(share.Path + @"\")) { string type = File.Exists(path) ? "f" : "d"; return type + share.Id + "_" + EncodeTo64(path.Substring(share.Path.Length + 1)); } else if (path == share.Path) { return "s" + share.Id; } } return String.Empty; }
private string PathToIdentifier(DirectoryInfo info, Share useShare = null) { if (useShare == null) { return PathToIdentifier(info.FullName, useShare); } return "d" + useShare.Id + "_" + EncodeTo64(info.FullName.Substring(useShare.Path.Length + 1)); }
private WebFileBasic ConvertFileInfoToFileBasic(FileInfo file, Share share = null) { return new WebFileBasic() { Title = file.Name, Path = new List<string>() { file.FullName }, DateAdded = file.CreationTime, Id = PathToIdentifier(file, share), LastAccessTime = file.LastAccessTime, LastModifiedTime = file.LastWriteTime, Size = file.Length }; }
private WebFolderBasic ConvertDirectoryInfoToFolderBasic(DirectoryInfo dir, Share share = null) { return new WebFolderBasic() { Title = dir.Name, Path = new List<string>() { dir.FullName }, DateAdded = dir.CreationTime, Id = PathToIdentifier(dir, share), LastAccessTime = dir.LastAccessTime, LastModifiedTime = dir.LastWriteTime }; }