Example #1
0
        // Token: 0x06000B54 RID: 2900 RVA: 0x0002DE60 File Offset: 0x0002C060
        private static ExchangeService CreateExchangeService(string domain, OrgExtensionTable.RequestData requestData)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            ADUser orgMailbox = OrgExtensionTable.GetOrgMailbox(domain);

            requestData.OrgMailboxAdUserLookupTime = stopwatch.ElapsedMilliseconds;
            if (orgMailbox == null)
            {
                return(null);
            }
            ExchangePrincipal exchangePrincipal;

            try
            {
                exchangePrincipal = ExchangePrincipal.FromADUser(orgMailbox, null);
            }
            catch (ObjectNotFoundException exception)
            {
                ExtensionDiagnostics.Logger.LogEvent(ApplicationLogicEventLogConstants.Tuple_OrganizationMailboxWebServiceUrlRetrievalFailed, domain, new object[]
                {
                    "ProcessOrgExtensions",
                    ExtensionDiagnostics.GetLoggedExceptionString(exception)
                });
                return(null);
            }
            Uri backEndWebServicesUrl;

            try
            {
                backEndWebServicesUrl = BackEndLocator.GetBackEndWebServicesUrl(exchangePrincipal.MailboxInfo);
                stopwatch.Stop();
                requestData.WebServiceUrlLookupTime = stopwatch.ElapsedMilliseconds - requestData.OrgMailboxAdUserLookupTime;
            }
            catch (BackEndLocatorException exception2)
            {
                ExtensionDiagnostics.Logger.LogEvent(ApplicationLogicEventLogConstants.Tuple_OrganizationMailboxWebServiceUrlRetrievalFailed, domain, new object[]
                {
                    "ProcessOrgExtensions",
                    ExtensionDiagnostics.GetLoggedExceptionString(exception2)
                });
                return(null);
            }
            ExchangeService exchangeService = new ExchangeService(4);

            exchangeService.Url = backEndWebServicesUrl;
            exchangeService.PrivilegedUserId            = new PrivilegedUserId(0, 2, orgMailbox.PrimarySmtpAddress.ToString());
            exchangeService.PrivilegedUserId.BudgetType = new PrivilegedUserIdBudgetType?(2);
            RemoteCertificateValidationCallback callback = (object param0, X509Certificate param1, X509Chain param2, SslPolicyErrors param3) => true;

            CertificateValidationManager.RegisterCallback("Extension.OrgExtensionTable", callback);
            exchangeService.HttpHeaders.Add(CertificateValidationManager.ComponentIdHeaderName, "Extension.OrgExtensionTable");
            return(exchangeService);
        }
Example #2
0
        // Token: 0x06000AFA RID: 2810 RVA: 0x0002C438 File Offset: 0x0002A638
        internal override MailAppsResult GetExchangeDiagnosticsInfoData(DiagnosableParameters argument)
        {
            MailAppsResult mailAppsResult = new MailAppsResult();
            string         text           = argument.Argument;

            if (!string.IsNullOrEmpty(text))
            {
                string value = null;
                string text2 = ",val=";
                int    num   = text.IndexOf(text2);
                if (num != -1)
                {
                    value = text.Substring(num + text2.Length);
                    text  = argument.Argument.Substring(0, num);
                }
                MailAppsArgument mailAppsArgument = new MailAppsArgument(text);
                if (mailAppsArgument.HasArgument("org") && mailAppsArgument.HasArgument("cmd"))
                {
                    bool              flag      = false;
                    string            argument2 = mailAppsArgument.GetArgument <string>("org");
                    ExchangePrincipal exchangePrincipal;
                    if (mailAppsArgument.HasArgument("usr"))
                    {
                        string            argument3  = mailAppsArgument.GetArgument <string>("usr");
                        ADSessionSettings adSettings = ADSessionSettings.RootOrgOrSingleTenantFromAcceptedDomainAutoDetect(argument2);
                        exchangePrincipal = ExchangePrincipal.FromProxyAddress(adSettings, argument3 + "@" + argument2, RemotingOptions.AllowCrossSite);
                    }
                    else
                    {
                        ADUser orgMailbox = OrgExtensionTable.GetOrgMailbox(argument2);
                        exchangePrincipal = ExchangePrincipal.FromADUser(orgMailbox, null);
                        flag = true;
                    }
                    using (MailboxSession mailboxSession = MailboxSession.OpenAsSystemService(exchangePrincipal, CultureInfo.CurrentCulture, "Client=WebServices"))
                    {
                        using (UserConfiguration folderConfiguration = UserConfigurationHelper.GetFolderConfiguration(mailboxSession, mailboxSession.GetDefaultFolderId(DefaultFolderType.Inbox), "ExtensionMasterTable", UserConfigurationTypes.XML, true, false))
                        {
                            using (Stream xmlStream = folderConfiguration.GetXmlStream())
                            {
                                if (string.Equals(mailAppsArgument.GetArgument <string>("cmd"), "set", StringComparison.OrdinalIgnoreCase) && num != -1)
                                {
                                    xmlStream.SetLength(0L);
                                    bool flag2 = string.IsNullOrEmpty(value);
                                    if (!flag2)
                                    {
                                        using (StreamWriter streamWriter = new StreamWriter(xmlStream, Encoding.UTF8))
                                        {
                                            streamWriter.Write(value);
                                        }
                                    }
                                    folderConfiguration.Save();
                                    if (flag)
                                    {
                                        OrgEmptyMasterTableCache.Singleton.Update(exchangePrincipal.MailboxInfo.OrganizationId, flag2);
                                    }
                                    mailAppsResult.Message = "Raw value saved.";
                                }
                                else
                                {
                                    using (StreamReader streamReader = new StreamReader(xmlStream, true))
                                    {
                                        mailAppsResult.RawMasterTable = streamReader.ReadToEnd();
                                        if (mailAppsArgument.HasArgument("len"))
                                        {
                                            int argument4 = mailAppsArgument.GetArgument <int>("len");
                                            if (argument4 > 0 && argument4 < mailAppsResult.RawMasterTable.Length)
                                            {
                                                mailAppsResult.RawMasterTable = mailAppsResult.RawMasterTable.Substring(0, argument4);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(mailAppsResult);
        }