public static Uri Query(string domain)
        {
            IAsyncResult asyncResult = AutoDiscoverDnsReader.BeginQuery(domain);

            if (!asyncResult.AsyncWaitHandle.WaitOne(Configuration.AutodiscoverSrvRecordLookupTimeoutInSeconds.Value, false))
            {
                AutoDiscoverDnsReader.DnsReaderTracer.TraceError <string>(0L, "DNS query for SRV records for domain {0} did not complete in time.", domain);
                return(null);
            }
            string text = AutoDiscoverDnsReader.FetchResults(asyncResult);

            if (string.IsNullOrEmpty(text))
            {
                AutoDiscoverDnsReader.DnsReaderTracer.TraceError <string>(0L, "DNS query for SRV record for domain {0} found an null SRV target", domain);
                return(null);
            }
            AutoDiscoverDnsReader.DnsReaderTracer.TraceDebug <string, string>(0L, "DNS query for SRV record for domain {0} found target '{1}'", domain, text);
            string text2 = string.Format("https://{0}/autodiscover/autodiscover.xml", text);

            if (string.IsNullOrEmpty(text2) || !Uri.IsWellFormedUriString(text2, UriKind.Absolute))
            {
                AutoDiscoverDnsReader.DnsReaderTracer.TraceError <string, string>(0L, "DNS query for SRV record for domain {0} found an non-valid autodiscover URL {1}", domain, text2);
                return(null);
            }
            AutoDiscoverDnsReader.DnsReaderTracer.TraceDebug <string, string>(0L, "DNS query for SRV record for domain {0] found {1}", domain, text2);
            return(new Uri(text2));
        }
        private static TargetForestConfiguration ConstructTargetForestConfiguration(AvailabilityAddressSpace addressSpace, ScpSearch localScpSearch)
        {
            TargetForestConfigurationCache.ConfigurationTracer.TraceDebug <string>(0L, "Processing AvailabilityAddressSpace name: {0}", addressSpace.ForestName);
            NetworkCredential     networkCredential     = null;
            AutodiscoverUrlSource autodiscoverUrlSource = AutodiscoverUrlSource.Unknown;
            Uri uri = null;

            if (addressSpace.AccessMethod != AvailabilityAccessMethod.OrgWideFB && addressSpace.AccessMethod != AvailabilityAccessMethod.PerUserFB)
            {
                if (addressSpace.AccessMethod != AvailabilityAccessMethod.OrgWideFBBasic)
                {
                    goto IL_1B2;
                }
            }
            try
            {
                networkCredential = TargetForestConfigurationCache.GetCredentials(addressSpace);
            }
            catch (InvalidCrossForestCredentialsException exception)
            {
                return(new TargetForestConfiguration(addressSpace.Id.ToString(), addressSpace.ForestName, exception));
            }
            if (addressSpace.TargetAutodiscoverEpr != null)
            {
                uri = addressSpace.TargetAutodiscoverEpr;
                TargetForestConfigurationCache.ConfigurationTracer.TraceDebug <Uri>(0L, "Retrieved Autodiscover URL {0} from address space.", uri);
                goto IL_1B2;
            }
            TargetForestConfigurationCache.ConfigurationTracer.TraceDebug <string>(0L, "Searching for SCP objects for domain {0}", addressSpace.ForestName);
            uri = localScpSearch.FindRemote(addressSpace.ForestName, networkCredential);
            if (uri != null)
            {
                TargetForestConfigurationCache.ConfigurationTracer.TraceDebug <string, Uri>(0L, "Found autodiscover URL from SCP objects for domain {0}. Url is: {1}", addressSpace.ForestName, uri);
                autodiscoverUrlSource = AutodiscoverUrlSource.SCP;
                goto IL_1B2;
            }
            TargetForestConfigurationCache.ConfigurationTracer.TraceDebug <string>(0L, "Found no suitable autodiscover URL from SCP objects for domain {0}. Trying well-known endpoints.", addressSpace.ForestName);
            uri = TargetForestConfigurationCache.DiscoverFromWellKnown(addressSpace.ForestName, networkCredential);
            if (uri != null)
            {
                TargetForestConfigurationCache.ConfigurationTracer.TraceDebug <string, Uri>(0L, "Found autodiscover URL from well-known endpoints for domain {0}. Url is: {1}", addressSpace.ForestName, uri);
                autodiscoverUrlSource = AutodiscoverUrlSource.WellKnown;
                goto IL_1B2;
            }
            TargetForestConfigurationCache.ConfigurationTracer.TraceDebug <string>(0L, "Found no suitable autodiscover URL from well-known endpoints for domain {0}. Trying SRV records from DNS.", addressSpace.ForestName);
            uri = AutoDiscoverDnsReader.Query(addressSpace.ForestName);
            if (uri != null)
            {
                TargetForestConfigurationCache.ConfigurationTracer.TraceDebug <string, Uri>(0L, "Found autodiscover URL from SRV records from DNS for domain {0}. Url is: {1}", addressSpace.ForestName, uri);
                autodiscoverUrlSource = AutodiscoverUrlSource.SRV;
                goto IL_1B2;
            }
            TargetForestConfigurationCache.ConfigurationTracer.TraceDebug <string>(0L, "Found no suitable autodiscover URL from well-known endpoint lookup for domain {0}.", addressSpace.ForestName);
            return(new TargetForestConfiguration(addressSpace.Id.ToString(), addressSpace.ForestName, new AutoDiscoverFailedException(Strings.descAvailabilityAddressSpaceFailed(addressSpace.Id.ToString()))));

IL_1B2:
            return(new TargetForestConfiguration(addressSpace.Id.ToString(), addressSpace.ForestName, addressSpace.AccessMethod, networkCredential, uri, autodiscoverUrlSource));
        }
Пример #3
0
        private static void Initialize(RequestLogger requestLogger)
        {
            requestLogger.CaptureRequestStage("CRInit");
            ConfigurationReader.ConfigurationTracer.TraceDebug(0L, "ConfigurationReader is now initializing NetworkServiceImpersonator.");
            NetworkServiceImpersonator.Initialize();
            requestLogger.CaptureRequestStage("CRNSInit");
            ConfigurationReader.ConfigurationTracer.TraceDebug(0L, "ConfigurationReader is done initializing NetworkServiceImpersonator.");
            ConfigurationReader.ConfigurationTracer.TraceDebug(0L, "ConfigurationReader is now initializing Dns for AS discovery.");
            AutoDiscoverDnsReader.Initialize();
            requestLogger.CaptureRequestStage("CRAD");
            ConfigurationReader.ConfigurationTracer.TraceDebug(0L, "ConfigurationReader is done initializing Dns for AS discovery.");
            DateTime populateDeadline = DateTime.UtcNow + ConfigurationReader.initializeTimeInterval;

            ConfigurationReader.ConfigurationTracer.TraceDebug(0L, "ConfigurationReader is now refreshing TargetForestConfigurationCache.");
            TargetForestConfigurationCache.Populate(populateDeadline);
            ConfigurationReader.ConfigurationTracer.TraceDebug(0L, "ConfigurationReader is done refreshing TargetForestConfigurationCache.");
            requestLogger.CaptureRequestStage("CRTC");
            ConfigurationReader.ASFaultInjectionTracer.RegisterExceptionInjectionCallback(new ExceptionInjectionCallback(FaultInjection.Callback));
            ConfigurationReader.RequestDispatchFaultInjectionTracer.RegisterExceptionInjectionCallback(new ExceptionInjectionCallback(FaultInjection.Callback));
        }