mirror of
https://github.com/fergalmoran/DnsServer.git
synced 2026-01-06 08:45:32 +00:00
ZoneTree: fixed bug in GetNextSubDomainZoneNode() which could cause listing of sub domains from another zone down the tree. fixed bug in FindNodeValue() to allow finding authority when key is for root. Fixed issue in FindZone() that would incorrectly report existence of sub domain.
This commit is contained in:
@@ -26,7 +26,7 @@ using TechnitiumLibrary.Net.Dns;
|
||||
|
||||
namespace DnsServerCore.Dns.Zones
|
||||
{
|
||||
public class ZoneTree<T> : ByteTree<string, T> where T : Zone
|
||||
class ZoneTree<T> : ByteTree<string, T> where T : Zone
|
||||
{
|
||||
#region variables
|
||||
|
||||
@@ -202,8 +202,18 @@ namespace DnsServerCore.Dns.Zones
|
||||
if (value != null)
|
||||
{
|
||||
T zone = value.Value;
|
||||
if ((zone != null) && (zone is SubDomainZone))
|
||||
return child; //child has value so return it
|
||||
if (zone != null)
|
||||
{
|
||||
if (zone is SubDomainZone)
|
||||
return child; //child has value so return it
|
||||
|
||||
if ((zone is PrimaryZone) || (zone is SecondaryZone) || (zone is StubZone) || (zone is ForwarderZone))
|
||||
{
|
||||
//skip to next child to avoid listing this auth zone's sub domains
|
||||
child = null; //set null to avoid child being set as current after the loop
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (child.Children != null)
|
||||
@@ -228,7 +238,7 @@ namespace DnsServerCore.Dns.Zones
|
||||
return null;
|
||||
}
|
||||
|
||||
private Node GetNextSubDomainNode(Node current, int baseDepth)
|
||||
private Node GetNextChildZoneNode(Node current, int baseDepth)
|
||||
{
|
||||
int k = 0;
|
||||
|
||||
@@ -395,7 +405,7 @@ namespace DnsServerCore.Dns.Zones
|
||||
Node wildcard = null;
|
||||
int i = 0;
|
||||
|
||||
while (i < key.Length)
|
||||
while (i <= key.Length)
|
||||
{
|
||||
//find authority zone
|
||||
NodeValue value = closestNode.Value;
|
||||
@@ -425,6 +435,9 @@ namespace DnsServerCore.Dns.Zones
|
||||
}
|
||||
}
|
||||
|
||||
if (i == key.Length)
|
||||
break;
|
||||
|
||||
Node[] children = closestNode.Children;
|
||||
if (children == null)
|
||||
break;
|
||||
@@ -504,6 +517,22 @@ namespace DnsServerCore.Dns.Zones
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool SubDomainExists(byte[] key, Node closestNode)
|
||||
{
|
||||
if (!closestNode.HasChildren)
|
||||
return false;
|
||||
|
||||
Node nextSubDomain = GetNextSubDomainZoneNode(closestNode, closestNode.Depth);
|
||||
if (nextSubDomain == null)
|
||||
return false;
|
||||
|
||||
NodeValue value = nextSubDomain.Value;
|
||||
if (value == null)
|
||||
return false;
|
||||
|
||||
return IsKeySubDomain(key, value.Key);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public
|
||||
@@ -627,7 +656,7 @@ namespace DnsServerCore.Dns.Zones
|
||||
zones.Add(ConvertKeyToLabel(GetNodeKey(current), bKey.Length));
|
||||
}
|
||||
|
||||
current = GetNextSubDomainNode(current, closestNode.Depth);
|
||||
current = GetNextChildZoneNode(current, closestNode.Depth);
|
||||
}
|
||||
while (current != null);
|
||||
|
||||
@@ -658,7 +687,7 @@ namespace DnsServerCore.Dns.Zones
|
||||
//check if current node has sub domains
|
||||
NodeValue value = closestNode.Value;
|
||||
if (value == null)
|
||||
hasSubDomains = closestNode.HasChildren;
|
||||
hasSubDomains = SubDomainExists(key, closestNode);
|
||||
else
|
||||
hasSubDomains = IsKeySubDomain(key, value.Key);
|
||||
|
||||
@@ -692,7 +721,7 @@ namespace DnsServerCore.Dns.Zones
|
||||
else
|
||||
authority = null;
|
||||
|
||||
hasSubDomains = closestNode.HasChildren;
|
||||
hasSubDomains = SubDomainExists(key, closestNode);
|
||||
return zoneValue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user