private static SharepointList GetListSpecifics(Uri uri, SharepointSession session, out ClassifyResult result) { SharepointList sharepointList = null; int num = 0; result = null; foreach (object[] array in session.GetView(ListBaseType.Any, new PropertyDefinition[] { DocumentLibrarySchema.Id }).GetRows(int.MaxValue)) { SharepointList sharepointList2 = SharepointList.Read(session, (ObjectId)array[0]); Uri uri2 = sharepointList2.Uri; int num2 = 0; int num3 = session.Uri.Segments.Length; while (num3 < uri2.Segments.Length && num3 < uri.Segments.Length && string.Compare(uri.Segments[num3].TrimEnd(new char[] { '/', '\\' }), uri2.Segments[num3].TrimEnd(new char[] { '/', '\\' }), StringComparison.CurrentCultureIgnoreCase) == 0) { num3++; num2++; } if (num2 > num) { sharepointList = sharepointList2; num = num2; } else if (num2 == num) { sharepointList = null; } } if (sharepointList == null) { result = new ClassifyResult(uri, ClassificationError.ObjectNotFound); } else if (sharepointList.ItemType == SharepointItemType.List) { result = new ClassifyResult(sharepointList.Id, uri, UriFlags.SharepointList); } else if (!uri.Query.Contains("&RootFolder=") && !uri.Query.Contains("?RootFolder=")) { Uri uri3 = sharepointList.Uri; if (string.Compare(uri.AbsolutePath, uri3.AbsolutePath, StringComparison.OrdinalIgnoreCase) == 0) { result = new ClassifyResult(sharepointList.Id, uri, UriFlags.SharepointDocumentLibrary); } else if (uri.Segments.Length == uri3.Segments.Length) { for (int j = 0; j < uri.Segments.Length - 1; j++) { if (string.Compare(uri3.Segments[j], uri.Segments[j], StringComparison.OrdinalIgnoreCase) != 0) { return(sharepointList); } } if (LinkClassifier.CheckIfLinkExists(uri, null)) { result = new ClassifyResult(sharepointList.Id, uri, UriFlags.SharepointDocumentLibrary); } else { result = new ClassifyResult(uri, ClassificationError.ObjectNotFound); } } } return(sharepointList); }
private static ClassifyResult ClassifySharepointLink(Uri uri, WindowsIdentity authenticatedUser) { WindowsImpersonationContext windowsImpersonationContext = null; ClassifyResult classifyResult = null; ClassifyResult result; try { windowsImpersonationContext = Utils.ImpersonateUser(authenticatedUser); Uri siteAddress = LinkClassifier.GetSiteAddress(uri, out classifyResult); if (classifyResult != null) { result = classifyResult; } else { SharepointSession session = SharepointSession.Open(new SharepointSiteId(siteAddress, UriFlags.Sharepoint), new WindowsPrincipal(authenticatedUser)); SharepointList listSpecifics = LinkClassifier.GetListSpecifics(uri, session, out classifyResult); if (classifyResult != null) { result = classifyResult; } else { IList <string> itemHierarchy = LinkClassifier.GetItemHierarchy(uri, listSpecifics); if (itemHierarchy.Count < 2) { Uri uri2 = listSpecifics.Uri; bool flag = false; if (itemHierarchy.Count == 0 || string.Compare(itemHierarchy[0].TrimEnd(new char[] { '/', '\\' }), Uri.UnescapeDataString(uri2.Segments[siteAddress.Segments.Length].TrimEnd(new char[] { '/', '\\' })), StringComparison.OrdinalIgnoreCase) != 0) { flag = true; } if (!flag) { result = new ClassifyResult(listSpecifics.Id, uri, UriFlags.SharepointDocumentLibrary); } else { result = new ClassifyResult(uri, ClassificationError.ObjectNotFound); } } else { string propertyValue = itemHierarchy[itemHierarchy.Count - 1]; itemHierarchy.RemoveAt(itemHierarchy.Count - 1); SharepointListId sharepointListId = (SharepointListId)listSpecifics.Id; SharepointDocumentLibraryItemId listId = new SharepointDocumentLibraryItemId("-1", sharepointListId.ListName, sharepointListId.SiteUri, listSpecifics.GetRegionalSettings(), UriFlags.SharepointFolder, itemHierarchy); ComparisonFilter query = new ComparisonFilter(ComparisonOperator.Equal, SharepointDocumentLibraryItemSchema.Name, propertyValue); PropertyDefinition[] propsToReturn = new PropertyDefinition[] { SharepointDocumentLibraryItemSchema.ID, SharepointDocumentLibraryItemSchema.FileSystemObjectType }; object[][] rows = SharepointDocumentLibraryFolder.InternalGetView(query, null, DocumentLibraryQueryOptions.FoldersAndFiles, propsToReturn, session, listId).GetRows(2); if (rows.Length == 1) { result = new ClassifyResult((DocumentLibraryObjectId)rows[0][0], uri, ((DocumentLibraryObjectId)rows[0][0]).UriFlags); } else { result = new ClassifyResult(uri, ClassificationError.ObjectNotFound); } } } } } catch (SoapException) { result = new ClassifyResult(uri, ClassificationError.ConnectionFailed); } catch (ObjectNotFoundException) { result = new ClassifyResult(uri, ClassificationError.ObjectNotFound); } catch (AccessDeniedException) { result = new ClassifyResult(uri, ClassificationError.AccessDenied); } catch (WebException ex) { result = LinkClassifier.GetClassificationResultFromWebException(uri, ex); } catch { Utils.UndoContext(ref windowsImpersonationContext); throw; } finally { Utils.UndoContext(ref windowsImpersonationContext); } return(result); }
private static ClassifyResult ClassifyUncLink(Uri uri, WindowsIdentity authenticatedUser) { WindowsImpersonationContext windowsImpersonationContext = null; ClassifyResult classifyResult = null; ClassifyResult result; try { windowsImpersonationContext = Utils.ImpersonateUser(authenticatedUser); UriFlags uriFlags = UriFlags.Other; if (!Utils.IsValidUncUri(uri)) { result = new ClassifyResult(uri, ClassificationError.InvalidUri); } else { if (uri.Segments.Length == 1) { try { UncObjectId objectId = new UncObjectId(uri, UriFlags.Unc); UncSession uncSession = UncSession.Open(objectId, new WindowsPrincipal(WindowsIdentity.GetCurrent())); uncSession.GetView(null, null, new PropertyDefinition[0]); } catch (AccessDeniedException) { return(new ClassifyResult(uri, ClassificationError.AccessDenied)); } catch (ObjectMovedOrDeletedException) { return(new ClassifyResult(uri, ClassificationError.ConnectionFailed)); } uriFlags = UriFlags.Unc; } else if (uri.Segments.Length >= 2) { if (uri.Segments.Length >= 3) { try { FileSystemInfo fileSystemInfo = new FileInfo(uri.LocalPath); if (fileSystemInfo.Attributes == (FileAttributes)(-1)) { return(new ClassifyResult(uri, ClassificationError.ObjectNotFound)); } if ((fileSystemInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory) { uriFlags = UriFlags.UncFolder; } else { uriFlags = UriFlags.UncDocument; } } catch (UnauthorizedAccessException) { classifyResult = new ClassifyResult(uri, ClassificationError.AccessDenied); } catch (FileNotFoundException) { classifyResult = new ClassifyResult(uri, ClassificationError.ObjectNotFound); } catch (IOException) { classifyResult = new ClassifyResult(uri, ClassificationError.AccessDenied); } } if (classifyResult != null || uri.Segments.Length == 2) { IntPtr intPtr; int num = UncSession.NetShareGetInfo(uri.Host, Uri.UnescapeDataString(uri.Segments[1].TrimEnd(new char[] { '\\', '/' })), 1, out intPtr); if (intPtr != IntPtr.Zero) { UncSession.NetApiBufferFree(intPtr); } else if (num == 5 || num == 2311) { classifyResult = new ClassifyResult(uri, ClassificationError.AccessDenied); } else if (num == 53 || num == 2250) { classifyResult = new ClassifyResult(uri, ClassificationError.ConnectionFailed); } else if (num == 2310) { classifyResult = new ClassifyResult(uri, ClassificationError.ObjectNotFound); } else if (num != 0) { classifyResult = new ClassifyResult(uri, ClassificationError.UnknownError); } uriFlags = UriFlags.UncDocumentLibrary; } if (classifyResult != null) { return(classifyResult); } } if ((uriFlags & UriFlags.Unc) != (UriFlags)0) { result = new ClassifyResult(new UncObjectId(uri, uriFlags), uri, uriFlags); } else { result = new ClassifyResult(uri, ClassificationError.ObjectNotFound); } } } catch { Utils.UndoContext(ref windowsImpersonationContext); throw; } finally { Utils.UndoContext(ref windowsImpersonationContext); } return(result); }