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;
     }
 }
Пример #2
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;
        }
Пример #3
0
        public static string TryParseStoreEntryIdMailboxDN(byte[] storeEntryId)
        {
            Util.ThrowOnNullArgument(storeEntryId, "storeEntryId");
            bool flag = false;
            StoreEntryIdInformation storeEntryIdInformation = StoreEntryId.TryParseStoreEntryId(storeEntryId, out flag);

            if (!flag)
            {
                return(null);
            }
            return(storeEntryIdInformation.MailboxLegacyDN);
        }
Пример #4
0
        public static byte[] ToProviderStoreEntryId(IExchangePrincipal exchangePrincipal, bool isPublicStore)
        {
            Util.ThrowOnNullArgument(exchangePrincipal, "exchangePrincipal");
            if (exchangePrincipal.MailboxInfo.IsRemote)
            {
                throw new ArgumentException("This method should not be used to remote connections.");
            }
            string mailboxLegacyDn   = exchangePrincipal.MailboxInfo.GetMailboxLegacyDn(exchangePrincipal.LegacyDn);
            string serverFqdn        = exchangePrincipal.MailboxInfo.Location.ServerFqdn;
            int    num               = serverFqdn.IndexOf(".", StringComparison.Ordinal);
            string serverNetBiosName = (num != -1) ? serverFqdn.Substring(0, num) : serverFqdn;

            return(StoreEntryId.ToProviderStoreEntryId(serverNetBiosName, mailboxLegacyDn, isPublicStore));
        }
Пример #5
0
        internal static StoreEntryIdInformation TryParseStoreEntryId(byte[] storeEntryId, out bool isValid)
        {
            isValid = false;
            if (storeEntryId == null)
            {
                return(null);
            }
            if (storeEntryId.Length < 30)
            {
                return(null);
            }
            StoreEntryIdInformation storeEntryIdInformation = null;

            using (BinaryWriter binaryWriter = new BinaryWriter(new MemoryStream()))
            {
                binaryWriter.Write(storeEntryId);
                using (BinaryReader binaryReader = new BinaryReader(binaryWriter.BaseStream))
                {
                    binaryReader.BaseStream.Position = 0L;
                    storeEntryIdInformation          = new StoreEntryIdInformation();
                    byte[] array = binaryReader.ReadBytes(4);
                    for (int i = 0; i < 4; i++)
                    {
                        if (array[i] != 0)
                        {
                            return(null);
                        }
                    }
                    byte[] array2 = binaryReader.ReadBytes(16);
                    if (!ArrayComparer <byte> .Comparer.Equals(array2, StoreEntryId.MuidStoreWrap))
                    {
                        return(null);
                    }
                    storeEntryIdInformation.WrappedStoreGuid = array2;
                    byte b = binaryReader.ReadByte();
                    if (b != 0)
                    {
                        return(null);
                    }
                    byte b2 = binaryReader.ReadByte();
                    if (b2 != 0)
                    {
                        return(null);
                    }
                    byte[] array3  = binaryReader.ReadBytes(14);
                    string @string = CTSGlobals.AsciiEncoding.GetString(array3, 0, array3.Length);
                    if ([email protected]("EMSMDB.DLL"))
                    {
                        return(null);
                    }
                    storeEntryIdInformation.ProviderFileName      = @string;
                    storeEntryIdInformation.ProviderFileNameBytes = array3;
                    byte[] array4 = binaryReader.ReadBytes(4);
                    for (int j = 0; j < 4; j++)
                    {
                        if (array4[j] != 0)
                        {
                            return(null);
                        }
                    }
                    byte[] array5 = binaryReader.ReadBytes(16);
                    if (ArrayComparer <byte> .Comparer.Equals(array5, StoreEntryId.PrivateStore))
                    {
                        storeEntryIdInformation.IsPublic = false;
                    }
                    else
                    {
                        if (!ArrayComparer <byte> .Comparer.Equals(array5, StoreEntryId.PublicStore))
                        {
                            return(null);
                        }
                        storeEntryIdInformation.IsPublic = true;
                    }
                    storeEntryIdInformation.StoreGuid = array5;
                    uint flagsInt = binaryReader.ReadUInt32();
                    storeEntryIdInformation.FlagsInt = flagsInt;
                    if ((storeEntryIdInformation.IsPublic && (storeEntryIdInformation.FlagsInt & 6U) == 0U) || (!storeEntryIdInformation.IsPublic && (storeEntryIdInformation.FlagsInt & 12U) == 0U))
                    {
                        return(null);
                    }
                    storeEntryIdInformation.ServerName = StoreEntryId.ParseStringToTerminator(binaryReader);
                    if (string.IsNullOrEmpty(storeEntryIdInformation.ServerName))
                    {
                        return(null);
                    }
                    storeEntryIdInformation.MailboxLegacyDN = StoreEntryId.ParseStringToTerminator(binaryReader);
                    if (string.IsNullOrEmpty(storeEntryIdInformation.MailboxLegacyDN))
                    {
                        return(null);
                    }
                }
            }
            isValid = true;
            return(storeEntryIdInformation);
        }
Пример #6
0
 public static byte[] ToProviderStoreEntryId(IExchangePrincipal exchangePrincipal)
 {
     return(StoreEntryId.ToProviderStoreEntryId(exchangePrincipal, false));
 }
Пример #7
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;
            }
        }