private void GetDirectoryCerts(List <RecipientAddress> addressList, AmbiguousRecipientToResolve recipient)
        {
            List <string> list = new List <string>(addressList.Count);

            foreach (RecipientAddress recipientAddress in addressList)
            {
                list.Add(recipientAddress.RoutingAddress);
            }
            Result <ADRawEntry>[] array = this.RecipientSession.FindByLegacyExchangeDNs(list.ToArray(), CertificateManager.adrecipientProperties);
            if (Command.CurrentCommand != null)
            {
                Command.CurrentCommand.Context.ProtocolLogger.SetValue(ProtocolLoggerData.DomainController, this.recipientSession.LastUsedDc);
            }
            for (int i = 0; i < array.Length; i++)
            {
                Result <ADRawEntry> result = array[i];
                if (result.Data != null)
                {
                    ResolvedRecipient resolvedRecipient = recipient.ResolvedTo[addressList[i].Index];
                    if (CertificateManager.IsADDistributionList((RecipientType)result.Data[ADRecipientSchema.RecipientType]))
                    {
                        CertificateManager.ADDistributionListExpansion addistributionListExpansion = new CertificateManager.ADDistributionListExpansion(this, new ADRecipientExpansion(CertificateManager.adrecipientProperties, this.organizationId));
                        addistributionListExpansion.Expand(result.Data);
                        resolvedRecipient.CertificateRecipientCount += addistributionListExpansion.Size;
                        resolvedRecipient.CertificateCount          += addistributionListExpansion.Certificates.Count;
                        if (!resolvedRecipient.GlobalCertLimitWasHit && resolvedRecipient.Certificates.Count + addistributionListExpansion.Certificates.Count <= this.certificateSlotsLeft)
                        {
                            resolvedRecipient.Certificates.AddRange(addistributionListExpansion.Certificates.ToArray());
                            this.certificateSlotsLeft -= addistributionListExpansion.Certificates.Count;
                        }
                        else
                        {
                            resolvedRecipient.GlobalCertLimitWasHit = true;
                            this.certificateSlotsLeft += resolvedRecipient.Certificates.Count;
                            resolvedRecipient.Certificates.Clear();
                        }
                    }
                    else
                    {
                        resolvedRecipient.CertificateRecipientCount++;
                        X509Certificate2 adrecipientCert = this.GetADRecipientCert(result.Data);
                        if (adrecipientCert != null)
                        {
                            resolvedRecipient.CertificateCount++;
                            if (!resolvedRecipient.GlobalCertLimitWasHit && this.certificateSlotsLeft <= 0)
                            {
                                resolvedRecipient.GlobalCertLimitWasHit = true;
                                this.certificateSlotsLeft += resolvedRecipient.Certificates.Count;
                                resolvedRecipient.Certificates.Clear();
                            }
                            else if (!resolvedRecipient.GlobalCertLimitWasHit)
                            {
                                resolvedRecipient.Certificates.Add(adrecipientCert);
                                this.certificateSlotsLeft--;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private void ReadXmlRequest()
        {
            XmlNode xmlRequest = base.XmlRequest;
            XmlNode xmlNode    = xmlRequest.FirstChild;
            bool    flag       = false;

            while (xmlNode != null)
            {
                if (xmlNode.LocalName == "To")
                {
                    if (string.IsNullOrEmpty(xmlNode.InnerText))
                    {
                        throw new AirSyncPermanentException(StatusCode.Sync_ServerError, this.GetValidationErrorXml(), null, false)
                              {
                                  ErrorStringForProtocolLogger = "EmptyToNode"
                              };
                    }
                    AmbiguousRecipientToResolve item = new AmbiguousRecipientToResolve(xmlNode.InnerText);
                    this.recipientsList.Add(item);
                    if (this.recipientsList.Count >= GlobalSettings.MaxRetrievedItems)
                    {
                        throw new AirSyncPermanentException(StatusCode.Sync_ServerError, this.GetValidationErrorXml(), null, false)
                              {
                                  ErrorStringForProtocolLogger = "TooManyRecipientsToResolve"
                              };
                    }
                }
                else
                {
                    if (!(xmlNode.LocalName == "Options"))
                    {
                        throw new AirSyncPermanentException(StatusCode.Sync_ServerError, this.GetValidationErrorXml(), null, false)
                              {
                                  ErrorStringForProtocolLogger = "NoOptionsNodeInResolveRecipients"
                              };
                    }
                    if (flag || xmlNode.ChildNodes == null || xmlNode.ChildNodes.Count == 0)
                    {
                        throw new AirSyncPermanentException(StatusCode.Sync_ServerError, this.GetValidationErrorXml(), null, false)
                              {
                                  ErrorStringForProtocolLogger = "DupeOrEmptyOptionsNodeInResolveRecipients"
                              };
                    }
                    this.ParseOptionsNode(xmlNode);
                    flag = true;
                }
                xmlNode = xmlNode.NextSibling;
            }
            if (this.recipientsList.Count == 0)
            {
                throw new AirSyncPermanentException(StatusCode.Sync_ServerError, this.GetValidationErrorXml(), null, false)
                      {
                          ErrorStringForProtocolLogger = "NoRecipientsInResolveRecipients"
                      };
            }
            base.ProtocolLogger.SetValue(ProtocolLoggerData.NumberOfRecipientsToResolve, this.recipientsList.Count);
            base.ProtocolLogger.SetValue(ProtocolLoggerData.AvailabilityRequested, (this.availabilityOptions != null) ? 1 : 0);
            base.ProtocolLogger.SetValue(ProtocolLoggerData.CertificatesRequested, (this.certificateRetrieval != ResolveRecipientsCommand.CertificateRetrievalType.None) ? 1 : 0);
            base.ProtocolLogger.SetValue(ProtocolLoggerData.PictureRequested, (this.pictureOptions != null) ? 1 : 0);
        }
        internal void GetRecipientCerts(AmbiguousRecipientToResolve recipient)
        {
            List <RecipientAddress> list = new List <RecipientAddress>(recipient.ResolvedTo.Count);
            int num = -1;

            foreach (ResolvedRecipient resolvedRecipient in recipient.ResolvedTo)
            {
                RecipientAddress resolvedTo = resolvedRecipient.ResolvedTo;
                num = (resolvedTo.Index = num + 1);
                switch (resolvedTo.AddressOrigin)
                {
                case AddressOrigin.Store:
                    resolvedRecipient.CertificateRecipientCount++;
                    this.GetContactCert(resolvedRecipient);
                    break;

                case AddressOrigin.Directory:
                    if (this.exchangePrincipal.MailboxInfo.IsAggregated)
                    {
                        resolvedRecipient.CertificateRecipientCount++;
                    }
                    else
                    {
                        list.Add(resolvedTo);
                    }
                    break;

                default:
                    resolvedRecipient.CertificateRecipientCount++;
                    break;
                }
            }
            if (list.Count > 0)
            {
                this.GetDirectoryCerts(list, recipient);
            }
        }
Esempio n. 4
0
        // Token: 0x06000369 RID: 873 RVA: 0x00013A64 File Offset: 0x00011C64
        public void ResolveOneRecipient(string name, bool searchADFirst, AmbiguousRecipientToResolve recipient)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            List <ResolvedRecipient> list  = new List <ResolvedRecipient>();
            List <ResolvedRecipient> list2 = new List <ResolvedRecipient>();
            string text;
            string text2;
            bool   flag = AnrManager.TryParseNameBeforeAnr(name, out text, out text2);

            if (searchADFirst)
            {
                switch (this.GetNamesByAnrFromAD(flag ? string.Format(CultureInfo.InvariantCulture, "{0}:{1}", new object[]
                {
                    text,
                    text2
                }) : name, list2))
                {
                case AnrManager.LookupState.FoundNone:
                {
                    AnrManager.LookupState namesByAnrFromContacts = this.GetNamesByAnrFromContacts(flag ? text2 : name, list);
                    recipient.ExactMatchFound = (namesByAnrFromContacts == AnrManager.LookupState.FoundExact);
                    break;
                }

                case AnrManager.LookupState.FoundExact:
                    recipient.ExactMatchFound = true;
                    break;

                case AnrManager.LookupState.FoundMany:
                    this.GetNamesByAnrFromContacts(flag ? text2 : name, list);
                    recipient.ExactMatchFound = false;
                    break;
                }
            }
            else
            {
                switch (this.GetNamesByAnrFromContacts(flag ? text2 : name, list))
                {
                case AnrManager.LookupState.FoundNone:
                {
                    AnrManager.LookupState namesByAnrFromAD = this.GetNamesByAnrFromAD(flag ? string.Format(CultureInfo.InvariantCulture, "{0}:{1}", new object[]
                        {
                            text,
                            text2
                        }) : name, list2);
                    recipient.ExactMatchFound = (namesByAnrFromAD == AnrManager.LookupState.FoundExact);
                    break;
                }

                case AnrManager.LookupState.FoundExact:
                    recipient.ExactMatchFound = true;
                    break;

                case AnrManager.LookupState.FoundMany:
                    this.GetNamesByAnrFromAD(flag ? string.Format(CultureInfo.InvariantCulture, "{0}:{1}", new object[]
                    {
                        text,
                        text2
                    }) : name, list2);
                    recipient.ExactMatchFound = false;
                    break;
                }
            }
            list.Sort();
            list2.Sort();
            list.AddRange(list2);
            int num = recipient.ExactMatchFound ? list.Count : Math.Min(this.nameLimit, list.Count);

            recipient.ResolvedNamesCount = list.Count;
            recipient.CompleteList       = (num == list.Count);
            list.RemoveRange(num, list.Count - num);
            recipient.ResolvedTo = list;
        }