예제 #1
0
        private void DnsQueryCallback(IAsyncResult ar)
        {
            IPAddress[] array;
            DnsStatus   dnsStatus = Dns.EndResolveToAddresses(ar, out array);
            bool        isMatch   = false;

            if (dnsStatus == DnsStatus.Success)
            {
                isMatch = this.MatchResult(array);
            }
            Provider.QueryAsyncResult queryAsyncResult = (Provider.QueryAsyncResult)ar.AsyncState;
            queryAsyncResult.QueryCompleted(isMatch, array);
        }
        internal static string FetchResults(IAsyncResult ar)
        {
            int priority = -1;
            int weight   = -1;

            SrvRecord[] array;
            DnsStatus   dnsStatus = Dns.EndResolveToSrvRecords(ar, out array);

            if (dnsStatus != DnsStatus.Success)
            {
                AutoDiscoverDnsReader.DnsReaderTracer.TraceError(0L, "Failed to get results from DNS.");
                return(null);
            }
            int length = array.GetLength(0);

            if (length == 0)
            {
                AutoDiscoverDnsReader.DnsReaderTracer.TraceError(0L, "No SRV records were returned.");
                return(null);
            }
            AutoDiscoverDnsReader.DnsReaderTracer.TraceDebug <int>(0L, "{0} SRV records were returned.", length);
            bool flag = false;

            for (int i = 0; i < length; i++)
            {
                if (array[i].Port == 443)
                {
                    priority = array[i].Priority;
                    weight   = array[i].Weight;
                    flag     = true;
                    break;
                }
            }
            if (!flag)
            {
                AutoDiscoverDnsReader.DnsReaderTracer.TraceError(0L, "No SRV records were returned with SSL Port specified.");
                return(null);
            }
            SrvRecord[] array2 = Array.FindAll <SrvRecord>(array, (SrvRecord srvRecord) => srvRecord.Port == 443 && priority == srvRecord.Priority && weight == srvRecord.Weight);
            int         num    = 0;

            length = array2.GetLength(0);
            AutoDiscoverDnsReader.DnsReaderTracer.TraceDebug <int, int>(0L, "Found {0} SRV records with priority = {1}.", length, array2[0].Priority);
            if (length > 1)
            {
                num = AutoDiscoverDnsReader.randomIndexSelector.Next(length);
            }
            return(array2[num].TargetHost);
        }
예제 #3
0
        private IPAddress[] ResolveInboundVirtualIPs(Dns dns, int partnerId, string fqdnTemplate)
        {
            string       domainName  = string.Format(fqdnTemplate, partnerId);
            IAsyncResult asyncResult = dns.BeginResolveToAddresses(domainName, AddressFamily.InterNetwork, null, null);

            asyncResult.AsyncWaitHandle.WaitOne();
            IPAddress[] result;
            DnsStatus   dnsStatus = Dns.EndResolveToAddresses(asyncResult, out result);

            if (dnsStatus != DnsStatus.Success)
            {
                base.WriteError(new InvalidOperationException("Unable to resolve inbound IPs.  Dns status = " + dnsStatus), ErrorCategory.InvalidOperation, null);
            }
            return(result);
        }
예제 #4
0
        private static Task <DnsTroubleshooter.SrvQueryResult> QuerySrvRecords(DnsTroubleshooter.DnsQueryContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("state");
            }
            context.SrvQuery = string.Format("_ldap._tcp.dc._msdcs.{0}", context.DomainFqdn);
            Dns client = DnsTroubleshooter.Client;

            return(Task.Factory.FromAsync <string, DnsQueryOptions, DnsTroubleshooter.SrvQueryResult>(new Func <string, DnsQueryOptions, AsyncCallback, object, IAsyncResult>(client.BeginRetrieveSrvRecords), delegate(IAsyncResult x)
            {
                ExTraceGlobals.FaultInjectionTracer.TraceTest(2244357437U);
                SrvRecord[] srvRecords;
                DnsStatus status = Dns.EndResolveToSrvRecords(x, out srvRecords);
                return new DnsTroubleshooter.SrvQueryResult(status, srvRecords);
            }, context.SrvQuery, DnsQueryOptions.UseTcpOnly | DnsQueryOptions.BypassCache, context, TaskCreationOptions.AttachedToParent));
        }
예제 #5
0
 public SrvQueryResult(DnsStatus status, SrvRecord[] srvRecords)
 {
     this.SrvRecords = srvRecords;
     this.Status     = status;
 }
예제 #6
0
        private static void AnalyzeDnsResultAndLogEvent(DnsTroubleshooter.DnsQueryContext context, DnsTroubleshooter.SrvQueryResult result)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (result == null)
            {
                throw new ArgumentNullException("result");
            }
            if (ExTraceGlobals.DnsTroubleshooterTracer.IsTraceEnabled(TraceType.DebugTrace))
            {
                StringBuilder stringBuilder = new StringBuilder();
                if (!result.SrvRecords.IsNullOrEmpty <SrvRecord>())
                {
                    foreach (SrvRecord srvRecord in result.SrvRecords)
                    {
                        stringBuilder.Append(srvRecord.TargetHost);
                        stringBuilder.Append(",");
                    }
                }
                ExTraceGlobals.DnsTroubleshooterTracer.TraceDebug(0L, "Domain Fqdn {0}. Server Fqdn {1}. Query {2}. ResultStatus {3}. Result Records {4}", new object[]
                {
                    context.DomainFqdn,
                    context.ServerFqdn ?? "<NULL>",
                    context.SrvQuery,
                    result.Status,
                    stringBuilder.ToString()
                });
            }
            DnsStatus status = result.Status;

            switch (status)
            {
            case DnsStatus.Success:
            {
                if (result.SrvRecords.IsNullOrEmpty <SrvRecord>())
                {
                    ExTraceGlobals.DnsTroubleshooterTracer.TraceDebug <string, DnsStatus>(0L, "{0} - Status {1}. No records found", context.DomainFqdn, result.Status);
                    Globals.LogEvent(DirectoryEventLogConstants.Tuple_DSC_EVENT_DNS_OTHER, context.DomainFqdn, new object[]
                        {
                            result.Status,
                            context.DomainFqdn,
                            context.SrvQuery
                        });
                    return;
                }
                StringBuilder stringBuilder2 = new StringBuilder();
                bool          flag           = false;
                foreach (SrvRecord srvRecord2 in result.SrvRecords)
                {
                    stringBuilder2.AppendLine(srvRecord2.TargetHost);
                    if (context.ServerFqdn != null && context.ServerFqdn.Equals(srvRecord2.TargetHost, StringComparison.OrdinalIgnoreCase))
                    {
                        flag = true;
                    }
                }
                ExTraceGlobals.DnsTroubleshooterTracer.TraceDebug <string, DnsStatus, bool>(0L, "{0} - Status {1}. isHostAdvertisedInDns {2}", context.DomainFqdn, result.Status, flag);
                if (string.IsNullOrEmpty(context.ServerFqdn))
                {
                    Globals.LogEvent(DirectoryEventLogConstants.Tuple_DSC_EVENT_DNS_NO_ERROR, context.DomainFqdn, new object[]
                        {
                            context.DomainFqdn,
                            context.SrvQuery,
                            stringBuilder2.ToString()
                        });
                    return;
                }
                if (flag)
                {
                    Globals.LogEvent(DirectoryEventLogConstants.Tuple_DSC_EVENT_DNS_NO_ERROR_DC_FOUND, context.ServerFqdn, new object[]
                        {
                            context.ServerFqdn,
                            context.SrvQuery,
                            stringBuilder2.ToString()
                        });
                    return;
                }
                string listOfZones = DnsTroubleshooter.GetListOfZones(context.DomainFqdn);
                string listOfClientDnsServerAddresses = DnsTroubleshooter.GetListOfClientDnsServerAddresses();
                ExTraceGlobals.DnsTroubleshooterTracer.TraceDebug(0L, "{0} - Status {1}. Zones {2}. Dns Servers {3}", new object[]
                    {
                        context.DomainFqdn,
                        result.Status,
                        listOfZones,
                        listOfClientDnsServerAddresses
                    });
                Globals.LogEvent(DirectoryEventLogConstants.Tuple_DSC_EVENT_DNS_NO_ERROR_DC_NOT_FOUND, context.ServerFqdn, new object[]
                    {
                        context.ServerFqdn,
                        context.DomainFqdn,
                        context.SrvQuery,
                        stringBuilder2.ToString(),
                        listOfClientDnsServerAddresses,
                        listOfZones
                    });
                return;
            }

            case DnsStatus.InfoNoRecords:
                break;

            case DnsStatus.InfoDomainNonexistent:
            {
                string listOfZones = DnsTroubleshooter.GetListOfZones(context.DomainFqdn);
                string listOfClientDnsServerAddresses = DnsTroubleshooter.GetListOfClientDnsServerAddresses();
                ExTraceGlobals.DnsTroubleshooterTracer.TraceDebug(0L, "{0} - Status {1}. Zones {2}. Dns Servers {3}", new object[]
                    {
                        context.DomainFqdn,
                        result.Status,
                        listOfZones,
                        listOfClientDnsServerAddresses
                    });
                Globals.LogEvent(DirectoryEventLogConstants.Tuple_DSC_EVENT_DNS_NAME_ERROR, context.DomainFqdn, new object[]
                    {
                        NativeMethods.HRESULT_FROM_WIN32(9003U).ToString("X"),
                        context.DomainFqdn,
                        context.SrvQuery,
                        listOfClientDnsServerAddresses,
                        listOfZones
                    });
                return;
            }

            default:
                switch (status)
                {
                case DnsStatus.ErrorRetry:
                case DnsStatus.ErrorTimeout:
                {
                    string listOfClientDnsServerAddresses = DnsTroubleshooter.GetListOfClientDnsServerAddresses();
                    ExTraceGlobals.DnsTroubleshooterTracer.TraceDebug <string, DnsStatus, string>(0L, "{0} - Status {1}. Dns Servers {2}", context.DomainFqdn, result.Status, listOfClientDnsServerAddresses);
                    Globals.LogEvent(DirectoryEventLogConstants.Tuple_DSC_EVENT_DNS_TIMEOUT, context.DomainFqdn, new object[]
                        {
                            NativeMethods.HRESULT_FROM_WIN32(1460U).ToString("X"),
                            context.DomainFqdn,
                            context.SrvQuery,
                            listOfClientDnsServerAddresses
                        });
                    return;
                }

                case DnsStatus.ServerFailure:
                {
                    string listOfZones = DnsTroubleshooter.GetListOfZones(context.DomainFqdn);
                    string listOfClientDnsServerAddresses = DnsTroubleshooter.GetListOfClientDnsServerAddresses();
                    ExTraceGlobals.DnsTroubleshooterTracer.TraceDebug(0L, "{0} - Status {1}. Zones {2}. Dns Servers {3}", new object[]
                        {
                            context.DomainFqdn,
                            result.Status,
                            listOfZones,
                            listOfClientDnsServerAddresses
                        });
                    Globals.LogEvent(DirectoryEventLogConstants.Tuple_DSC_EVENT_DNS_DIAG_SERVER_FAILURE, context.DomainFqdn, new object[]
                        {
                            NativeMethods.HRESULT_FROM_WIN32(9002U).ToString("X"),
                            context.DomainFqdn,
                            context.SrvQuery,
                            listOfClientDnsServerAddresses,
                            listOfZones
                        });
                    return;
                }
                }
                break;
            }
            Globals.LogEvent(DirectoryEventLogConstants.Tuple_DSC_EVENT_DNS_OTHER, context.DomainFqdn, new object[]
            {
                result.Status,
                context.DomainFqdn,
                context.SrvQuery
            });
        }
 public object Index([FromServices] DnsStatus status)
 {
     return(status);
 }