From 03ad45c3b14b8efa889ccd11dd6717b0d58808c5 Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sat, 2 Feb 2019 14:32:04 +0530 Subject: [PATCH] Zone: added DomainEquals() method for correct wild card domain name matching. --- DnsServerCore/Zone.cs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/DnsServerCore/Zone.cs b/DnsServerCore/Zone.cs index eaed4fc3..b20e50bd 100644 --- a/DnsServerCore/Zone.cs +++ b/DnsServerCore/Zone.cs @@ -107,6 +107,23 @@ namespace DnsServerCore return path; } + private static bool DomainEquals(string domain1, string domain2) + { + string[] path1 = ConvertDomainToPath(domain1); + string[] path2 = ConvertDomainToPath(domain2); + + if (path1.Length != path2.Length) + return false; + + for (int i = 0; i < path1.Length; i++) + { + if ((path1[i] != path2[i]) && (path1[i] != "*") && (path2[i] != "*")) + return false; + } + + return true; + } + private static Zone CreateZone(Zone rootZone, string domain) { Zone currentZone = rootZone; @@ -528,7 +545,7 @@ namespace DnsServerCore if (closestAuthority[0].Type == DnsResourceRecordType.SOA) { //zone is hosted on this server - if (closestZone._zoneName.Equals(domain) || (closestZone._zoneLabel == "*")) + if (DomainEquals(closestZone._zoneName, domain)) { //zone found DnsResourceRecord[] records = closestZone.QueryRecords(question.Type, false); @@ -540,7 +557,7 @@ namespace DnsServerCore else { //record type found - if (closestZone._zoneLabel == "*") + if (closestZone._zoneName.Contains("*")) { DnsResourceRecord[] wildcardRecords = new DnsResourceRecord[records.Length];