internal override void ParseSharingMessageProvider(SharingContext context, SharingMessageProvider sharingMessageProvider)
 {
     if (!AddressBookEntryId.IsAddressBookEntryId(context.InitiatorEntryId))
     {
         ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: InitiatorEntryId is invalid.", context.UserLegacyDN);
         throw new InvalidSharingDataException("InitiatorEntryId", HexConverter.ByteArrayToHexString(context.InitiatorEntryId));
     }
     if (!string.IsNullOrEmpty(sharingMessageProvider.FolderId))
     {
         try
         {
             context.FolderId = StoreObjectId.FromHexEntryId(sharingMessageProvider.FolderId, ObjectClass.GetObjectType(context.FolderClass));
         }
         catch (CorruptDataException)
         {
             ExTraceGlobals.SharingTracer.TraceError <string, string>((long)this.GetHashCode(), "{0}: FolderId is invalid: {1}", context.UserLegacyDN, sharingMessageProvider.FolderId);
             throw new InvalidSharingDataException("FolderId", sharingMessageProvider.FolderId);
         }
     }
     if (!string.IsNullOrEmpty(sharingMessageProvider.MailboxId))
     {
         byte[] array = HexConverter.HexStringToByteArray(sharingMessageProvider.MailboxId);
         if (StoreEntryId.TryParseStoreEntryIdMailboxDN(array) == null)
         {
             ExTraceGlobals.SharingTracer.TraceError <string, string>((long)this.GetHashCode(), "{0}: MailboxId is invalid: {1}", context.UserLegacyDN, sharingMessageProvider.MailboxId);
             throw new InvalidSharingDataException("MailboxId", sharingMessageProvider.MailboxId);
         }
         context.MailboxId = array;
     }
 }
Example #2
0
		public static bool IsAddressBookEntryId(byte[] entryId, out Eidt eidt, out string emailAddr)
		{
			eidt = Eidt.User;
			emailAddr = null;
			if (entryId == null)
			{
				return false;
			}
			int num = 0;
			int num2 = entryId.Length;
			bool result = false;
			if (num2 <= AddressBookEntryId.AddressBookEntryIdSize || !AddressBookEntryId.ArrayMatch(entryId, AddressBookEntryId.SkipEntryIdFlagsOffset, AddressBookEntryId.ExchAddrGuid) || entryId[num2 - 1] != 0)
			{
				return result;
			}
			num += AddressBookEntryId.SkipEntryIdFlagsOffset + AddressBookEntryId.ExchAddrGuid.Length + AddressBookEntryId.BinaryHelper.DWordSize;
			try
			{
				eidt = (Eidt)AddressBookEntryId.BinaryHelper.GetDword(entryId, ref num, num2);
				emailAddr = AddressBookEntryId.BinaryHelper.GetStringFromASCII(entryId, ref num, num2);
				result = true;
			}
			catch (ArgumentOutOfRangeException)
			{
			}
			return result;
		}
Example #3
0
		public static SecurityIdentifier MakeSidFromLocalDirctoryAddressBookEntryId(byte[] entryId)
		{
			if (!AddressBookEntryId.IsLocalDirctoryAddressBookEntryId(entryId))
			{
				throw new InvalidParamException(new LocalizedString("Invalid local directory address book entry ID."));
			}
			return new SecurityIdentifier(entryId, AddressBookEntryId.AddressBookEntryIdSize);
		}
Example #4
0
 public static bool TryGetUserFromEntryId(byte[] memberEntryId, StoreSession session, IRecipientSession recipientSession, LazilyInitialized <ExternalUserCollection> externalUsers, out string legacyDN, out SecurityIdentifier securityIdentifier, out List <SecurityIdentifier> sidHistory, out bool isGroup, out string displayName)
 {
     legacyDN = AclHelper.LegacyDnFromEntryId(memberEntryId);
     if (AddressBookEntryId.IsLocalDirctoryAddressBookEntryId(memberEntryId))
     {
         sidHistory = null;
         return(AclHelper.ResolveLocalDirectoryUserFromAddressBookEntryId(memberEntryId, externalUsers, out securityIdentifier, out isGroup, out displayName));
     }
     return(AclHelper.ResolveRecipientParametersFromLegacyDN(legacyDN, session, recipientSession, out securityIdentifier, out sidHistory, out isGroup, out displayName));
 }
Example #5
0
        public static CalendarGroupEntry Create(MailboxSession session, string legacyDistinguishedName, CalendarGroup parentGroup)
        {
            Util.ThrowOnNullOrEmptyArgument(legacyDistinguishedName, "legacyDistinguishedName");
            CalendarGroupEntry calendarGroupEntry = CalendarGroupEntry.Create(session, parentGroup.GroupClassId, parentGroup.GroupName);

            calendarGroupEntry[FolderTreeDataSchema.Type] = FolderTreeDataType.SharedFolder;
            calendarGroupEntry[FolderTreeDataSchema.FolderTreeDataFlags] = 0;
            calendarGroupEntry.SharerAddressBookEntryId    = AddressBookEntryId.MakeAddressBookEntryID(legacyDistinguishedName, false);
            calendarGroupEntry.UserAddressBookStoreEntryId = Microsoft.Exchange.Data.Storage.StoreEntryId.ToProviderStoreEntryId(session.MailboxOwner);
            return(calendarGroupEntry);
        }
Example #6
0
        internal SharingContext(Folder folderToShare, SharingProvider sharingProvider) : this()
        {
            Util.ThrowOnNullArgument(folderToShare, "folderToShare");
            MailboxSession     mailboxSession = folderToShare.Session as MailboxSession;
            IExchangePrincipal mailboxOwner   = mailboxSession.MailboxOwner;

            if (sharingProvider == null)
            {
                SharingProvider[] compatibleProviders = SharingProvider.GetCompatibleProviders(folderToShare);
                if (compatibleProviders.Length == 0)
                {
                    ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: Cannot share folder {1}: no compatible provider was found.", mailboxOwner, folderToShare.Id);
                    throw new CannotShareFolderException(ServerStrings.NoProviderSupportShareFolder);
                }
                for (int i = 0; i < compatibleProviders.Length; i++)
                {
                    ExTraceGlobals.SharingTracer.TraceDebug <IExchangePrincipal, SharingProvider, VersionedId>((long)this.GetHashCode(), "{0}: Find compatible provider {1} for folder {2}.", mailboxOwner, compatibleProviders[i], folderToShare.Id);
                    this.AvailableSharingProviders.Add(compatibleProviders[i], null);
                }
            }
            else if (!sharingProvider.IsCompatible(folderToShare))
            {
                ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId, SharingProvider>((long)this.GetHashCode(), "{0}: Cannot share folder {1} with sharing provider: {2}.", mailboxOwner, folderToShare.Id, sharingProvider);
                if (sharingProvider == SharingProvider.SharingProviderPublish)
                {
                    throw new FolderNotPublishedException();
                }
                throw new CannotShareFolderException(ServerStrings.NoProviderSupportShareFolder);
            }
            else
            {
                this.AvailableSharingProviders.Add(sharingProvider, null);
                if (sharingProvider == SharingProvider.SharingProviderPublish)
                {
                    this.PopulateUrls(folderToShare);
                }
            }
            this.InitiatorName        = mailboxOwner.MailboxInfo.DisplayName;
            this.InitiatorSmtpAddress = mailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString();
            this.InitiatorEntryId     = AddressBookEntryId.MakeAddressBookEntryID(mailboxOwner);
            this.FolderClass          = folderToShare.ClassName;
            this.FolderId             = folderToShare.StoreObjectId;
            this.IsPrimary            = (mailboxSession.IsDefaultFolderType(this.FolderId) != DefaultFolderType.None);
            this.FolderName           = (this.IsPrimary ? this.DataType.DisplayName.ToString(mailboxSession.InternalPreferedCulture) : folderToShare.DisplayName);
            this.MailboxId            = StoreEntryId.ToProviderStoreEntryId(mailboxOwner);
            this.SharingMessageType   = SharingMessageType.Invitation;
            this.SharingPermissions   = SharingContextPermissions.Reviewer;
            if (StringComparer.OrdinalIgnoreCase.Equals(folderToShare.ClassName, "IPF.Appointment"))
            {
                this.SharingDetail = (this.IsPrimary ? SharingContextDetailLevel.AvailabilityOnly : SharingContextDetailLevel.FullDetails);
            }
            this.SetDefaultCapabilities();
            this.UserLegacyDN = mailboxOwner.LegacyDn;
        }
Example #7
0
        private static bool ResolveLocalDirectoryUserFromAddressBookEntryId(byte[] entryId, LazilyInitialized <ExternalUserCollection> externalUsers, out SecurityIdentifier securityIdentifier, out bool isGroup, out string displayName)
        {
            securityIdentifier = null;
            isGroup            = false;
            displayName        = string.Empty;
            securityIdentifier = AddressBookEntryId.MakeSidFromLocalDirctoryAddressBookEntryId(entryId);
            ExternalUser externalUser = AclHelper.TryGetExternalUser(securityIdentifier, externalUsers);

            if (externalUser == null)
            {
                throw new ExternalUserNotFoundException(securityIdentifier);
            }
            displayName = externalUser.Name;
            return(true);
        }
Example #8
0
        internal static string LegacyDnFromEntryId(byte[] entryId)
        {
            string result;
            Eidt   eidt;

            if (entryId.Length == 0)
            {
                result = string.Empty;
            }
            else if (AddressBookEntryId.IsLocalDirctoryAddressBookEntryId(entryId))
            {
                result = AddressBookEntryId.MakeLegacyDnFromLocalDirctoryAddressBookEntryId(entryId);
                eidt   = Eidt.User;
            }
            else if (!AddressBookEntryId.IsAddressBookEntryId(entryId, out eidt, out result))
            {
                throw new InvalidParamException(new LocalizedString("Invalid ABEID"));
            }
            return(result);
        }
Example #9
0
        private void ReadFromMessageProperties(MessageItem messageItem)
        {
            SharingFlavor?valueAsNullable = messageItem.GetValueAsNullable <SharingFlavor>(InternalSchema.SharingFlavor);

            if (valueAsNullable == null)
            {
                ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: SharingFlavor is missing", messageItem.Session.UserLegacyDN);
                throw new InvalidSharingMessageException("SharingFlavor");
            }
            this.context.SharingFlavor = valueAsNullable.Value;
            SharingCapabilities?valueAsNullable2 = messageItem.GetValueAsNullable <SharingCapabilities>(InternalSchema.SharingCapabilities);

            if (valueAsNullable2 == null)
            {
                ExTraceGlobals.SharingTracer.TraceDebug <string>((long)this.GetHashCode(), "{0}: SharingCapabilities is missing, use default value", messageItem.Session.UserLegacyDN);
                this.context.SetDefaultCapabilities();
            }
            else
            {
                this.context.SharingCapabilities = valueAsNullable2.Value;
            }
            string valueOrDefault = messageItem.GetValueOrDefault <string>(InternalSchema.SharingInitiatorName, null);

            if (valueOrDefault == null)
            {
                ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: SharingInitiatorName is missing.", messageItem.Session.UserLegacyDN);
                throw new InvalidSharingMessageException("SharingInitiatorName");
            }
            this.context.InitiatorName = valueOrDefault;
            string valueOrDefault2 = messageItem.GetValueOrDefault <string>(InternalSchema.SharingInitiatorSmtp, null);

            if (valueOrDefault2 == null)
            {
                ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: SharingInitiatorSmtp is missing.", messageItem.Session.UserLegacyDN);
                throw new InvalidSharingMessageException("SharingInitiatorSmtp");
            }
            if (!SmtpAddress.IsValidSmtpAddress(valueOrDefault2))
            {
                ExTraceGlobals.SharingTracer.TraceError <string, string>((long)this.GetHashCode(), "{0}: SharingInitiatorSmtp is invalid: {1}", messageItem.Session.UserLegacyDN, valueOrDefault2);
                throw new InvalidSharingMessageException("SharingInitiatorSmtp");
            }
            this.context.InitiatorSmtpAddress = valueOrDefault2;
            byte[] valueOrDefault3 = messageItem.GetValueOrDefault <byte[]>(InternalSchema.SharingInitiatorEntryId, null);
            if (valueOrDefault3 == null)
            {
                ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: SharingInitiatorEntryId is missing.", messageItem.Session.UserLegacyDN);
                throw new InvalidSharingMessageException("SharingInitiatorEntryId");
            }
            if (!AddressBookEntryId.IsAddressBookEntryId(valueOrDefault3))
            {
                ExTraceGlobals.SharingTracer.TraceError <string, byte[]>((long)this.GetHashCode(), "{0}: SharingInitiatorEntryId is invalid: {1}", messageItem.Session.UserLegacyDN, valueOrDefault3);
                throw new InvalidSharingMessageException("SharingInitiatorEntryId");
            }
            this.context.InitiatorEntryId = valueOrDefault3;
            string valueOrDefault4 = messageItem.GetValueOrDefault <string>(InternalSchema.SharingRemoteType, null);

            if (valueOrDefault4 == null)
            {
                ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: SharingRemoteType is missing.", messageItem.Session.UserLegacyDN);
                throw new InvalidSharingMessageException("SharingRemoteType");
            }
            if (SharingDataType.FromContainerClass(valueOrDefault4) == null)
            {
                ExTraceGlobals.SharingTracer.TraceError <string, string>((long)this.GetHashCode(), "{0}: SharingRemoteType is invalid: {1}.", messageItem.Session.UserLegacyDN, valueOrDefault4);
                throw new InvalidSharingMessageException("SharingRemoteType");
            }
            this.context.FolderClass = valueOrDefault4;
            string valueOrDefault5 = messageItem.GetValueOrDefault <string>(InternalSchema.SharingRemoteName, null);

            if (valueOrDefault5 == null)
            {
                ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: SharingRemoteName is missing.", messageItem.Session.UserLegacyDN);
                throw new InvalidSharingMessageException("SharingRemoteName");
            }
            this.context.FolderName = valueOrDefault5;
            string valueOrDefault6 = messageItem.GetValueOrDefault <string>(InternalSchema.SharingRemoteUid, null);

            if (valueOrDefault6 == null)
            {
                ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: SharingRemoteUid is missing.", messageItem.Session.UserLegacyDN);
                throw new InvalidSharingMessageException("SharingRemoteUid");
            }
            try
            {
                this.context.FolderId = StoreObjectId.FromHexEntryId(valueOrDefault6, ObjectClass.GetObjectType(valueOrDefault4));
            }
            catch (CorruptDataException)
            {
                ExTraceGlobals.SharingTracer.TraceError <string, string>((long)this.GetHashCode(), "{0}: SharingRemoteUid is invalid: {1}", messageItem.Session.UserLegacyDN, valueOrDefault6);
                throw new InvalidSharingMessageException("SharingRemoteUid");
            }
            string valueOrDefault7 = messageItem.GetValueOrDefault <string>(InternalSchema.SharingRemoteStoreUid, null);

            if (valueOrDefault7 == null)
            {
                ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: SharingRemoteStoreUid is missing.", messageItem.Session.UserLegacyDN);
                throw new InvalidSharingMessageException("SharingRemoteStoreUid");
            }
            byte[] array = null;
            try
            {
                array = HexConverter.HexStringToByteArray(valueOrDefault7);
            }
            catch (FormatException)
            {
            }
            if (array == null || StoreEntryId.TryParseStoreEntryIdMailboxDN(array) == null)
            {
                ExTraceGlobals.SharingTracer.TraceError <string, string>((long)this.GetHashCode(), "{0}: SharingRemoteStoreUid is invalid: {1}", messageItem.Session.UserLegacyDN, valueOrDefault7);
                throw new InvalidSharingMessageException("SharingRemoteStoreUid");
            }
            this.context.MailboxId = array;
            SharingContextPermissions?valueAsNullable3 = messageItem.GetValueAsNullable <SharingContextPermissions>(InternalSchema.SharingPermissions);

            if (valueAsNullable3 != null)
            {
                this.context.SharingPermissions = valueAsNullable3.Value;
            }
            SharingContextDetailLevel?valueAsNullable4 = messageItem.GetValueAsNullable <SharingContextDetailLevel>(InternalSchema.SharingDetail);

            if (valueAsNullable4 != null)
            {
                this.context.SharingDetail = valueAsNullable4.Value;
                return;
            }
            if (this.context.DataType == SharingDataType.Calendar)
            {
                this.context.SharingDetail = SharingContextDetailLevel.FullDetails;
            }
        }
Example #10
0
        internal static CalendarGroupEntryInfo GetCalendarGroupEntryInfoFromRow(IStorePropertyBag row)
        {
            VersionedId versionedId = (VersionedId)row.TryGetProperty(ItemSchema.Id);

            byte[] valueOrDefault  = row.GetValueOrDefault <byte[]>(CalendarGroupEntrySchema.NodeEntryId, null);
            byte[] valueOrDefault2 = row.GetValueOrDefault <byte[]>(FolderTreeDataSchema.ParentGroupClassId, null);
            string valueOrDefault3 = row.GetValueOrDefault <string>(ItemSchema.Subject, string.Empty);
            LegacyCalendarColor valueOrDefault4 = row.GetValueOrDefault <LegacyCalendarColor>(CalendarGroupEntrySchema.CalendarColor, LegacyCalendarColor.Auto);

            byte[]              valueOrDefault5  = row.GetValueOrDefault <byte[]>(FolderTreeDataSchema.Ordinal, null);
            byte[]              valueOrDefault6  = row.GetValueOrDefault <byte[]>(CalendarGroupEntrySchema.SharerAddressBookEntryId, null);
            byte[]              valueOrDefault7  = row.GetValueOrDefault <byte[]>(CalendarGroupEntrySchema.StoreEntryId, null);
            ExDateTime          valueOrDefault8  = row.GetValueOrDefault <ExDateTime>(StoreObjectSchema.LastModifiedTime, ExDateTime.MinValue);
            FolderTreeDataType  valueOrDefault9  = row.GetValueOrDefault <FolderTreeDataType>(FolderTreeDataSchema.Type, FolderTreeDataType.NormalFolder);
            FolderTreeDataFlags valueOrDefault10 = row.GetValueOrDefault <FolderTreeDataFlags>(FolderTreeDataSchema.FolderTreeDataFlags, FolderTreeDataFlags.None);
            Guid safeGuidFromByteArray           = FolderTreeData.GetSafeGuidFromByteArray(valueOrDefault2);

            if (safeGuidFromByteArray.Equals(Guid.Empty))
            {
                ExTraceGlobals.StorageTracer.TraceDebug <int>(0L, "Found CalendarGroupEntry with invalid parent group class id. ArrayLength: {0}", (valueOrDefault2 == null) ? -1 : valueOrDefault2.Length);
                return(null);
            }
            if (valueOrDefault9 != FolderTreeDataType.SharedFolder)
            {
                if (IdConverter.IsFolderId(valueOrDefault))
                {
                    StoreObjectId storeObjectId = StoreObjectId.FromProviderSpecificId(valueOrDefault);
                    if ((valueOrDefault10 & FolderTreeDataFlags.IsDefaultStore) == FolderTreeDataFlags.IsDefaultStore)
                    {
                        return(new LocalCalendarGroupEntryInfo(valueOrDefault3, versionedId, valueOrDefault4, storeObjectId, valueOrDefault5, safeGuidFromByteArray, (valueOrDefault10 & FolderTreeDataFlags.ICalFolder) == FolderTreeDataFlags.ICalFolder || (valueOrDefault10 & FolderTreeDataFlags.SharedIn) == FolderTreeDataFlags.SharedIn, valueOrDefault8));
                    }
                    if ((valueOrDefault10 & FolderTreeDataFlags.PublicFolder) == FolderTreeDataFlags.PublicFolder)
                    {
                        string calendarOwner = Microsoft.Exchange.Data.Storage.StoreEntryId.TryParseStoreEntryIdMailboxDN(valueOrDefault7);
                        storeObjectId = StoreObjectId.FromLegacyFavoritePublicFolderId(storeObjectId);
                        return(new LinkedCalendarGroupEntryInfo(valueOrDefault3, versionedId, valueOrDefault4, storeObjectId, calendarOwner, safeGuidFromByteArray, valueOrDefault5, false, true, valueOrDefault8));
                    }
                    ExTraceGlobals.StorageTracer.TraceDebug <StoreObjectType, string, VersionedId>(0L, "Found CalendarGroupEntry of type {0} referencing a non-calendar folder. ObjectType: {0}. CalendarName: {1}. Id: {2}.", storeObjectId.ObjectType, valueOrDefault3, versionedId);
                }
                return(null);
            }
            bool   flag = true;
            Eidt   eidt;
            string text;

            if (!AddressBookEntryId.IsAddressBookEntryId(valueOrDefault6, out eidt, out text))
            {
                ExTraceGlobals.StorageTracer.TraceDebug <string>(0L, "AddressBookEntryId is missing, not primary calendar {0}", valueOrDefault3);
                if (valueOrDefault7 == null)
                {
                    ExTraceGlobals.StorageTracer.TraceDebug <string>(0L, "StoreEntryId is missing for calendar: {0} - invalid entry, skipping.", valueOrDefault3);
                    return(null);
                }
                text = Microsoft.Exchange.Data.Storage.StoreEntryId.TryParseStoreEntryIdMailboxDN(valueOrDefault7);
                flag = false;
            }
            if (text == null)
            {
                ExTraceGlobals.StorageTracer.TraceDebug <string>(0L, "Unable to determine owner of shared calendar: {0}. Skipping.", valueOrDefault3);
                return(null);
            }
            StoreObjectId storeObjectId2 = IdConverter.IsFolderId(valueOrDefault) ? StoreObjectId.FromProviderSpecificId(valueOrDefault) : null;

            if (!flag && storeObjectId2 == null)
            {
                ExTraceGlobals.StorageTracer.TraceDebug <string>(0L, "Secondary shared calendar without a folder id encountered {0}. Skipping.", valueOrDefault3);
                return(null);
            }
            return(new LinkedCalendarGroupEntryInfo(valueOrDefault3, versionedId, valueOrDefault4, storeObjectId2, text, safeGuidFromByteArray, valueOrDefault5, flag, false, valueOrDefault8));
        }
Example #11
0
        private static List <AclTableEntry> BuildAclTableFromSecurityDescriptor(RawSecurityDescriptor securityDescriptor, RawSecurityDescriptor freeBusySecurityDescriptor, LazilyInitialized <ExternalUserCollection> lazilyInitializedExternalUserCollection, IRecipientSession recipientSession, AclTableIdMap aclTableIdMap, out bool isCanonical, out string canonicalErrorInformation)
        {
            FolderSecurity.AnnotatedAceList annotatedAceList = new FolderSecurity.AnnotatedAceList(securityDescriptor, freeBusySecurityDescriptor, (SecurityIdentifier securityIdentifier) => AclModifyTable.GetSecurityIdentifierType(recipientSession, securityIdentifier));
            isCanonical = annotatedAceList.IsCanonical(out canonicalErrorInformation);
            IList <FolderSecurity.SecurityIdentifierAndFolderRights> list;

            if (isCanonical)
            {
                list = annotatedAceList.GetSecurityIdentifierAndRightsList();
            }
            else
            {
                ExTraceGlobals.StorageTracer.TraceWarning <string, string>(0L, "Got non canonical SD: {0}, ErrorInfo: ", securityDescriptor.GetSddlForm(AccessControlSections.All), canonicalErrorInformation);
                list = Array <FolderSecurity.SecurityIdentifierAndFolderRights> .Empty;
            }
            List <AclTableEntry> list2 = new List <AclTableEntry>(list.Count + 1);

            foreach (FolderSecurity.SecurityIdentifierAndFolderRights securityIdentifierAndFolderRights in list)
            {
                MemberRights memberRights = (MemberRights)(securityIdentifierAndFolderRights.AllowRights & ~(MemberRights)securityIdentifierAndFolderRights.DenyRights);
                bool         flag         = false;
                bool         flag2        = false;
                byte[]       entryId;
                string       text;
                List <SecurityIdentifier> list3;
                SecurityIdentifier        securityIdentifier;
                if (securityIdentifierAndFolderRights.SecurityIdentifier.IsWellKnown(WellKnownSidType.WorldSid))
                {
                    entryId = Array <byte> .Empty;
                    text    = string.Empty;
                    string legacyDN = string.Empty;
                    securityIdentifier = securityIdentifierAndFolderRights.SecurityIdentifier;
                    list3 = null;
                    flag2 = true;
                }
                else if (securityIdentifierAndFolderRights.SecurityIdentifier.IsWellKnown(WellKnownSidType.AnonymousSid))
                {
                    entryId            = Array <byte> .Empty;
                    text               = "Anonymous";
                    securityIdentifier = securityIdentifierAndFolderRights.SecurityIdentifier;
                    list3              = null;
                }
                else if (ExternalUser.IsExternalUserSid(securityIdentifierAndFolderRights.SecurityIdentifier))
                {
                    ExternalUser externalUser = AclHelper.TryGetExternalUser(securityIdentifierAndFolderRights.SecurityIdentifier, lazilyInitializedExternalUserCollection);
                    if (externalUser == null)
                    {
                        ExTraceGlobals.StorageTracer.TraceWarning <SecurityIdentifier>(0L, "Cannot find external user with SID {0}, build entry from information we have", securityIdentifierAndFolderRights.SecurityIdentifier);
                        string text2 = AclHelper.CreateLocalUserStrignRepresentation(securityIdentifierAndFolderRights.SecurityIdentifier);
                        text = text2;
                    }
                    else
                    {
                        text = externalUser.Name;
                        string legacyDN = externalUser.LegacyDn;
                    }
                    entryId            = AddressBookEntryId.MakeAddressBookEntryIDFromLocalDirectorySid(securityIdentifierAndFolderRights.SecurityIdentifier);
                    securityIdentifier = securityIdentifierAndFolderRights.SecurityIdentifier;
                    list3 = null;
                }
                else
                {
                    MiniRecipient miniRecipient = recipientSession.FindMiniRecipientBySid <MiniRecipient>(securityIdentifierAndFolderRights.SecurityIdentifier, Array <PropertyDefinition> .Empty);
                    string        legacyDN;
                    if (miniRecipient == null)
                    {
                        ExTraceGlobals.StorageTracer.TraceWarning <SecurityIdentifier>(0L, "Cannot find recipient with SID {0}, build entry from the information we have", securityIdentifierAndFolderRights.SecurityIdentifier);
                        flag = (securityIdentifierAndFolderRights.SecurityIdentifierType == FolderSecurity.SecurityIdentifierType.Group);
                        string text3 = AclHelper.CreateNTUserStrignRepresentation(securityIdentifierAndFolderRights.SecurityIdentifier);
                        text               = text3;
                        legacyDN           = text3;
                        securityIdentifier = securityIdentifierAndFolderRights.SecurityIdentifier;
                        list3              = null;
                    }
                    else
                    {
                        flag = AclHelper.IsGroupRecipientType(miniRecipient.RecipientType);
                        if (string.IsNullOrEmpty(miniRecipient.DisplayName))
                        {
                            text = AclHelper.CreateNTUserStrignRepresentation(securityIdentifierAndFolderRights.SecurityIdentifier);
                        }
                        else
                        {
                            text = miniRecipient.DisplayName;
                        }
                        if (string.IsNullOrEmpty(miniRecipient.LegacyExchangeDN))
                        {
                            legacyDN = text;
                        }
                        else
                        {
                            legacyDN = miniRecipient.LegacyExchangeDN;
                        }
                        SecurityIdentifier masterAccountSid = miniRecipient.MasterAccountSid;
                        if (masterAccountSid != null && !masterAccountSid.IsWellKnown(WellKnownSidType.SelfSid))
                        {
                            securityIdentifier = masterAccountSid;
                            list3 = null;
                        }
                        else
                        {
                            securityIdentifier = miniRecipient.Sid;
                            MultiValuedProperty <SecurityIdentifier> sidHistory = miniRecipient.SidHistory;
                            if (sidHistory != null && sidHistory.Count != 0)
                            {
                                list3 = new List <SecurityIdentifier>(sidHistory);
                            }
                            else
                            {
                                list3 = null;
                            }
                        }
                    }
                    entryId = AddressBookEntryId.MakeAddressBookEntryID(legacyDN, flag);
                }
                AclTableEntry aclTableEntry = list2.Find((AclTableEntry entry) => entry.SecurityIdentifier == securityIdentifier);
                if (aclTableEntry == null && list3 != null)
                {
                    using (List <SecurityIdentifier> .Enumerator enumerator2 = list3.GetEnumerator())
                    {
                        while (enumerator2.MoveNext())
                        {
                            SecurityIdentifier sid = enumerator2.Current;
                            aclTableEntry = list2.Find((AclTableEntry entry) => entry.SecurityIdentifier == sid);
                            if (aclTableEntry != null)
                            {
                                break;
                            }
                        }
                    }
                }
                if (aclTableEntry == null)
                {
                    aclTableEntry = new AclTableEntry(AclModifyTable.GetIdForSecurityIdentifier(securityIdentifier, list3, aclTableIdMap), entryId, text, memberRights);
                    aclTableEntry.SetSecurityIdentifier(securityIdentifier, flag);
                    if (flag2)
                    {
                        list2.Insert(0, aclTableEntry);
                    }
                    else
                    {
                        list2.Add(aclTableEntry);
                    }
                }
                else
                {
                    aclTableEntry.MemberRights &= memberRights;
                    if (aclTableEntry.IsGroup != flag)
                    {
                        throw new NonCanonicalACLException(annotatedAceList.CreateErrorInformation((LID)35788U, new int[0]));
                    }
                    aclTableEntry.SetSecurityIdentifier(securityIdentifier, flag);
                }
            }
            return(list2);
        }
Example #12
0
		public static bool IsAddressBookEntryId(byte[] entryId)
		{
			Eidt eidt;
			string text;
			return AddressBookEntryId.IsAddressBookEntryId(entryId, out eidt, out text);
		}
Example #13
0
		public static byte[] MakeAddressBookEntryID(string legacyDN, bool isDL)
		{
			Eidt eidt = isDL ? Eidt.List : Eidt.User;
			return AddressBookEntryId.MakeAddressBookEntryID(legacyDN, eidt);
		}
Example #14
0
		public static byte[] MakeAddressBookEntryID(IExchangePrincipal exchangePrincipal)
		{
			Util.ThrowOnNullArgument(exchangePrincipal, "exchangePrincipal");
			return AddressBookEntryId.MakeAddressBookEntryID(exchangePrincipal.LegacyDn, false);
		}
Example #15
0
		public static string MakeLegacyDnFromLocalDirctoryAddressBookEntryId(byte[] entryId)
		{
			SecurityIdentifier securityIdentifier = AddressBookEntryId.MakeSidFromLocalDirctoryAddressBookEntryId(entryId);
			return string.Format("{0}{1}", "LocalUser:", securityIdentifier.ToString());
		}
Example #16
0
		public static bool IsLocalDirctoryAddressBookEntryId(byte[] entryId)
		{
			return entryId != null && entryId.Length >= AddressBookEntryId.MinLocalDirectoryAddressBookEntryIdSize && entryId.Length <= AddressBookEntryId.MaxLocalDirectoryAddressBookEntryIdSize && AddressBookEntryId.ArrayMatch(entryId, AddressBookEntryId.SkipEntryIdFlagsOffset, AddressBookEntryId.MuidLocalDirectoryUser);
		}